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

Add TranspileErrors to routing passes for coupling_map=None #7141

Merged
merged 5 commits into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
5 changes: 4 additions & 1 deletion qiskit/transpiler/passes/routing/basic_swap.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,16 @@ def run(self, dag):

Raises:
TranspilerError: if the coupling map or the layout are not
compatible with the DAG.
compatible with the DAG, or if the coupling_map=None.
"""
if self.fake_run:
return self.fake_run(dag)

new_dag = dag._copy_circuit_metadata()

if self.coupling_map is None:
raise TranspilerError("BasicSwap cannot run with coupling_map=None")

if len(dag.qregs) != 1 or dag.qregs.get("q", None) is None:
raise TranspilerError("Basic swap runs on physical circuits only")

Expand Down
6 changes: 5 additions & 1 deletion qiskit/transpiler/passes/routing/lookahead_swap.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,12 @@ def run(self, dag):
the property_set.
Raises:
TranspilerError: if the coupling map or the layout are not
compatible with the DAG
compatible with the DAG, or if the coupling_map=None
"""

if self.coupling_map is None:
raise TranspilerError("LookaheadSwap cannot run with coupling_map=None")

if len(dag.qregs) != 1 or dag.qregs.get("q", None) is None:
raise TranspilerError("Lookahead swap runs on physical circuits only")

Expand Down
6 changes: 5 additions & 1 deletion qiskit/transpiler/passes/routing/sabre_swap.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,12 @@ def run(self, dag):
DAGCircuit: A dag mapped to be compatible with the coupling_map.
Raises:
TranspilerError: if the coupling map or the layout are not
compatible with the DAG
compatible with the DAG, or if the coupling_map=None
"""

if self.coupling_map is None:
raise TranspilerError("SabreSwap cannot run with coupling_map=None")

if len(dag.qregs) != 1 or dag.qregs.get("q", None) is None:
raise TranspilerError("Sabre swap runs on physical circuits only.")

Expand Down
5 changes: 4 additions & 1 deletion qiskit/transpiler/passes/routing/stochastic_swap.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,12 @@ def run(self, dag):

Raises:
TranspilerError: if the coupling map or the layout are not
compatible with the DAG
compatible with the DAG, or if the coupling_map=None
"""

if self.coupling_map is None:
raise TranspilerError("StochasticSwap cannot run with coupling_map=None")

if len(dag.qregs) != 1 or dag.qregs.get("q", None) is None:
raise TranspilerError("StochasticSwap runs on physical circuits only")

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
fixes:
- |
Throw ``TranspileError`` when routing passes (``StochasticSwap``, ``SabreSwap``,
``LookaheadSwap``, and ``BasicSwap``) run with ``coupling_map=None``. Refer to
`#7127 <https://github.com/Qiskit/qiskit-terra/issues/7127>` for more details.