From f9fc4beba38b217400620509058fc14e40ab5613 Mon Sep 17 00:00:00 2001 From: Edoardo-Pedicillo Date: Wed, 11 Dec 2024 15:09:51 +0400 Subject: [PATCH 1/6] fix: graph not built if no edges are provided --- src/qibo/backends/__init__.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/qibo/backends/__init__.py b/src/qibo/backends/__init__.py index 73b139c5d9..8a546e0c3d 100644 --- a/src/qibo/backends/__init__.py +++ b/src/qibo/backends/__init__.py @@ -141,9 +141,14 @@ def _default_transpiler(cls): if ( qubits is not None and natives is not None - and connectivity_edges is not None ): - connectivity = nx.Graph(connectivity_edges) + if len(connectivity_edges) == 0: + connectivity = nx.Graph() + qubits = cls._backend.platform.qubits.keys() + connectivity.add_nodes_from(qubits) + else: + connectivity = nx.Graph(connectivity_edges) + return Passes( connectivity=connectivity, passes=[ @@ -152,7 +157,6 @@ def _default_transpiler(cls): Unroller(NativeGates[natives]), ], ) - return Passes(passes=[]) From 101e591eac5bab50049ccc8dfd94722eb62e99fd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 11 Dec 2024 11:27:57 +0000 Subject: [PATCH 2/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/qibo/backends/__init__.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/qibo/backends/__init__.py b/src/qibo/backends/__init__.py index 8a546e0c3d..4f18ae5d1d 100644 --- a/src/qibo/backends/__init__.py +++ b/src/qibo/backends/__init__.py @@ -138,11 +138,8 @@ def _default_transpiler(cls): qubits = cls._backend.qubits natives = cls._backend.natives connectivity_edges = cls._backend.connectivity - if ( - qubits is not None - and natives is not None - ): - if len(connectivity_edges) == 0: + if qubits is not None and natives is not None: + if len(connectivity_edges) == 0: connectivity = nx.Graph() qubits = cls._backend.platform.qubits.keys() connectivity.add_nodes_from(qubits) From 85362c97385e4f08c1ca9cff26c62b14f313eb49 Mon Sep 17 00:00:00 2001 From: Edoardo Pedicillo Date: Wed, 11 Dec 2024 15:37:54 +0400 Subject: [PATCH 3/6] Update src/qibo/backends/__init__.py Co-authored-by: Alessandro Candido --- src/qibo/backends/__init__.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/qibo/backends/__init__.py b/src/qibo/backends/__init__.py index 4f18ae5d1d..7cb89d4c08 100644 --- a/src/qibo/backends/__init__.py +++ b/src/qibo/backends/__init__.py @@ -139,12 +139,8 @@ def _default_transpiler(cls): natives = cls._backend.natives connectivity_edges = cls._backend.connectivity if qubits is not None and natives is not None: - if len(connectivity_edges) == 0: - connectivity = nx.Graph() - qubits = cls._backend.platform.qubits.keys() - connectivity.add_nodes_from(qubits) - else: - connectivity = nx.Graph(connectivity_edges) + connectivity = nx.Graph(connectivity_edges) if connectivity_edges is not None else nx.Graph() + connectivity.add_nodes_from(qubits) return Passes( connectivity=connectivity, From 30922a5e3f6d626e7cc0097973146640b3a61c30 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 11 Dec 2024 11:40:20 +0000 Subject: [PATCH 4/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/qibo/backends/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/qibo/backends/__init__.py b/src/qibo/backends/__init__.py index 7cb89d4c08..8bf3309929 100644 --- a/src/qibo/backends/__init__.py +++ b/src/qibo/backends/__init__.py @@ -139,7 +139,11 @@ def _default_transpiler(cls): natives = cls._backend.natives connectivity_edges = cls._backend.connectivity if qubits is not None and natives is not None: - connectivity = nx.Graph(connectivity_edges) if connectivity_edges is not None else nx.Graph() + connectivity = ( + nx.Graph(connectivity_edges) + if connectivity_edges is not None + else nx.Graph() + ) connectivity.add_nodes_from(qubits) return Passes( From 97bf4b5040fbf6efc7a433acaa22d9c662cbf793 Mon Sep 17 00:00:00 2001 From: Edoardo-Pedicillo Date: Wed, 11 Dec 2024 17:01:33 +0400 Subject: [PATCH 5/6] test: increase coverage adding connectivity examples --- tests/test_backends_global.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/tests/test_backends_global.py b/tests/test_backends_global.py index dc0b6dfeaa..728f0bddfa 100644 --- a/tests/test_backends_global.py +++ b/tests/test_backends_global.py @@ -148,8 +148,14 @@ def test_default_transpiler_sim(): and backend.qubits is None ) - -def test_default_transpiler_hw(): +CONNECTIVITY = [ + [("A1", "A2"), ("A2", "A3"), ("A3", "A4"), ("A4", "A5")], + [("A1", "A2")], + [], +] + +@pytest.mark.parametrize("connectivity", CONNECTIVITY) +def test_default_transpiler_hw(connectivity): class TempBackend(NumpyBackend): def __init__(self): super().__init__() @@ -161,7 +167,7 @@ def qubits(self): @property def connectivity(self): - return [("A1", "A2"), ("A2", "A3"), ("A3", "A4"), ("A4", "A5")] + return connectivity @property def natives(self): @@ -172,13 +178,10 @@ def natives(self): transpiler = _Global.transpiler() assert list(transpiler.connectivity.nodes) == ["A1", "A2", "A3", "A4", "A5"] - assert list(transpiler.connectivity.edges) == [ - ("A1", "A2"), - ("A2", "A3"), - ("A3", "A4"), - ("A4", "A5"), - ] + assert list(transpiler.connectivity.edges) == connectivity assert ( NativeGates.CZ in transpiler.native_gates and NativeGates.GPI2 in transpiler.native_gates ) + + From 91e989090d8d11f5ac290f6ed796f66d55dd526a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 11 Dec 2024 13:02:04 +0000 Subject: [PATCH 6/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_backends_global.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_backends_global.py b/tests/test_backends_global.py index 728f0bddfa..16ac92d258 100644 --- a/tests/test_backends_global.py +++ b/tests/test_backends_global.py @@ -148,11 +148,13 @@ def test_default_transpiler_sim(): and backend.qubits is None ) + CONNECTIVITY = [ [("A1", "A2"), ("A2", "A3"), ("A3", "A4"), ("A4", "A5")], [("A1", "A2")], [], -] +] + @pytest.mark.parametrize("connectivity", CONNECTIVITY) def test_default_transpiler_hw(connectivity): @@ -183,5 +185,3 @@ def natives(self): NativeGates.CZ in transpiler.native_gates and NativeGates.GPI2 in transpiler.native_gates ) - -