Skip to content

Delay.__eq__ does not compare the delay unit #13812

@wshanks

Description

@wshanks

Environment

  • Qiskit version: 1.3.2 or 9ae0a80
  • Python version: 3.11
  • Operating system: Fedora Linux 41

What is happening?

When comparing two Delay instructions, only the duration argument to __init__ matters, not the unit argument.

How can we reproduce the issue?

from qiskit import QuantumCircuit
from qiskit.circuit.delay import Delay

qc1 = QuantumCircuit(1)
qc1.delay(1, 0, unit="s")

qc2 = QuantumCircuit(1)
qc2.delay(1, 0, unit="dt")

print("Compare circuits:", qc1 == qc2)
print("Compare delays:", Delay(1, "dt") == Delay(1, "s"))

What should happen?

The code above should print False/False but it prints False/True.

Any suggestions?

Before #13486, both the circuit and instruction comparisons above were true. Now the circuit one is false. This came up in Qiskit Experiments because of this other bug with delay units and qpy. A test that ran a circuit with a delay roundtrip through qpy that used to pass even though the delay unit was lost started to fail.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions