From ea5294ccd7c0b7d740535b65ea03b272b0d56179 Mon Sep 17 00:00:00 2001 From: changsookim <> Date: Tue, 29 Oct 2024 12:20:47 +0400 Subject: [PATCH 1/2] feat: unsupported native gates --- src/qibo/transpiler/unroller.py | 9 +++++++-- tests/test_transpiler_unroller.py | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/qibo/transpiler/unroller.py b/src/qibo/transpiler/unroller.py index ee6e15d0a1..e28cebc0eb 100644 --- a/src/qibo/transpiler/unroller.py +++ b/src/qibo/transpiler/unroller.py @@ -4,7 +4,7 @@ from qibo import gates from qibo.backends import _check_backend -from qibo.config import raise_error +from qibo.config import log, raise_error from qibo.models import Circuit from qibo.transpiler._exceptions import DecompositionError from qibo.transpiler.decompositions import ( @@ -22,7 +22,11 @@ class FlagMeta(EnumMeta): def __getitem__(cls, keys): if isinstance(keys, str): - return super().__getitem__(keys) + try: + return super().__getitem__(keys) + except KeyError: + log.info(f"Native gate {keys} is not supported by qibo.") + return super().__getitem__("NONE") return reduce(or_, [cls[key] for key in keys]) # pylint: disable=E1136 @@ -44,6 +48,7 @@ class NativeGates(Flag, metaclass=FlagMeta): - :class:`qibo.gates.gates.CNOT` """ + NONE = 0 I = auto() Z = auto() RZ = auto() diff --git a/tests/test_transpiler_unroller.py b/tests/test_transpiler_unroller.py index d3aa3e9ba9..e09147b179 100644 --- a/tests/test_transpiler_unroller.py +++ b/tests/test_transpiler_unroller.py @@ -27,8 +27,8 @@ def test_native_gate_str_list(): for gate in testlist: assert NativeGates[gate] in natives - with pytest.raises(KeyError): - NativeGates[["qi", "bo"]] # Invalid gate names + natives = NativeGates[["qi", "bo"]] # Invalid gate names + assert natives == NativeGates(0) def test_translate_gate_error_1q(): From 23423a9b0b45d5acddd839eb19ceac3197c82954 Mon Sep 17 00:00:00 2001 From: changsookim <> Date: Tue, 29 Oct 2024 16:53:08 +0400 Subject: [PATCH 2/2] fix: remove log --- src/qibo/transpiler/unroller.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/qibo/transpiler/unroller.py b/src/qibo/transpiler/unroller.py index e28cebc0eb..17e2e385aa 100644 --- a/src/qibo/transpiler/unroller.py +++ b/src/qibo/transpiler/unroller.py @@ -25,7 +25,6 @@ def __getitem__(cls, keys): try: return super().__getitem__(keys) except KeyError: - log.info(f"Native gate {keys} is not supported by qibo.") return super().__getitem__("NONE") return reduce(or_, [cls[key] for key in keys]) # pylint: disable=E1136