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

Add ZipLongest to cirq_google #6074

Merged
merged 4 commits into from
Apr 25, 2023
Merged

Conversation

dstrain115
Copy link
Collaborator

  • This class is similar to cirq.Zip but repeats the last value if the combined sweeps are not the same length.

- This class is similar to cirq.Zip but repeats the
last value if the combined sweeps are not the same
length.
@maffoo
Copy link
Contributor

maffoo commented Apr 21, 2023

Can this go into cirq.study? Seems generally useful and not specific to cirq_google

Copy link
Collaborator

@pavoljuhas pavoljuhas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please see the inline comments

sweep1 = cirq.ZipLongest(cirq.Points('a', [1, 2, 3]), cirq.Points('b', [4, 5, 6, 7]))
sweep2 = cirq.ZipLongest(cirq.Points('a', [1, 2, 3]), cirq.Points('b', [4, 5, 6, 7]))
sweep3 = cirq.ZipLongest(cirq.Points('a', [1, 2]), cirq.Points('b', [4, 5, 6, 7]))
sweep4 = cirq.Zip(cirq.Points('a', [1, 2]), cirq.Points('b', [4, 5, 6, 7]))
Copy link
Collaborator

@pavoljuhas pavoljuhas Apr 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it is, both sweep3 == sweep4 and hash(sweep3) == hash(sweep4) evaluate to True.
Perhaps we need to use a strict type(other) is Zip in the Zip.__eq__ function

def __eq__(self, other):
if not isinstance(other, Zip):
return NotImplemented
return self.sweeps == other.sweeps

and insert ZipLongest or a similar type-marker to the hashed tuple at

def __hash__(self) -> int:
return hash(tuple(self.sweeps))

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to use 'is not Zip' and also changed the test to use Cirq's equality tester.

Copy link
Collaborator

@pavoljuhas pavoljuhas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but I noticed yet another corner case we should clean up.

@dstrain115 dstrain115 added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Apr 25, 2023
@dstrain115 dstrain115 merged commit c1d6451 into quantumlib:master Apr 25, 2023
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this pull request Oct 31, 2024
* Add ZipLongest to cirq_google

- This class is similar to cirq.Zip but repeats the
last value if the combined sweeps are not the same
length.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Tells CirqBot to sync and merge this PR. (If it's running.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants