Skip to content

Commit 4cebf07

Browse files
authored
Clarify test assertion for UnitarySynthesis (#15489)
In a rework of `UnitarySynthesis` I'm working on, I was (temporarily) failing this test, but didn't have much to go on because the failure message was just "False is not true". This commit changes the assertion to something more useful, so that the failing edges all appear in the output.
1 parent aedc6f0 commit 4cebf07

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

test/python/transpiler/test_unitary_synthesis.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -357,12 +357,12 @@ def construct_passmanager(basis_gates, coupling_map, synthesis_fidelity, pulse_o
357357

358358
qv64_1 = pm1.run(qv64.decompose())
359359
qv64_2 = pm2.run(qv64.decompose())
360-
edges = [list(edge) for edge in coupling_map.get_edges()]
361-
self.assertTrue(
362-
all(
363-
[qv64_1.qubits.index(qubit) for qubit in instr.qubits] in edges
360+
self.assertLessEqual(
361+
{
362+
tuple(qv64_1.qubits.index(qubit) for qubit in instr.qubits)
364363
for instr in qv64_1.get_instructions("cx")
365-
)
364+
},
365+
{tuple(edge) for edge in coupling_map.get_edges()},
366366
)
367367
self.assertEqual(Operator(qv64_1), Operator(qv64_2))
368368

@@ -1039,24 +1039,25 @@ def test_two_qubit_synthesis_to_directional_cx_multiple_registers_target(
10391039
def test_two_qubit_natural_direction_true_duration_fallback_target(self):
10401040
"""Verify fallback path when pulse_optimize==True."""
10411041
basis_gates = ["id", "rz", "sx", "x", "cx", "reset"]
1042-
qr = QuantumRegister(2)
1042+
qr = QuantumRegister(5)
10431043
coupling_map = CouplingMap([[0, 1], [1, 0], [1, 2], [1, 3], [3, 4]])
10441044
backend = GenericBackendV2(
10451045
num_qubits=5, basis_gates=basis_gates, coupling_map=coupling_map, seed=1
10461046
)
1047-
1048-
triv_layout_pass = TrivialLayout(coupling_map)
10491047
qc = QuantumCircuit(qr)
10501048
qc.unitary(random_unitary(4, seed=12), [0, 1])
10511049
unisynth_pass = UnitarySynthesis(
10521050
target=backend.target,
10531051
pulse_optimize=True,
10541052
natural_direction=True,
10551053
)
1056-
pm = PassManager([triv_layout_pass, unisynth_pass])
1057-
qc_out = pm.run(qc)
1058-
self.assertTrue(
1059-
all(((qr[0], qr[1]) == instr.qubits for instr in qc_out.get_instructions("cx")))
1054+
qc_out = unisynth_pass(qc)
1055+
self.assertEqual(
1056+
{
1057+
tuple(qc_out.find_bit(q).index for q in instr.qubits)
1058+
for instr in qc_out.get_instructions("cx")
1059+
},
1060+
{(0, 1)},
10601061
)
10611062

10621063

0 commit comments

Comments
 (0)