Skip to content

Commit c446a84

Browse files
mergify[bot]gadialmtreinish
authored
Fixed a bug where nonequal boxes were considered equal (#14716) (#14722)
* Fixed a bug where nonequal boxes were considered equal * Release note * Update releasenotes/notes/fix-box-eq-check-1ff339fcc1db983f.yaml * Update releasenotes/notes/fix-box-eq-check-1ff339fcc1db983f.yaml --------- (cherry picked from commit 925f144) Co-authored-by: gadial <[email protected]> Co-authored-by: Matthew Treinish <[email protected]>
1 parent bd80b6c commit c446a84

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

qiskit/dagcircuit/dagnode.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ def _for_loop_eq(node1, node2, bit_indices1, bit_indices2):
174174
def _box_eq(node1, node2, bit_indices1, bit_indices2):
175175
return (
176176
(node1.op.duration == node2.op.duration)
177+
and (node1.op.unit == node2.op.unit)
177178
and (
178179
_circuit_to_dag(node1.op.blocks[0], node1.qargs, node1.cargs, bit_indices1)
179180
== _circuit_to_dag(node2.op.blocks[0], node2.qargs, node2.cargs, bit_indices2)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
fixes:
3+
- |
4+
Fixed a bug in the :class:`.DAGOpNode` equality check, where comparing two :class:`.DAGOpNode`
5+
objects that contain a :class:`.BoxOp` instruction. Previously, the :attr:`.BoxOp.unit` attribute was not
6+
considered as part of the equality check which could lead to a two unequal nodes be evaluated as
7+
equal.

test/python/dagcircuit/test_dagcircuit.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
WhileLoopOp,
4646
CASE_DEFAULT,
4747
Store,
48+
BoxOp,
4849
)
4950
from qiskit.circuit.classical import expr, types
5051
from qiskit.circuit.library import (
@@ -1734,6 +1735,34 @@ def test_unitary_gate_variants_eq(self):
17341735

17351736
self.assertEqual(node1, node2)
17361737

1738+
def test_boxop_neq(self):
1739+
"""Test non equality of nonequal DAGOpNodes and QuantumCircuits containing BoxOp gates."""
1740+
qc = QuantumCircuit()
1741+
1742+
box1 = BoxOp(body=qc, duration=300.0, unit="dt")
1743+
box2 = BoxOp(body=qc, duration=300.0, unit="ms")
1744+
node1 = DAGOpNode(op=box1, qargs=(), cargs=())
1745+
node2 = DAGOpNode(op=box2, qargs=(), cargs=())
1746+
self.assertNotEqual(node1, node2)
1747+
1748+
qc1 = QuantumCircuit()
1749+
qc2 = QuantumCircuit()
1750+
qc1.append(box1)
1751+
qc2.append(box2)
1752+
self.assertNotEqual(qc1, qc2)
1753+
1754+
box1 = BoxOp(body=qc, duration=300.0, unit="dt")
1755+
box2 = BoxOp(body=qc, duration=200.0, unit="dt")
1756+
node1 = DAGOpNode(op=box1, qargs=(), cargs=())
1757+
node2 = DAGOpNode(op=box2, qargs=(), cargs=())
1758+
self.assertNotEqual(node1, node2)
1759+
1760+
qc1 = QuantumCircuit()
1761+
qc2 = QuantumCircuit()
1762+
qc1.append(box1)
1763+
qc2.append(box2)
1764+
self.assertNotEqual(qc1, qc2)
1765+
17371766
def test_dag_eq(self):
17381767
"""DAG equivalence check: True."""
17391768
# ┌───┐ ┌───┐

0 commit comments

Comments
 (0)