Incorrect behaviour when inserting classical control circuit element, causing ValueError
#6727
Labels
good first issue
This issue can be resolved by someone who is not familiar with the codebase. A good starting issue.
kind/bug-report
Something doesn't seem to work.
triage/accepted
there is consensus amongst maintainers that this is a real bug or a reasonable feature to add
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.Circuit that doesn't work looks like this:
┌───────────┐ q0: ──────────────────────M('results')─── │ q1: ────────Ry(0.205π)────M────────────── ║ │ q2: ────────╫─────────────M────────────── ║ │ q3: ────────╫─────────────M────────────── ║ │ q4: ───────M╫─────────────M────────────── ║║ │ q5: ───────╫╫─────────────M────────────── ║║ cbit0: ════@^════════════════════════════ └───────────┘
This also throws an error:
Circuit that works looks like this:
q0: ───────────────────────M('results')─── │ q1: ──────────Ry(0.205π)───M────────────── ║ │ q2: ──────────╫────────────M────────────── ║ │ q3: ──────────╫────────────M────────────── ║ │ q4: ──────M───╫────────────M────────────── ║ ║ │ q5: ──────╫───╫────────────M────────────── ║ ║ cbit0: ═══@═══^═══════════════════════════
Using
align right
would give the same looking circuit without any exceptions thrown:┌───────────┐ q0: ──────────────────────M('results')─── │ q1: ────────Ry(0.205π)────M────────────── ║ │ q2: ────────╫─────────────M────────────── ║ │ q3: ────────╫─────────────M────────────── ║ │ q4: ───────M╫─────────────M────────────── ║║ │ q5: ───────╫╫─────────────M────────────── ║║ cbit0: ════@^════════════════════════════ └───────────┘
Cirq version
1.4.1
The text was updated successfully, but these errors were encountered: