Skip to content

Commit

Permalink
Merge pull request #1540 from qiboteam/graph
Browse files Browse the repository at this point in the history
Graph not built if no edges are provided
  • Loading branch information
Edoardo-Pedicillo authored Dec 12, 2024
2 parents 15fbaf9 + 91e9890 commit 4588671
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
15 changes: 8 additions & 7 deletions src/qibo/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=[
Expand All @@ -152,7 +154,6 @@ def _default_transpiler(cls):
Unroller(NativeGates[natives]),
],
)

return Passes(passes=[])


Expand Down
19 changes: 11 additions & 8 deletions tests/test_backends_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__()
Expand All @@ -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):
Expand All @@ -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
Expand Down

0 comments on commit 4588671

Please sign in to comment.