Skip to content

HoareOptimizer crashes with ValueError: DAGOpNode is not in list #14969

@p51lee

Description

@p51lee

Environment

  • Qiskit version: 2.1.2
  • Python version: 3.13
  • Operating system: MacOS 15.6

What is happening?

Running PassManager(HoareOptimizer()) on the cirucuit below crashes with:

ValueError: DAGOpNode(op=Instruction(name='cy', ...)) is not in list

How can we reproduce the issue?

from qiskit.transpiler import PassManager
from qiskit.transpiler.passes import HoareOptimizer
from qiskit.qasm3 import loads as qasm3_loads

bug_qasm = """OPENQASM 3.0;
include "stdgates.inc";
gate rzx(p0) _gate_q_0, _gate_q_1 {
  h _gate_q_1;
  cx _gate_q_0, _gate_q_1;
  rz(p0) _gate_q_1;
  cx _gate_q_0, _gate_q_1;
  h _gate_q_1;
}
gate cu1(p0) _gate_q_0, _gate_q_1 {
  p(0.5*p0) _gate_q_0;
  cx _gate_q_0, _gate_q_1;
  p((-0.5)*p0) _gate_q_1;
  cx _gate_q_0, _gate_q_1;
  p(0.5*p0) _gate_q_1;
}
gate cu1_o0(p0) _gate_q_0, _gate_q_1 {
  x _gate_q_0;
  cu1(p0) _gate_q_0, _gate_q_1;
  x _gate_q_0;
}
gate cz_o0 _gate_q_0, _gate_q_1 {
  x _gate_q_0;
  cz _gate_q_0, _gate_q_1;
  x _gate_q_0;
}
bit[1] c;
qubit[4] q;
cu1_o0(6) q[3], q[2];
cy q[2], q[1];
rzx(2) q[1], q[3];
cx q[1], q[0];
rx(2) q[0];
cx q[1], q[0];
cy q[0], q[3];
sdg q[0];
x q[0];
cz_o0 q[3], q[0];
sdg q[0];
sdg q[0];
cz_o0 q[0], q[1];
cz q[3], q[2];
s q[2];
swap q[3], q[2];
x q[2];
rz(5) q[2];
id q[2];
y q[2];
id q[2];
c[0] = measure q[2];
"""
pm = PassManager(HoareOptimizer())

circuit = qasm3_loads(bug_qasm)
circuit = pm.run(circuit)
ValueError: DAGOpNode(op=Instruction(name='cy', num_qubits=2, num_clbits=0, params=[]), qargs=(<Qubit register=(4, "q"), index=2>, <Qubit register=(4, "q"), index=1>), cargs=()) is not in list

What should happen?

The transpilation pass should run normally, or a clear diagnostic instead of an internal ValueError if the circuit violates an assumption.

Any suggestions?

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