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

Inconsistent ordering of tags #6123

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
only comparing description when given
  • Loading branch information
skushnir123 committed Jun 7, 2023
commit 29c7bfa4a8ee49a822d5d995c8a5106dc8c6a708
7 changes: 4 additions & 3 deletions cirq-core/cirq/ops/gateset.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@ def _default_name(self) -> str:
def _default_description(self) -> str:
check_type = r'g == {}' if isinstance(self.gate, raw_types.Gate) else r'isinstance(g, {})'
tags_to_accept_str = (
f'\nAccepted tags: {sorted(list(self._tags_to_accept))}' if self._tags_to_accept else ''
f'\nAccepted tags: {list(self._tags_to_accept)}' if self._tags_to_accept else ''
)
tags_to_ignore_str = (
f'\nIgnored tags: {sorted(list(self._tags_to_ignore))}' if self._tags_to_ignore else ''
f'\nIgnored tags: {list(self._tags_to_ignore)}' if self._tags_to_ignore else ''
)
return (
f'Accepts `cirq.Gate` instances `g` s.t. `{check_type.format(self._gate_str())}`'
Expand Down Expand Up @@ -257,11 +257,12 @@ def __repr__(self) -> str:

def _value_equality_values_(self) -> Any:
# `isinstance` is used to ensure the a gate type and gate instance is not compared.
description = self.description if self.description != self._default_description() else None
return (
isinstance(self.gate, raw_types.Gate),
self.gate,
self.name,
self.description,
description,
self._ignore_global_phase,
self._tags_to_accept,
self._tags_to_ignore,
Expand Down
10 changes: 7 additions & 3 deletions cirq-core/cirq/ops/gateset_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def test_gate_family_default_name_and_description(gate, tags_to_accept, tags_to_
ignored_match = re.compile('.*Ignored tags.*', re.DOTALL).match(g.description)
assert (ignored_match is None) == (tags_to_ignore == [])


@pytest.mark.parametrize(
'tags_to_accept_fam1, tags_to_ignore_fam1, tags_to_accept_fam2, tags_to_ignore_fam2',
[
Expand All @@ -88,9 +89,12 @@ def test_gate_family_default_name_and_description(gate, tags_to_accept, tags_to_
([], frozenset("qwerty"), [], frozenset("ytrewq")),
],
)
def test_gate_family_equality_with_tags(tags_to_accept_fam1, tags_to_ignore_fam1, tags_to_accept_fam2, tags_to_ignore_fam2):
gate_fam1 = cirq.GateFamily(cirq.X, tags_to_accept=tags_to_accept_fam1, tags_to_ignore=tags_to_ignore_fam1)
gate_fam2 = cirq.GateFamily(cirq.X, tags_to_accept=tags_to_accept_fam2, tags_to_ignore=tags_to_ignore_fam2)
def test_gate_family_equality_with_tags(tags_to_accept_fam1, tags_to_ignore_fam1,
tags_to_accept_fam2, tags_to_ignore_fam2):
gate_fam1 = cirq.GateFamily(cirq.X, tags_to_accept=tags_to_accept_fam1,
tags_to_ignore=tags_to_ignore_fam1)
gate_fam2 = cirq.GateFamily(cirq.X, tags_to_accept=tags_to_accept_fam2,
tags_to_ignore=tags_to_ignore_fam2)

assert gate_fam1 == gate_fam2

Expand Down