Skip to content

Commit

Permalink
Fix PassManagerConfig.from_backend with BackendV1 and no CouplingMap (#…
Browse files Browse the repository at this point in the history
…10172)

* Fix PassManagerConfig.from_backend with BackendV1 and no CouplingMap

This commit fixes an issue in the PassManagerConfig.from_backend
constructor method when using BackendV1 based simulator backends. The
pass was incorrectly handling the case when the backend configuration
didn't have a coupling map defined and incorrectly creating a coupling
map with 0 qubits instead of using None to indicate the lack of
connectivity. This has been fixed so the coupling map creation is
skipped if there is no coupling map attribute in the backend's
configuration.

Fixes #10171

* Fix tests

(cherry picked from commit 4762e26)
  • Loading branch information
mtreinish authored and mergify[bot] committed May 30, 2023
1 parent 5f39f6b commit 2cb96b0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion qiskit/transpiler/passmanager_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ def from_backend(cls, backend, **pass_manager_options):
res.inst_map = backend.instruction_schedule_map
if res.coupling_map is None:
if backend_version < 2:
res.coupling_map = CouplingMap(getattr(config, "coupling_map", None))
cmap_edge_list = getattr(config, "coupling_map", None)
if cmap_edge_list is not None:
res.coupling_map = CouplingMap(cmap_edge_list)
else:
res.coupling_map = backend.coupling_map
if res.instruction_durations is None:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
fixes:
- |
Fixed an issue with the :meth:`.PassManagerConfig.from_backend` constructor
when building a :class:`~.PassManagerConfig` object from a :class:`~.BackendV1`
instance that didn't have a coupling map attribute defined. Previously, the
constructor would incorrectly create a :class:`~.CouplingMap` object with
0 qubits instead of using ``None``.
Fixed `#10171 <https://github.com/Qiskit/qiskit-terra/issues/10171>`__
3 changes: 2 additions & 1 deletion test/python/transpiler/test_passmanager_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def test_simulator_backend_v1(self):
config = PassManagerConfig.from_backend(backend)
self.assertIsInstance(config, PassManagerConfig)
self.assertIsNone(config.inst_map)
self.assertIsNone(config.coupling_map)

def test_invalid_user_option(self):
"""Test from_backend() with an invalid user option."""
Expand All @@ -103,7 +104,7 @@ def test_str(self):
initial_layout: None
basis_gates: ['id', 'rz', 'sx', 'x']
inst_map: None
coupling_map:
coupling_map: None
layout_method: None
routing_method: None
translation_method: None
Expand Down

0 comments on commit 2cb96b0

Please sign in to comment.