Skip to content

Commit

Permalink
Merge pull request #1504 from qiboteam/bug/no_natives
Browse files Browse the repository at this point in the history
Unsupported native gates
  • Loading branch information
csookim authored Nov 4, 2024
2 parents f37c024 + 23423a9 commit 05b57e9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 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,10 @@ class FlagMeta(EnumMeta):

def __getitem__(cls, keys):
if isinstance(keys, str):
return super().__getitem__(keys)
try:
return super().__getitem__(keys)
except KeyError:
return super().__getitem__("NONE")
return reduce(or_, [cls[key] for key in keys]) # pylint: disable=E1136


Expand All @@ -44,6 +47,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 05b57e9

Please sign in to comment.