Skip to content

Commit

Permalink
feat: unsupported native gates
Browse files Browse the repository at this point in the history
  • Loading branch information
changsookim committed Oct 29, 2024
1 parent a074d17 commit ea5294c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/qibo/transpiler/unroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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


Expand All @@ -44,6 +48,7 @@ class NativeGates(Flag, metaclass=FlagMeta):
- :class:`qibo.gates.gates.CNOT`
"""

NONE = 0
I = auto()
Z = auto()
RZ = auto()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_transpiler_unroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit ea5294c

Please sign in to comment.