Skip to content

Commit 05b57e9

Browse files
authored
Merge pull request #1504 from qiboteam/bug/no_natives
Unsupported native gates
2 parents f37c024 + 23423a9 commit 05b57e9

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/qibo/transpiler/unroller.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from qibo import gates
66
from qibo.backends import _check_backend
7-
from qibo.config import raise_error
7+
from qibo.config import log, raise_error
88
from qibo.models import Circuit
99
from qibo.transpiler._exceptions import DecompositionError
1010
from qibo.transpiler.decompositions import (
@@ -22,7 +22,10 @@ class FlagMeta(EnumMeta):
2222

2323
def __getitem__(cls, keys):
2424
if isinstance(keys, str):
25-
return super().__getitem__(keys)
25+
try:
26+
return super().__getitem__(keys)
27+
except KeyError:
28+
return super().__getitem__("NONE")
2629
return reduce(or_, [cls[key] for key in keys]) # pylint: disable=E1136
2730

2831

@@ -44,6 +47,7 @@ class NativeGates(Flag, metaclass=FlagMeta):
4447
- :class:`qibo.gates.gates.CNOT`
4548
"""
4649

50+
NONE = 0
4751
I = auto()
4852
Z = auto()
4953
RZ = auto()

tests/test_transpiler_unroller.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ def test_native_gate_str_list():
2727
for gate in testlist:
2828
assert NativeGates[gate] in natives
2929

30-
with pytest.raises(KeyError):
31-
NativeGates[["qi", "bo"]] # Invalid gate names
30+
natives = NativeGates[["qi", "bo"]] # Invalid gate names
31+
assert natives == NativeGates(0)
3232

3333

3434
def test_translate_gate_error_1q():

0 commit comments

Comments
 (0)