Fix bug in circuit.insert#7823
Conversation
Change _group_into_moment_compatible to take into account measurement and control keys.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7823 +/- ##
==========================================
- Coverage 99.63% 99.63% -0.01%
==========================================
Files 1110 1110
Lines 100072 100136 +64
==========================================
+ Hits 99710 99773 +63
- Misses 362 363 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Allowing multiple measurements to the same key in the same moment was a requirement from the HW team. Unless that has changed, this would be breaking. |
|
Thank you for pointing this out @daxfohl ! Doesn't this mean this condition here is also wrong: Cirq/cirq-core/cirq/circuits/circuit.py Line 2146 in ceb9432 |
|
Maybe. Though it can't be removed completely, because then it could fall through to earlier moments and break commutativity. (There's a lot of https://xkcd.com/1172/ in the circuit construction code). |
|
cirq-cync - @codrut3 - please create an issue for this PR, e.g., to request that measurement and control keys cannot overlap in the same moment. This would be potentially a breaking change so request feedback from Ilya Drozdov and Christopher Wood for the issue to comment if the current behavior is needed in some situations. |
|
Thank you! I created #7829 |
|
This pull request has been automatically labeled as stale because 90 days have passed without activity. If no further activity occurs and the If you have questions or feedback about this process, please open a new issue in this repository to let us know. You can also send email to the maintainers at quantum-oss-maintainers@google.com. |
the same moment. See the discussion in https://github.com/quantumlib/Cirq/issues#7829.
|
@pavoljuhas Thank you for checking! I updated the PR by allowing operations with the same measurement key in the same moment, in the context of the methods changed by this PR ( However, there is older code in circuit.py where one checks that measurement keys are disjoint: for example in _PlacementCache, or here. Should I remove these checks to be consistent everywhere? |
There is a distinction in Cirq between MeasurementGate acting on 2 qubits with common key, Do we need to allow that case or can HW team do with the first scenario? |
|
cynq discussion - let us do a check for overlapping measurement keys in Circuit.insert, but first verify if it breaks anything in the internal code. Circuits should use
|
Disallow one-qubit measurement operations with overlapping keys. These should be replaced with `cirq.measure(q0, q1, key="k")`. Keep the new tests, but adjust them for expected behavior. This partially reverts commit 0ca9121.
Skip potentially expensive lookup of measurement and control keys from a Moment when inserted operation has no such keys. No change in code function.
|
I have restored the comparison with measurement keys in 42c13d6 and ran unit tests (those which use cirq) for the internal code at Once this is merged and out in a dev-release, I will run a full internal test suite on the CI to be sure this is not breaking anything. |
|
Confirming the internal CI passed successfully with this change at q-cl/150609 (not submitted, test only). Adding |
Change
_group_into_moment_compatibleto take into account measurement and control keys. Otherwise two incompatible operations can be put in the same moment.I also changed
_can_add_op_atto look at measurement and control keys.I added unit tests that show the issue.