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

Fix __len__ of empty Product sweep to match actual length #6575

Merged
merged 2 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 0 additions & 2 deletions cirq-core/cirq/study/sweeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,6 @@ def keys(self) -> List['cirq.TParamKey']:
return sum((factor.keys for factor in self.factors), [])

def __len__(self) -> int:
if not self.factors:
return 0
length = 1
for factor in self.factors:
length *= len(factor)
Expand Down
5 changes: 5 additions & 0 deletions cirq-core/cirq/study/sweeps_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ def test_product():
assert _values(sweep, 'b') == [4, 5, 6, 7, 4, 5, 6, 7, 4, 5, 6, 7]


def test_empty_product():
sweep = cirq.Product()
assert len(sweep) == len(list(sweep)) == 1


def test_slice_access_error():
sweep = cirq.Points('a', [1, 2, 3])
with pytest.raises(TypeError, match='<class \'str\'>'):
Expand Down
Loading