-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Conversation
dstrain115
commented
Apr 21, 2023
- 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.
Can this go into |
There was a problem hiding this 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
cirq-core/cirq/study/sweeps_test.py
Outdated
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])) |
There was a problem hiding this comment.
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
Cirq/cirq-core/cirq/study/sweeps.py
Lines 294 to 297 in 58d0205
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
Cirq/cirq-core/cirq/study/sweeps.py
Lines 364 to 365 in 58d0205
def __hash__(self) -> int: | |
return hash(tuple(self.sweeps)) |
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
* 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.