cirq-core 1.7.0.dev20250807224154__py3-none-any.whl → 1.7.0.dev20250812001555__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/contrib/noise_models/noise_models.py +8 -8
- cirq/contrib/quimb/grid_circuits.py +1 -1
- cirq/contrib/quimb/grid_circuits_test.py +10 -5
- cirq/contrib/quimb/mps_simulator.py +3 -3
- cirq/contrib/quimb/mps_simulator_test.py +41 -42
- cirq/contrib/quimb/state_vector_test.py +14 -13
- cirq/contrib/quirk/export_to_quirk_test.py +2 -2
- cirq/contrib/quirk/linearize_circuit.py +1 -1
- cirq/contrib/routing/device.py +1 -1
- cirq/contrib/routing/device_test.py +7 -5
- cirq/contrib/routing/greedy_test.py +7 -2
- cirq/contrib/routing/initialization_test.py +1 -1
- cirq/contrib/routing/router_test.py +9 -10
- cirq/contrib/routing/swap_network_test.py +10 -4
- cirq/contrib/routing/utils_test.py +4 -4
- cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking.py +9 -9
- cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking_test.py +18 -16
- cirq/contrib/svg/svg.py +1 -1
- cirq/devices/grid_device_metadata_test.py +12 -12
- cirq/devices/grid_qubit_test.py +52 -52
- cirq/devices/line_qubit_test.py +37 -37
- cirq/devices/named_topologies.py +7 -5
- cirq/devices/named_topologies_test.py +3 -2
- cirq/devices/noise_model.py +1 -1
- cirq/devices/noise_properties_test.py +1 -1
- cirq/devices/noise_utils.py +1 -1
- cirq/devices/noise_utils_test.py +6 -6
- cirq/devices/superconducting_qubits_noise_properties_test.py +31 -24
- cirq/devices/thermal_noise_model_test.py +48 -44
- cirq/devices/unconstrained_device.py +1 -1
- cirq/devices/unconstrained_device_test.py +3 -3
- cirq/experiments/benchmarking/parallel_xeb.py +24 -17
- cirq/experiments/benchmarking/parallel_xeb_test.py +42 -28
- cirq/experiments/fidelity_estimation.py +5 -5
- cirq/experiments/fidelity_estimation_test.py +7 -7
- cirq/experiments/purity_estimation.py +1 -1
- cirq/experiments/purity_estimation_test.py +1 -1
- cirq/experiments/qubit_characterizations_test.py +10 -10
- cirq/experiments/random_quantum_circuit_generation.py +1 -1
- cirq/experiments/random_quantum_circuit_generation_test.py +18 -13
- cirq/experiments/readout_confusion_matrix_test.py +12 -8
- cirq/experiments/single_qubit_readout_calibration_test.py +13 -13
- cirq/experiments/t2_decay_experiment.py +1 -1
- cirq/experiments/t2_decay_experiment_test.py +13 -13
- cirq/experiments/two_qubit_xeb_test.py +20 -22
- cirq/experiments/xeb_fitting.py +3 -3
- cirq/experiments/xeb_fitting_test.py +21 -19
- cirq/experiments/xeb_sampling.py +2 -2
- cirq/experiments/xeb_sampling_test.py +9 -9
- cirq/experiments/xeb_simulation.py +1 -1
- cirq/experiments/xeb_simulation_test.py +6 -6
- cirq/ops/measure_util.py +2 -0
- {cirq_core-1.7.0.dev20250807224154.dist-info → cirq_core-1.7.0.dev20250812001555.dist-info}/METADATA +1 -1
- {cirq_core-1.7.0.dev20250807224154.dist-info → cirq_core-1.7.0.dev20250812001555.dist-info}/RECORD +59 -59
- {cirq_core-1.7.0.dev20250807224154.dist-info → cirq_core-1.7.0.dev20250812001555.dist-info}/WHEEL +0 -0
- {cirq_core-1.7.0.dev20250807224154.dist-info → cirq_core-1.7.0.dev20250812001555.dist-info}/licenses/LICENSE +0 -0
- {cirq_core-1.7.0.dev20250807224154.dist-info → cirq_core-1.7.0.dev20250812001555.dist-info}/top_level.txt +0 -0
cirq/_version.py
CHANGED
cirq/_version_test.py
CHANGED
|
@@ -45,7 +45,7 @@ class DepolarizingNoiseModel(devices.NoiseModel):
|
|
|
45
45
|
self._prepend = prepend
|
|
46
46
|
|
|
47
47
|
@property
|
|
48
|
-
def depol_prob(self):
|
|
48
|
+
def depol_prob(self) -> float:
|
|
49
49
|
"""The depolarizing probability."""
|
|
50
50
|
return self._depol_prob
|
|
51
51
|
|
|
@@ -100,7 +100,7 @@ class ReadoutNoiseModel(devices.NoiseModel):
|
|
|
100
100
|
self._prepend = prepend
|
|
101
101
|
|
|
102
102
|
@property
|
|
103
|
-
def bitflip_prob(self):
|
|
103
|
+
def bitflip_prob(self) -> float:
|
|
104
104
|
"""The probability of a bit-flip during measurement."""
|
|
105
105
|
return self._bitflip_prob
|
|
106
106
|
|
|
@@ -154,7 +154,7 @@ class DampedReadoutNoiseModel(devices.NoiseModel):
|
|
|
154
154
|
self._prepend = prepend
|
|
155
155
|
|
|
156
156
|
@property
|
|
157
|
-
def decay_prob(self):
|
|
157
|
+
def decay_prob(self) -> float:
|
|
158
158
|
"""The probability of T1 decay during measurement."""
|
|
159
159
|
return self._decay_prob
|
|
160
160
|
|
|
@@ -207,12 +207,12 @@ class DepolarizingWithReadoutNoiseModel(devices.NoiseModel):
|
|
|
207
207
|
self.readout_noise_gate = ops.BitFlipChannel(bitflip_prob)
|
|
208
208
|
|
|
209
209
|
@property
|
|
210
|
-
def depol_prob(self):
|
|
210
|
+
def depol_prob(self) -> float:
|
|
211
211
|
"""The depolarizing probability."""
|
|
212
212
|
return self._depol_prob
|
|
213
213
|
|
|
214
214
|
@property
|
|
215
|
-
def bitflip_prob(self):
|
|
215
|
+
def bitflip_prob(self) -> float:
|
|
216
216
|
"""The probability of a bit-flip during measurement."""
|
|
217
217
|
return self._bitflip_prob
|
|
218
218
|
|
|
@@ -262,17 +262,17 @@ class DepolarizingWithDampedReadoutNoiseModel(devices.NoiseModel):
|
|
|
262
262
|
self.readout_decay_gate = ops.AmplitudeDampingChannel(decay_prob)
|
|
263
263
|
|
|
264
264
|
@property
|
|
265
|
-
def depol_prob(self):
|
|
265
|
+
def depol_prob(self) -> float:
|
|
266
266
|
"""The depolarizing probability."""
|
|
267
267
|
return self._depol_prob
|
|
268
268
|
|
|
269
269
|
@property
|
|
270
|
-
def bitflip_prob(self):
|
|
270
|
+
def bitflip_prob(self) -> float:
|
|
271
271
|
"""Probability of a bit-flip during measurement."""
|
|
272
272
|
return self._bitflip_prob
|
|
273
273
|
|
|
274
274
|
@property
|
|
275
|
-
def decay_prob(self):
|
|
275
|
+
def decay_prob(self) -> float:
|
|
276
276
|
"""The probability of T1 decay during measurement."""
|
|
277
277
|
return self._decay_prob
|
|
278
278
|
|
|
@@ -105,7 +105,7 @@ def get_grid_moments(
|
|
|
105
105
|
)
|
|
106
106
|
|
|
107
107
|
|
|
108
|
-
def simplify_expectation_value_circuit(circuit_sand: cirq.Circuit):
|
|
108
|
+
def simplify_expectation_value_circuit(circuit_sand: cirq.Circuit) -> None:
|
|
109
109
|
"""For low weight operators on low-degree circuits, we can simplify
|
|
110
110
|
the circuit representation of an expectation value.
|
|
111
111
|
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
from typing import Sequence
|
|
6
|
+
|
|
5
7
|
import networkx as nx
|
|
6
8
|
import numpy as np
|
|
7
9
|
import pytest
|
|
@@ -26,12 +28,13 @@ def _get_circuit(width, height, rs, p=2):
|
|
|
26
28
|
return circuit, qubits
|
|
27
29
|
|
|
28
30
|
|
|
29
|
-
def test_simplify_sandwich():
|
|
31
|
+
def test_simplify_sandwich() -> None:
|
|
30
32
|
rs = np.random.RandomState(52)
|
|
31
33
|
for width in [2, 3]:
|
|
32
34
|
for height in [1, 3]:
|
|
33
35
|
for p in [1, 2]:
|
|
34
36
|
circuit, qubits = _get_circuit(width=width, height=height, p=p, rs=rs)
|
|
37
|
+
operator: cirq.PauliString
|
|
35
38
|
operator = cirq.PauliString(
|
|
36
39
|
{q: cirq.Z for q in rs.choice(qubits, size=2, replace=False)}
|
|
37
40
|
)
|
|
@@ -47,11 +50,12 @@ def test_simplify_sandwich():
|
|
|
47
50
|
|
|
48
51
|
|
|
49
52
|
@pytest.mark.parametrize('simplify', [False, True])
|
|
50
|
-
def test_circuit_to_tensors(simplify):
|
|
51
|
-
|
|
53
|
+
def test_circuit_to_tensors(simplify) -> None:
|
|
54
|
+
qubits: Sequence[cirq.Qid]
|
|
52
55
|
qubits = cirq.LineQubit.range(2)
|
|
53
56
|
circuit = cirq.testing.random_circuit(qubits=qubits, n_moments=10, op_density=0.8)
|
|
54
|
-
operator
|
|
57
|
+
operator: cirq.PauliString
|
|
58
|
+
operator = cirq.PauliString(dict.fromkeys(qubits, cirq.Z))
|
|
55
59
|
|
|
56
60
|
circuit_sand = ccq.circuit_for_expectation_value(circuit, operator)
|
|
57
61
|
if simplify:
|
|
@@ -62,13 +66,14 @@ def test_circuit_to_tensors(simplify):
|
|
|
62
66
|
np.testing.assert_allclose(u_tn, u_cirq, atol=1e-6)
|
|
63
67
|
|
|
64
68
|
|
|
65
|
-
def test_tensor_expectation_value():
|
|
69
|
+
def test_tensor_expectation_value() -> None:
|
|
66
70
|
for _ in range(10):
|
|
67
71
|
for width in [2, 3]:
|
|
68
72
|
for height in [1, 3]:
|
|
69
73
|
for p in [1, 2]:
|
|
70
74
|
rs = np.random.RandomState(52)
|
|
71
75
|
circuit, qubits = _get_circuit(width=width, height=height, p=p, rs=rs)
|
|
76
|
+
operator: cirq.PauliString
|
|
72
77
|
operator = cirq.PauliString(
|
|
73
78
|
{q: cirq.Z for q in rs.choice(qubits, size=2, replace=False)},
|
|
74
79
|
coefficient=rs.uniform(-1, 1),
|
|
@@ -183,7 +183,7 @@ class MPSSimulatorStepResult(simulator_base.StepResultBase['MPSState']):
|
|
|
183
183
|
super().__init__(sim_state)
|
|
184
184
|
|
|
185
185
|
@property
|
|
186
|
-
def state(self):
|
|
186
|
+
def state(self) -> MPSState:
|
|
187
187
|
return self._merged_sim_state
|
|
188
188
|
|
|
189
189
|
def __str__(self) -> str:
|
|
@@ -646,10 +646,10 @@ class MPSState(SimulationState[_MPSHandler]):
|
|
|
646
646
|
"""Delegates the action to self.apply_op"""
|
|
647
647
|
return self._state.apply_op(action, self.get_axes(qubits), self.prng)
|
|
648
648
|
|
|
649
|
-
def estimation_stats(self):
|
|
649
|
+
def estimation_stats(self) -> dict[str, float]:
|
|
650
650
|
"""Returns some statistics about the memory usage and quality of the approximation."""
|
|
651
651
|
return self._state.estimation_stats()
|
|
652
652
|
|
|
653
653
|
@property
|
|
654
|
-
def M(self):
|
|
654
|
+
def M(self) -> list[qtn.Tensor]:
|
|
655
655
|
return self._state._M
|
|
@@ -15,7 +15,7 @@ import cirq.testing
|
|
|
15
15
|
from cirq import value
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
def assert_same_output_as_dense(circuit, qubit_order, initial_state=0, grouping=None):
|
|
18
|
+
def assert_same_output_as_dense(circuit, qubit_order, initial_state=0, grouping=None) -> None:
|
|
19
19
|
mps_simulator = ccq.mps_simulator.MPSSimulator(grouping=grouping)
|
|
20
20
|
ref_simulator = cirq.Simulator()
|
|
21
21
|
|
|
@@ -27,7 +27,7 @@ def assert_same_output_as_dense(circuit, qubit_order, initial_state=0, grouping=
|
|
|
27
27
|
assert len(actual.measurements) == 0
|
|
28
28
|
|
|
29
29
|
|
|
30
|
-
def test_various_gates_1d():
|
|
30
|
+
def test_various_gates_1d() -> None:
|
|
31
31
|
gate_op_cls = [cirq.I, cirq.H, cirq.X, cirq.Y, cirq.Z, cirq.T]
|
|
32
32
|
cross_gate_op_cls = [cirq.CNOT, cirq.SWAP]
|
|
33
33
|
|
|
@@ -43,7 +43,7 @@ def test_various_gates_1d():
|
|
|
43
43
|
)
|
|
44
44
|
|
|
45
45
|
|
|
46
|
-
def test_various_gates_1d_flip():
|
|
46
|
+
def test_various_gates_1d_flip() -> None:
|
|
47
47
|
q0, q1 = cirq.LineQubit.range(2)
|
|
48
48
|
|
|
49
49
|
circuit = cirq.Circuit(cirq.H(q1), cirq.CNOT(q1, q0))
|
|
@@ -52,7 +52,7 @@ def test_various_gates_1d_flip():
|
|
|
52
52
|
assert_same_output_as_dense(circuit=circuit, qubit_order=[q1, q0])
|
|
53
53
|
|
|
54
54
|
|
|
55
|
-
def test_various_gates_2d():
|
|
55
|
+
def test_various_gates_2d() -> None:
|
|
56
56
|
gate_op_cls = [cirq.I, cirq.H]
|
|
57
57
|
cross_gate_op_cls = [cirq.CNOT, cirq.SWAP]
|
|
58
58
|
|
|
@@ -77,7 +77,7 @@ def test_various_gates_2d():
|
|
|
77
77
|
)
|
|
78
78
|
|
|
79
79
|
|
|
80
|
-
def test_grouping():
|
|
80
|
+
def test_grouping() -> None:
|
|
81
81
|
q0, q1, q2 = cirq.LineQubit.range(3)
|
|
82
82
|
|
|
83
83
|
circuit = cirq.Circuit(
|
|
@@ -107,7 +107,7 @@ def test_grouping():
|
|
|
107
107
|
)
|
|
108
108
|
|
|
109
109
|
|
|
110
|
-
def test_grouping_does_not_overlap():
|
|
110
|
+
def test_grouping_does_not_overlap() -> None:
|
|
111
111
|
q0, q1 = cirq.LineQubit.range(2)
|
|
112
112
|
mps_simulator = ccq.mps_simulator.MPSSimulator(grouping={q0: 0})
|
|
113
113
|
|
|
@@ -115,7 +115,7 @@ def test_grouping_does_not_overlap():
|
|
|
115
115
|
mps_simulator.simulate(cirq.Circuit(), qubit_order={q0: 0, q1: 1})
|
|
116
116
|
|
|
117
117
|
|
|
118
|
-
def test_same_partial_trace():
|
|
118
|
+
def test_same_partial_trace() -> None:
|
|
119
119
|
qubit_order = cirq.LineQubit.range(2)
|
|
120
120
|
q0, q1 = qubit_order
|
|
121
121
|
|
|
@@ -134,14 +134,14 @@ def test_same_partial_trace():
|
|
|
134
134
|
final_state = mps_simulator.simulate(
|
|
135
135
|
circuit, qubit_order=qubit_order, initial_state=initial_state
|
|
136
136
|
).final_state
|
|
137
|
-
actual_density_matrix = final_state.partial_trace(
|
|
138
|
-
actual_partial_trace = final_state.partial_trace(
|
|
137
|
+
actual_density_matrix = final_state.partial_trace({q0, q1})
|
|
138
|
+
actual_partial_trace = final_state.partial_trace({q0})
|
|
139
139
|
|
|
140
140
|
np.testing.assert_allclose(actual_density_matrix, expected_density_matrix, atol=1e-4)
|
|
141
141
|
np.testing.assert_allclose(actual_partial_trace, expected_partial_trace, atol=1e-4)
|
|
142
142
|
|
|
143
143
|
|
|
144
|
-
def test_probs_dont_sum_up_to_one():
|
|
144
|
+
def test_probs_dont_sum_up_to_one() -> None:
|
|
145
145
|
q0 = cirq.NamedQid('q0', dimension=2)
|
|
146
146
|
circuit = cirq.Circuit(cirq.measure(q0))
|
|
147
147
|
|
|
@@ -153,7 +153,7 @@ def test_probs_dont_sum_up_to_one():
|
|
|
153
153
|
simulator.run(circuit, repetitions=1)
|
|
154
154
|
|
|
155
155
|
|
|
156
|
-
def test_empty():
|
|
156
|
+
def test_empty() -> None:
|
|
157
157
|
q0 = cirq.NamedQid('q0', dimension=2)
|
|
158
158
|
q1 = cirq.NamedQid('q1', dimension=3)
|
|
159
159
|
q2 = cirq.NamedQid('q2', dimension=5)
|
|
@@ -165,7 +165,7 @@ def test_empty():
|
|
|
165
165
|
)
|
|
166
166
|
|
|
167
167
|
|
|
168
|
-
def test_cnot():
|
|
168
|
+
def test_cnot() -> None:
|
|
169
169
|
q0, q1 = cirq.LineQubit.range(2)
|
|
170
170
|
circuit = cirq.Circuit(cirq.CNOT(q0, q1))
|
|
171
171
|
|
|
@@ -175,7 +175,7 @@ def test_cnot():
|
|
|
175
175
|
)
|
|
176
176
|
|
|
177
177
|
|
|
178
|
-
def test_cnot_flipped():
|
|
178
|
+
def test_cnot_flipped() -> None:
|
|
179
179
|
q0, q1 = cirq.LineQubit.range(2)
|
|
180
180
|
circuit = cirq.Circuit(cirq.CNOT(q1, q0))
|
|
181
181
|
|
|
@@ -185,7 +185,7 @@ def test_cnot_flipped():
|
|
|
185
185
|
)
|
|
186
186
|
|
|
187
187
|
|
|
188
|
-
def test_simulation_state():
|
|
188
|
+
def test_simulation_state() -> None:
|
|
189
189
|
q0, q1 = qubit_order = cirq.LineQubit.range(2)
|
|
190
190
|
circuit = cirq.Circuit(cirq.CNOT(q1, q0))
|
|
191
191
|
mps_simulator = ccq.mps_simulator.MPSSimulator()
|
|
@@ -202,7 +202,7 @@ def test_simulation_state():
|
|
|
202
202
|
assert len(actual.measurements) == 0
|
|
203
203
|
|
|
204
204
|
|
|
205
|
-
def test_three_qubits():
|
|
205
|
+
def test_three_qubits() -> None:
|
|
206
206
|
q0, q1, q2 = cirq.LineQubit.range(3)
|
|
207
207
|
circuit = cirq.Circuit(cirq.CCX(q0, q1, q2))
|
|
208
208
|
|
|
@@ -210,7 +210,7 @@ def test_three_qubits():
|
|
|
210
210
|
assert_same_output_as_dense(circuit=circuit, qubit_order=[q0, q1, q2])
|
|
211
211
|
|
|
212
212
|
|
|
213
|
-
def test_measurement_1qubit():
|
|
213
|
+
def test_measurement_1qubit() -> None:
|
|
214
214
|
q0, q1 = cirq.LineQubit.range(2)
|
|
215
215
|
circuit = cirq.Circuit(cirq.X(q0), cirq.H(q1), cirq.measure(q1))
|
|
216
216
|
|
|
@@ -221,7 +221,7 @@ def test_measurement_1qubit():
|
|
|
221
221
|
assert sum(result.measurements['q(1)'])[0] > 20
|
|
222
222
|
|
|
223
223
|
|
|
224
|
-
def test_reset():
|
|
224
|
+
def test_reset() -> None:
|
|
225
225
|
q = cirq.LineQubit(0)
|
|
226
226
|
simulator = ccq.mps_simulator.MPSSimulator()
|
|
227
227
|
c = cirq.Circuit(cirq.X(q), cirq.reset(q), cirq.measure(q))
|
|
@@ -232,7 +232,7 @@ def test_reset():
|
|
|
232
232
|
assert simulator.sample(c)['q(0)'][0] == 0
|
|
233
233
|
|
|
234
234
|
|
|
235
|
-
def test_measurement_2qubits():
|
|
235
|
+
def test_measurement_2qubits() -> None:
|
|
236
236
|
q0, q1, q2 = cirq.LineQubit.range(3)
|
|
237
237
|
circuit = cirq.Circuit(cirq.H(q0), cirq.H(q1), cirq.H(q2), cirq.measure(q0, q2))
|
|
238
238
|
|
|
@@ -252,7 +252,7 @@ def test_measurement_2qubits():
|
|
|
252
252
|
assert result_count < repetitions * 0.35
|
|
253
253
|
|
|
254
254
|
|
|
255
|
-
def test_measurement_str():
|
|
255
|
+
def test_measurement_str() -> None:
|
|
256
256
|
q0 = cirq.NamedQid('q0', dimension=3)
|
|
257
257
|
circuit = cirq.Circuit(cirq.measure(q0))
|
|
258
258
|
|
|
@@ -262,7 +262,7 @@ def test_measurement_str():
|
|
|
262
262
|
assert str(result) == "q0 (d=3)=0000000"
|
|
263
263
|
|
|
264
264
|
|
|
265
|
-
def test_trial_result_str():
|
|
265
|
+
def test_trial_result_str() -> None:
|
|
266
266
|
q0 = cirq.LineQubit(0)
|
|
267
267
|
final_simulator_state = ccq.mps_simulator.MPSState(
|
|
268
268
|
qubits=(q0,),
|
|
@@ -277,7 +277,7 @@ def test_trial_result_str():
|
|
|
277
277
|
assert 'output state: TensorNetwork' in str(result)
|
|
278
278
|
|
|
279
279
|
|
|
280
|
-
def test_trial_result_repr_pretty():
|
|
280
|
+
def test_trial_result_repr_pretty() -> None:
|
|
281
281
|
q0 = cirq.LineQubit(0)
|
|
282
282
|
final_simulator_state = ccq.mps_simulator.MPSState(
|
|
283
283
|
qubits=(q0,),
|
|
@@ -293,14 +293,14 @@ def test_trial_result_repr_pretty():
|
|
|
293
293
|
cirq.testing.assert_repr_pretty(result, "cirq.MPSTrialResult(...)", cycle=True)
|
|
294
294
|
|
|
295
295
|
|
|
296
|
-
def test_empty_step_result():
|
|
296
|
+
def test_empty_step_result() -> None:
|
|
297
297
|
q0 = cirq.LineQubit(0)
|
|
298
298
|
sim = ccq.mps_simulator.MPSSimulator()
|
|
299
299
|
step_result = next(sim.simulate_moment_steps(cirq.Circuit(cirq.measure(q0))))
|
|
300
300
|
assert 'TensorNetwork' in str(step_result)
|
|
301
301
|
|
|
302
302
|
|
|
303
|
-
def test_step_result_repr_pretty():
|
|
303
|
+
def test_step_result_repr_pretty() -> None:
|
|
304
304
|
q0 = cirq.LineQubit(0)
|
|
305
305
|
sim = ccq.mps_simulator.MPSSimulator()
|
|
306
306
|
step_result = next(sim.simulate_moment_steps(cirq.Circuit(cirq.measure(q0))))
|
|
@@ -308,7 +308,7 @@ def test_step_result_repr_pretty():
|
|
|
308
308
|
cirq.testing.assert_repr_pretty(step_result, "cirq.MPSSimulatorStepResult(...)", cycle=True)
|
|
309
309
|
|
|
310
310
|
|
|
311
|
-
def test_state_equal():
|
|
311
|
+
def test_state_equal() -> None:
|
|
312
312
|
q0, q1 = cirq.LineQubit.range(2)
|
|
313
313
|
state0 = ccq.mps_simulator.MPSState(
|
|
314
314
|
qubits=(q0,),
|
|
@@ -330,7 +330,7 @@ def test_state_equal():
|
|
|
330
330
|
assert state1a != state1b
|
|
331
331
|
|
|
332
332
|
|
|
333
|
-
def test_random_circuits_equal_more_rows():
|
|
333
|
+
def test_random_circuits_equal_more_rows() -> None:
|
|
334
334
|
circuit = cirq.testing.random_circuit(
|
|
335
335
|
qubits=cirq.GridQubit.rect(3, 2), n_moments=6, op_density=1.0
|
|
336
336
|
)
|
|
@@ -338,7 +338,7 @@ def test_random_circuits_equal_more_rows():
|
|
|
338
338
|
assert_same_output_as_dense(circuit, qubits)
|
|
339
339
|
|
|
340
340
|
|
|
341
|
-
def test_random_circuits_equal_more_cols():
|
|
341
|
+
def test_random_circuits_equal_more_cols() -> None:
|
|
342
342
|
circuit = cirq.testing.random_circuit(
|
|
343
343
|
qubits=cirq.GridQubit.rect(2, 3), n_moments=6, op_density=1.0
|
|
344
344
|
)
|
|
@@ -346,10 +346,9 @@ def test_random_circuits_equal_more_cols():
|
|
|
346
346
|
assert_same_output_as_dense(circuit, qubits)
|
|
347
347
|
|
|
348
348
|
|
|
349
|
-
def test_tensor_index_names():
|
|
349
|
+
def test_tensor_index_names() -> None:
|
|
350
350
|
qubits = cirq.LineQubit.range(12)
|
|
351
|
-
|
|
352
|
-
state = ccq.mps_simulator.MPSState(qubits=qubit_map, prng=value.parse_random_state(0))
|
|
351
|
+
state = ccq.mps_simulator.MPSState(qubits=qubits, prng=value.parse_random_state(0))
|
|
353
352
|
|
|
354
353
|
assert state.i_str(0) == "i_00"
|
|
355
354
|
assert state.i_str(11) == "i_11"
|
|
@@ -357,7 +356,7 @@ def test_tensor_index_names():
|
|
|
357
356
|
assert state.mu_str(3, 0) == "mu_0_3"
|
|
358
357
|
|
|
359
358
|
|
|
360
|
-
def test_simulate_moment_steps_sample():
|
|
359
|
+
def test_simulate_moment_steps_sample() -> None:
|
|
361
360
|
q0, q1 = cirq.LineQubit.range(2)
|
|
362
361
|
circuit = cirq.Circuit(cirq.H(q0), cirq.CNOT(q0, q1))
|
|
363
362
|
|
|
@@ -366,7 +365,7 @@ def test_simulate_moment_steps_sample():
|
|
|
366
365
|
for i, step in enumerate(simulator.simulate_moment_steps(circuit)):
|
|
367
366
|
if i == 0:
|
|
368
367
|
np.testing.assert_almost_equal(
|
|
369
|
-
step._simulator_state().to_numpy(),
|
|
368
|
+
step._simulator_state().to_numpy(), # type: ignore[attr-defined]
|
|
370
369
|
np.asarray([1.0 / math.sqrt(2), 0.0, 1.0 / math.sqrt(2), 0.0]),
|
|
371
370
|
)
|
|
372
371
|
# There are two "Tensor()" copies in the string.
|
|
@@ -377,12 +376,12 @@ def test_simulate_moment_steps_sample():
|
|
|
377
376
|
sample, [False, False]
|
|
378
377
|
)
|
|
379
378
|
np.testing.assert_almost_equal(
|
|
380
|
-
step._simulator_state().to_numpy(),
|
|
379
|
+
step._simulator_state().to_numpy(), # type: ignore[attr-defined]
|
|
381
380
|
np.asarray([1.0 / math.sqrt(2), 0.0, 1.0 / math.sqrt(2), 0.0]),
|
|
382
381
|
)
|
|
383
382
|
else:
|
|
384
383
|
np.testing.assert_almost_equal(
|
|
385
|
-
step._simulator_state().to_numpy(),
|
|
384
|
+
step._simulator_state().to_numpy(), # type: ignore[attr-defined]
|
|
386
385
|
np.asarray([1.0 / math.sqrt(2), 0.0, 0.0, 1.0 / math.sqrt(2)]),
|
|
387
386
|
)
|
|
388
387
|
# There are two "Tensor()" copies in the string.
|
|
@@ -394,7 +393,7 @@ def test_simulate_moment_steps_sample():
|
|
|
394
393
|
)
|
|
395
394
|
|
|
396
395
|
|
|
397
|
-
def test_sample_seed():
|
|
396
|
+
def test_sample_seed() -> None:
|
|
398
397
|
q = cirq.NamedQubit('q')
|
|
399
398
|
circuit = cirq.Circuit(cirq.H(q), cirq.measure(q))
|
|
400
399
|
simulator = ccq.mps_simulator.MPSSimulator(seed=1234)
|
|
@@ -404,7 +403,7 @@ def test_sample_seed():
|
|
|
404
403
|
assert result_string == '01011001110111011011'
|
|
405
404
|
|
|
406
405
|
|
|
407
|
-
def test_run_no_repetitions():
|
|
406
|
+
def test_run_no_repetitions() -> None:
|
|
408
407
|
q0 = cirq.LineQubit(0)
|
|
409
408
|
simulator = ccq.mps_simulator.MPSSimulator()
|
|
410
409
|
circuit = cirq.Circuit(cirq.H(q0), cirq.measure(q0))
|
|
@@ -412,7 +411,7 @@ def test_run_no_repetitions():
|
|
|
412
411
|
assert len(result.measurements['q(0)']) == 0
|
|
413
412
|
|
|
414
413
|
|
|
415
|
-
def test_run_parameters_not_resolved():
|
|
414
|
+
def test_run_parameters_not_resolved() -> None:
|
|
416
415
|
a = cirq.LineQubit(0)
|
|
417
416
|
simulator = ccq.mps_simulator.MPSSimulator()
|
|
418
417
|
circuit = cirq.Circuit(cirq.XPowGate(exponent=sympy.Symbol('a'))(a), cirq.measure(a))
|
|
@@ -420,7 +419,7 @@ def test_run_parameters_not_resolved():
|
|
|
420
419
|
_ = simulator.run_sweep(circuit, cirq.ParamResolver({}))
|
|
421
420
|
|
|
422
421
|
|
|
423
|
-
def test_deterministic_gate_noise():
|
|
422
|
+
def test_deterministic_gate_noise() -> None:
|
|
424
423
|
q = cirq.LineQubit(0)
|
|
425
424
|
circuit = cirq.Circuit(cirq.I(q), cirq.measure(q))
|
|
426
425
|
|
|
@@ -438,7 +437,7 @@ def test_deterministic_gate_noise():
|
|
|
438
437
|
assert result1 != result3
|
|
439
438
|
|
|
440
439
|
|
|
441
|
-
def test_nondeterministic_mixture_noise():
|
|
440
|
+
def test_nondeterministic_mixture_noise() -> None:
|
|
442
441
|
q = cirq.LineQubit(0)
|
|
443
442
|
circuit = cirq.Circuit(cirq.I(q), cirq.measure(q))
|
|
444
443
|
|
|
@@ -451,12 +450,12 @@ def test_nondeterministic_mixture_noise():
|
|
|
451
450
|
assert result1 != result2
|
|
452
451
|
|
|
453
452
|
|
|
454
|
-
def test_unsupported_noise_fails():
|
|
453
|
+
def test_unsupported_noise_fails() -> None:
|
|
455
454
|
with pytest.raises(ValueError, match='noise must be unitary or mixture but was'):
|
|
456
455
|
ccq.mps_simulator.MPSSimulator(noise=cirq.amplitude_damp(0.5))
|
|
457
456
|
|
|
458
457
|
|
|
459
|
-
def test_state_copy():
|
|
458
|
+
def test_state_copy() -> None:
|
|
460
459
|
sim = ccq.mps_simulator.MPSSimulator()
|
|
461
460
|
|
|
462
461
|
q = cirq.LineQubit(0)
|
|
@@ -471,7 +470,7 @@ def test_state_copy():
|
|
|
471
470
|
assert not np.shares_memory(x[i], y[i])
|
|
472
471
|
|
|
473
472
|
|
|
474
|
-
def test_simulation_state_initializer():
|
|
473
|
+
def test_simulation_state_initializer() -> None:
|
|
475
474
|
expected_classical_data = cirq.ClassicalDataDictionaryStore(
|
|
476
475
|
_records={cirq.MeasurementKey('test'): [(4,)]}
|
|
477
476
|
)
|
|
@@ -489,7 +488,7 @@ def test_simulation_state_initializer():
|
|
|
489
488
|
}
|
|
490
489
|
|
|
491
490
|
|
|
492
|
-
def test_act_on_gate():
|
|
491
|
+
def test_act_on_gate() -> None:
|
|
493
492
|
args = ccq.mps_simulator.MPSState(qubits=cirq.LineQubit.range(3), prng=np.random.RandomState(0))
|
|
494
493
|
|
|
495
494
|
cirq.act_on(cirq.X, args, [cirq.LineQubit(1)])
|
|
@@ -12,7 +12,7 @@ import cirq
|
|
|
12
12
|
import cirq.contrib.quimb as ccq
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
def test_tensor_state_vector_1():
|
|
15
|
+
def test_tensor_state_vector_1() -> None:
|
|
16
16
|
q = cirq.LineQubit.range(2)
|
|
17
17
|
c = cirq.Circuit(cirq.YPowGate(exponent=0.25).on(q[0]))
|
|
18
18
|
|
|
@@ -21,7 +21,7 @@ def test_tensor_state_vector_1():
|
|
|
21
21
|
np.testing.assert_allclose(psi1, psi2, atol=1e-15)
|
|
22
22
|
|
|
23
23
|
|
|
24
|
-
def test_tensor_state_vector_implicit_qubits():
|
|
24
|
+
def test_tensor_state_vector_implicit_qubits() -> None:
|
|
25
25
|
q = cirq.LineQubit.range(2)
|
|
26
26
|
c = cirq.Circuit(cirq.YPowGate(exponent=0.25).on(q[0]))
|
|
27
27
|
|
|
@@ -30,7 +30,7 @@ def test_tensor_state_vector_implicit_qubits():
|
|
|
30
30
|
np.testing.assert_allclose(psi1, psi2, atol=1e-15)
|
|
31
31
|
|
|
32
32
|
|
|
33
|
-
def test_tensor_state_vector_2():
|
|
33
|
+
def test_tensor_state_vector_2() -> None:
|
|
34
34
|
q = cirq.LineQubit.range(2)
|
|
35
35
|
rs = np.random.RandomState(52)
|
|
36
36
|
for _ in range(10):
|
|
@@ -41,7 +41,7 @@ def test_tensor_state_vector_2():
|
|
|
41
41
|
np.testing.assert_allclose(psi1, psi2, atol=1e-8)
|
|
42
42
|
|
|
43
43
|
|
|
44
|
-
def test_tensor_state_vector_3():
|
|
44
|
+
def test_tensor_state_vector_3() -> None:
|
|
45
45
|
qubits = cirq.LineQubit.range(10)
|
|
46
46
|
circuit = cirq.testing.random_circuit(qubits=qubits, n_moments=10, op_density=0.8)
|
|
47
47
|
psi1 = cirq.final_state_vector(circuit, dtype=np.complex128)
|
|
@@ -49,7 +49,7 @@ def test_tensor_state_vector_3():
|
|
|
49
49
|
np.testing.assert_allclose(psi1, psi2, atol=1e-8)
|
|
50
50
|
|
|
51
51
|
|
|
52
|
-
def test_tensor_state_vector_4():
|
|
52
|
+
def test_tensor_state_vector_4() -> None:
|
|
53
53
|
qubits = cirq.LineQubit.range(4)
|
|
54
54
|
circuit = cirq.testing.random_circuit(qubits=qubits, n_moments=100, op_density=0.8)
|
|
55
55
|
psi1 = cirq.final_state_vector(circuit, dtype=np.complex128)
|
|
@@ -57,7 +57,7 @@ def test_tensor_state_vector_4():
|
|
|
57
57
|
np.testing.assert_allclose(psi1, psi2, atol=1e-8)
|
|
58
58
|
|
|
59
59
|
|
|
60
|
-
def test_sandwich_operator_identity():
|
|
60
|
+
def test_sandwich_operator_identity() -> None:
|
|
61
61
|
qubits = cirq.LineQubit.range(6)
|
|
62
62
|
circuit = cirq.testing.random_circuit(qubits=qubits, n_moments=10, op_density=0.8)
|
|
63
63
|
tot_c = ccq.circuit_for_expectation_value(circuit, cirq.PauliString({}))
|
|
@@ -74,7 +74,7 @@ def _random_pauli_string(qubits, rs, coefficients=False):
|
|
|
74
74
|
return ps
|
|
75
75
|
|
|
76
76
|
|
|
77
|
-
def test_sandwich_operator_expect_val():
|
|
77
|
+
def test_sandwich_operator_expect_val() -> None:
|
|
78
78
|
rs = np.random.RandomState(52)
|
|
79
79
|
qubits = cirq.LineQubit.range(5)
|
|
80
80
|
for _ in range(10): # try a bunch of different ones
|
|
@@ -89,7 +89,7 @@ def test_sandwich_operator_expect_val():
|
|
|
89
89
|
np.testing.assert_allclose(eval_sandwich, eval_normal, atol=1e-5)
|
|
90
90
|
|
|
91
91
|
|
|
92
|
-
def test_tensor_unitary():
|
|
92
|
+
def test_tensor_unitary() -> None:
|
|
93
93
|
rs = np.random.RandomState(52)
|
|
94
94
|
for _ in range(10):
|
|
95
95
|
qubits = cirq.LineQubit.range(5)
|
|
@@ -104,7 +104,7 @@ def test_tensor_unitary():
|
|
|
104
104
|
np.testing.assert_allclose(u_tn, u_cirq, atol=1e-6)
|
|
105
105
|
|
|
106
106
|
|
|
107
|
-
def test_tensor_unitary_implicit_qubits():
|
|
107
|
+
def test_tensor_unitary_implicit_qubits() -> None:
|
|
108
108
|
rs = np.random.RandomState(52)
|
|
109
109
|
for _ in range(10):
|
|
110
110
|
qubits = cirq.LineQubit.range(5)
|
|
@@ -119,7 +119,7 @@ def test_tensor_unitary_implicit_qubits():
|
|
|
119
119
|
np.testing.assert_allclose(u_tn, u_cirq, atol=1e-6)
|
|
120
120
|
|
|
121
121
|
|
|
122
|
-
def test_tensor_expectation_value():
|
|
122
|
+
def test_tensor_expectation_value() -> None:
|
|
123
123
|
rs = np.random.RandomState(52)
|
|
124
124
|
for _ in range(10):
|
|
125
125
|
for n_qubit in [2, 7]:
|
|
@@ -140,17 +140,18 @@ def test_tensor_expectation_value():
|
|
|
140
140
|
np.testing.assert_allclose(eval_tn, eval_normal, atol=1e-3)
|
|
141
141
|
|
|
142
142
|
|
|
143
|
-
def test_bad_init_state():
|
|
143
|
+
def test_bad_init_state() -> None:
|
|
144
144
|
qubits = cirq.LineQubit.range(5)
|
|
145
145
|
circuit = cirq.testing.random_circuit(qubits=qubits, n_moments=10, op_density=0.8)
|
|
146
146
|
with pytest.raises(ValueError):
|
|
147
147
|
ccq.circuit_to_tensors(circuit=circuit, qubits=qubits, initial_state=1)
|
|
148
148
|
|
|
149
149
|
|
|
150
|
-
def test_too_much_ram():
|
|
150
|
+
def test_too_much_ram() -> None:
|
|
151
151
|
qubits = cirq.LineQubit.range(30)
|
|
152
152
|
circuit = cirq.testing.random_circuit(qubits=qubits, n_moments=20, op_density=0.8)
|
|
153
|
-
op
|
|
153
|
+
op: cirq.PauliString
|
|
154
|
+
op = functools.reduce(operator.mul, [cirq.Z(q) for q in qubits], cirq.PauliString())
|
|
154
155
|
with pytest.raises(MemoryError) as e:
|
|
155
156
|
ccq.tensor_expectation_value(circuit=circuit, pauli_string=op)
|
|
156
157
|
|
|
@@ -172,10 +172,10 @@ class MysteryOperation(cirq.Operation):
|
|
|
172
172
|
self._qubits = qubits
|
|
173
173
|
|
|
174
174
|
@property
|
|
175
|
-
def qubits(self):
|
|
175
|
+
def qubits(self) -> tuple[cirq.Qid, ...]:
|
|
176
176
|
return self._qubits
|
|
177
177
|
|
|
178
|
-
def with_qubits(self, *new_qubits):
|
|
178
|
+
def with_qubits(self, *new_qubits) -> MysteryOperation:
|
|
179
179
|
return MysteryOperation(*new_qubits)
|
|
180
180
|
|
|
181
181
|
|
|
@@ -29,7 +29,7 @@ class QubitMapper:
|
|
|
29
29
|
def map_moment(self, moment: circuits.Moment) -> circuits.Moment:
|
|
30
30
|
return circuits.Moment(self.map_operation(op) for op in moment.operations)
|
|
31
31
|
|
|
32
|
-
def optimize_circuit(self, circuit: circuits.Circuit):
|
|
32
|
+
def optimize_circuit(self, circuit: circuits.Circuit) -> None:
|
|
33
33
|
circuit[:] = (self.map_moment(m) for m in circuit)
|
|
34
34
|
|
|
35
35
|
|
cirq/contrib/routing/device.py
CHANGED
|
@@ -36,7 +36,7 @@ def get_grid_device_graph(*args, **kwargs) -> nx.Graph:
|
|
|
36
36
|
return gridqubits_to_graph_device(cirq.GridQubit.rect(*args, **kwargs))
|
|
37
37
|
|
|
38
38
|
|
|
39
|
-
def gridqubits_to_graph_device(qubits: Iterable[cirq.GridQubit]):
|
|
39
|
+
def gridqubits_to_graph_device(qubits: Iterable[cirq.GridQubit]) -> nx.Graph:
|
|
40
40
|
"""Gets the graph of a set of grid qubits."""
|
|
41
41
|
return nx.Graph(
|
|
42
42
|
pair for pair in itertools.combinations(qubits, 2) if _manhattan_distance(*pair) == 1
|