diff --git a/src/qibo/backends/__init__.py b/src/qibo/backends/__init__.py index 73b139c5d9..8bf3309929 100644 --- a/src/qibo/backends/__init__.py +++ b/src/qibo/backends/__init__.py @@ -138,12 +138,14 @@ 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 - and connectivity_edges is not None - ): - connectivity = nx.Graph(connectivity_edges) + 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.add_nodes_from(qubits) + return Passes( connectivity=connectivity, passes=[ @@ -152,7 +154,6 @@ def _default_transpiler(cls): Unroller(NativeGates[natives]), ], ) - return Passes(passes=[]) diff --git a/tests/test_backends_global.py b/tests/test_backends_global.py index dc0b6dfeaa..16ac92d258 100644 --- a/tests/test_backends_global.py +++ b/tests/test_backends_global.py @@ -149,7 +149,15 @@ def test_default_transpiler_sim(): ) -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 +169,7 @@ def qubits(self): @property def connectivity(self): - return [("A1", "A2"), ("A2", "A3"), ("A3", "A4"), ("A4", "A5")] + return connectivity @property def natives(self): @@ -172,12 +180,7 @@ 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