Skip to content

commutative_cancellation removes repeated CX even though one is classically controlled #2668

@kdk

Description

@kdk
>> qc = qk.QuantumCircuit(3,2)
>>> qc.h(0)
<qiskit.circuit.instructionset.InstructionSet object at 0x12a19cc18>
>>> qc.measure(0,0)
<qiskit.circuit.instructionset.InstructionSet object at 0x12a19ccc0>
>>> qc.cx(1,2)
<qiskit.circuit.instructionset.InstructionSet object at 0x12a19ccf8>
>>> qc.cx(1,2).c_if(qc.cregs[0], 0)
<qiskit.circuit.instructionset.InstructionSet object at 0x12a19ccc0>
>>> qc.measure([1,2],[0,1])
<qiskit.circuit.instructionset.InstructionSet object at 0x12a19ccf8>
>>> print(qc)
        ┌───┐┌─┐
q_0: |0>┤ H ├┤M├─────────────
        └───┘└╥┘       ┌─┐
q_1: |0>──■───╫────■───┤M├───
        ┌─┴─┐ ║  ┌─┴─┐ └╥┘┌─┐
q_2: |0>┤ X ├─╫──┤ X ├──╫─┤M├
        └───┘ ║  └─┬─┘  ║ └╥┘
              ║ ┌──┴──┐ ║  ║
 c_0: 0 ══════╩═╡     ╞═╩══╬═
                │ = 0 │    ║
 c_1: 0 ════════╡     ╞════╩═
                └─────┘
>>> print(qk.transpile(qc, optimization_level=2))
        ┌───┐┌─┐
q_0: |0>┤ H ├┤M├───
        └───┘└╥┘┌─┐
q_1: |0>──────╫─┤M├
         ┌─┐  ║ └╥┘
q_2: |0>─┤M├──╫──╫─
         └╥┘  ║  ║
 c_0: 0 ══╬═══╩══╩═
          ║
 c_1: 0 ══╩════════

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions