Skip to content

Commit

Permalink
Add TranspileErrors to routing passes for coupling_map=None (Qiskit#7141
Browse files Browse the repository at this point in the history
)

* Adding TranspileErrors to routing passes that run with coupling_map=None

* Add changelog

---------

Co-authored-by: Matthew Treinish <[email protected]>
  • Loading branch information
2 people authored and Eric-Arellano committed Feb 23, 2023
1 parent 2a49cb0 commit 23a29f2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
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_empty_like()

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 @@ -108,8 +108,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 @@ -174,8 +174,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 @@ -86,9 +86,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.

0 comments on commit 23a29f2

Please sign in to comment.