Skip to content

Transpiler eliminates classical condition for optimization_level 3 #6016

@ehchen

Description

@ehchen

Information

  • Qiskit Terra version:
  • 0.17.0.dev0+83eb665
  • Python version:
  • 3.9.1 (default, Dec 11 2020, 06:28:49) [Clang 10.0.0 ]
  • Operating system:
  • Darwin

What is the current behavior?

Circuits with feed-forward logic are incorrectly transpiled for optimization levels >0

Steps to reproduce the problem

from qiskit import execute, QuantumCircuit, QuantumRegister, ClassicalRegister
from qiskit import transpile
from qiskit.transpiler import CouplingMap
from qiskit.converters import dag_to_circuit
circ = QuantumCircuit()
registers = [
            QuantumRegister(1,name='qr_data'),
            QuantumRegister(1,name='qr_anci'),
            ClassicalRegister(1,name='cr_data'),
            ClassicalRegister(1,name='cr_anci'),
            ]
for regs in registers:
    circ.add_register(regs)
circ.h(0)
circ.cx(0,1)
circ.measure(1,1)
circ.h(0).c_if(registers[3],1)
# make coupling maps
CMap = CouplingMap().from_ring(12)
CMap.add_physical_qubit(12)
CMap.add_edge(11,12)
CMap.add_edge(12,5)
CMap.make_symmetric()

def callback(**kwargs):
    print(kwargs['pass_'])
    print(dag_to_circuit(kwargs['dag']))

transpile_opts       =  {
                        'optimization_level': 3,
                        'callback': callback,
                        'coupling_map': CMap,
                        'basis_gates': ['cx', 'id', 'u1', 'u2', 'u3']
                        }
circ_transpiled = transpile(circ,**transpile_opts)
circ_transpiled.draw()

What is the expected behavior?

The condition on the last h gate is preserved when transpiler optimization level 3 is run. Looking through the output of the callback function it is dropped by the consolidate blocks pass

Suggested solutions

Examine consolidate blocks section of transpiler (identified by @mtreinish )

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions