From d9ac1b3bb0aff87e13d677830fb1516945c78be4 Mon Sep 17 00:00:00 2001 From: changsookim <> Date: Thu, 24 Oct 2024 11:28:40 +0400 Subject: [PATCH] fix: natives() return any available gate --- src/qibolab/backends.py | 28 +++++++++++++++++++++++----- tests/test_backends.py | 1 + 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/qibolab/backends.py b/src/qibolab/backends.py index 09e984746..823e22b73 100644 --- a/src/qibolab/backends.py +++ b/src/qibolab/backends.py @@ -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.""" @@ -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: diff --git a/tests/test_backends.py b/tests/test_backends.py index 94a01887a..d3effec88 100644 --- a/tests/test_backends.py +++ b/tests/test_backends.py @@ -53,6 +53,7 @@ def test_natives(): "RZ", "U3", "CZ", + "CNOT", "GPI2", "GPI", "M",