cirq-core 1.7.0.dev20250915211227__py3-none-any.whl → 1.7.0.dev20250917002151__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/_version.py +1 -1
- cirq/_version_test.py +1 -1
- cirq/circuits/circuit_operation_test.py +5 -0
- cirq/ops/classically_controlled_operation.py +3 -7
- cirq/ops/measure_util.py +7 -6
- cirq/ops/pauli_string_test.py +2 -2
- cirq/ops/raw_types.py +19 -2
- cirq/protocols/has_stabilizer_effect_protocol_test.py +11 -9
- cirq/protocols/has_unitary_protocol_test.py +3 -3
- cirq/protocols/json_serialization.py +3 -3
- cirq/protocols/json_serialization_test.py +31 -31
- cirq/protocols/kraus_protocol_test.py +5 -5
- cirq/protocols/measurement_key_protocol.py +31 -8
- cirq/protocols/mixture_protocol.py +1 -1
- cirq/protocols/mixture_protocol_test.py +7 -7
- cirq/protocols/mul_protocol_test.py +4 -4
- cirq/protocols/phase_protocol.py +13 -4
- cirq/protocols/pow_protocol_test.py +5 -5
- cirq/protocols/resolve_parameters.py +1 -1
- cirq/protocols/unitary_protocol_test.py +31 -19
- cirq/qis/clifford_tableau.py +14 -14
- cirq/qis/clifford_tableau_test.py +17 -17
- cirq/qis/entropy.py +1 -1
- cirq/qis/entropy_test.py +1 -1
- cirq/qis/states_test.py +54 -54
- cirq/sim/classical_simulator_test.py +56 -28
- cirq/sim/clifford/clifford_simulator.py +5 -5
- cirq/sim/clifford/clifford_simulator_test.py +50 -49
- cirq/sim/clifford/stabilizer_state_ch_form.py +9 -9
- cirq/sim/density_matrix_simulation_state.py +6 -6
- cirq/sim/density_matrix_simulator.py +1 -1
- cirq/sim/density_matrix_simulator_test.py +94 -84
- cirq/sim/density_matrix_utils_test.py +1 -1
- cirq/sim/mux_test.py +26 -26
- cirq/sim/simulation_product_state_test.py +7 -7
- cirq/sim/simulation_state.py +4 -4
- cirq/sim/simulation_state_base.py +1 -1
- cirq/sim/simulation_state_test.py +5 -5
- cirq/sim/simulator.py +2 -2
- cirq/sim/simulator_base_test.py +49 -35
- cirq/sim/simulator_test.py +39 -35
- cirq/sim/sparse_simulator.py +1 -1
- cirq/sim/sparse_simulator_test.py +92 -82
- cirq/sim/state_vector.py +1 -1
- cirq/sim/state_vector_simulation_state.py +7 -7
- cirq/sim/state_vector_simulator_test.py +9 -9
- cirq/sim/state_vector_test.py +37 -37
- cirq/study/result_test.py +20 -20
- cirq/study/sweepable_test.py +20 -20
- cirq/study/sweeps_test.py +43 -43
- cirq/testing/circuit_compare_test.py +16 -14
- cirq/testing/consistent_channels.py +2 -2
- cirq/testing/consistent_controlled_gate_op.py +1 -1
- cirq/testing/consistent_decomposition.py +4 -2
- cirq/testing/consistent_phase_by.py +1 -1
- cirq/testing/consistent_qasm.py +2 -2
- cirq/testing/consistent_qasm_test.py +3 -3
- cirq/transformers/eject_z.py +1 -0
- {cirq_core-1.7.0.dev20250915211227.dist-info → cirq_core-1.7.0.dev20250917002151.dist-info}/METADATA +1 -1
- {cirq_core-1.7.0.dev20250915211227.dist-info → cirq_core-1.7.0.dev20250917002151.dist-info}/RECORD +63 -63
- {cirq_core-1.7.0.dev20250915211227.dist-info → cirq_core-1.7.0.dev20250917002151.dist-info}/WHEEL +0 -0
- {cirq_core-1.7.0.dev20250915211227.dist-info → cirq_core-1.7.0.dev20250917002151.dist-info}/licenses/LICENSE +0 -0
- {cirq_core-1.7.0.dev20250915211227.dist-info → cirq_core-1.7.0.dev20250917002151.dist-info}/top_level.txt +0 -0
cirq/sim/simulator_test.py
CHANGED
|
@@ -56,13 +56,13 @@ class FakeStepResult(cirq.StepResult):
|
|
|
56
56
|
def _simulator_state(self):
|
|
57
57
|
return self._final_state # pragma: no cover
|
|
58
58
|
|
|
59
|
-
def state_vector(self):
|
|
59
|
+
def state_vector(self) -> None:
|
|
60
60
|
pass
|
|
61
61
|
|
|
62
62
|
def __setstate__(self, state):
|
|
63
63
|
pass
|
|
64
64
|
|
|
65
|
-
def sample(self, qubits, repetitions=1, seed=None):
|
|
65
|
+
def sample(self, qubits, repetitions=1, seed=None) -> np.ndarray:
|
|
66
66
|
return np.array([[qubit in self._ones_qubits for qubit in qubits]] * repetitions)
|
|
67
67
|
|
|
68
68
|
|
|
@@ -99,7 +99,7 @@ class SimulatesIntermediateStateImpl(
|
|
|
99
99
|
)
|
|
100
100
|
|
|
101
101
|
|
|
102
|
-
def test_run_simulator_run():
|
|
102
|
+
def test_run_simulator_run() -> None:
|
|
103
103
|
expected_records = {'a': np.array([[[1]]])}
|
|
104
104
|
simulator = FakeSimulatesSamples(expected_records)
|
|
105
105
|
circuit = cirq.Circuit(cirq.measure(cirq.LineQubit(0), key='k'))
|
|
@@ -110,7 +110,7 @@ def test_run_simulator_run():
|
|
|
110
110
|
)
|
|
111
111
|
|
|
112
112
|
|
|
113
|
-
def test_run_simulator_sweeps():
|
|
113
|
+
def test_run_simulator_sweeps() -> None:
|
|
114
114
|
expected_records = {'a': np.array([[[1]]])}
|
|
115
115
|
simulator = FakeSimulatesSamples(expected_records)
|
|
116
116
|
circuit = cirq.Circuit(cirq.measure(cirq.LineQubit(0), key='k'))
|
|
@@ -127,8 +127,8 @@ def test_run_simulator_sweeps():
|
|
|
127
127
|
@mock.patch.multiple(
|
|
128
128
|
SimulatesIntermediateStateImpl, __abstractmethods__=set(), simulate_moment_steps=mock.Mock()
|
|
129
129
|
)
|
|
130
|
-
def test_intermediate_simulator():
|
|
131
|
-
simulator = SimulatesIntermediateStateImpl()
|
|
130
|
+
def test_intermediate_simulator() -> None:
|
|
131
|
+
simulator: SimulatesIntermediateStateImpl = SimulatesIntermediateStateImpl()
|
|
132
132
|
|
|
133
133
|
final_simulator_state = np.array([1, 0, 0, 0])
|
|
134
134
|
|
|
@@ -141,7 +141,7 @@ def test_intermediate_simulator():
|
|
|
141
141
|
result._simulator_state.return_value = final_simulator_state
|
|
142
142
|
yield result
|
|
143
143
|
|
|
144
|
-
simulator.simulate_moment_steps.side_effect = steps
|
|
144
|
+
simulator.simulate_moment_steps.side_effect = steps # type: ignore[attr-defined]
|
|
145
145
|
circuit = mock.Mock(cirq.Circuit)
|
|
146
146
|
param_resolver = cirq.ParamResolver({})
|
|
147
147
|
qubit_order = mock.Mock(cirq.QubitOrder)
|
|
@@ -158,8 +158,8 @@ def test_intermediate_simulator():
|
|
|
158
158
|
@mock.patch.multiple(
|
|
159
159
|
SimulatesIntermediateStateImpl, __abstractmethods__=set(), simulate_moment_steps=mock.Mock()
|
|
160
160
|
)
|
|
161
|
-
def test_intermediate_sweeps():
|
|
162
|
-
simulator = SimulatesIntermediateStateImpl()
|
|
161
|
+
def test_intermediate_sweeps() -> None:
|
|
162
|
+
simulator: SimulatesIntermediateStateImpl = SimulatesIntermediateStateImpl()
|
|
163
163
|
|
|
164
164
|
final_state = np.array([1, 0, 0, 0])
|
|
165
165
|
|
|
@@ -169,7 +169,7 @@ def test_intermediate_sweeps():
|
|
|
169
169
|
result._simulator_state.return_value = final_state
|
|
170
170
|
yield result
|
|
171
171
|
|
|
172
|
-
simulator.simulate_moment_steps.side_effect = steps
|
|
172
|
+
simulator.simulate_moment_steps.side_effect = steps # type: ignore[attr-defined]
|
|
173
173
|
circuit = mock.Mock(cirq.Circuit)
|
|
174
174
|
param_resolvers = [cirq.ParamResolver({}), cirq.ParamResolver({})]
|
|
175
175
|
qubit_order = mock.Mock(cirq.QubitOrder)
|
|
@@ -192,7 +192,7 @@ def test_intermediate_sweeps():
|
|
|
192
192
|
assert results == expected_results
|
|
193
193
|
|
|
194
194
|
|
|
195
|
-
def test_step_sample_measurement_ops():
|
|
195
|
+
def test_step_sample_measurement_ops() -> None:
|
|
196
196
|
q0, q1, q2 = cirq.LineQubit.range(3)
|
|
197
197
|
measurement_ops = [cirq.measure(q0, q1), cirq.measure(q2)]
|
|
198
198
|
step_result = FakeStepResult(ones_qubits=[q1])
|
|
@@ -201,7 +201,7 @@ def test_step_sample_measurement_ops():
|
|
|
201
201
|
np.testing.assert_equal(measurements, {'q(0),q(1)': [[False, True]], 'q(2)': [[False]]})
|
|
202
202
|
|
|
203
203
|
|
|
204
|
-
def test_step_sample_measurement_ops_repetitions():
|
|
204
|
+
def test_step_sample_measurement_ops_repetitions() -> None:
|
|
205
205
|
q0, q1, q2 = cirq.LineQubit.range(3)
|
|
206
206
|
measurement_ops = [cirq.measure(q0, q1), cirq.measure(q2)]
|
|
207
207
|
step_result = FakeStepResult(ones_qubits=[q1])
|
|
@@ -210,7 +210,7 @@ def test_step_sample_measurement_ops_repetitions():
|
|
|
210
210
|
np.testing.assert_equal(measurements, {'q(0),q(1)': [[False, True]] * 3, 'q(2)': [[False]] * 3})
|
|
211
211
|
|
|
212
212
|
|
|
213
|
-
def test_step_sample_measurement_ops_invert_mask():
|
|
213
|
+
def test_step_sample_measurement_ops_invert_mask() -> None:
|
|
214
214
|
q0, q1, q2 = cirq.LineQubit.range(3)
|
|
215
215
|
measurement_ops = [
|
|
216
216
|
cirq.measure(q0, q1, invert_mask=(True,)),
|
|
@@ -222,9 +222,11 @@ def test_step_sample_measurement_ops_invert_mask():
|
|
|
222
222
|
np.testing.assert_equal(measurements, {'q(0),q(1)': [[True, True]], 'q(2)': [[False]]})
|
|
223
223
|
|
|
224
224
|
|
|
225
|
-
def test_step_sample_measurement_ops_confusion_map():
|
|
225
|
+
def test_step_sample_measurement_ops_confusion_map() -> None:
|
|
226
226
|
q0, q1, q2 = cirq.LineQubit.range(3)
|
|
227
|
+
cmap_01: dict[tuple[int, ...], np.ndarray]
|
|
227
228
|
cmap_01 = {(0, 1): np.array([[0, 1, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [0, 0, 1, 0]])}
|
|
229
|
+
cmap_2: dict[tuple[int, ...], np.ndarray]
|
|
228
230
|
cmap_2 = {(0,): np.array([[0, 1], [1, 0]])}
|
|
229
231
|
measurement_ops = [
|
|
230
232
|
cirq.measure(q0, q1, confusion_map=cmap_01),
|
|
@@ -236,21 +238,21 @@ def test_step_sample_measurement_ops_confusion_map():
|
|
|
236
238
|
np.testing.assert_equal(measurements, {'q(0),q(1)': [[False, True]], 'q(2)': [[False]]})
|
|
237
239
|
|
|
238
240
|
|
|
239
|
-
def test_step_sample_measurement_ops_no_measurements():
|
|
241
|
+
def test_step_sample_measurement_ops_no_measurements() -> None:
|
|
240
242
|
step_result = FakeStepResult(ones_qubits=[])
|
|
241
243
|
|
|
242
244
|
measurements = step_result.sample_measurement_ops([])
|
|
243
245
|
assert measurements == {}
|
|
244
246
|
|
|
245
247
|
|
|
246
|
-
def test_step_sample_measurement_ops_not_measurement():
|
|
248
|
+
def test_step_sample_measurement_ops_not_measurement() -> None:
|
|
247
249
|
q0 = cirq.LineQubit(0)
|
|
248
250
|
step_result = FakeStepResult(ones_qubits=[q0])
|
|
249
251
|
with pytest.raises(ValueError, match='MeasurementGate'):
|
|
250
252
|
step_result.sample_measurement_ops([cirq.X(q0)])
|
|
251
253
|
|
|
252
254
|
|
|
253
|
-
def test_step_sample_measurement_ops_repeated_qubit():
|
|
255
|
+
def test_step_sample_measurement_ops_repeated_qubit() -> None:
|
|
254
256
|
q0, q1, q2 = cirq.LineQubit.range(3)
|
|
255
257
|
step_result = FakeStepResult(ones_qubits=[q0])
|
|
256
258
|
with pytest.raises(ValueError, match=r'Measurement key q\(0\) repeated'):
|
|
@@ -259,7 +261,7 @@ def test_step_sample_measurement_ops_repeated_qubit():
|
|
|
259
261
|
)
|
|
260
262
|
|
|
261
263
|
|
|
262
|
-
def test_simulation_trial_result_equality():
|
|
264
|
+
def test_simulation_trial_result_equality() -> None:
|
|
263
265
|
eq = cirq.testing.EqualsTester()
|
|
264
266
|
eq.add_equality_group(
|
|
265
267
|
cirq.SimulationTrialResult(
|
|
@@ -290,7 +292,7 @@ def test_simulation_trial_result_equality():
|
|
|
290
292
|
)
|
|
291
293
|
|
|
292
294
|
|
|
293
|
-
def test_simulation_trial_result_repr():
|
|
295
|
+
def test_simulation_trial_result_repr() -> None:
|
|
294
296
|
assert repr(
|
|
295
297
|
cirq.SimulationTrialResult(
|
|
296
298
|
params=cirq.ParamResolver({'s': 1}),
|
|
@@ -305,7 +307,7 @@ def test_simulation_trial_result_repr():
|
|
|
305
307
|
)
|
|
306
308
|
|
|
307
309
|
|
|
308
|
-
def test_simulation_trial_result_str():
|
|
310
|
+
def test_simulation_trial_result_str() -> None:
|
|
309
311
|
assert (
|
|
310
312
|
str(
|
|
311
313
|
cirq.SimulationTrialResult(
|
|
@@ -349,7 +351,7 @@ def test_simulation_trial_result_str():
|
|
|
349
351
|
)
|
|
350
352
|
|
|
351
353
|
|
|
352
|
-
def test_pretty_print():
|
|
354
|
+
def test_pretty_print() -> None:
|
|
353
355
|
result = cirq.SimulationTrialResult(cirq.ParamResolver(), {}, np.array([1]))
|
|
354
356
|
|
|
355
357
|
# Test Jupyter console output from
|
|
@@ -371,7 +373,7 @@ def test_pretty_print():
|
|
|
371
373
|
|
|
372
374
|
|
|
373
375
|
@duet.sync
|
|
374
|
-
async def test_async_sample():
|
|
376
|
+
async def test_async_sample() -> None:
|
|
375
377
|
m = {'mock': np.array([[[0]], [[1]]])}
|
|
376
378
|
simulator = FakeSimulatesSamples(m)
|
|
377
379
|
|
|
@@ -381,16 +383,16 @@ async def test_async_sample():
|
|
|
381
383
|
np.testing.assert_equal(result.records, m)
|
|
382
384
|
|
|
383
385
|
|
|
384
|
-
def test_simulation_trial_result_qubit_map():
|
|
386
|
+
def test_simulation_trial_result_qubit_map() -> None:
|
|
385
387
|
q = cirq.LineQubit.range(2)
|
|
386
388
|
result = cirq.Simulator().simulate(cirq.Circuit([cirq.CZ(q[0], q[1])]))
|
|
387
389
|
assert result.qubit_map == {q[0]: 0, q[1]: 1}
|
|
388
390
|
|
|
389
|
-
|
|
390
|
-
assert
|
|
391
|
+
result2 = cirq.DensityMatrixSimulator().simulate(cirq.Circuit([cirq.CZ(q[0], q[1])]))
|
|
392
|
+
assert result2.qubit_map == {q[0]: 0, q[1]: 1}
|
|
391
393
|
|
|
392
394
|
|
|
393
|
-
def test_sample_repeated_measurement_keys():
|
|
395
|
+
def test_sample_repeated_measurement_keys() -> None:
|
|
394
396
|
q = cirq.LineQubit.range(2)
|
|
395
397
|
circuit = cirq.Circuit()
|
|
396
398
|
circuit.append(
|
|
@@ -408,7 +410,7 @@ def test_sample_repeated_measurement_keys():
|
|
|
408
410
|
assert len(result.records['b'][0]) == 2
|
|
409
411
|
|
|
410
412
|
|
|
411
|
-
def test_classical_controls_go_to_suffix_if_corresponding_measurement_does():
|
|
413
|
+
def test_classical_controls_go_to_suffix_if_corresponding_measurement_does() -> None:
|
|
412
414
|
subcircuit = cirq.CircuitOperation(cirq.FrozenCircuit()).with_classical_controls('a')
|
|
413
415
|
m = cirq.measure(cirq.LineQubit(0), key='a')
|
|
414
416
|
circuit = cirq.Circuit(m, subcircuit)
|
|
@@ -419,7 +421,7 @@ def test_classical_controls_go_to_suffix_if_corresponding_measurement_does():
|
|
|
419
421
|
assert suffix == circuit
|
|
420
422
|
|
|
421
423
|
|
|
422
|
-
def test_simulate_with_invert_mask():
|
|
424
|
+
def test_simulate_with_invert_mask() -> None:
|
|
423
425
|
q0, q1, q2, q3, q4 = cirq.LineQid.for_qid_shape((2, 3, 3, 3, 4))
|
|
424
426
|
c = cirq.Circuit(
|
|
425
427
|
cirq.XPowGate(dimension=2)(q0),
|
|
@@ -431,7 +433,7 @@ def test_simulate_with_invert_mask():
|
|
|
431
433
|
assert np.all(cirq.Simulator().run(c).measurements['a'] == [[0, 1, 0, 2, 3]])
|
|
432
434
|
|
|
433
435
|
|
|
434
|
-
def test_monte_carlo_on_unknown_channel():
|
|
436
|
+
def test_monte_carlo_on_unknown_channel() -> None:
|
|
435
437
|
class Reset11To00(cirq.Gate):
|
|
436
438
|
def num_qubits(self) -> int:
|
|
437
439
|
return 2
|
|
@@ -451,8 +453,10 @@ def test_monte_carlo_on_unknown_channel():
|
|
|
451
453
|
)
|
|
452
454
|
|
|
453
455
|
|
|
454
|
-
def test_iter_definitions():
|
|
455
|
-
mock_trial_result = SimulationTrialResult(
|
|
456
|
+
def test_iter_definitions() -> None:
|
|
457
|
+
mock_trial_result: SimulationTrialResult = SimulationTrialResult(
|
|
458
|
+
params=cirq.ParamResolver(), measurements={}, final_simulator_state=[]
|
|
459
|
+
)
|
|
456
460
|
|
|
457
461
|
class FakeNonIterSimulatorImpl(
|
|
458
462
|
SimulatesAmplitudes, SimulatesExpectationValues, SimulatesFinalState
|
|
@@ -495,7 +499,7 @@ def test_iter_definitions():
|
|
|
495
499
|
q0 = cirq.LineQubit(0)
|
|
496
500
|
circuit = cirq.Circuit(cirq.X(q0))
|
|
497
501
|
bitstrings = [0b0]
|
|
498
|
-
params = {}
|
|
502
|
+
params: cirq.ParamMappingType = {}
|
|
499
503
|
assert non_iter_sim.compute_amplitudes_sweep(circuit, bitstrings, params) == [[1.0]]
|
|
500
504
|
amp_iter = non_iter_sim.compute_amplitudes_sweep_iter(circuit, bitstrings, params)
|
|
501
505
|
assert next(amp_iter) == [1.0]
|
|
@@ -510,7 +514,7 @@ def test_iter_definitions():
|
|
|
510
514
|
assert next(state_iter) == mock_trial_result
|
|
511
515
|
|
|
512
516
|
|
|
513
|
-
def test_missing_iter_definitions():
|
|
517
|
+
def test_missing_iter_definitions() -> None:
|
|
514
518
|
class FakeMissingIterSimulatorImpl(
|
|
515
519
|
SimulatesAmplitudes, SimulatesExpectationValues, SimulatesFinalState
|
|
516
520
|
):
|
|
@@ -520,7 +524,7 @@ def test_missing_iter_definitions():
|
|
|
520
524
|
q0 = cirq.LineQubit(0)
|
|
521
525
|
circuit = cirq.Circuit(cirq.X(q0))
|
|
522
526
|
bitstrings = [0b0]
|
|
523
|
-
params = {}
|
|
527
|
+
params: cirq.ParamMappingType = {}
|
|
524
528
|
with pytest.raises(RecursionError):
|
|
525
529
|
missing_iter_sim.compute_amplitudes_sweep(circuit, bitstrings, params)
|
|
526
530
|
with pytest.raises(RecursionError):
|
|
@@ -541,7 +545,7 @@ def test_missing_iter_definitions():
|
|
|
541
545
|
next(state_iter)
|
|
542
546
|
|
|
543
547
|
|
|
544
|
-
def test_trial_result_initializer():
|
|
548
|
+
def test_trial_result_initializer() -> None:
|
|
545
549
|
resolver = cirq.ParamResolver()
|
|
546
550
|
state = 3
|
|
547
551
|
x = SimulationTrialResult(resolver, {}, state)
|
cirq/sim/sparse_simulator.py
CHANGED
|
@@ -239,7 +239,7 @@ class SparseSimulatorStep(
|
|
|
239
239
|
self._dtype = dtype
|
|
240
240
|
self._state_vector: np.ndarray | None = None
|
|
241
241
|
|
|
242
|
-
def state_vector(self, copy: bool = False):
|
|
242
|
+
def state_vector(self, copy: bool = False) -> np.ndarray:
|
|
243
243
|
"""Return the state vector at this point in the computation.
|
|
244
244
|
|
|
245
245
|
The state is returned in the computational basis with these basis
|