Skip to content

Commit 1e3f7f7

Browse files
wshanksmergify[bot]
authored andcommitted
Fix tests failing against Qiskit main due to change in delay behavior (#1509)
A long-standing bug in qpy leads to the units of delay instructions being overwritten to `dt`. See: Qiskit/qiskit#10662 Some experiments test that their circuits are round-trip serializable through qpy (perhaps not as necessary as it once was as the room for sticking arbitrary Python into circuits is reduced with the move to Rust). The T1 and Tphi circuits have delays and so were affected by the qpy bug. However, there is a second bug related to delays which canceled this bug out for those tests. `Delay.__eq__` does not check that the units are the same for the two delay instructions, so the loss of the original unit did not matter for the tests. Following this change: Qiskit/qiskit#13486 Comparing circuits with delays now includes the delay units in the determination of equality. `Delay.__eq__` itself still does not consider the unit but some part of adding the delay to a circuit converts it into a Rust object that does check the unit. Here the tests are given a backend with a `dt` value so that the experiments will generate circuits with delays in `dt` and so still have delays with the same `dt` after the qpy roundtrip. (cherry picked from commit ad2341d)
1 parent aecea7b commit 1e3f7f7

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

test/library/characterization/test_t1.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from qiskit.circuit import Delay, Parameter
1919
from qiskit.circuit.library import CXGate, Measure, RXGate
2020
from qiskit.qobj.utils import MeasLevel
21+
from qiskit.providers.fake_provider import GenericBackendV2
2122
from qiskit.transpiler import InstructionProperties, Target
2223
from qiskit_ibm_runtime.fake_provider import FakeAthensV2
2324
from qiskit_experiments.test.noisy_delay_aer_simulator import NoisyDelayAerBackend
@@ -310,7 +311,8 @@ def test_roundtrip_serializable(self):
310311

311312
def test_circuit_roundtrip_serializable(self):
312313
"""Test circuit round trip JSON serialization"""
313-
exp = T1([0], [1, 2, 3, 4, 5])
314+
backend = GenericBackendV2(num_qubits=2)
315+
exp = T1([0], [1, 2, 3, 4, 5], backend=backend)
314316
self.assertRoundTripSerializable(exp._transpiled_circuits())
315317

316318
def test_analysis_config(self):

test/library/characterization/test_tphi.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"""
1515
from test.base import QiskitExperimentsTestCase
1616
from qiskit.exceptions import QiskitError
17+
from qiskit.providers.fake_provider import GenericBackendV2
1718
from qiskit_experiments.library import Tphi, T2Hahn, T2Ramsey
1819
from qiskit_experiments.test.noisy_delay_aer_simulator import NoisyDelayAerBackend
1920
from qiskit_experiments.library.characterization.analysis import (
@@ -146,11 +147,12 @@ def test_roundtrip_serializable(self):
146147

147148
def test_circuits_roundtrip_serializable(self):
148149
"""Test round trip JSON serialization"""
149-
exp = Tphi([0], [1], [2])
150+
backend = GenericBackendV2(num_qubits=2)
151+
exp = Tphi([0], [1e-6], [2e-6], backend=backend)
150152
self.assertRoundTripSerializable(exp._transpiled_circuits())
151-
exp = Tphi([0], [1], [2], "hahn", 3)
153+
exp = Tphi([0], [1e-6], [2e-6], "hahn", 3, backend=backend)
152154
self.assertRoundTripSerializable(exp._transpiled_circuits())
153-
exp = Tphi([0], [1], [2], "ramsey", 0)
155+
exp = Tphi([0], [1e-6], [2e-6], "ramsey", 0, backend=backend)
154156
self.assertRoundTripSerializable(exp._transpiled_circuits())
155157

156158
def test_analysis_config(self):

0 commit comments

Comments
 (0)