Skip to content

Make BaseDensePauliString an Iterable class #4837

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

Closed
tanujkhattar opened this issue Jan 13, 2022 · 1 comment · Fixed by #4861
Closed

Make BaseDensePauliString an Iterable class #4837

tanujkhattar opened this issue Jan 13, 2022 · 1 comment · Fixed by #4861
Labels
area/gates area/paulis kind/health For CI/testing/release process/refactoring/technical debt items triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on

Comments

@tanujkhattar
Copy link
Collaborator

Description of the issue
BaseDensePauliString already defines a __getitem__ method which works for ints, and hence is already implicitly an iterable. However, mypy doesn't recognize it as an Iterable unless an explicit __iter__ method is defined.

>>> import cirq
>>> from typing import Iterable
>>> m = cirq.DensePauliString("XYZ")
>>> print([p for p in m])
[cirq.X, cirq.Y, cirq.Z]
>>> isinstance(p, Iterable) # Should return true.
False 

We can easily define the __iter__ method as:

    def __iter__(self) -> Iterator['cirq.Gate']:
        for i in range(len(self)):
            yield self[i]

However, this currently breaks a test due to an unfortunate combination of two bugs: #4835 and #4834

Cirq version
0.14.0.dev

@tanujkhattar tanujkhattar added triage/discuss Needs decision / discussion, bring these up during Cirq Cynque kind/health For CI/testing/release process/refactoring/technical debt items labels Jan 13, 2022
@tanujkhattar tanujkhattar added triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on and removed triage/discuss Needs decision / discussion, bring these up during Cirq Cynque labels Jan 19, 2022
@tanujkhattar
Copy link
Collaborator Author

From cirq sync: +1, should be done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/gates area/paulis kind/health For CI/testing/release process/refactoring/technical debt items triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants