Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix BasicSwap FakeRun Typo (backport #10274) #10278

Merged
merged 1 commit into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion qiskit/transpiler/passes/routing/basic_swap.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def run(self, dag):
compatible with the DAG, or if the coupling_map=None.
"""
if self.fake_run:
return self.fake_run(dag)
return self._fake_run(dag)

new_dag = dag.copy_empty_like()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fixes:
- |
Fixes a typo where BasicSwap called ``fake_run()`` the attribute instead of ``_fake_run()`` the function.
Refer to `#10149 <hhttps://github.com/Qiskit/qiskit-terra/issues/10147>` for more details.
39 changes: 39 additions & 0 deletions test/python/transpiler/test_basic_swap.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

import unittest
from qiskit.transpiler.passes import BasicSwap
from qiskit.transpiler.passmanager import PassManager
from qiskit.transpiler.layout import Layout
from qiskit.transpiler import CouplingMap, Target
from qiskit.circuit.library import CXGate
from qiskit.converters import circuit_to_dag
Expand Down Expand Up @@ -369,6 +371,43 @@ def test_far_swap_with_gate_the_middle(self):

self.assertEqual(circuit_to_dag(expected), after)

def test_fake_run(self):
"""A fake run, doesn't change dag
q0:--(+)-------.--
| |
q1:---|--------|--
|
q2:---|--------|--
| |
q3:---.--[H]--(+)-

CouplingMap map: [0]--[1]--[2]--[3]

q0:-------(+)-------.---
| |
q1:-----X--.--[H]--(+)--
|
q2:--X--X---------------
|
q3:--X------------------

"""
coupling = CouplingMap([[0, 1], [1, 2], [2, 3]])

qr = QuantumRegister(4, "q")
circuit = QuantumCircuit(qr)
circuit.cx(qr[3], qr[0])
circuit.h(qr[3])
circuit.cx(qr[0], qr[3])

fake_pm = PassManager([BasicSwap(coupling, fake_run=True)])
real_pm = PassManager([BasicSwap(coupling, fake_run=False)])

self.assertEqual(circuit, fake_pm.run(circuit))
self.assertNotEqual(circuit, real_pm.run(circuit))
self.assertIsInstance(fake_pm.property_set["final_layout"], Layout)
self.assertEqual(fake_pm.property_set["final_layout"], real_pm.property_set["final_layout"])


if __name__ == "__main__":
unittest.main()