Open Bennybenassius opened 2 weeks ago
Looks like the INLINE
strategy here https://github.com/quantumlib/Cirq/blob/d74e0dce73adf45f15b873bf28236ef355d960ce/cirq-core/cirq/circuits/circuit.py#L2095-L2098, the _can_add_op_at
it calls doesn't take measurement keys into account. This seems like it would also allow for creating multiple measurement ops measuring to the same key in the same moment.
Description of the issue Under specific circumstances, it seems that classical controls are inserted wrongly and causing errors when getting measurement keys.
How to reproduce the issue
Run the following code:
The code above will run into an issue where the
ry
gate with classical controls will return an error where it cannot find the keycbit0
, even though it was inserted before it.Changing the circuit such that the passes use an insert strategy of
EARLIEST
orNEW_THEN_INLINE
would make it work. Changing the pass to apply on the circuit toalign_left
instead would also make the circuit not throw an exception, however the resulting circuit would look the same as the wrong one. The commented lines of code above can be uncommented to demonstrate this.Cirq version
1.4.1