Skip to content

Commit

Permalink
fix: natives() return any available gate
Browse files Browse the repository at this point in the history
  • Loading branch information
changsookim committed Oct 24, 2024
1 parent ad547da commit d9ac1b3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
28 changes: 23 additions & 5 deletions src/qibolab/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ def connectivity(self) -> list[tuple[Union[str, int], Union[str, int]]]:
"""Returns the list of connected qubits."""
return list(self.platform.pairs)

# @property
# 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)]

# check_2q = ["CZ", "CNOT"]
# for gate in check_2q:
# if gate in natives and any(
# not self._is_gate_calibrated(getattr(gates, gate)(*pair), compiler)
# for pair in self.connectivity
# ):
# natives.remove(gate)
# return natives
@property
def natives(self) -> list[str]:
"""Returns the list of native gates supported by the platform."""
Expand All @@ -70,11 +84,15 @@ def natives(self) -> list[str]:

check_2q = ["CZ", "CNOT"]
for gate in check_2q:
if gate in natives and any(
not self._is_gate_calibrated(getattr(gates, gate)(*pair), compiler)
for pair in self.connectivity
):
natives.remove(gate)
if gate in natives:
for pair in self.connectivity:
logical_pair = [list(self.platform.qubits).index(q) for q in pair]
if self._is_gate_calibrated(
getattr(gates, gate)(*logical_pair), compiler
):
break
else:
natives.remove(gate)
return natives

def _is_gate_calibrated(self, gate, compiler) -> bool:
Expand Down
1 change: 1 addition & 0 deletions tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def test_natives():
"RZ",
"U3",
"CZ",
"CNOT",
"GPI2",
"GPI",
"M",
Expand Down

0 comments on commit d9ac1b3

Please sign in to comment.