diff --git a/qiskit/transpiler/passmanager_config.py b/qiskit/transpiler/passmanager_config.py index 5c1720ccb1d6..ae1f43b3c243 100644 --- a/qiskit/transpiler/passmanager_config.py +++ b/qiskit/transpiler/passmanager_config.py @@ -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: diff --git a/releasenotes/notes/fix-pm-config-from-backend-f3b71b11858b4f08.yaml b/releasenotes/notes/fix-pm-config-from-backend-f3b71b11858b4f08.yaml new file mode 100644 index 000000000000..c85355478f06 --- /dev/null +++ b/releasenotes/notes/fix-pm-config-from-backend-f3b71b11858b4f08.yaml @@ -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 `__ diff --git a/test/python/transpiler/test_passmanager_config.py b/test/python/transpiler/test_passmanager_config.py index d78b52e86542..96721e1884a3 100644 --- a/test/python/transpiler/test_passmanager_config.py +++ b/test/python/transpiler/test_passmanager_config.py @@ -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.""" @@ -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