-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Scoping for control keys #4736
Conversation
Use control keys in circuit construction to block controlled gates "earliest" append method from falling back to before the measurement.
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) |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
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.
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.
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.
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.