From f5b6778e524ff5af540cf66fb0a42eb0a2a0b6c8 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Wed, 1 May 2024 16:03:58 -0400 Subject: [PATCH] Add test to test we skip after layout --- .../transpiler/test_elide_permutations.py | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/test/python/transpiler/test_elide_permutations.py b/test/python/transpiler/test_elide_permutations.py index c1084e663091..c312c51d8442 100644 --- a/test/python/transpiler/test_elide_permutations.py +++ b/test/python/transpiler/test_elide_permutations.py @@ -304,11 +304,27 @@ class TestElidePermutationsInTranspileFlow(QiskitTestCase): as to preserve unitary equivalence. """ - # ToDo: update the tests when ElidePermutations is merged into transpiler flow. + def test_not_run_after_layout(self): + """Test ElidePermutations doesn't do anything after layout.""" + qc = QuantumCircuit(3) + qc.h(0) + qc.swap(0, 2) + qc.cx(0, 1) + qc.swap(1, 0) + qc.h(1) + + spm = generate_preset_pass_manager( + optimization_level=3, initial_layout=list(range(2, -1, -1)), seed_transpiler=42 + ) + spm.layout += ElidePermutations() + spm.post_optimization = PassManager([FinalizeLayouts()]) + res = spm.run(qc) + self.assertTrue(Operator.from_circuit(res).equiv(Operator(qc))) + self.assertIn("swap", res.count_ops()) + self.assertTrue(res.layout.final_index_layout(), [0, 1, 2]) def test_unitary_equivalence(self): """Test unitary equivalence of the original and transpiled circuits.""" - qc = QuantumCircuit(3) qc.h(0) qc.swap(0, 2)