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 |
pavoljuhas
left a comment
There was a problem hiding this comment.
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])) |
There was a problem hiding this comment.
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
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
There was a problem hiding this comment.
Changed to use 'is not Zip' and also changed the test to use Cirq's equality tester.
pavoljuhas
left a comment
There was a problem hiding this comment.
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.