Skip to content

Commit a2cc03d

Browse files
committed
Fix tests again
1 parent 01625cc commit a2cc03d

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

test/python/qpy/test_roundtrip.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
"""Tests for python write/rust read flow and vice versa"""
1414

1515
import io
16+
import uuid
1617

1718
from ddt import ddt, idata, unpack
1819

19-
from qiskit.circuit import QuantumCircuit, QuantumRegister, ClassicalRegister
20+
from qiskit.circuit import QuantumCircuit, QuantumRegister, ClassicalRegister, Duration
2021
from qiskit.circuit.library import PauliEvolutionGate
2122
from qiskit.circuit.random import random_circuit
2223
from qiskit.circuit.parameter import Parameter
@@ -253,3 +254,12 @@ def test_delay_roundtrip(self, version, write_with, read_with):
253254
qc = QuantumCircuit(1)
254255
qc.delay(1, 0, "dt")
255256
self.assert_roundtrip_equal(qc, version=version, read_with=read_with, write_with=write_with)
257+
258+
@all_qpy_combinations(QPY_RUST_READ_MIN_VERSION)
259+
def test_delay_expr_roundtrip(self, version, write_with, read_with):
260+
stretch_expr = QuantumCircuit(1, name="stretch_expr_delay_circuit")
261+
s = expr.Stretch(uuid.uuid4(), "a")
262+
stretch = stretch_expr.add_stretch(s)
263+
stretch_expr.delay(stretch, 0)
264+
stretch_expr.delay(expr.add(Duration.dt(200), stretch), 0)
265+
stretch_expr.delay(expr.sub(Duration.ns(3.14159), stretch), 0)

test/qpy_compat/test_qpy.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,7 @@ def generate_box():
944944
nested.x(0)
945945
nested.noop(1)
946946

947-
labeled = QuantumCircuit(2)
947+
labeled = QuantumCircuit(2, name="labeled boxes")
948948
with labeled.box():
949949
labeled.cx(0, 1)
950950
with labeled.box(duration=1, unit="dt", label="hello"):
@@ -965,15 +965,16 @@ def generate_delay():
965965
def generate_delay_stretch():
966966
"""Circuits that contain a stretch delay. Added in QPY 14 in Qiskit 2.0."""
967967
from qiskit.circuit.classical import expr
968+
from qiskit.circuit import Duration
968969
import uuid
969970

970-
stretch_expr = QuantumCircuit(name="stretch_expr")
971+
stretch_expr = QuantumCircuit(1, name="stretch_expr_delay_circuit")
971972
s = expr.Stretch(uuid.UUID(bytes=b"hallo, QPY_world", version=4), "a")
972973
stretch = stretch_expr.add_stretch(s)
973-
qc = QuantumCircuit(1)
974-
qc.add_stretch(stretch)
975-
qc.delay(stretch)
976-
return [qc]
974+
stretch_expr.delay(stretch, 0)
975+
stretch_expr.delay(expr.add(Duration.dt(200), stretch), 1)
976+
stretch_expr.delay(expr.sub(Duration.ns(3.14159), stretch), 0)
977+
return [stretch_expr]
977978

978979

979980
def generate_circuits(generating_version, current_version, load_context=False):

0 commit comments

Comments
 (0)