Skip to content

Commit 5828147

Browse files
authored
Fix __len__ of empty Product sweep to match actual length (#6575)
1 parent 3ff41a4 commit 5828147

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

cirq-core/cirq/study/sweeps.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,6 @@ def keys(self) -> List['cirq.TParamKey']:
236236
return sum((factor.keys for factor in self.factors), [])
237237

238238
def __len__(self) -> int:
239-
if not self.factors:
240-
return 0
241239
length = 1
242240
for factor in self.factors:
243241
length *= len(factor)

cirq-core/cirq/study/sweeps_test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ def test_product():
142142
assert _values(sweep, 'b') == [4, 5, 6, 7, 4, 5, 6, 7, 4, 5, 6, 7]
143143

144144

145+
def test_empty_product():
146+
sweep = cirq.Product()
147+
assert len(sweep) == len(list(sweep)) == 1
148+
149+
145150
def test_slice_access_error():
146151
sweep = cirq.Points('a', [1, 2, 3])
147152
with pytest.raises(TypeError, match='<class \'str\'>'):

0 commit comments

Comments
 (0)