From 90d52cc4fe150d8ac5f4a4144efee32a3084805e Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Thu, 18 Aug 2022 09:39:33 -0400 Subject: [PATCH] Fix test failures This commit updates tests which started to fail because of the different RNG behavior used by the parallel SabreSwap seed trials. For the most part these are just mechanical changes that either changed the expected layout with a fixed seed or updating a fixed seed so the output matches the expected result. The one interesting case was the TestTranspileLevelsSwap change which was caused by different swaps being inserted that for optimization level enabled the 2q block optimization passes to synthesize away the swap as part of its optimization. This was fixed by changing the seed, but it was a different case than the other failures. --- test/python/transpiler/test_mappers.py | 2 +- .../transpiler/test_preset_passmanagers.py | 30 +++++++++---------- test/python/transpiler/test_sabre_layout.py | 18 +++++------ 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/test/python/transpiler/test_mappers.py b/test/python/transpiler/test_mappers.py index ef061f7c7d28..6a3d0d1748e3 100644 --- a/test/python/transpiler/test_mappers.py +++ b/test/python/transpiler/test_mappers.py @@ -294,7 +294,7 @@ class TestsSabreSwap(SwapperCommonTestCases, QiskitTestCase): """Test SwapperCommonTestCases using SabreSwap.""" pass_class = SabreSwap - additional_args = {"seed": 4242} + additional_args = {"seed": 1242} if __name__ == "__main__": diff --git a/test/python/transpiler/test_preset_passmanagers.py b/test/python/transpiler/test_preset_passmanagers.py index 2ce8ef1d0343..2186813bf6ef 100644 --- a/test/python/transpiler/test_preset_passmanagers.py +++ b/test/python/transpiler/test_preset_passmanagers.py @@ -698,25 +698,25 @@ def test_layout_tokyo_fully_connected_cx(self, level): } sabre_layout = { - 6: qr[0], - 11: qr[1], - 10: qr[2], - 5: qr[3], - 16: qr[4], + 11: qr[0], + 17: qr[1], + 16: qr[2], + 6: qr[3], + 18: qr[4], 0: ancilla[0], 1: ancilla[1], 2: ancilla[2], 3: ancilla[3], 4: ancilla[4], - 7: ancilla[5], - 8: ancilla[6], - 9: ancilla[7], - 12: ancilla[8], - 13: ancilla[9], - 14: ancilla[10], - 15: ancilla[11], - 17: ancilla[12], - 18: ancilla[13], + 5: ancilla[5], + 7: ancilla[6], + 8: ancilla[7], + 9: ancilla[8], + 10: ancilla[9], + 12: ancilla[10], + 13: ancilla[11], + 14: ancilla[12], + 15: ancilla[13], 19: ancilla[14], } @@ -913,7 +913,7 @@ def test_2(self, level): optimization_level=level, basis_gates=basis, coupling_map=coupling_map, - seed_transpiler=42, + seed_transpiler=42123, ) self.assertIsInstance(result, QuantumCircuit) resulting_basis = {node.name for node in circuit_to_dag(result).op_nodes()} diff --git a/test/python/transpiler/test_sabre_layout.py b/test/python/transpiler/test_sabre_layout.py index 85a975dd6a48..85561f102e47 100644 --- a/test/python/transpiler/test_sabre_layout.py +++ b/test/python/transpiler/test_sabre_layout.py @@ -56,10 +56,10 @@ def test_5q_circuit_20q_coupling(self): pass_.run(dag) layout = pass_.property_set["layout"] - self.assertEqual(layout[qr[0]], 11) - self.assertEqual(layout[qr[1]], 6) - self.assertEqual(layout[qr[2]], 12) - self.assertEqual(layout[qr[3]], 5) + self.assertEqual(layout[qr[0]], 10) + self.assertEqual(layout[qr[1]], 12) + self.assertEqual(layout[qr[2]], 7) + self.assertEqual(layout[qr[3]], 11) self.assertEqual(layout[qr[4]], 13) def test_6q_circuit_20q_coupling(self): @@ -92,12 +92,12 @@ def test_6q_circuit_20q_coupling(self): pass_.run(dag) layout = pass_.property_set["layout"] - self.assertEqual(layout[qr0[0]], 8) - self.assertEqual(layout[qr0[1]], 2) + self.assertEqual(layout[qr0[0]], 2) + self.assertEqual(layout[qr0[1]], 3) self.assertEqual(layout[qr0[2]], 10) - self.assertEqual(layout[qr1[0]], 3) - self.assertEqual(layout[qr1[1]], 12) - self.assertEqual(layout[qr1[2]], 11) + self.assertEqual(layout[qr1[0]], 1) + self.assertEqual(layout[qr1[1]], 7) + self.assertEqual(layout[qr1[2]], 5) if __name__ == "__main__":