Skip to content

Commit

Permalink
Merge branch 'qibo_global_patch' into qibo_wire_patch
Browse files Browse the repository at this point in the history
  • Loading branch information
changsookim committed Oct 25, 2024
2 parents 712510a + 6471dfb commit 28a0c64
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
27 changes: 7 additions & 20 deletions src/qibolab/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import numpy as np
from qibo import __version__ as qibo_version
from qibo import gates
from qibo.backends import NumpyBackend
from qibo.config import raise_error
from qibo.models import Circuit
Expand Down Expand Up @@ -67,29 +66,17 @@ def natives(self) -> list[str]:
"""Returns the list of native gates supported by the platform."""
compiler = Compiler.default()
natives = [g.__name__ for g in list(compiler.rules)]
calibrated = self.platform.pairs

check_2q = ["CZ", "CNOT"]
for gate in check_2q:
if gate in natives:
for pair in self.connectivity:
logical_pair = tuple(
self.platform.wire_names.index(q) for q in pair
)
if self._is_gate_calibrated(
getattr(gates, gate)(*logical_pair), compiler
):
break
else:
natives.remove(gate)
return natives
if gate in natives and all(
getattr(calibrated[p].native_gates, gate) is None
for p in self.connectivity
):
natives.remove(gate)

def _is_gate_calibrated(self, gate, compiler) -> bool:
"""Helper method to check if a gate is calibrated."""
try:
compiler[type(gate)](gate, self.platform)
return True
except ValueError:
return False
return natives

def apply_gate(self, gate, state, nqubits): # pragma: no cover
raise_error(NotImplementedError, "Qibolab cannot apply gates directly.")
Expand Down
18 changes: 18 additions & 0 deletions tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,24 @@ def test_natives():
}


def test_natives_no_cz_cnot():
platform = create_platform("dummy")
for p in platform.pairs:
platform.pairs[p].native_gates.CZ = None
platform.pairs[p].native_gates.CNOT = None

backend = QibolabBackend(platform)
assert set(backend.natives) == {
"I",
"Z",
"RZ",
"U3",
"GPI2",
"GPI",
"M",
}


def test_execute_circuit_initial_state():
backend = QibolabBackend("dummy")
circuit = Circuit(1)
Expand Down

0 comments on commit 28a0c64

Please sign in to comment.