qiskit icon indicating copy to clipboard operation
qiskit copied to clipboard

`HoareOptimizer` crashes with `ValueError: DAGOpNode is not in list`

Open p51lee opened this issue 4 months ago • 3 comments

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?

  • Removing any single operation from the program avoids the crash so it seems sensitive to a specific pattern rather than a single gate.
  • Might be related to #13165 but this is a different exception type.

p51lee avatar Sep 01 '25 07:09 p51lee

Sorry for the slow reply on this, and thanks for the report.

I'd be very happy to accept a PR fixing this (and other PRs fixing the myriad of other bugs affecting the HoareOptimizer), but to set expectations, I don't think anybody from the internal Qiskit team will have time to look at the pass any time soon.

jakelishman avatar Oct 02 '25 16:10 jakelishman

@jakelishman please take a look of my PR. thanks.

littlebullGit avatar Oct 04 '25 22:10 littlebullGit

@jakelishman @p51lee , can you take a look of my PR to see if the issue got resolved ?Fix HoareOptimizer cache recursion and add regression test #15111

littlebullGit avatar Dec 08 '25 13:12 littlebullGit