cirq-core 1.6.0.dev20250516060316__py3-none-any.whl → 1.6.0.dev20250516154249__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of cirq-core might be problematic. Click here for more details.
- cirq/_import_test.py +2 -2
- cirq/_version.py +1 -1
- cirq/_version_test.py +1 -1
- cirq/interop/quirk/cells/parse_test.py +10 -10
- cirq/testing/equals_tester_test.py +19 -17
- cirq/value/random_state_test.py +3 -3
- cirq/value/timestamp.py +4 -0
- cirq/value/timestamp_test.py +10 -10
- cirq/vis/density_matrix_test.py +17 -17
- cirq/work/collector_test.py +13 -10
- cirq/work/observable_measurement.py +14 -2
- cirq/work/observable_measurement_data.py +3 -3
- cirq/work/observable_measurement_test.py +43 -27
- cirq/work/observable_settings.py +2 -12
- cirq/work/observable_settings_test.py +7 -7
- cirq/work/pauli_sum_collector_test.py +7 -9
- cirq/work/sampler_test.py +25 -22
- {cirq_core-1.6.0.dev20250516060316.dist-info → cirq_core-1.6.0.dev20250516154249.dist-info}/METADATA +1 -1
- {cirq_core-1.6.0.dev20250516060316.dist-info → cirq_core-1.6.0.dev20250516154249.dist-info}/RECORD +22 -22
- {cirq_core-1.6.0.dev20250516060316.dist-info → cirq_core-1.6.0.dev20250516154249.dist-info}/WHEEL +0 -0
- {cirq_core-1.6.0.dev20250516060316.dist-info → cirq_core-1.6.0.dev20250516154249.dist-info}/licenses/LICENSE +0 -0
- {cirq_core-1.6.0.dev20250516060316.dist-info → cirq_core-1.6.0.dev20250516154249.dist-info}/top_level.txt +0 -0
cirq/_import_test.py
CHANGED
|
@@ -17,9 +17,9 @@ from __future__ import annotations
|
|
|
17
17
|
from cirq import _import
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
def test_lazy_loader():
|
|
20
|
+
def test_lazy_loader() -> None:
|
|
21
21
|
linalg = _import.LazyLoader("linalg", globals(), "scipy.linalg")
|
|
22
|
-
linalg.fun = 1
|
|
22
|
+
linalg.fun = 1 # type: ignore[attr-defined]
|
|
23
23
|
assert linalg._module is None
|
|
24
24
|
assert "linalg" not in linalg.__dict__
|
|
25
25
|
|
cirq/_version.py
CHANGED
cirq/_version_test.py
CHANGED
|
@@ -19,7 +19,7 @@ import sympy
|
|
|
19
19
|
from cirq.interop.quirk.cells.parse import parse_complex, parse_formula, parse_matrix
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
def test_parse_matrix():
|
|
22
|
+
def test_parse_matrix() -> None:
|
|
23
23
|
s = np.sqrt(0.5)
|
|
24
24
|
np.testing.assert_allclose(
|
|
25
25
|
parse_matrix('{{√½,√½},{-√½,√½}}'), np.array([[s, s], [-s, s]]), atol=1e-8
|
|
@@ -32,7 +32,7 @@ def test_parse_matrix():
|
|
|
32
32
|
)
|
|
33
33
|
|
|
34
34
|
|
|
35
|
-
def test_parse_matrix_failures():
|
|
35
|
+
def test_parse_matrix_failures() -> None:
|
|
36
36
|
with pytest.raises(ValueError, match='Not surrounded by {{}}'):
|
|
37
37
|
_ = parse_matrix('1')
|
|
38
38
|
with pytest.raises(ValueError, match='Not surrounded by {{}}'):
|
|
@@ -45,7 +45,7 @@ def test_parse_matrix_failures():
|
|
|
45
45
|
_ = parse_matrix('{{x}}')
|
|
46
46
|
|
|
47
47
|
|
|
48
|
-
def test_parse_real_formula():
|
|
48
|
+
def test_parse_real_formula() -> None:
|
|
49
49
|
t = sympy.Symbol('t')
|
|
50
50
|
assert parse_formula('1/2') == 0.5
|
|
51
51
|
assert parse_formula('t*t + ln(t)') == t * t + sympy.ln(t)
|
|
@@ -58,12 +58,12 @@ def test_parse_real_formula():
|
|
|
58
58
|
_ = parse_formula('i')
|
|
59
59
|
|
|
60
60
|
|
|
61
|
-
def test_parse_formula_failures():
|
|
61
|
+
def test_parse_formula_failures() -> None:
|
|
62
62
|
with pytest.raises(TypeError, match='formula must be a string'):
|
|
63
|
-
_ = parse_formula(2)
|
|
63
|
+
_ = parse_formula(2) # type: ignore[arg-type]
|
|
64
64
|
|
|
65
65
|
with pytest.raises(TypeError, match='formula must be a string'):
|
|
66
|
-
_ = parse_formula([])
|
|
66
|
+
_ = parse_formula([]) # type: ignore[arg-type]
|
|
67
67
|
|
|
68
68
|
with pytest.raises(ValueError, match='Unrecognized token'):
|
|
69
69
|
_ = parse_formula('5*__**DSA **)SADD')
|
|
@@ -72,7 +72,7 @@ def test_parse_formula_failures():
|
|
|
72
72
|
_ = parse_formula('5*x')
|
|
73
73
|
|
|
74
74
|
|
|
75
|
-
def test_parse_complex():
|
|
75
|
+
def test_parse_complex() -> None:
|
|
76
76
|
assert parse_complex('0') == 0
|
|
77
77
|
assert parse_complex('1') == 1
|
|
78
78
|
assert parse_complex('i') == 1j
|
|
@@ -84,7 +84,7 @@ def test_parse_complex():
|
|
|
84
84
|
np.testing.assert_allclose(parse_complex('exp 2'), np.e**2, atol=1e-8)
|
|
85
85
|
|
|
86
86
|
|
|
87
|
-
def test_parse_complex_raw_cases_from_quirk():
|
|
87
|
+
def test_parse_complex_raw_cases_from_quirk() -> None:
|
|
88
88
|
assert parse_complex("0") == 0
|
|
89
89
|
assert parse_complex("1") == 1
|
|
90
90
|
assert parse_complex("-1") == -1
|
|
@@ -116,7 +116,7 @@ def test_parse_complex_raw_cases_from_quirk():
|
|
|
116
116
|
np.testing.assert_allclose(parse_complex("2 pi"), 2 * np.pi)
|
|
117
117
|
|
|
118
118
|
|
|
119
|
-
def test_parse_complex_expression_cases_from_quirk():
|
|
119
|
+
def test_parse_complex_expression_cases_from_quirk() -> None:
|
|
120
120
|
np.testing.assert_allclose(parse_complex("1/3"), 1 / 3)
|
|
121
121
|
np.testing.assert_allclose(parse_complex("2/3/5"), (2 / 3) / 5)
|
|
122
122
|
np.testing.assert_allclose(parse_complex("2/3/5*7/13"), ((((2 / 3) / 5)) * 7) / 13)
|
|
@@ -152,7 +152,7 @@ def test_parse_complex_expression_cases_from_quirk():
|
|
|
152
152
|
np.testing.assert_allclose(parse_complex("cos(acos(0.5))"), 0.5, atol=1e-8)
|
|
153
153
|
|
|
154
154
|
|
|
155
|
-
def test_parse_complex_expression_failures():
|
|
155
|
+
def test_parse_complex_expression_failures() -> None:
|
|
156
156
|
with pytest.raises(ValueError, match='Incomplete expression'):
|
|
157
157
|
_ = parse_formula('(')
|
|
158
158
|
with pytest.raises(ValueError, match=r"unmatched '\)'"):
|
|
@@ -19,7 +19,7 @@ import pytest
|
|
|
19
19
|
from cirq.testing.equals_tester import EqualsTester
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
def test_add_equality_group_correct():
|
|
22
|
+
def test_add_equality_group_correct() -> None:
|
|
23
23
|
eq = EqualsTester()
|
|
24
24
|
|
|
25
25
|
eq.add_equality_group(fractions.Fraction(1, 1))
|
|
@@ -39,7 +39,7 @@ def test_add_equality_group_correct():
|
|
|
39
39
|
eq.add_equality_group('unrelated')
|
|
40
40
|
|
|
41
41
|
|
|
42
|
-
def test_assert_make_equality_group():
|
|
42
|
+
def test_assert_make_equality_group() -> None:
|
|
43
43
|
eq = EqualsTester()
|
|
44
44
|
|
|
45
45
|
with pytest.raises(AssertionError, match="can't be in the same"):
|
|
@@ -57,20 +57,20 @@ def test_assert_make_equality_group():
|
|
|
57
57
|
eq.make_equality_group(lambda: 3)
|
|
58
58
|
|
|
59
59
|
|
|
60
|
-
def test_add_equality_group_not_equivalent():
|
|
60
|
+
def test_add_equality_group_not_equivalent() -> None:
|
|
61
61
|
eq = EqualsTester()
|
|
62
62
|
with pytest.raises(AssertionError, match="can't be in the same"):
|
|
63
63
|
eq.add_equality_group(1, 2)
|
|
64
64
|
|
|
65
65
|
|
|
66
|
-
def test_add_equality_group_not_disjoint():
|
|
66
|
+
def test_add_equality_group_not_disjoint() -> None:
|
|
67
67
|
eq = EqualsTester()
|
|
68
68
|
eq.add_equality_group(1)
|
|
69
69
|
with pytest.raises(AssertionError, match="can't be in different"):
|
|
70
70
|
eq.add_equality_group(1)
|
|
71
71
|
|
|
72
72
|
|
|
73
|
-
def test_add_equality_group_bad_hash():
|
|
73
|
+
def test_add_equality_group_bad_hash() -> None:
|
|
74
74
|
class KeyHash:
|
|
75
75
|
def __init__(self, k, h):
|
|
76
76
|
self._k = k
|
|
@@ -94,7 +94,7 @@ def test_add_equality_group_bad_hash():
|
|
|
94
94
|
eq.add_equality_group(KeyHash('c', 2), KeyHash('c', 3))
|
|
95
95
|
|
|
96
96
|
|
|
97
|
-
def test_add_equality_group_exception_hash():
|
|
97
|
+
def test_add_equality_group_exception_hash() -> None:
|
|
98
98
|
class FailHash:
|
|
99
99
|
def __hash__(self):
|
|
100
100
|
raise ValueError('injected failure')
|
|
@@ -104,7 +104,7 @@ def test_add_equality_group_exception_hash():
|
|
|
104
104
|
eq.add_equality_group(FailHash())
|
|
105
105
|
|
|
106
106
|
|
|
107
|
-
def test_fails_when_forgot_type_check():
|
|
107
|
+
def test_fails_when_forgot_type_check() -> None:
|
|
108
108
|
eq = EqualsTester()
|
|
109
109
|
|
|
110
110
|
class NoTypeCheckEqualImplementation:
|
|
@@ -124,11 +124,12 @@ def test_fails_when_forgot_type_check():
|
|
|
124
124
|
eq.add_equality_group(NoTypeCheckEqualImplementation())
|
|
125
125
|
|
|
126
126
|
|
|
127
|
-
def test_fails_when_equal_to_everything():
|
|
127
|
+
def test_fails_when_equal_to_everything() -> None:
|
|
128
128
|
eq = EqualsTester()
|
|
129
129
|
|
|
130
130
|
class AllEqual:
|
|
131
|
-
__hash__
|
|
131
|
+
def __hash__(self) -> int:
|
|
132
|
+
return 0
|
|
132
133
|
|
|
133
134
|
def __eq__(self, other):
|
|
134
135
|
return True
|
|
@@ -136,11 +137,12 @@ def test_fails_when_equal_to_everything():
|
|
|
136
137
|
def __ne__(self, other):
|
|
137
138
|
return False
|
|
138
139
|
|
|
140
|
+
assert hash(AllEqual()) == 0
|
|
139
141
|
with pytest.raises(AssertionError, match="can't be in different"):
|
|
140
142
|
eq.add_equality_group(AllEqual())
|
|
141
143
|
|
|
142
144
|
|
|
143
|
-
def test_fails_hash_is_default_and_inconsistent():
|
|
145
|
+
def test_fails_hash_is_default_and_inconsistent() -> None:
|
|
144
146
|
eq = EqualsTester()
|
|
145
147
|
|
|
146
148
|
class DefaultHashImplementation:
|
|
@@ -161,7 +163,7 @@ def test_fails_hash_is_default_and_inconsistent():
|
|
|
161
163
|
eq.make_equality_group(DefaultHashImplementation)
|
|
162
164
|
|
|
163
165
|
|
|
164
|
-
def test_fails_when_ne_is_inconsistent():
|
|
166
|
+
def test_fails_when_ne_is_inconsistent() -> None:
|
|
165
167
|
eq = EqualsTester()
|
|
166
168
|
|
|
167
169
|
class InconsistentNeImplementation:
|
|
@@ -185,7 +187,7 @@ def test_fails_when_ne_is_inconsistent():
|
|
|
185
187
|
eq.make_equality_group(InconsistentNeImplementation)
|
|
186
188
|
|
|
187
189
|
|
|
188
|
-
def test_fails_when_ne_is_inconsistent_due_to_not_implemented():
|
|
190
|
+
def test_fails_when_ne_is_inconsistent_due_to_not_implemented() -> None:
|
|
189
191
|
eq = EqualsTester()
|
|
190
192
|
|
|
191
193
|
class InconsistentNeImplementation:
|
|
@@ -207,7 +209,7 @@ def test_fails_when_ne_is_inconsistent_due_to_not_implemented():
|
|
|
207
209
|
eq.make_equality_group(InconsistentNeImplementation)
|
|
208
210
|
|
|
209
211
|
|
|
210
|
-
def test_fails_when_not_reflexive():
|
|
212
|
+
def test_fails_when_not_reflexive() -> None:
|
|
211
213
|
eq = EqualsTester()
|
|
212
214
|
|
|
213
215
|
class NotReflexiveImplementation:
|
|
@@ -226,7 +228,7 @@ def test_fails_when_not_reflexive():
|
|
|
226
228
|
eq.add_equality_group(NotReflexiveImplementation())
|
|
227
229
|
|
|
228
230
|
|
|
229
|
-
def test_fails_when_not_commutative():
|
|
231
|
+
def test_fails_when_not_commutative() -> None:
|
|
230
232
|
eq = EqualsTester()
|
|
231
233
|
|
|
232
234
|
class NotCommutativeImplementation:
|
|
@@ -248,14 +250,14 @@ def test_fails_when_not_commutative():
|
|
|
248
250
|
eq.add_equality_group(NotCommutativeImplementation(1), NotCommutativeImplementation(0))
|
|
249
251
|
|
|
250
252
|
|
|
251
|
-
def test_works_on_types():
|
|
253
|
+
def test_works_on_types() -> None:
|
|
252
254
|
eq = EqualsTester()
|
|
253
255
|
eq.add_equality_group(object)
|
|
254
256
|
eq.add_equality_group(int)
|
|
255
257
|
eq.add_equality_group(object())
|
|
256
258
|
|
|
257
259
|
|
|
258
|
-
def test_returns_not_implemented_for_other_types():
|
|
260
|
+
def test_returns_not_implemented_for_other_types() -> None:
|
|
259
261
|
# First we demonstrate an example of the problem.
|
|
260
262
|
|
|
261
263
|
# FirstClass is the class that is broken.
|
|
@@ -323,7 +325,7 @@ def test_returns_not_implemented_for_other_types():
|
|
|
323
325
|
eq.add_equality_group(ThirdClass("a"), ThirdClass("a"))
|
|
324
326
|
|
|
325
327
|
|
|
326
|
-
def test_not_implemented_error():
|
|
328
|
+
def test_not_implemented_error() -> None:
|
|
327
329
|
# Common bug is to return NotImplementedError instead of NotImplemented.
|
|
328
330
|
class NotImplementedErrorCase:
|
|
329
331
|
def __init__(self, val):
|
cirq/value/random_state_test.py
CHANGED
|
@@ -17,7 +17,7 @@ import numpy as np
|
|
|
17
17
|
import cirq
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
def test_parse_random_state():
|
|
20
|
+
def test_parse_random_state() -> None:
|
|
21
21
|
global_state = np.random.get_state()
|
|
22
22
|
|
|
23
23
|
def rand(prng):
|
|
@@ -34,11 +34,11 @@ def test_parse_random_state():
|
|
|
34
34
|
eq.add_equality_group(*vals)
|
|
35
35
|
|
|
36
36
|
seed = np.random.randint(2**31)
|
|
37
|
-
|
|
37
|
+
prngs1 = [
|
|
38
38
|
np.random.RandomState(seed),
|
|
39
39
|
cirq.value.parse_random_state(np.random.RandomState(seed)),
|
|
40
40
|
cirq.value.parse_random_state(seed),
|
|
41
41
|
]
|
|
42
|
-
vals = [prng.rand() for prng in
|
|
42
|
+
vals = [prng.rand() for prng in prngs1]
|
|
43
43
|
eq = cirq.testing.EqualsTester()
|
|
44
44
|
eq.add_equality_group(*vals)
|
cirq/value/timestamp.py
CHANGED
|
@@ -64,6 +64,10 @@ class Timestamp:
|
|
|
64
64
|
def __sub__(self, other: Duration) -> 'Timestamp':
|
|
65
65
|
pass
|
|
66
66
|
|
|
67
|
+
@overload
|
|
68
|
+
def __sub__(self, other: timedelta) -> 'Timestamp':
|
|
69
|
+
pass
|
|
70
|
+
|
|
67
71
|
def __sub__(self, other):
|
|
68
72
|
if isinstance(other, Duration):
|
|
69
73
|
return Timestamp(picos=self._picos - other.total_picos())
|
cirq/value/timestamp_test.py
CHANGED
|
@@ -20,7 +20,7 @@ import cirq
|
|
|
20
20
|
from cirq import Duration, Timestamp
|
|
21
21
|
|
|
22
22
|
|
|
23
|
-
def test_init():
|
|
23
|
+
def test_init() -> None:
|
|
24
24
|
assert Timestamp().raw_picos() == 0
|
|
25
25
|
assert Timestamp(picos=513).raw_picos() == 513
|
|
26
26
|
assert Timestamp(picos=-5).raw_picos() == -5
|
|
@@ -33,13 +33,13 @@ def test_init():
|
|
|
33
33
|
assert isinstance(Timestamp(nanos=1.0).raw_picos(), float)
|
|
34
34
|
|
|
35
35
|
|
|
36
|
-
def test_str():
|
|
36
|
+
def test_str() -> None:
|
|
37
37
|
assert str(Timestamp(picos=1000, nanos=1000)) == 't=1001000'
|
|
38
38
|
assert str(Timestamp(nanos=5.0)) == 't=5000.0'
|
|
39
39
|
assert str(Timestamp(picos=-100)) == 't=-100'
|
|
40
40
|
|
|
41
41
|
|
|
42
|
-
def test_repr():
|
|
42
|
+
def test_repr() -> None:
|
|
43
43
|
a = Timestamp(picos=1000, nanos=1000)
|
|
44
44
|
cirq.testing.assert_equivalent_repr(a)
|
|
45
45
|
b = Timestamp(nanos=5.0)
|
|
@@ -48,14 +48,14 @@ def test_repr():
|
|
|
48
48
|
cirq.testing.assert_equivalent_repr(c)
|
|
49
49
|
|
|
50
50
|
|
|
51
|
-
def test_eq():
|
|
51
|
+
def test_eq() -> None:
|
|
52
52
|
eq = cirq.testing.EqualsTester()
|
|
53
53
|
eq.add_equality_group(Timestamp(), Timestamp(picos=0), Timestamp(nanos=0.0))
|
|
54
54
|
eq.add_equality_group(Timestamp(picos=1000), Timestamp(nanos=1))
|
|
55
55
|
eq.make_equality_group(lambda: Timestamp(picos=-1))
|
|
56
56
|
|
|
57
57
|
|
|
58
|
-
def test_cmp():
|
|
58
|
+
def test_cmp() -> None:
|
|
59
59
|
ordered_groups = [
|
|
60
60
|
Timestamp(picos=-1),
|
|
61
61
|
Timestamp(),
|
|
@@ -81,7 +81,7 @@ def test_cmp():
|
|
|
81
81
|
assert Timestamp() != Duration()
|
|
82
82
|
|
|
83
83
|
|
|
84
|
-
def test_cmp_vs_other_type():
|
|
84
|
+
def test_cmp_vs_other_type() -> None:
|
|
85
85
|
with pytest.raises(TypeError):
|
|
86
86
|
_ = Timestamp() < Duration()
|
|
87
87
|
with pytest.raises(TypeError):
|
|
@@ -94,7 +94,7 @@ def test_cmp_vs_other_type():
|
|
|
94
94
|
_ = Timestamp() > 0
|
|
95
95
|
|
|
96
96
|
|
|
97
|
-
def test_add():
|
|
97
|
+
def test_add() -> None:
|
|
98
98
|
assert Timestamp(picos=1) + Duration(picos=2) == Timestamp(picos=3)
|
|
99
99
|
assert Duration(picos=3) + Timestamp(picos=-5) == Timestamp(picos=-2)
|
|
100
100
|
|
|
@@ -109,7 +109,7 @@ def test_add():
|
|
|
109
109
|
_ = Timestamp() + 1
|
|
110
110
|
|
|
111
111
|
|
|
112
|
-
def test_sub():
|
|
112
|
+
def test_sub() -> None:
|
|
113
113
|
assert Timestamp() - Timestamp() == Duration()
|
|
114
114
|
assert Timestamp(picos=1) - Timestamp(picos=2) == Duration(picos=-1)
|
|
115
115
|
assert Timestamp(picos=5) - Duration(picos=2) == Timestamp(picos=3)
|
|
@@ -118,6 +118,6 @@ def test_sub():
|
|
|
118
118
|
with pytest.raises(TypeError):
|
|
119
119
|
_ = Duration() - Timestamp()
|
|
120
120
|
with pytest.raises(TypeError):
|
|
121
|
-
_ = 1 - Timestamp()
|
|
121
|
+
_ = 1 - Timestamp() # type: ignore[operator]
|
|
122
122
|
with pytest.raises(TypeError):
|
|
123
|
-
_ = Timestamp() - 1
|
|
123
|
+
_ = Timestamp() - 1 # type: ignore[operator]
|
cirq/vis/density_matrix_test.py
CHANGED
|
@@ -24,7 +24,7 @@ from cirq.vis.density_matrix import _plot_element_of_density_matrix, plot_densit
|
|
|
24
24
|
@pytest.mark.usefixtures('closefigures')
|
|
25
25
|
@pytest.mark.parametrize('show_text', [True, False])
|
|
26
26
|
@pytest.mark.parametrize('size', [2, 4, 8, 16])
|
|
27
|
-
def test_density_matrix_plotter(size, show_text):
|
|
27
|
+
def test_density_matrix_plotter(size, show_text) -> None:
|
|
28
28
|
matrix = cirq.testing.random_density_matrix(size)
|
|
29
29
|
# Check that the title shows back up
|
|
30
30
|
ax = plot_density_matrix(matrix, show_text=show_text, title='Test Density Matrix Plot')
|
|
@@ -48,16 +48,16 @@ def test_density_matrix_plotter(size, show_text):
|
|
|
48
48
|
@pytest.mark.usefixtures('closefigures')
|
|
49
49
|
@pytest.mark.parametrize('show_text', [True, False])
|
|
50
50
|
@pytest.mark.parametrize('size', [2, 4, 8, 16])
|
|
51
|
-
def test_density_matrix_circle_rectangle_sizes(size, show_text):
|
|
51
|
+
def test_density_matrix_circle_rectangle_sizes(size, show_text) -> None:
|
|
52
52
|
matrix = cirq.testing.random_density_matrix(size)
|
|
53
53
|
ax = plot_density_matrix(matrix, show_text=show_text, title='Test Density Matrix Plot')
|
|
54
54
|
# Check that the radius of all the circles in the matrix is correct
|
|
55
|
-
|
|
56
|
-
mean_radius = np.mean([c.radius for c in
|
|
55
|
+
circle_list = [c for c in ax.get_children() if isinstance(c, patches.Circle)]
|
|
56
|
+
mean_radius = np.mean([c.radius for c in circle_list if c.fill])
|
|
57
57
|
mean_value = np.mean(np.abs(matrix))
|
|
58
|
-
circles = np.array(
|
|
59
|
-
(
|
|
60
|
-
)
|
|
58
|
+
circles = np.array(
|
|
59
|
+
sorted(circle_list, key=lambda x: (x.fill, x.center[0], -x.center[1]))
|
|
60
|
+
).reshape((2, size, size))
|
|
61
61
|
for i in range(size):
|
|
62
62
|
for j in range(size):
|
|
63
63
|
assert np.isclose(
|
|
@@ -65,15 +65,15 @@ def test_density_matrix_circle_rectangle_sizes(size, show_text):
|
|
|
65
65
|
)
|
|
66
66
|
|
|
67
67
|
# Check that all the rectangles are of the right height, and only on the diagonal elements
|
|
68
|
-
|
|
68
|
+
rect_list = [
|
|
69
69
|
r
|
|
70
70
|
for r in ax.get_children()
|
|
71
71
|
if isinstance(r, patches.Rectangle) and r.get_alpha() is not None
|
|
72
72
|
]
|
|
73
|
-
assert len(
|
|
74
|
-
mean_size = np.mean([r.get_height() for r in
|
|
73
|
+
assert len(rect_list) == size
|
|
74
|
+
mean_size = np.mean([r.get_height() for r in rect_list])
|
|
75
75
|
mean_value = np.trace(np.abs(matrix)) / size
|
|
76
|
-
rects = np.array(sorted(
|
|
76
|
+
rects = np.array(sorted(rect_list, key=lambda x: x.get_x()))
|
|
77
77
|
for i in range(size):
|
|
78
78
|
# Ensuring that the rectangle is the right height
|
|
79
79
|
assert np.isclose(np.abs(matrix[i, i]) * mean_size / mean_value, rects[i].get_height())
|
|
@@ -90,7 +90,7 @@ def test_density_matrix_circle_rectangle_sizes(size, show_text):
|
|
|
90
90
|
@pytest.mark.usefixtures('closefigures')
|
|
91
91
|
@pytest.mark.parametrize('show_text', [True, False])
|
|
92
92
|
@pytest.mark.parametrize('size', [2, 4, 8, 16])
|
|
93
|
-
def test_density_matrix_sizes_upper_bounds(size, show_text):
|
|
93
|
+
def test_density_matrix_sizes_upper_bounds(size, show_text) -> None:
|
|
94
94
|
matrix = cirq.testing.random_density_matrix(size)
|
|
95
95
|
ax = plot_density_matrix(matrix, show_text=show_text, title='Test Density Matrix Plot')
|
|
96
96
|
|
|
@@ -113,7 +113,7 @@ def test_density_matrix_sizes_upper_bounds(size, show_text):
|
|
|
113
113
|
@pytest.mark.usefixtures('closefigures')
|
|
114
114
|
@pytest.mark.parametrize('show_rect', [True, False])
|
|
115
115
|
@pytest.mark.parametrize('value', [0.0, 1.0, 0.5 + 0.3j, 0.2 + 0.1j, 0.5 + 0.5j])
|
|
116
|
-
def test_density_element_plot(value, show_rect):
|
|
116
|
+
def test_density_element_plot(value, show_rect) -> None:
|
|
117
117
|
_, ax = plt.subplots(figsize=(10, 10))
|
|
118
118
|
_plot_element_of_density_matrix(
|
|
119
119
|
ax, 0, 0, np.abs(value), np.angle(value), show_rect=False, show_text=False
|
|
@@ -122,9 +122,9 @@ def test_density_element_plot(value, show_rect):
|
|
|
122
122
|
plotted_lines = [c for c in ax.get_children() if isinstance(c, lines.Line2D)]
|
|
123
123
|
assert len(plotted_lines) == 1
|
|
124
124
|
line_position = plotted_lines[0].get_xydata()
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
)
|
|
125
|
+
numerator = line_position[1, 1] - line_position[0, 1] # type: ignore
|
|
126
|
+
denumerator = line_position[1, 0] - line_position[0, 0] # type: ignore
|
|
127
|
+
angle = np.arctan(numerator / denumerator)
|
|
128
128
|
assert np.isclose(np.angle(value), angle)
|
|
129
129
|
# Check if the circles are the right size ratio, given the value of the element
|
|
130
130
|
circles_in = [c for c in ax.get_children() if isinstance(c, patches.Circle) and c.fill]
|
|
@@ -151,6 +151,6 @@ def test_density_element_plot(value, show_rect):
|
|
|
151
151
|
np.random.random((4, 8)) * np.exp(np.random.random((4, 8)) * 2 * np.pi * 1j),
|
|
152
152
|
],
|
|
153
153
|
)
|
|
154
|
-
def test_density_matrix_type_error(matrix):
|
|
154
|
+
def test_density_matrix_type_error(matrix) -> None:
|
|
155
155
|
with pytest.raises(ValueError, match="Incorrect shape for density matrix:*"):
|
|
156
156
|
plot_density_matrix(matrix)
|
cirq/work/collector_test.py
CHANGED
|
@@ -18,7 +18,7 @@ import pytest
|
|
|
18
18
|
import cirq
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
def test_circuit_sample_job_equality():
|
|
21
|
+
def test_circuit_sample_job_equality() -> None:
|
|
22
22
|
eq = cirq.testing.EqualsTester()
|
|
23
23
|
c1 = cirq.Circuit()
|
|
24
24
|
c2 = cirq.Circuit(cirq.measure(cirq.LineQubit(0)))
|
|
@@ -32,14 +32,14 @@ def test_circuit_sample_job_equality():
|
|
|
32
32
|
eq.add_equality_group(cirq.CircuitSampleJob(c1, repetitions=10, tag='test'))
|
|
33
33
|
|
|
34
34
|
|
|
35
|
-
def test_circuit_sample_job_repr():
|
|
35
|
+
def test_circuit_sample_job_repr() -> None:
|
|
36
36
|
cirq.testing.assert_equivalent_repr(
|
|
37
37
|
cirq.CircuitSampleJob(cirq.Circuit(cirq.H(cirq.LineQubit(0))), repetitions=10, tag='guess')
|
|
38
38
|
)
|
|
39
39
|
|
|
40
40
|
|
|
41
41
|
@duet.sync
|
|
42
|
-
async def test_async_collect():
|
|
42
|
+
async def test_async_collect() -> None:
|
|
43
43
|
received = []
|
|
44
44
|
|
|
45
45
|
class TestCollector(cirq.Collector):
|
|
@@ -51,14 +51,13 @@ async def test_async_collect():
|
|
|
51
51
|
def on_job_result(self, job, result):
|
|
52
52
|
received.append(job.tag)
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
await TestCollector().collect_async(
|
|
55
55
|
sampler=cirq.Simulator(), max_total_samples=100, concurrency=5
|
|
56
56
|
)
|
|
57
|
-
assert result is None
|
|
58
57
|
assert received == ['test'] * 10
|
|
59
58
|
|
|
60
59
|
|
|
61
|
-
def test_collect():
|
|
60
|
+
def test_collect() -> None:
|
|
62
61
|
received = []
|
|
63
62
|
|
|
64
63
|
class TestCollector(cirq.Collector):
|
|
@@ -74,7 +73,7 @@ def test_collect():
|
|
|
74
73
|
assert received == ['test'] * 10
|
|
75
74
|
|
|
76
75
|
|
|
77
|
-
def test_failed_job():
|
|
76
|
+
def test_failed_job() -> None:
|
|
78
77
|
class FailingSampler:
|
|
79
78
|
async def run_async(self, circuit, repetitions):
|
|
80
79
|
await duet.completed_future(None)
|
|
@@ -90,10 +89,14 @@ def test_failed_job():
|
|
|
90
89
|
pass
|
|
91
90
|
|
|
92
91
|
with pytest.raises(Exception, match='job failed!'):
|
|
93
|
-
TestCollector().collect(
|
|
92
|
+
TestCollector().collect(
|
|
93
|
+
sampler=FailingSampler(), # type:ignore
|
|
94
|
+
max_total_samples=100,
|
|
95
|
+
concurrency=5,
|
|
96
|
+
)
|
|
94
97
|
|
|
95
98
|
|
|
96
|
-
def test_collect_with_reaction():
|
|
99
|
+
def test_collect_with_reaction() -> None:
|
|
97
100
|
events = [0]
|
|
98
101
|
sent = 0
|
|
99
102
|
received = 0
|
|
@@ -123,7 +126,7 @@ def test_collect_with_reaction():
|
|
|
123
126
|
assert all(events.index(-k) > events.index(k) for k in range(1, 11))
|
|
124
127
|
|
|
125
128
|
|
|
126
|
-
def test_flatten_jobs_terminate_from_collector():
|
|
129
|
+
def test_flatten_jobs_terminate_from_collector() -> None:
|
|
127
130
|
sent = False
|
|
128
131
|
received = []
|
|
129
132
|
|
|
@@ -20,7 +20,19 @@ import itertools
|
|
|
20
20
|
import os
|
|
21
21
|
import tempfile
|
|
22
22
|
import warnings
|
|
23
|
-
from typing import
|
|
23
|
+
from typing import (
|
|
24
|
+
Any,
|
|
25
|
+
Dict,
|
|
26
|
+
Iterable,
|
|
27
|
+
List,
|
|
28
|
+
Mapping,
|
|
29
|
+
Optional,
|
|
30
|
+
Sequence,
|
|
31
|
+
Set,
|
|
32
|
+
Tuple,
|
|
33
|
+
TYPE_CHECKING,
|
|
34
|
+
Union,
|
|
35
|
+
)
|
|
24
36
|
|
|
25
37
|
import numpy as np
|
|
26
38
|
import pandas as pd
|
|
@@ -246,7 +258,7 @@ def _aggregate_n_repetitions(next_chunk_repetitions: Set[int]) -> int:
|
|
|
246
258
|
|
|
247
259
|
def _check_meas_specs_still_todo(
|
|
248
260
|
meas_specs: List[_MeasurementSpec],
|
|
249
|
-
accumulators:
|
|
261
|
+
accumulators: Mapping[_MeasurementSpec, BitstringAccumulator],
|
|
250
262
|
stopping_criteria: StoppingCriteria,
|
|
251
263
|
) -> Tuple[List[_MeasurementSpec], int]:
|
|
252
264
|
"""Filter `meas_specs` in case some are done.
|
|
@@ -45,7 +45,7 @@ def _check_and_get_real_coef(observable: cirq.PauliString, atol: float):
|
|
|
45
45
|
|
|
46
46
|
def _obs_vals_from_measurements(
|
|
47
47
|
bitstrings: np.ndarray,
|
|
48
|
-
qubit_to_index:
|
|
48
|
+
qubit_to_index: Mapping[cirq.Qid, int],
|
|
49
49
|
observable: cirq.PauliString,
|
|
50
50
|
atol: float,
|
|
51
51
|
):
|
|
@@ -63,7 +63,7 @@ def _obs_vals_from_measurements(
|
|
|
63
63
|
|
|
64
64
|
def _stats_from_measurements(
|
|
65
65
|
bitstrings: np.ndarray,
|
|
66
|
-
qubit_to_index:
|
|
66
|
+
qubit_to_index: Mapping[cirq.Qid, int],
|
|
67
67
|
observable: cirq.PauliString,
|
|
68
68
|
atol: float,
|
|
69
69
|
) -> Tuple[float, float]:
|
|
@@ -216,7 +216,7 @@ class BitstringAccumulator:
|
|
|
216
216
|
self,
|
|
217
217
|
meas_spec: _MeasurementSpec,
|
|
218
218
|
simul_settings: List[InitObsSetting],
|
|
219
|
-
qubit_to_index:
|
|
219
|
+
qubit_to_index: Mapping[cirq.Qid, int],
|
|
220
220
|
bitstrings: Optional[np.ndarray] = None,
|
|
221
221
|
chunksizes: Optional[np.ndarray] = None,
|
|
222
222
|
timestamps: Optional[np.ndarray] = None,
|
|
@@ -16,6 +16,7 @@ from typing import Dict, Iterable, List
|
|
|
16
16
|
|
|
17
17
|
import numpy as np
|
|
18
18
|
import pytest
|
|
19
|
+
import sympy
|
|
19
20
|
|
|
20
21
|
import cirq
|
|
21
22
|
import cirq.work as cw
|
|
@@ -37,7 +38,7 @@ from cirq.work.observable_measurement import (
|
|
|
37
38
|
)
|
|
38
39
|
|
|
39
40
|
|
|
40
|
-
def test_with_parameterized_layers():
|
|
41
|
+
def test_with_parameterized_layers() -> None:
|
|
41
42
|
qs = cirq.LineQubit.range(3)
|
|
42
43
|
circuit = cirq.Circuit([cirq.H.on_each(*qs), cirq.CZ(qs[0], qs[1]), cirq.CZ(qs[1], qs[2])])
|
|
43
44
|
circuit2 = _with_parameterized_layers(circuit, qubits=qs, needs_init_layer=False)
|
|
@@ -46,9 +47,11 @@ def test_with_parameterized_layers():
|
|
|
46
47
|
*_, xlayer, ylayer, measurelayer = circuit2.moments
|
|
47
48
|
for op in xlayer.operations:
|
|
48
49
|
assert isinstance(op.gate, cirq.XPowGate)
|
|
50
|
+
assert isinstance(op.gate.exponent, sympy.Symbol)
|
|
49
51
|
assert op.gate.exponent.name.endswith('-Xf')
|
|
50
52
|
for op in ylayer.operations:
|
|
51
53
|
assert isinstance(op.gate, cirq.YPowGate)
|
|
54
|
+
assert isinstance(op.gate.exponent, sympy.Symbol)
|
|
52
55
|
assert op.gate.exponent.name.endswith('-Yf')
|
|
53
56
|
for op in measurelayer:
|
|
54
57
|
assert isinstance(op.gate, cirq.MeasurementGate)
|
|
@@ -60,13 +63,15 @@ def test_with_parameterized_layers():
|
|
|
60
63
|
xlayer, ylayer, *_ = circuit3.moments
|
|
61
64
|
for op in xlayer.operations:
|
|
62
65
|
assert isinstance(op.gate, cirq.XPowGate)
|
|
66
|
+
assert isinstance(op.gate.exponent, sympy.Symbol)
|
|
63
67
|
assert op.gate.exponent.name.endswith('-Xi')
|
|
64
68
|
for op in ylayer.operations:
|
|
65
69
|
assert isinstance(op.gate, cirq.YPowGate)
|
|
70
|
+
assert isinstance(op.gate.exponent, sympy.Symbol)
|
|
66
71
|
assert op.gate.exponent.name.endswith('-Yi')
|
|
67
72
|
|
|
68
73
|
|
|
69
|
-
def test_get_params_for_setting():
|
|
74
|
+
def test_get_params_for_setting() -> None:
|
|
70
75
|
qubits = cirq.LineQubit.range(3)
|
|
71
76
|
a, b, c = qubits
|
|
72
77
|
|
|
@@ -82,10 +87,10 @@ def test_get_params_for_setting():
|
|
|
82
87
|
needs_init_layer = True
|
|
83
88
|
with pytest.raises(ValueError):
|
|
84
89
|
_get_params_for_setting(
|
|
85
|
-
padded_setting, flips=[
|
|
90
|
+
padded_setting, flips=[False, False], qubits=qubits, needs_init_layer=needs_init_layer
|
|
86
91
|
)
|
|
87
92
|
params = _get_params_for_setting(
|
|
88
|
-
padded_setting, flips=[
|
|
93
|
+
padded_setting, flips=[False, False, True], qubits=qubits, needs_init_layer=needs_init_layer
|
|
89
94
|
)
|
|
90
95
|
assert all(
|
|
91
96
|
x in params
|
|
@@ -116,7 +121,7 @@ def test_get_params_for_setting():
|
|
|
116
121
|
np.testing.assert_allclose([ma, mb, mc], [1, 0, -1])
|
|
117
122
|
|
|
118
123
|
|
|
119
|
-
def test_params_and_settings():
|
|
124
|
+
def test_params_and_settings() -> None:
|
|
120
125
|
qubits = cirq.LineQubit.range(1)
|
|
121
126
|
(q,) = qubits
|
|
122
127
|
tests = [
|
|
@@ -143,7 +148,7 @@ def test_params_and_settings():
|
|
|
143
148
|
assert np.abs(coef - z) < 1e-2, f'{init} {obs} {coef}'
|
|
144
149
|
|
|
145
150
|
|
|
146
|
-
def test_subdivide_meas_specs():
|
|
151
|
+
def test_subdivide_meas_specs() -> None:
|
|
147
152
|
qubits = cirq.LineQubit.range(2)
|
|
148
153
|
q0, q1 = qubits
|
|
149
154
|
setting = cw.InitObsSetting(
|
|
@@ -177,7 +182,7 @@ def test_subdivide_meas_specs():
|
|
|
177
182
|
]
|
|
178
183
|
|
|
179
184
|
|
|
180
|
-
def test_aggregate_n_repetitions():
|
|
185
|
+
def test_aggregate_n_repetitions() -> None:
|
|
181
186
|
with pytest.warns(UserWarning):
|
|
182
187
|
reps = _aggregate_n_repetitions({5, 6})
|
|
183
188
|
assert reps == 6
|
|
@@ -197,7 +202,7 @@ class _MockBitstringAccumulator(BitstringAccumulator):
|
|
|
197
202
|
return cov / len(self.bitstrings)
|
|
198
203
|
|
|
199
204
|
|
|
200
|
-
def test_variance_stopping_criteria():
|
|
205
|
+
def test_variance_stopping_criteria() -> None:
|
|
201
206
|
stop = cw.VarianceStoppingCriteria(variance_bound=1e-6)
|
|
202
207
|
acc = _MockBitstringAccumulator()
|
|
203
208
|
assert stop.more_repetitions(acc) == 10_000
|
|
@@ -222,22 +227,30 @@ class _WildVarianceStoppingCriteria(StoppingCriteria):
|
|
|
222
227
|
return [5, 6][self._state % 2]
|
|
223
228
|
|
|
224
229
|
|
|
225
|
-
def test_variance_stopping_criteria_aggregate_n_repetitions():
|
|
230
|
+
def test_variance_stopping_criteria_aggregate_n_repetitions() -> None:
|
|
231
|
+
q0, q1 = cirq.LineQubit.range(2)
|
|
226
232
|
stop = _WildVarianceStoppingCriteria()
|
|
227
233
|
acc1 = _MockBitstringAccumulator()
|
|
228
234
|
acc2 = _MockBitstringAccumulator()
|
|
229
|
-
|
|
235
|
+
setting = InitObsSetting(
|
|
236
|
+
init_state=cirq.KET_ZERO(q0) * cirq.KET_ZERO(q1), observable=cirq.X(q0) * cirq.Y(q1)
|
|
237
|
+
)
|
|
238
|
+
meas_spec = _MeasurementSpec(
|
|
239
|
+
max_setting=setting, circuit_params={'beta': 0.123, 'gamma': 0.456}
|
|
240
|
+
)
|
|
241
|
+
meas_spec2 = _MeasurementSpec(
|
|
242
|
+
max_setting=setting, circuit_params={'beta': 0.123, 'gamma': 0.456}
|
|
243
|
+
)
|
|
244
|
+
accumulators = {meas_spec: acc1, meas_spec2: acc2}
|
|
230
245
|
with pytest.warns(UserWarning, match='the largest value will be used: 6.'):
|
|
231
246
|
still_todo, reps = _check_meas_specs_still_todo(
|
|
232
|
-
meas_specs=
|
|
233
|
-
accumulators=accumulators,
|
|
234
|
-
stopping_criteria=stop,
|
|
247
|
+
meas_specs=[meas_spec, meas_spec2], accumulators=accumulators, stopping_criteria=stop
|
|
235
248
|
)
|
|
236
|
-
assert still_todo == [
|
|
249
|
+
assert still_todo == [meas_spec, meas_spec2]
|
|
237
250
|
assert reps == 6
|
|
238
251
|
|
|
239
252
|
|
|
240
|
-
def test_repetitions_stopping_criteria():
|
|
253
|
+
def test_repetitions_stopping_criteria() -> None:
|
|
241
254
|
stop = cw.RepetitionsStoppingCriteria(total_repetitions=50_000)
|
|
242
255
|
acc = _MockBitstringAccumulator()
|
|
243
256
|
|
|
@@ -248,7 +261,7 @@ def test_repetitions_stopping_criteria():
|
|
|
248
261
|
assert todos == [10_000] * 5 + [0, 0]
|
|
249
262
|
|
|
250
263
|
|
|
251
|
-
def test_repetitions_stopping_criteria_partial():
|
|
264
|
+
def test_repetitions_stopping_criteria_partial() -> None:
|
|
252
265
|
stop = cw.RepetitionsStoppingCriteria(total_repetitions=5_000, repetitions_per_chunk=1_000_000)
|
|
253
266
|
acc = _MockBitstringAccumulator()
|
|
254
267
|
assert stop.more_repetitions(acc) == 5_000
|
|
@@ -268,7 +281,7 @@ def _set_up_meas_specs_for_testing():
|
|
|
268
281
|
return bsa, meas_spec
|
|
269
282
|
|
|
270
283
|
|
|
271
|
-
def test_meas_specs_still_todo():
|
|
284
|
+
def test_meas_specs_still_todo() -> None:
|
|
272
285
|
bsa, meas_spec = _set_up_meas_specs_for_testing()
|
|
273
286
|
stop = cw.RepetitionsStoppingCriteria(1_000)
|
|
274
287
|
|
|
@@ -296,7 +309,7 @@ def test_meas_specs_still_todo():
|
|
|
296
309
|
assert reps == 0
|
|
297
310
|
|
|
298
311
|
|
|
299
|
-
def test_meas_spec_still_todo_bad_spec():
|
|
312
|
+
def test_meas_spec_still_todo_bad_spec() -> None:
|
|
300
313
|
bsa, meas_spec = _set_up_meas_specs_for_testing()
|
|
301
314
|
|
|
302
315
|
class BadStopping(StoppingCriteria):
|
|
@@ -310,7 +323,7 @@ def test_meas_spec_still_todo_bad_spec():
|
|
|
310
323
|
)
|
|
311
324
|
|
|
312
325
|
|
|
313
|
-
def test_meas_spec_still_todo_too_many_params(monkeypatch):
|
|
326
|
+
def test_meas_spec_still_todo_too_many_params(monkeypatch) -> None:
|
|
314
327
|
monkeypatch.setattr(cw.observable_measurement, 'MAX_REPETITIONS_PER_JOB', 30_000)
|
|
315
328
|
bsa, meas_spec = _set_up_meas_specs_for_testing()
|
|
316
329
|
lots_of_meas_spec = [meas_spec] * 3_001
|
|
@@ -321,7 +334,7 @@ def test_meas_spec_still_todo_too_many_params(monkeypatch):
|
|
|
321
334
|
)
|
|
322
335
|
|
|
323
336
|
|
|
324
|
-
def test_meas_spec_still_todo_lots_of_params(monkeypatch):
|
|
337
|
+
def test_meas_spec_still_todo_lots_of_params(monkeypatch) -> None:
|
|
325
338
|
monkeypatch.setattr(cw.observable_measurement, 'MAX_REPETITIONS_PER_JOB', 30_000)
|
|
326
339
|
bsa, meas_spec = _set_up_meas_specs_for_testing()
|
|
327
340
|
lots_of_meas_spec = [meas_spec] * 4
|
|
@@ -332,7 +345,7 @@ def test_meas_spec_still_todo_lots_of_params(monkeypatch):
|
|
|
332
345
|
)
|
|
333
346
|
|
|
334
347
|
|
|
335
|
-
def test_checkpoint_options():
|
|
348
|
+
def test_checkpoint_options() -> None:
|
|
336
349
|
# There are three ~binary options (the latter two can be either specified or `None`. We
|
|
337
350
|
# test those 2^3 cases.
|
|
338
351
|
|
|
@@ -345,12 +358,15 @@ def test_checkpoint_options():
|
|
|
345
358
|
_parse_checkpoint_options(False, 'test1', 'test2')
|
|
346
359
|
|
|
347
360
|
chk, chkprev = _parse_checkpoint_options(True, None, None)
|
|
361
|
+
assert chk is not None
|
|
362
|
+
assert chkprev is not None
|
|
348
363
|
assert chk.startswith(tempfile.gettempdir())
|
|
349
364
|
assert chk.endswith('observables.json')
|
|
350
365
|
assert chkprev.startswith(tempfile.gettempdir())
|
|
351
366
|
assert chkprev.endswith('observables.prev.json')
|
|
352
367
|
|
|
353
368
|
chk, chkprev = _parse_checkpoint_options(True, None, 'prev.json')
|
|
369
|
+
assert chk is not None
|
|
354
370
|
assert chk.startswith(tempfile.gettempdir())
|
|
355
371
|
assert chk.endswith('observables.json')
|
|
356
372
|
assert chkprev == 'prev.json'
|
|
@@ -381,7 +397,7 @@ def test_checkpoint_options():
|
|
|
381
397
|
|
|
382
398
|
|
|
383
399
|
@pytest.mark.parametrize(('with_circuit_sweep', 'checkpoint'), [(True, True), (False, False)])
|
|
384
|
-
def test_measure_grouped_settings(with_circuit_sweep, checkpoint, tmpdir):
|
|
400
|
+
def test_measure_grouped_settings(with_circuit_sweep, checkpoint, tmpdir) -> None:
|
|
385
401
|
qubits = cirq.LineQubit.range(1)
|
|
386
402
|
(q,) = qubits
|
|
387
403
|
tests = [
|
|
@@ -431,7 +447,7 @@ def _get_some_grouped_settings():
|
|
|
431
447
|
return grouped_settings, qubits
|
|
432
448
|
|
|
433
449
|
|
|
434
|
-
def test_measure_grouped_settings_calibration_validation():
|
|
450
|
+
def test_measure_grouped_settings_calibration_validation() -> None:
|
|
435
451
|
mock_ro_calib = _MockBitstringAccumulator()
|
|
436
452
|
grouped_settings, qubits = _get_some_grouped_settings()
|
|
437
453
|
|
|
@@ -448,7 +464,7 @@ def test_measure_grouped_settings_calibration_validation():
|
|
|
448
464
|
)
|
|
449
465
|
|
|
450
466
|
|
|
451
|
-
def test_measure_grouped_settings_read_checkpoint(tmpdir):
|
|
467
|
+
def test_measure_grouped_settings_read_checkpoint(tmpdir) -> None:
|
|
452
468
|
qubits = cirq.LineQubit.range(1)
|
|
453
469
|
(q,) = qubits
|
|
454
470
|
|
|
@@ -495,7 +511,7 @@ Q = cirq.NamedQubit('q')
|
|
|
495
511
|
(cirq.Circuit(cirq.Y(Q) ** 0.5, cirq.Z(Q) ** 0.2), cirq.X(Q)),
|
|
496
512
|
],
|
|
497
513
|
)
|
|
498
|
-
def test_XYZ_point8(circuit, observable):
|
|
514
|
+
def test_XYZ_point8(circuit, observable) -> None:
|
|
499
515
|
# each circuit, observable combination should result in the observable value of 0.8
|
|
500
516
|
df = measure_observables_df(
|
|
501
517
|
circuit,
|
|
@@ -517,7 +533,7 @@ def _each_in_its_own_group_grouper(
|
|
|
517
533
|
@pytest.mark.parametrize(
|
|
518
534
|
'grouper', ['greedy', group_settings_greedy, _each_in_its_own_group_grouper]
|
|
519
535
|
)
|
|
520
|
-
def test_measure_observable_grouper(grouper):
|
|
536
|
+
def test_measure_observable_grouper(grouper) -> None:
|
|
521
537
|
circuit = cirq.Circuit(cirq.X(Q) ** 0.2)
|
|
522
538
|
observables = [cirq.Z(Q), cirq.Z(cirq.NamedQubit('q2'))]
|
|
523
539
|
results = measure_observables(
|
|
@@ -532,7 +548,7 @@ def test_measure_observable_grouper(grouper):
|
|
|
532
548
|
np.testing.assert_allclose(1, results[1].mean, atol=1e-9)
|
|
533
549
|
|
|
534
550
|
|
|
535
|
-
def test_measure_observable_bad_grouper():
|
|
551
|
+
def test_measure_observable_bad_grouper() -> None:
|
|
536
552
|
circuit = cirq.Circuit(cirq.X(Q) ** 0.2)
|
|
537
553
|
observables = [cirq.Z(Q), cirq.Z(cirq.NamedQubit('q2'))]
|
|
538
554
|
with pytest.raises(ValueError, match=r'Unknown grouping function'):
|
cirq/work/observable_settings.py
CHANGED
|
@@ -16,17 +16,7 @@ from __future__ import annotations
|
|
|
16
16
|
|
|
17
17
|
import dataclasses
|
|
18
18
|
import numbers
|
|
19
|
-
from typing import
|
|
20
|
-
AbstractSet,
|
|
21
|
-
Dict,
|
|
22
|
-
FrozenSet,
|
|
23
|
-
Iterable,
|
|
24
|
-
Mapping,
|
|
25
|
-
Optional,
|
|
26
|
-
Tuple,
|
|
27
|
-
TYPE_CHECKING,
|
|
28
|
-
Union,
|
|
29
|
-
)
|
|
19
|
+
from typing import Dict, FrozenSet, Iterable, Mapping, Optional, Tuple, TYPE_CHECKING, Union
|
|
30
20
|
|
|
31
21
|
import sympy
|
|
32
22
|
|
|
@@ -156,7 +146,7 @@ def _fix_precision(val: Union[value.Scalar, sympy.Expr], precision) -> Union[int
|
|
|
156
146
|
|
|
157
147
|
|
|
158
148
|
def _hashable_param(
|
|
159
|
-
param_tuples:
|
|
149
|
+
param_tuples: Iterable[Tuple[Union[str, sympy.Expr], Union[value.Scalar, sympy.Expr]]],
|
|
160
150
|
precision=1e7,
|
|
161
151
|
) -> FrozenSet[Tuple[str, Union[int, Tuple[int, int]]]]:
|
|
162
152
|
"""Hash circuit parameters using fixed precision.
|
|
@@ -20,7 +20,7 @@ from cirq.work import _MeasurementSpec, InitObsSetting, observables_to_settings
|
|
|
20
20
|
from cirq.work.observable_settings import _hashable_param, _max_weight_observable, _max_weight_state
|
|
21
21
|
|
|
22
22
|
|
|
23
|
-
def test_init_obs_setting():
|
|
23
|
+
def test_init_obs_setting() -> None:
|
|
24
24
|
q0, q1 = cirq.LineQubit.range(2)
|
|
25
25
|
setting = InitObsSetting(
|
|
26
26
|
init_state=cirq.KET_ZERO(q0) * cirq.KET_ZERO(q1), observable=cirq.X(q0) * cirq.Y(q1)
|
|
@@ -32,7 +32,7 @@ def test_init_obs_setting():
|
|
|
32
32
|
setting = InitObsSetting(init_state=cirq.KET_ZERO(q0), observable=cirq.X(q0) * cirq.Y(q1))
|
|
33
33
|
|
|
34
34
|
|
|
35
|
-
def test_max_weight_observable():
|
|
35
|
+
def test_max_weight_observable() -> None:
|
|
36
36
|
q0, q1 = cirq.LineQubit.range(2)
|
|
37
37
|
observables = [cirq.X(q0), cirq.X(q1)]
|
|
38
38
|
assert _max_weight_observable(observables) == cirq.X(q0) * cirq.X(q1)
|
|
@@ -41,7 +41,7 @@ def test_max_weight_observable():
|
|
|
41
41
|
assert _max_weight_observable(observables) is None
|
|
42
42
|
|
|
43
43
|
|
|
44
|
-
def test_max_weight_state():
|
|
44
|
+
def test_max_weight_state() -> None:
|
|
45
45
|
q0, q1 = cirq.LineQubit.range(2)
|
|
46
46
|
states = [cirq.KET_PLUS(q0), cirq.KET_PLUS(q1)]
|
|
47
47
|
assert _max_weight_state(states) == cirq.KET_PLUS(q0) * cirq.KET_PLUS(q1)
|
|
@@ -50,7 +50,7 @@ def test_max_weight_state():
|
|
|
50
50
|
assert _max_weight_state(states) is None
|
|
51
51
|
|
|
52
52
|
|
|
53
|
-
def test_observable_to_setting():
|
|
53
|
+
def test_observable_to_setting() -> None:
|
|
54
54
|
q0, q1, q2 = cirq.LineQubit.range(3)
|
|
55
55
|
observables = [cirq.X(q0) * cirq.Y(q1), cirq.Z(q2) * 1]
|
|
56
56
|
|
|
@@ -62,7 +62,7 @@ def test_observable_to_setting():
|
|
|
62
62
|
assert list(observables_to_settings(observables, qubits=[q0, q1, q2])) == settings_should_be
|
|
63
63
|
|
|
64
64
|
|
|
65
|
-
def test_param_hash():
|
|
65
|
+
def test_param_hash() -> None:
|
|
66
66
|
params1 = [('beta', 1.23), ('gamma', 4.56)]
|
|
67
67
|
params2 = [('beta', 1.23), ('gamma', 4.56)]
|
|
68
68
|
params3 = [('beta', 1.24), ('gamma', 4.57)]
|
|
@@ -81,7 +81,7 @@ def test_param_hash():
|
|
|
81
81
|
assert hash(_hashable_param(params4)) == hash(_hashable_param(params5))
|
|
82
82
|
|
|
83
83
|
|
|
84
|
-
def test_measurement_spec():
|
|
84
|
+
def test_measurement_spec() -> None:
|
|
85
85
|
q0, q1 = cirq.LineQubit.range(2)
|
|
86
86
|
setting = InitObsSetting(
|
|
87
87
|
init_state=cirq.KET_ZERO(q0) * cirq.KET_ZERO(q1), observable=cirq.X(q0) * cirq.Y(q1)
|
|
@@ -96,7 +96,7 @@ def test_measurement_spec():
|
|
|
96
96
|
cirq.testing.assert_equivalent_repr(meas_spec)
|
|
97
97
|
|
|
98
98
|
|
|
99
|
-
def test_measurement_spec_no_symbols():
|
|
99
|
+
def test_measurement_spec_no_symbols() -> None:
|
|
100
100
|
q0, q1 = cirq.LineQubit.range(2)
|
|
101
101
|
setting = InitObsSetting(
|
|
102
102
|
init_state=cirq.KET_ZERO(q0) * cirq.KET_ZERO(q1), observable=cirq.X(q0) * cirq.Y(q1)
|
|
@@ -18,7 +18,7 @@ import cirq
|
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
@duet.sync
|
|
21
|
-
async def test_pauli_string_sample_collector():
|
|
21
|
+
async def test_pauli_string_sample_collector() -> None:
|
|
22
22
|
a, b = cirq.LineQubit.range(2)
|
|
23
23
|
p = cirq.PauliSumCollector(
|
|
24
24
|
circuit=cirq.Circuit(cirq.H(a), cirq.CNOT(a, b), cirq.X(a), cirq.Z(b)),
|
|
@@ -28,26 +28,24 @@ async def test_pauli_string_sample_collector():
|
|
|
28
28
|
+ (1 - 0j),
|
|
29
29
|
samples_per_term=100,
|
|
30
30
|
)
|
|
31
|
-
|
|
32
|
-
assert result is None
|
|
31
|
+
await p.collect_async(sampler=cirq.Simulator())
|
|
33
32
|
energy = p.estimated_energy()
|
|
34
33
|
assert isinstance(energy, float) and energy == 12
|
|
35
34
|
|
|
36
35
|
|
|
37
36
|
@duet.sync
|
|
38
|
-
async def test_pauli_string_sample_single():
|
|
37
|
+
async def test_pauli_string_sample_single() -> None:
|
|
39
38
|
a, b = cirq.LineQubit.range(2)
|
|
40
39
|
p = cirq.PauliSumCollector(
|
|
41
40
|
circuit=cirq.Circuit(cirq.H(a), cirq.CNOT(a, b), cirq.X(a), cirq.Z(b)),
|
|
42
41
|
observable=cirq.X(a) * cirq.X(b),
|
|
43
42
|
samples_per_term=100,
|
|
44
43
|
)
|
|
45
|
-
|
|
46
|
-
assert result is None
|
|
44
|
+
await p.collect_async(sampler=cirq.Simulator())
|
|
47
45
|
assert p.estimated_energy() == -1
|
|
48
46
|
|
|
49
47
|
|
|
50
|
-
def test_pauli_string_sample_collector_identity():
|
|
48
|
+
def test_pauli_string_sample_collector_identity() -> None:
|
|
51
49
|
p = cirq.PauliSumCollector(
|
|
52
50
|
circuit=cirq.Circuit(), observable=cirq.PauliSum() + 2j, samples_per_term=100
|
|
53
51
|
)
|
|
@@ -55,7 +53,7 @@ def test_pauli_string_sample_collector_identity():
|
|
|
55
53
|
assert p.estimated_energy() == 2j
|
|
56
54
|
|
|
57
55
|
|
|
58
|
-
def test_pauli_string_sample_collector_extra_qubit_z():
|
|
56
|
+
def test_pauli_string_sample_collector_extra_qubit_z() -> None:
|
|
59
57
|
a, b = cirq.LineQubit.range(2)
|
|
60
58
|
p = cirq.PauliSumCollector(
|
|
61
59
|
circuit=cirq.Circuit(cirq.H(a)), observable=3 * cirq.Z(b), samples_per_term=100
|
|
@@ -64,7 +62,7 @@ def test_pauli_string_sample_collector_extra_qubit_z():
|
|
|
64
62
|
assert p.estimated_energy() == 3
|
|
65
63
|
|
|
66
64
|
|
|
67
|
-
def test_pauli_string_sample_collector_extra_qubit_x():
|
|
65
|
+
def test_pauli_string_sample_collector_extra_qubit_x() -> None:
|
|
68
66
|
a, b = cirq.LineQubit.range(2)
|
|
69
67
|
p = cirq.PauliSumCollector(
|
|
70
68
|
circuit=cirq.Circuit(cirq.H(a)), observable=3 * cirq.X(b), samples_per_term=10000
|
cirq/work/sampler_test.py
CHANGED
|
@@ -28,7 +28,7 @@ import cirq
|
|
|
28
28
|
|
|
29
29
|
|
|
30
30
|
@duet.sync
|
|
31
|
-
async def test_run_async():
|
|
31
|
+
async def test_run_async() -> None:
|
|
32
32
|
sim = cirq.Simulator()
|
|
33
33
|
result = await sim.run_async(
|
|
34
34
|
cirq.Circuit(cirq.measure(cirq.GridQubit(0, 0), key='m')), repetitions=10
|
|
@@ -37,7 +37,7 @@ async def test_run_async():
|
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
@duet.sync
|
|
40
|
-
async def test_run_sweep_async():
|
|
40
|
+
async def test_run_sweep_async() -> None:
|
|
41
41
|
sim = cirq.Simulator()
|
|
42
42
|
results = await sim.run_sweep_async(
|
|
43
43
|
cirq.Circuit(cirq.measure(cirq.GridQubit(0, 0), key='m')),
|
|
@@ -50,7 +50,7 @@ async def test_run_sweep_async():
|
|
|
50
50
|
|
|
51
51
|
|
|
52
52
|
@duet.sync
|
|
53
|
-
async def test_sampler_async_fail():
|
|
53
|
+
async def test_sampler_async_fail() -> None:
|
|
54
54
|
class FailingSampler(cirq.Sampler):
|
|
55
55
|
def run_sweep(self, program, params, repetitions: int = 1):
|
|
56
56
|
raise ValueError('test')
|
|
@@ -62,7 +62,7 @@ async def test_sampler_async_fail():
|
|
|
62
62
|
await FailingSampler().run_sweep_async(cirq.Circuit(), repetitions=1, params=None)
|
|
63
63
|
|
|
64
64
|
|
|
65
|
-
def test_run_sweep_impl():
|
|
65
|
+
def test_run_sweep_impl() -> None:
|
|
66
66
|
"""Test run_sweep implemented in terms of run_sweep_async."""
|
|
67
67
|
|
|
68
68
|
class AsyncSampler(cirq.Sampler):
|
|
@@ -81,7 +81,7 @@ def test_run_sweep_impl():
|
|
|
81
81
|
|
|
82
82
|
|
|
83
83
|
@duet.sync
|
|
84
|
-
async def test_run_sweep_async_impl():
|
|
84
|
+
async def test_run_sweep_async_impl() -> None:
|
|
85
85
|
"""Test run_sweep_async implemented in terms of run_sweep."""
|
|
86
86
|
|
|
87
87
|
class SyncSampler(cirq.Sampler):
|
|
@@ -98,7 +98,7 @@ async def test_run_sweep_async_impl():
|
|
|
98
98
|
np.testing.assert_equal(result.records['m'], np.zeros((10, 1, 1)))
|
|
99
99
|
|
|
100
100
|
|
|
101
|
-
def test_sampler_sample_multiple_params():
|
|
101
|
+
def test_sampler_sample_multiple_params() -> None:
|
|
102
102
|
a, b = cirq.LineQubit.range(2)
|
|
103
103
|
s = sympy.Symbol('s')
|
|
104
104
|
t = sympy.Symbol('t')
|
|
@@ -132,7 +132,7 @@ def test_sampler_sample_multiple_params():
|
|
|
132
132
|
)
|
|
133
133
|
|
|
134
134
|
|
|
135
|
-
def test_sampler_sample_sweep():
|
|
135
|
+
def test_sampler_sample_sweep() -> None:
|
|
136
136
|
a = cirq.LineQubit(0)
|
|
137
137
|
t = sympy.Symbol('t')
|
|
138
138
|
sampler = cirq.Simulator()
|
|
@@ -158,7 +158,7 @@ def test_sampler_sample_sweep():
|
|
|
158
158
|
)
|
|
159
159
|
|
|
160
160
|
|
|
161
|
-
def test_sampler_sample_no_params():
|
|
161
|
+
def test_sampler_sample_no_params() -> None:
|
|
162
162
|
a, b = cirq.LineQubit.range(2)
|
|
163
163
|
sampler = cirq.Simulator()
|
|
164
164
|
circuit = cirq.Circuit(cirq.X(a), cirq.measure(a, b, key='out'))
|
|
@@ -168,7 +168,7 @@ def test_sampler_sample_no_params():
|
|
|
168
168
|
)
|
|
169
169
|
|
|
170
170
|
|
|
171
|
-
def test_sampler_sample_inconsistent_keys():
|
|
171
|
+
def test_sampler_sample_inconsistent_keys() -> None:
|
|
172
172
|
q = cirq.LineQubit(0)
|
|
173
173
|
sampler = cirq.Simulator()
|
|
174
174
|
circuit = cirq.Circuit(cirq.measure(q, key='out'))
|
|
@@ -177,7 +177,7 @@ def test_sampler_sample_inconsistent_keys():
|
|
|
177
177
|
|
|
178
178
|
|
|
179
179
|
@duet.sync
|
|
180
|
-
async def test_sampler_async_not_run_inline():
|
|
180
|
+
async def test_sampler_async_not_run_inline() -> None:
|
|
181
181
|
ran = False
|
|
182
182
|
|
|
183
183
|
class S(cirq.Sampler):
|
|
@@ -192,7 +192,7 @@ async def test_sampler_async_not_run_inline():
|
|
|
192
192
|
assert ran
|
|
193
193
|
|
|
194
194
|
|
|
195
|
-
def test_sampler_run_batch():
|
|
195
|
+
def test_sampler_run_batch() -> None:
|
|
196
196
|
sampler = cirq.ZerosSampler()
|
|
197
197
|
a = cirq.LineQubit(0)
|
|
198
198
|
circuit1 = cirq.Circuit(cirq.X(a) ** sympy.Symbol('t'), cirq.measure(a, key='m'))
|
|
@@ -215,7 +215,7 @@ def test_sampler_run_batch():
|
|
|
215
215
|
|
|
216
216
|
|
|
217
217
|
@duet.sync
|
|
218
|
-
async def test_run_batch_async_calls_run_sweep_asynchronously():
|
|
218
|
+
async def test_run_batch_async_calls_run_sweep_asynchronously() -> None:
|
|
219
219
|
"""Test run_batch_async calls run_sweep_async without waiting."""
|
|
220
220
|
finished = []
|
|
221
221
|
a = cirq.LineQubit(0)
|
|
@@ -241,7 +241,7 @@ async def test_run_batch_async_calls_run_sweep_asynchronously():
|
|
|
241
241
|
assert finished == list(reversed(params_list))
|
|
242
242
|
|
|
243
243
|
|
|
244
|
-
def test_sampler_run_batch_default_params_and_repetitions():
|
|
244
|
+
def test_sampler_run_batch_default_params_and_repetitions() -> None:
|
|
245
245
|
sampler = cirq.ZerosSampler()
|
|
246
246
|
a = cirq.LineQubit(0)
|
|
247
247
|
circuit1 = cirq.Circuit(cirq.X(a), cirq.measure(a, key='m'))
|
|
@@ -256,7 +256,7 @@ def test_sampler_run_batch_default_params_and_repetitions():
|
|
|
256
256
|
assert result.measurements == {'m': np.array([[0]], dtype='uint8')}
|
|
257
257
|
|
|
258
258
|
|
|
259
|
-
def test_sampler_run_batch_bad_input_lengths():
|
|
259
|
+
def test_sampler_run_batch_bad_input_lengths() -> None:
|
|
260
260
|
sampler = cirq.ZerosSampler()
|
|
261
261
|
a = cirq.LineQubit(0)
|
|
262
262
|
circuit1 = cirq.Circuit(cirq.X(a) ** sympy.Symbol('t'), cirq.measure(a, key='m'))
|
|
@@ -271,7 +271,7 @@ def test_sampler_run_batch_bad_input_lengths():
|
|
|
271
271
|
)
|
|
272
272
|
|
|
273
273
|
|
|
274
|
-
def test_sampler_simple_sample_expectation_values():
|
|
274
|
+
def test_sampler_simple_sample_expectation_values() -> None:
|
|
275
275
|
a = cirq.LineQubit(0)
|
|
276
276
|
sampler = cirq.Simulator()
|
|
277
277
|
circuit = cirq.Circuit(cirq.H(a))
|
|
@@ -281,7 +281,7 @@ def test_sampler_simple_sample_expectation_values():
|
|
|
281
281
|
assert np.allclose(results, [[1]])
|
|
282
282
|
|
|
283
283
|
|
|
284
|
-
def test_sampler_sample_expectation_values_calculation():
|
|
284
|
+
def test_sampler_sample_expectation_values_calculation() -> None:
|
|
285
285
|
class DeterministicImbalancedStateSampler(cirq.Sampler):
|
|
286
286
|
"""A simple, deterministic mock sampler.
|
|
287
287
|
Pretends to sample from a state vector with a 3:1 balance between the
|
|
@@ -311,7 +311,7 @@ def test_sampler_sample_expectation_values_calculation():
|
|
|
311
311
|
assert np.allclose(results, [[0.5]])
|
|
312
312
|
|
|
313
313
|
|
|
314
|
-
def test_sampler_sample_expectation_values_multi_param():
|
|
314
|
+
def test_sampler_sample_expectation_values_multi_param() -> None:
|
|
315
315
|
a = cirq.LineQubit(0)
|
|
316
316
|
t = sympy.Symbol('t')
|
|
317
317
|
sampler = cirq.Simulator(seed=1)
|
|
@@ -324,20 +324,23 @@ def test_sampler_sample_expectation_values_multi_param():
|
|
|
324
324
|
assert np.allclose(results, [[1], [-1], [1]])
|
|
325
325
|
|
|
326
326
|
|
|
327
|
-
def test_sampler_sample_expectation_values_complex_param():
|
|
327
|
+
def test_sampler_sample_expectation_values_complex_param() -> None:
|
|
328
328
|
a = cirq.LineQubit(0)
|
|
329
329
|
t = sympy.Symbol('t')
|
|
330
330
|
sampler = cirq.Simulator(seed=1)
|
|
331
331
|
circuit = cirq.Circuit(cirq.global_phase_operation(t))
|
|
332
332
|
obs = cirq.Z(a)
|
|
333
333
|
results = sampler.sample_expectation_values(
|
|
334
|
-
circuit,
|
|
334
|
+
circuit,
|
|
335
|
+
[obs],
|
|
336
|
+
num_samples=5,
|
|
337
|
+
params=cirq.Points('t', [1, 1j, (1 + 1j) / np.sqrt(2)]), # type: ignore[list-item]
|
|
335
338
|
)
|
|
336
339
|
|
|
337
340
|
assert np.allclose(results, [[1], [1], [1]])
|
|
338
341
|
|
|
339
342
|
|
|
340
|
-
def test_sampler_sample_expectation_values_multi_qubit():
|
|
343
|
+
def test_sampler_sample_expectation_values_multi_qubit() -> None:
|
|
341
344
|
q = cirq.LineQubit.range(3)
|
|
342
345
|
sampler = cirq.Simulator(seed=1)
|
|
343
346
|
circuit = cirq.Circuit(cirq.X(q[0]), cirq.X(q[1]), cirq.X(q[2]))
|
|
@@ -347,7 +350,7 @@ def test_sampler_sample_expectation_values_multi_qubit():
|
|
|
347
350
|
assert np.allclose(results, [[-3]])
|
|
348
351
|
|
|
349
352
|
|
|
350
|
-
def test_sampler_sample_expectation_values_composite():
|
|
353
|
+
def test_sampler_sample_expectation_values_composite() -> None:
|
|
351
354
|
# Tests multi-{param,qubit} sampling together in one circuit.
|
|
352
355
|
q = cirq.LineQubit.range(3)
|
|
353
356
|
t = [sympy.Symbol(f't{x}') for x in range(3)]
|
|
@@ -376,7 +379,7 @@ def test_sampler_sample_expectation_values_composite():
|
|
|
376
379
|
)
|
|
377
380
|
|
|
378
381
|
|
|
379
|
-
def test_sampler_simple_sample_expectation_requirements():
|
|
382
|
+
def test_sampler_simple_sample_expectation_requirements() -> None:
|
|
380
383
|
a = cirq.LineQubit(0)
|
|
381
384
|
sampler = cirq.Simulator(seed=1)
|
|
382
385
|
circuit = cirq.Circuit(cirq.H(a))
|
{cirq_core-1.6.0.dev20250516060316.dist-info → cirq_core-1.6.0.dev20250516154249.dist-info}/METADATA
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cirq-core
|
|
3
|
-
Version: 1.6.0.
|
|
3
|
+
Version: 1.6.0.dev20250516154249
|
|
4
4
|
Summary: A framework for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits.
|
|
5
5
|
Home-page: http://github.com/quantumlib/cirq
|
|
6
6
|
Author: The Cirq Developers
|
{cirq_core-1.6.0.dev20250516060316.dist-info → cirq_core-1.6.0.dev20250516154249.dist-info}/RECORD
RENAMED
|
@@ -3,9 +3,9 @@ cirq/_compat.py,sha256=WAe4w7ZvaLlmn5J-YQMoHNwlosFaTUW6XiI1bXhPCrA,29569
|
|
|
3
3
|
cirq/_compat_test.py,sha256=t51ZXkEuomg1SMI871Ws-5pk68DGBsAf2TGNjVXtZ8I,34755
|
|
4
4
|
cirq/_doc.py,sha256=GlE8YPG5aEuA_TNMQMvqS6Pd8654akVJavUnNngtWUg,2915
|
|
5
5
|
cirq/_import.py,sha256=bXzIRteBSrBl6D5KBIMP0uE8T-jjwMAgoF8yTC03tSc,8457
|
|
6
|
-
cirq/_import_test.py,sha256=
|
|
7
|
-
cirq/_version.py,sha256=
|
|
8
|
-
cirq/_version_test.py,sha256=
|
|
6
|
+
cirq/_import_test.py,sha256=oF4izzOVZLc7NZ0aZHFcGv-r01eiFFt_JORx_x7_D4s,1089
|
|
7
|
+
cirq/_version.py,sha256=WSIwZgUQEbYEPZoFmf0OjrFqsw7VpCbcC620BKjTZqY,1206
|
|
8
|
+
cirq/_version_test.py,sha256=0xhiwZjQOG9e_f2WcSSRHNd3f048dCQTYPqqtsMdPWQ,155
|
|
9
9
|
cirq/conftest.py,sha256=X7yLFL8GLhg2CjPw0hp5e_dGASfvHx1-QT03aUbhKJw,1168
|
|
10
10
|
cirq/json_resolver_cache.py,sha256=-4KqEEYb6aps-seafnFTHTp3SZc0D8mr4O-pCKIajn8,13653
|
|
11
11
|
cirq/py.typed,sha256=VFSlmh_lNwnaXzwY-ZuW-C2Ws5PkuDoVgBdNCs0jXJE,63
|
|
@@ -237,7 +237,7 @@ cirq/interop/quirk/cells/input_rotation_cells_test.py,sha256=6UhV6T5Os3omTDGNy8v
|
|
|
237
237
|
cirq/interop/quirk/cells/measurement_cells.py,sha256=_6a6jm-EP9khPm2eZZu2ArlTdvfLzo1bW7LZ9GFaXVg,1539
|
|
238
238
|
cirq/interop/quirk/cells/measurement_cells_test.py,sha256=guP6XrUdM2gxOhjqc3QyWOSLYpkb9gZOZRPuyC5gPhM,1582
|
|
239
239
|
cirq/interop/quirk/cells/parse.py,sha256=Ilyzz9rbe9XYExVlj4rcJsrIWN4TnAj6LlVl37S9MO8,11873
|
|
240
|
-
cirq/interop/quirk/cells/parse_test.py,sha256=
|
|
240
|
+
cirq/interop/quirk/cells/parse_test.py,sha256=zmhvD08_yU7UMOvmG3i0dTwOIY-Qy9Q4iovpLleAIWA,7589
|
|
241
241
|
cirq/interop/quirk/cells/qubit_permutation_cells.py,sha256=swv_ovLaqO073j-uo6JtII_Sw_Nh51e53tSq-8JREoM,3424
|
|
242
242
|
cirq/interop/quirk/cells/qubit_permutation_cells_test.py,sha256=Yk1zMK1G-M58jph3m9vLwA_ouLbtgoEq0hC2Go-8N88,4516
|
|
243
243
|
cirq/interop/quirk/cells/scalar_cells.py,sha256=rHgoPJX3a9CGFAcjnJJMjc6xIsDTKdGJyGaMXGZYlnc,1281
|
|
@@ -1000,7 +1000,7 @@ cirq/testing/deprecation_test.py,sha256=CtEW1pOd9wALHVU96DNPGrANT9XRm5fF3nFdZBa2
|
|
|
1000
1000
|
cirq/testing/devices.py,sha256=i3v7hOGgblJXxOdZhWeAd-XszsF2PX4-ooTmqUdkAoM,3259
|
|
1001
1001
|
cirq/testing/devices_test.py,sha256=4cqjBi9BhmJpBdUq-nEsrtRYNhIdvTQKYynfA_CoFH8,2885
|
|
1002
1002
|
cirq/testing/equals_tester.py,sha256=3rTAyPAQs-Ocy8v26SzSSjmaqz3ROk0oZw0DpNWaWs0,6587
|
|
1003
|
-
cirq/testing/equals_tester_test.py,sha256=
|
|
1003
|
+
cirq/testing/equals_tester_test.py,sha256=SR0wJuRWFydBkQIAPxbupRHSN43v0HpbqQHD_DwAYeU,10559
|
|
1004
1004
|
cirq/testing/equivalent_basis_map.py,sha256=y9OlbBOWn-AC7l5x4iLfq5T4q8SxaWX_a-__QjL8_p0,2633
|
|
1005
1005
|
cirq/testing/equivalent_basis_map_test.py,sha256=uJ4Uxa7Dmvvgh_FX65jaXXtfTU8afigPg7X7LyI88fs,1503
|
|
1006
1006
|
cirq/testing/equivalent_repr_eval.py,sha256=vM8M9j-kVoxMg5BA1BCfZ3TgjFL5XthO7gXcau6BOak,3378
|
|
@@ -1182,15 +1182,15 @@ cirq/value/probability_test.py,sha256=TyomoRJ97eO0Wcmzc0Dlm7_iqFFTgKetnTwYcbvhL4
|
|
|
1182
1182
|
cirq/value/product_state.py,sha256=C72NlKOkHXhlAeh6Zz2uO1JzZD1p-E67RhU2Hws_8aw,9026
|
|
1183
1183
|
cirq/value/product_state_test.py,sha256=-xEbZ7TCPvkBcveKvDO6FgbPzvqdQCuZndFZK7Gwwjs,5945
|
|
1184
1184
|
cirq/value/random_state.py,sha256=aJ2czSgM7Oiy4lrL4QPWirZy3o7C5MdKn8TDKR-aBVw,2063
|
|
1185
|
-
cirq/value/random_state_test.py,sha256=
|
|
1186
|
-
cirq/value/timestamp.py,sha256=
|
|
1187
|
-
cirq/value/timestamp_test.py,sha256=
|
|
1185
|
+
cirq/value/random_state_test.py,sha256=jfwVpo8Aos4QCGI1Tj_UHj0EJo1zKoD4YkZBroxzyCE,1358
|
|
1186
|
+
cirq/value/timestamp.py,sha256=nVAbM4PaAqu9a67u1wRewcOPC_S_-wn_3dedba20qUc,3688
|
|
1187
|
+
cirq/value/timestamp_test.py,sha256=lewJmgbIclbeKZ-_lbP51yr2BJgTKWzTQlvxy80r_2w,4146
|
|
1188
1188
|
cirq/value/type_alias.py,sha256=bmKOnIIiHbjU4x62QBxAPyvdzsyv9fGyMEBz_ivwBo8,1128
|
|
1189
1189
|
cirq/value/value_equality_attr.py,sha256=ZaCd8VW36yKENuBlmxjbdUp8NZa9wlegJqnE9vTN7G0,10545
|
|
1190
1190
|
cirq/value/value_equality_attr_test.py,sha256=7CO1U7ct4IeloutMygx5SBrQQu9FffhORI0K3eB2-cA,6520
|
|
1191
1191
|
cirq/vis/__init__.py,sha256=YzNrNjIyUiTxKHGzYw92qzOYzx8aXkm2y_1hkfVohtU,1171
|
|
1192
1192
|
cirq/vis/density_matrix.py,sha256=8jadiGKgOG86llpgCahDcBJnWw0IpCooWWREJcNGXP4,4819
|
|
1193
|
-
cirq/vis/density_matrix_test.py,sha256=
|
|
1193
|
+
cirq/vis/density_matrix_test.py,sha256=gsCjGjWVsAgyEdliFqaGKuEWZSwLH-JP0unZ2D7XxYk,7045
|
|
1194
1194
|
cirq/vis/heatmap.py,sha256=zQi8LqyZZUFXKKAzFgyFWPoo5MK51D126ODIqRFhtjg,17765
|
|
1195
1195
|
cirq/vis/heatmap_test.py,sha256=6CEVTaS6jfpdE7EhJIs7D_AXclA0pS_calDAHx0gW2Q,20550
|
|
1196
1196
|
cirq/vis/histogram.py,sha256=Zo4JCkQm7zNqUmae9e4hYd0fFcEY__TXaGl5mNkG-5M,5107
|
|
@@ -1201,25 +1201,25 @@ cirq/vis/vis_utils.py,sha256=CsNHb9vMBF9UjxZ2k5XqMESbATOx0FXhWAwxFbq-9pQ,1239
|
|
|
1201
1201
|
cirq/vis/vis_utils_test.py,sha256=V_41sZlIRzuvmhk_wgDyQl6XyXzEOTSr9CmXWzxnD34,947
|
|
1202
1202
|
cirq/work/__init__.py,sha256=qbw_dKRx_88FxNH_f_CfpVGMrrJKxtjDncx6m7dEWYs,1771
|
|
1203
1203
|
cirq/work/collector.py,sha256=UqvhkMJm4fl4M_Xhc0xI2xc7FlVmMRDwKrQ6N6v-Icc,7870
|
|
1204
|
-
cirq/work/collector_test.py,sha256=
|
|
1204
|
+
cirq/work/collector_test.py,sha256=Vz41CZUvBhp4dKb_V6jW4RegAARQEGt7D5yBMPTSv5s,4968
|
|
1205
1205
|
cirq/work/observable_grouping.py,sha256=Nx-oeih6fCDVxux3E3b6_Q4xDBJaEhzujc9Y2xYX8uY,3492
|
|
1206
1206
|
cirq/work/observable_grouping_test.py,sha256=NzTPw6PD0-jvRRsGj4Q1kmZRj68I9SXbKR_PBr7OZAM,5875
|
|
1207
|
-
cirq/work/observable_measurement.py,sha256=
|
|
1208
|
-
cirq/work/observable_measurement_data.py,sha256=
|
|
1207
|
+
cirq/work/observable_measurement.py,sha256=Y6cl2IJSRoMxdhgbJyMeRoqEJh5aLwDvS61ZD9NkizQ,28364
|
|
1208
|
+
cirq/work/observable_measurement_data.py,sha256=kQxXJaZqU2seYrQ6Zt58XgWC7CZKa7Ws20nYcK41v5w,21195
|
|
1209
1209
|
cirq/work/observable_measurement_data_test.py,sha256=vI_SMbG4riMu0XD0tN9d_Kbq2u73k6kxTWU6Vx_tfOI,19696
|
|
1210
|
-
cirq/work/observable_measurement_test.py,sha256=
|
|
1210
|
+
cirq/work/observable_measurement_test.py,sha256=5nqIYbHcF5AFSWQVDG9A05eyg55mB36n-Cgly_ldI2Q,21046
|
|
1211
1211
|
cirq/work/observable_readout_calibration.py,sha256=XM8pY3lAJqwQSuCqVDhx4P2XeDzk-QC2nXMVlhlDz5s,1921
|
|
1212
1212
|
cirq/work/observable_readout_calibration_test.py,sha256=5XpRIP3VQ1EGtbvnOetElWHIDpKv6d086eyHtAxDeh0,1849
|
|
1213
|
-
cirq/work/observable_settings.py,sha256
|
|
1214
|
-
cirq/work/observable_settings_test.py,sha256=
|
|
1213
|
+
cirq/work/observable_settings.py,sha256=-FTSGTT_Dn-uC619zJMO_F_PJc8Qi3FRmT4TzaKU61Q,6744
|
|
1214
|
+
cirq/work/observable_settings_test.py,sha256=i4BMv74RT_32QPuf8W7pbAFygq_hJtwjUVfaYEglris,4337
|
|
1215
1215
|
cirq/work/pauli_sum_collector.py,sha256=5Ld5nOS6qe5a9ZZzx7rOinFC78FovWpbObMcPg61lFY,4250
|
|
1216
|
-
cirq/work/pauli_sum_collector_test.py,sha256=
|
|
1216
|
+
cirq/work/pauli_sum_collector_test.py,sha256=PG8rO_XyD21Z4pjcWGA3MLgcE8Nvy0H2iDfX6TQZ9D8,2407
|
|
1217
1217
|
cirq/work/sampler.py,sha256=b7O3B8bc77KQb8ReLx7qeF8owP1Qwb5_I-RwC6-M_C8,19118
|
|
1218
|
-
cirq/work/sampler_test.py,sha256=
|
|
1218
|
+
cirq/work/sampler_test.py,sha256=SsMrRvLDYELyOAWLKISjkdEfrBwLYWRsT6D8WrsLM3Q,13533
|
|
1219
1219
|
cirq/work/zeros_sampler.py,sha256=vHCfqkXmUcPkaDuKHlY-UQ71dUHVroEtm_XW51mZpHs,2390
|
|
1220
1220
|
cirq/work/zeros_sampler_test.py,sha256=lQLgQDGBLtfImryys2HzQ2jOSGxHgc7-koVBUhv8qYk,3345
|
|
1221
|
-
cirq_core-1.6.0.
|
|
1222
|
-
cirq_core-1.6.0.
|
|
1223
|
-
cirq_core-1.6.0.
|
|
1224
|
-
cirq_core-1.6.0.
|
|
1225
|
-
cirq_core-1.6.0.
|
|
1221
|
+
cirq_core-1.6.0.dev20250516154249.dist-info/licenses/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
|
|
1222
|
+
cirq_core-1.6.0.dev20250516154249.dist-info/METADATA,sha256=jSyePk9-nEc2wJpPfNOe3UPh7_gxwTGwj3NHqiDalos,4857
|
|
1223
|
+
cirq_core-1.6.0.dev20250516154249.dist-info/WHEEL,sha256=Nw36Djuh_5VDukK0H78QzOX-_FQEo6V37m3nkm96gtU,91
|
|
1224
|
+
cirq_core-1.6.0.dev20250516154249.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
|
|
1225
|
+
cirq_core-1.6.0.dev20250516154249.dist-info/RECORD,,
|
{cirq_core-1.6.0.dev20250516060316.dist-info → cirq_core-1.6.0.dev20250516154249.dist-info}/WHEEL
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|