Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unsupported native gates #1504

Merged
merged 2 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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