Skip to content

Commit a5a5842

Browse files
committed
Update tests for deprecation (sorry!)
1 parent a086581 commit a5a5842

1 file changed

Lines changed: 43 additions & 36 deletions

File tree

test/python/compiler/test_transpiler.py

Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,20 +1301,24 @@ def test_circuit_with_delay(self, optimization_level):
13011301
qc.delay(500, 1)
13021302
qc.cx(0, 1)
13031303

1304-
with self.assertWarnsRegex(
1305-
DeprecationWarning,
1306-
expected_regex="The `target` parameter should be used instead",
1307-
):
1308-
out = transpile(
1309-
qc,
1310-
scheduling_method="alap",
1311-
basis_gates=["h", "cx"],
1312-
instruction_durations=[("h", 0, 200), ("cx", [0, 1], 700)],
1313-
dt=1e-9,
1314-
optimization_level=optimization_level,
1315-
seed_transpiler=42,
1316-
)
1304+
target = Target(num_qubits=2, dt=1e-9)
1305+
target.add_instruction(
1306+
HGate(), {(i,): InstructionProperties(duration=200 * 1e-9) for i in range(2)}
1307+
)
1308+
target.add_instruction(
1309+
CXGate(),
1310+
{(0, 1): InstructionProperties(duration=700 * 1e-9)},
1311+
)
1312+
target.add_instruction(Delay(Parameter("t")), {(i,): None for i in range(2)})
1313+
out = transpile(
1314+
qc,
1315+
scheduling_method="alap",
1316+
target=target,
1317+
optimization_level=optimization_level,
1318+
seed_transpiler=42,
1319+
)
13171320

1321+
self.assertEqual(out.unit, "dt")
13181322
self.assertEqual(out.duration, 1200)
13191323

13201324
@data(0, 1, 2, 3)
@@ -1333,20 +1337,25 @@ def test_circuit_with_delay_expr_duration(self, optimization_level):
13331337
qc.delay(delay_expr, 1)
13341338
qc.cx(0, 1)
13351339

1336-
with self.assertWarnsRegex(
1337-
DeprecationWarning,
1338-
expected_regex="The `target` parameter should be used instead",
1339-
):
1340-
out = transpile(
1341-
qc,
1342-
scheduling_method="alap",
1343-
basis_gates=["h", "cx"],
1344-
instruction_durations=[("h", 0, 200), ("cx", [0, 1], 700)],
1345-
dt=1e-9,
1346-
optimization_level=optimization_level,
1347-
seed_transpiler=42,
1348-
)
1340+
target = Target(num_qubits=2, dt=1e-9)
1341+
target.add_instruction(
1342+
HGate(), {(i,): InstructionProperties(duration=200 * 1e-9) for i in range(2)}
1343+
)
1344+
target.add_instruction(
1345+
CXGate(),
1346+
{(0, 1): InstructionProperties(duration=700 * 1e-9)},
1347+
)
1348+
target.add_instruction(Delay(Parameter("t")), {(i,): None for i in range(2)})
1349+
1350+
out = transpile(
1351+
qc,
1352+
scheduling_method="alap",
1353+
target=target,
1354+
optimization_level=optimization_level,
1355+
seed_transpiler=42,
1356+
)
13491357

1358+
self.assertEqual(out.unit, "dt")
13501359
self.assertEqual(out.duration, 1200)
13511360

13521361
def test_delay_converts_to_dt(self):
@@ -1478,16 +1487,14 @@ def test_delay_expr_evaluation_dt_without_target_dt(self):
14781487
qc = QuantumCircuit(2)
14791488
qc.delay(delay_expr, 1)
14801489

1481-
with self.assertWarnsRegex(
1482-
DeprecationWarning,
1483-
expected_regex="The `target` parameter should be used instead",
1484-
):
1485-
out = transpile(
1486-
qc,
1487-
basis_gates=[],
1488-
instruction_durations=[],
1489-
seed_transpiler=42,
1490-
)
1490+
target = Target(num_qubits=2, dt=None)
1491+
target.add_instruction(Delay(Parameter("t")), {(i,): None for i in range(2)})
1492+
1493+
out = transpile(
1494+
qc,
1495+
target=target,
1496+
seed_transpiler=42,
1497+
)
14911498

14921499
self.assertEqual(out.data[0].operation.unit, "dt")
14931500
self.assertTrue(math.isclose(out.data[0].operation.duration, 300, rel_tol=1e-07))

0 commit comments

Comments
 (0)