Skip to content

Commit

Permalink
Treat default gate families with tags_to_ignore or tags_to_accept as …
Browse files Browse the repository at this point in the history
…custom gate families in Gatesets (quantumlib#5553)

* Treat default gate families with tags_to_ignore or tags_to_accept as custom gate families

* Add more tests and uncomment known_devices_test

* Replace equals with is
  • Loading branch information
tanujkhattar authored Jun 21, 2022
1 parent c1aac6e commit 08f7fa0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
10 changes: 9 additions & 1 deletion cirq/ops/gateset.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,14 @@ def name(self) -> str:
def description(self) -> str:
return self._description

@property
def tags_to_accept(self) -> FrozenSet[Hashable]:
return self._tags_to_accept

@property
def tags_to_ignore(self) -> FrozenSet[Hashable]:
return self._tags_to_ignore

def _predicate(self, gate: raw_types.Gate) -> bool:
"""Checks whether `cirq.Gate` instance `gate` belongs to this GateFamily.
Expand Down Expand Up @@ -370,7 +378,7 @@ def __init__(
)

for g in unique_gate_list:
if type(g) == GateFamily:
if type(g) is GateFamily and not (g.tags_to_ignore or g.tags_to_accept):
if isinstance(g.gate, raw_types.Gate):
self._instance_gate_families[g.gate] = g
else:
Expand Down
20 changes: 20 additions & 0 deletions cirq/ops/gateset_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,3 +416,23 @@ def test_gateset_eq():
)
)
)


def test_gateset_contains_with_tags():
tag = "PhysicalZTag"
gf_accept = cirq.GateFamily(cirq.ZPowGate, tags_to_accept=[tag])
gf_ignore = cirq.GateFamily(cirq.ZPowGate, tags_to_ignore=[tag])
op = cirq.Z(q)
op_with_tag = cirq.Z(q).with_tags(tag)

# Only tags to ignore.
assert op in cirq.Gateset(gf_ignore)
assert op_with_tag not in cirq.Gateset(gf_ignore)

# Only tags to accept
assert op not in cirq.Gateset(gf_accept)
assert op_with_tag in cirq.Gateset(gf_accept)

# Both tags to accept and tags to ignore
assert op in cirq.Gateset(gf_accept, gf_ignore)
assert op_with_tag in cirq.Gateset(gf_accept, gf_ignore)

0 comments on commit 08f7fa0

Please sign in to comment.