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

Deprecates StochasticSwap and suggests the use of SabreSwap #12983

Merged
merged 17 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
8 changes: 8 additions & 0 deletions qiskit/transpiler/passes/routing/stochastic_swap.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from qiskit._accelerate import stochastic_swap as stochastic_swap_rs
from qiskit._accelerate import nlayout
from qiskit.transpiler.passes.layout import disjoint_utils
from qiskit.utils import deprecate_func

from .utils import get_swap_map_dag

Expand All @@ -59,6 +60,12 @@ class StochasticSwap(TransformationPass):
the circuit.
"""

@deprecate_func(
since="1.3",
removal_timeline="in the 2.0 release",
additional_msg="The `StochasticSwap` tranpilation pass is a suboptimal "
"routing algorithm and will has been superseded by :class:`.SabreSwap` pass.",
danielbultrini marked this conversation as resolved.
Show resolved Hide resolved
)
def __init__(self, coupling_map, trials=20, seed=None, fake_run=False, initial_layout=None):
"""StochasticSwap initializer.

Expand All @@ -76,6 +83,7 @@ def __init__(self, coupling_map, trials=20, seed=None, fake_run=False, initial_l
initial_layout (Layout): starting layout at beginning of pass.
"""
super().__init__()

if isinstance(coupling_map, Target):
self.target = coupling_map
self.coupling_map = self.target.build_coupling_map()
Expand Down
46 changes: 46 additions & 0 deletions releasenotes/notes/deprecate-StochasticSwap-451f46b273602b7b.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
deprecations_transpiler:
- |
Deprecated ``StochasticSwap`` which has been superseded by :class:`.SabreSwap`.
If the class is called from the transpile method, the change would be, for example::
danielbultrini marked this conversation as resolved.
Show resolved Hide resolved

tqc = transpile(
circuit,
routing_method="stochastic",
layout_method="dense",
seed_transpiler=12342,
target=GenericBackendV2(
num_qubits=27,
coupling_map=MUMBAI_CMAP,
).target,
)

to::

tqc = transpile(
circuit,
routing_method="sabre",
layout_method="sabre",
seed_transpiler=12342,
target=GenericBackendV2(
num_qubits=27,
coupling_map=MUMBAI_CMAP,
).target,
)

While for a pass mananager change::

qr = QuantumRegister(4, "q")
qc = QuantumCircuit(qr)
passmanager = StochasticSwap(coupling, 20, 13)
ElePT marked this conversation as resolved.
Show resolved Hide resolved
ElePT marked this conversation as resolved.
Show resolved Hide resolved
new_qc = passmanager.run(qc)

to::

qr = QuantumRegister(5, "q")
qc = QuantumCircuit(qr)
passmanager = PassManager(SabreSwap(target, "basic"))
new_qc = passmanager.run(qc)



Loading
Loading