From 36115ee257f03bf6b80796e085612cd063167309 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Fri, 26 May 2023 14:30:27 -0400 Subject: [PATCH 1/2] 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 --- qiskit/transpiler/passmanager_config.py | 4 +++- .../fix-pm-config-from-backend-f3b71b11858b4f08.yaml | 9 +++++++++ test/python/transpiler/test_passmanager_config.py | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/fix-pm-config-from-backend-f3b71b11858b4f08.yaml 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..79b9c2012532 100644 --- a/test/python/transpiler/test_passmanager_config.py +++ b/test/python/transpiler/test_passmanager_config.py @@ -79,6 +79,7 @@ def test_from_backendv1_inst_map_is_none(self): config = PassManagerConfig.from_backend(backend) self.assertIsInstance(config, PassManagerConfig) self.assertIsNone(config.inst_map) + self.assertIsNone(config.coupling_map) def test_simulator_backend_v1(self): """Test that from_backend() works with backendv1 simulator.""" From 4f36589205bbf2e116b834ec39aa89a3ff120c90 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Fri, 26 May 2023 16:50:12 -0400 Subject: [PATCH 2/2] Fix tests --- test/python/transpiler/test_passmanager_config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/python/transpiler/test_passmanager_config.py b/test/python/transpiler/test_passmanager_config.py index 79b9c2012532..96721e1884a3 100644 --- a/test/python/transpiler/test_passmanager_config.py +++ b/test/python/transpiler/test_passmanager_config.py @@ -79,7 +79,6 @@ def test_from_backendv1_inst_map_is_none(self): config = PassManagerConfig.from_backend(backend) self.assertIsInstance(config, PassManagerConfig) self.assertIsNone(config.inst_map) - self.assertIsNone(config.coupling_map) def test_simulator_backend_v1(self): """Test that from_backend() works with backendv1 simulator.""" @@ -87,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.""" @@ -104,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