Skip to content

Commit

Permalink
Fix __len__ of empty Product sweep to match actual length (#6575)
Browse files Browse the repository at this point in the history
  • Loading branch information
maffoo authored Apr 25, 2024
1 parent 3ff41a4 commit 5828147
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
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

0 comments on commit 5828147

Please sign in to comment.