Skip to content

Commit

Permalink
Fix BasicSwap FakeRun Typo (#10274) (#10278)
Browse files Browse the repository at this point in the history
* fix typo, issue #10147

* create basicswap fake_run test

* release note for #10149 fix

* ensure fake_run modifes layout prop, not the circuit logic

* black formatting, test_basic_swap

(cherry picked from commit 7df290b)

Co-authored-by: Evan McKinney <47376937+evmckinney9@users.noreply.github.com>
  • Loading branch information
mergify[bot] and evmckinney9 authored Jun 14, 2023
1 parent 2c3166c commit 9f18b91
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
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()

0 comments on commit 9f18b91

Please sign in to comment.