Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scoping for control keys #4736

Merged
merged 106 commits into from
Dec 20, 2021
Merged

Scoping for control keys #4736

merged 106 commits into from
Dec 20, 2021

Conversation

daxfohl
Copy link
Collaborator

@daxfohl daxfohl commented Dec 8, 2021

Part 12 of https://tinyurl.com/cirq-feedforward

Allow for classically controlled subcircuits to be controlled by measurements done prior to that subcircuit.

Such behavior "already worked" for subcircuits without repetitions. But for subcircuits with repetitions, all measurement/control keys were "lifted" to the repetition id. i.e. in a subcircuit containing control key "A", that would be lifted to "0:A" and "1:A" to distinguish them. However if the measurement 'A' is outside of the subcircuit, then that lifting would cause the control keys to no longer match the measurement key.

This PR fixes the above problem by passing context data through subcircuit decomposition. The behavior is that if a control key matches a measurement key from the same subcircuit, then both are lifted to the corresponding repetition. Otherwise the control key matches to the nearest-scoped measurement key outside of the subcircuit.

@daxfohl daxfohl marked this pull request as ready for review December 12, 2021 06:22
@daxfohl daxfohl marked this pull request as draft December 12, 2021 07:38
@daxfohl daxfohl marked this pull request as ready for review December 12, 2021 20:13
all_keys = all_keys.union(protocols.control_keys(op))
return all_keys.difference(protocols.measurement_key_objs(self))
controls = frozenset(k for op in self.all_operations() for k in protocols.control_keys(op))
return controls - protocols.measurement_key_objs(self)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To confirm: a circuit which contains control and measurement of key "A" excludes "A" from what it returns here because "A" is internal, correct? (i.e. it's measured and used entirely within the circuit)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the protocol returns all keys that must be defined externally before this element can be used.

Copy link
Collaborator

@95-martin-orion 95-martin-orion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this has come together neatly. One final, non-blocking question above, then we can merge.

@95-martin-orion 95-martin-orion added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Dec 20, 2021
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Dec 20, 2021
@CirqBot CirqBot merged commit 4ebfb1c into quantumlib:master Dec 20, 2021
@CirqBot CirqBot removed automerge Tells CirqBot to sync and merge this PR. (If it's running.) front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. labels Dec 20, 2021
@daxfohl daxfohl deleted the scope5 branch December 21, 2021 02:37
MichaelBroughton pushed a commit to MichaelBroughton/Cirq that referenced this pull request Jan 22, 2022
Part 12 of https://tinyurl.com/cirq-feedforward

Allow for classically controlled subcircuits to be controlled by measurements done prior to that subcircuit.

Such behavior "already worked" for subcircuits without repetitions. But for subcircuits with repetitions, all measurement/control keys were "lifted" to the repetition id. i.e. in a subcircuit containing control key "A", that would be lifted to "0:A" and "1:A" to distinguish them. However if the measurement 'A' is outside of the subcircuit, then that lifting would cause the control keys to no longer match the measurement key.

This PR fixes the above problem by passing context data through subcircuit decomposition. The behavior is that if a control key matches a measurement key from the same subcircuit, then both are lifted to the corresponding repetition. Otherwise the control key matches to the nearest-scoped measurement key outside of the subcircuit.
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
Part 12 of https://tinyurl.com/cirq-feedforward

Allow for classically controlled subcircuits to be controlled by measurements done prior to that subcircuit.

Such behavior "already worked" for subcircuits without repetitions. But for subcircuits with repetitions, all measurement/control keys were "lifted" to the repetition id. i.e. in a subcircuit containing control key "A", that would be lifted to "0:A" and "1:A" to distinguish them. However if the measurement 'A' is outside of the subcircuit, then that lifting would cause the control keys to no longer match the measurement key.

This PR fixes the above problem by passing context data through subcircuit decomposition. The behavior is that if a control key matches a measurement key from the same subcircuit, then both are lifted to the corresponding repetition. Otherwise the control key matches to the nearest-scoped measurement key outside of the subcircuit.
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this pull request Oct 31, 2024
Part 12 of https://tinyurl.com/cirq-feedforward

Allow for classically controlled subcircuits to be controlled by measurements done prior to that subcircuit.

Such behavior "already worked" for subcircuits without repetitions. But for subcircuits with repetitions, all measurement/control keys were "lifted" to the repetition id. i.e. in a subcircuit containing control key "A", that would be lifted to "0:A" and "1:A" to distinguish them. However if the measurement 'A' is outside of the subcircuit, then that lifting would cause the control keys to no longer match the measurement key.

This PR fixes the above problem by passing context data through subcircuit decomposition. The behavior is that if a control key matches a measurement key from the same subcircuit, then both are lifted to the corresponding repetition. Otherwise the control key matches to the nearest-scoped measurement key outside of the subcircuit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: L 250< lines changed <1000
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants