Skip to content

Commit

Permalink
Merge branch 'master' into rename_methods
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoRobbiati committed Dec 15, 2024
2 parents 53ffdc3 + 4588671 commit d11dc9d
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 d11dc9d

Please sign in to comment.