-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Environment
- Qiskit Terra version: 0.25
- Python version: 3.9
- Operating system: MacOS
What is happening?
The GateDirection
transpiler pass has an unnecessary check that input circuits only contain 1 register:
How can we reproduce the issue?
from qiskit.circuit import QuantumRegister, QuantumCircuit
from qiskit.transpiler import PassManager, CouplingMap
from qiskit.transpiler.passes import GateDirection
q1 = QuantumRegister(1)
q2 = QuantumRegister(1)
qc = QuantumCircuit(q1, q2)
qc.cx(1, 0)
qc.cx(0, 1)
cmap = CouplingMap([[0, 1]])
pm = PassManager([GateDirection(coupling_map=cmap)])
pm.run(qc)
raises
TranspilerError: "GateDirection expects a single qreg input DAG,but input DAG had qregs: OrderedDict([('q67', QuantumRegister(1, 'q67')), ('q68', QuantumRegister(1, 'q68'))])."
What should happen?
If the check is removed it works as you would expect:
class GateDirectionFixed(GateDirection):
def run(self, dag):
layout_map = {bit: i for i, bit in enumerate(dag.qubits)}
if self.target is None:
return self._run_coupling_map(dag, layout_map)
return self._run_target(dag, layout_map)
pm = PassManager([GateDirectionFixed(coupling_map=cmap)])
pm.run(qc).draw()
┌───┐ ┌───┐
q77: ┤ H ├──■──┤ H ├──■──
├───┤┌─┴─┐├───┤┌─┴─┐
q78: ┤ H ├┤ X ├┤ H ├┤ X ├
└───┘└───┘└───┘└───┘
Any suggestions?
Remove the incorrect check for a single register from the GateDirection.run
method
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working