diff --git a/CHANGELOG.md b/CHANGELOG.md index edcdcc9576..5fecb5c37d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -100,8 +100,7 @@ The format is based on [Keep a Changelog]. using the option ``with_layout=False`` in the method ``QuantumCircuit.draw``. (\#2739) - Q-sphere visualization is enhanced and corrected (\#2932) -- The default layout selector for transpile optimization level 1 is ``DenseLayout`` - instead of ``TrivialLayout`` (\#2845). + ### Removed - The ability to set the `Timeslot`s for a pulse `Instruction` at initialization. diff --git a/qiskit/transpiler/preset_passmanagers/level1.py b/qiskit/transpiler/preset_passmanagers/level1.py index a91b5b52d1..d9426b49e1 100644 --- a/qiskit/transpiler/preset_passmanagers/level1.py +++ b/qiskit/transpiler/preset_passmanagers/level1.py @@ -27,7 +27,7 @@ from qiskit.transpiler.passes import Decompose from qiskit.transpiler.passes import CheckMap from qiskit.transpiler.passes import CXDirection from qiskit.transpiler.passes import SetLayout -from qiskit.transpiler.passes import DenseLayout +from qiskit.transpiler.passes import TrivialLayout from qiskit.transpiler.passes import BarrierBeforeFinalMeasurements from qiskit.transpiler.passes import StochasticSwap from qiskit.transpiler.passes import FullAncillaAllocation @@ -65,13 +65,13 @@ def level_1_pass_manager(transpile_config): initial_layout = transpile_config.initial_layout seed_transpiler = transpile_config.seed_transpiler - # 1. Use dense layout if no layout given + # 1. Use trivial layout if no layout given _given_layout = SetLayout(initial_layout) def _choose_layout_condition(property_set): return not property_set['layout'] - _choose_layout = DenseLayout(coupling_map) + _choose_layout = TrivialLayout(coupling_map) # 2. Use a better layout on densely connected qubits, if circuit needs swaps _layout_check = CheckMap(coupling_map) diff --git a/test/python/compiler/test_transpiler.py b/test/python/compiler/test_transpiler.py index 50eea12d95..2324996784 100644 --- a/test/python/compiler/test_transpiler.py +++ b/test/python/compiler/test_transpiler.py @@ -422,11 +422,12 @@ class TestTranspile(QiskitTestCase): theta = Parameter('theta') qc.rz(theta, qr[0]) - transpiled_qc = transpile(qc, backend=FakeMelbourne()) + transpiled_qc = transpile(qc, backend=FakeMelbourne(), + initial_layout=Layout.generate_trivial_layout(qr)) qr = QuantumRegister(14, 'q') expected_qc = QuantumCircuit(qr) - expected_qc.u1(theta, qr[1]) + expected_qc.u1(theta, qr[0]) self.assertEqual(expected_qc, transpiled_qc) @@ -457,11 +458,12 @@ class TestTranspile(QiskitTestCase): square = theta * theta qc.rz(square, qr[0]) - transpiled_qc = transpile(qc, backend=FakeMelbourne()) + transpiled_qc = transpile(qc, backend=FakeMelbourne(), + initial_layout=Layout.generate_trivial_layout(qr)) qr = QuantumRegister(14, 'q') expected_qc = QuantumCircuit(qr) - expected_qc.u1(square, qr[1]) + expected_qc.u1(square, qr[0]) self.assertEqual(expected_qc, transpiled_qc) diff --git a/test/python/transpiler/test_preset_passmanagers.py b/test/python/transpiler/test_preset_passmanagers.py index fcaf3a5342..c7988c95cb 100644 --- a/test/python/transpiler/test_preset_passmanagers.py +++ b/test/python/transpiler/test_preset_passmanagers.py @@ -257,23 +257,19 @@ class TestFinalLayouts(QiskitTestCase): qc.cx(qr2[0], qr2[1]) ancilla = QuantumRegister(15, 'ancilla') - + trivial_layout = {0: qr1[0], 1: qr1[1], 2: qr1[2], 3: qr2[0], 4: qr2[1], + 5: ancilla[0], 6: ancilla[1], 7: ancilla[2], 8: ancilla[3], + 9: ancilla[4], 10: ancilla[5], 11: ancilla[6], 12: ancilla[7], + 13: ancilla[8], 14: ancilla[9], 15: ancilla[10], 16: ancilla[11], + 17: ancilla[12], 18: ancilla[13], 19: ancilla[14]} # TrivialLayout - expected_layout_level0 = {0: qr1[0], 1: qr1[1], 2: qr1[2], 3: qr2[0], 4: qr2[1], - 5: ancilla[0], 6: ancilla[1], 7: ancilla[2], 8: ancilla[3], - 9: ancilla[4], 10: ancilla[5], 11: ancilla[6], 12: ancilla[7], - 13: ancilla[8], 14: ancilla[9], 15: ancilla[10], 16: ancilla[11], - 17: ancilla[12], 18: ancilla[13], 19: ancilla[14]} - # DenseLayout - expected_layout_level1 = {0: qr2[1], 1: ancilla[0], 2: ancilla[1], 3: ancilla[2], - 4: ancilla[3], 5: qr2[0], 6: qr1[2], 7: ancilla[4], 8: ancilla[5], - 9: ancilla[6], 10: qr1[1], 11: qr1[0], 12: ancilla[7], - 13: ancilla[8], 14: ancilla[9], 15: ancilla[10], 16: ancilla[11], - 17: ancilla[12], 18: ancilla[13], 19: ancilla[14]} + expected_layout_level0 = trivial_layout + expected_layout_level1 = trivial_layout # NoiseAdaptiveLayout (in FakeTokyo, no errors. Therefore, TrivialLayout) - expected_layout_level2 = expected_layout_level0 - expected_layout_level3 = expected_layout_level0 + # TODO See https://github.com/Qiskit/qiskit-terra/issues/2970 + expected_layout_level2 = trivial_layout + expected_layout_level3 = trivial_layout expected_layouts = [expected_layout_level0, expected_layout_level1, expected_layout_level2,