cirq-core 1.1.0.dev20221219200817__py3-none-any.whl → 1.2.0__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.
- cirq/__init__.py +8 -0
- cirq/_compat.py +29 -4
- cirq/_compat_test.py +24 -26
- cirq/_version.py +32 -1
- cirq/_version_test.py +1 -1
- cirq/circuits/_block_diagram_drawer_test.py +4 -3
- cirq/circuits/circuit.py +109 -63
- cirq/circuits/circuit_operation.py +2 -3
- cirq/circuits/circuit_operation_test.py +4 -4
- cirq/circuits/circuit_test.py +11 -0
- cirq/circuits/frozen_circuit.py +13 -1
- cirq/circuits/frozen_circuit_test.py +5 -1
- cirq/circuits/moment.py +39 -14
- cirq/circuits/moment_test.py +7 -0
- cirq/circuits/text_diagram_drawer.py +1 -1
- cirq/circuits/text_diagram_drawer_test.py +3 -7
- cirq/conftest.py +8 -0
- cirq/contrib/acquaintance/bipartite.py +1 -1
- cirq/contrib/acquaintance/devices.py +2 -2
- cirq/contrib/acquaintance/executor.py +5 -2
- cirq/contrib/acquaintance/gates.py +3 -2
- cirq/contrib/acquaintance/permutation.py +13 -2
- cirq/contrib/acquaintance/testing.py +3 -5
- cirq/contrib/paulistring/recombine.py +3 -6
- cirq/contrib/qasm_import/_parser.py +17 -21
- cirq/contrib/qasm_import/_parser_test.py +30 -45
- cirq/contrib/qcircuit/qcircuit_test.py +3 -7
- cirq/contrib/quantum_volume/quantum_volume.py +3 -3
- cirq/contrib/quimb/mps_simulator.py +1 -1
- cirq/contrib/quimb/state_vector.py +2 -0
- cirq/contrib/quirk/quirk_gate.py +1 -0
- cirq/contrib/svg/svg.py +4 -7
- cirq/contrib/svg/svg_test.py +29 -1
- cirq/devices/grid_qubit.py +26 -28
- cirq/devices/grid_qubit_test.py +21 -5
- cirq/devices/line_qubit.py +10 -12
- cirq/devices/line_qubit_test.py +9 -2
- cirq/devices/named_topologies.py +1 -1
- cirq/devices/noise_model.py +4 -1
- cirq/devices/superconducting_qubits_noise_properties.py +1 -3
- cirq/experiments/n_qubit_tomography.py +1 -1
- cirq/experiments/qubit_characterizations.py +2 -2
- cirq/experiments/single_qubit_readout_calibration.py +1 -1
- cirq/experiments/t2_decay_experiment.py +1 -1
- cirq/experiments/xeb_simulation_test.py +2 -2
- cirq/interop/quirk/cells/testing.py +1 -1
- cirq/json_resolver_cache.py +1 -0
- cirq/linalg/__init__.py +2 -0
- cirq/linalg/decompositions_test.py +4 -4
- cirq/linalg/diagonalize_test.py +5 -6
- cirq/linalg/transformations.py +72 -9
- cirq/linalg/transformations_test.py +23 -7
- cirq/ops/__init__.py +4 -0
- cirq/ops/arithmetic_operation.py +4 -6
- cirq/ops/classically_controlled_operation.py +10 -3
- cirq/ops/clifford_gate.py +1 -7
- cirq/ops/common_channels.py +21 -15
- cirq/ops/common_gate_families.py +2 -3
- cirq/ops/common_gates.py +48 -11
- cirq/ops/common_gates_test.py +4 -0
- cirq/ops/controlled_gate.py +44 -18
- cirq/ops/controlled_operation.py +13 -5
- cirq/ops/dense_pauli_string.py +14 -19
- cirq/ops/diagonal_gate.py +3 -4
- cirq/ops/eigen_gate.py +8 -10
- cirq/ops/eigen_gate_test.py +6 -0
- cirq/ops/gate_operation.py +11 -6
- cirq/ops/gate_operation_test.py +11 -2
- cirq/ops/gateset.py +2 -1
- cirq/ops/gateset_test.py +38 -5
- cirq/ops/global_phase_op.py +28 -2
- cirq/ops/global_phase_op_test.py +21 -0
- cirq/ops/identity.py +1 -1
- cirq/ops/kraus_channel_test.py +2 -2
- cirq/ops/linear_combinations.py +7 -6
- cirq/ops/linear_combinations_test.py +26 -10
- cirq/ops/matrix_gates.py +8 -4
- cirq/ops/matrix_gates_test.py +25 -3
- cirq/ops/measure_util.py +13 -5
- cirq/ops/measure_util_test.py +8 -2
- cirq/ops/measurement_gate.py +1 -1
- cirq/ops/measurement_gate_test.py +9 -4
- cirq/ops/mixed_unitary_channel_test.py +4 -4
- cirq/ops/named_qubit.py +2 -4
- cirq/ops/parity_gates.py +5 -1
- cirq/ops/parity_gates_test.py +6 -0
- cirq/ops/pauli_gates.py +9 -9
- cirq/ops/pauli_string.py +4 -2
- cirq/ops/pauli_string_raw_types.py +4 -11
- cirq/ops/pauli_string_test.py +13 -13
- cirq/ops/pauli_sum_exponential.py +6 -1
- cirq/ops/qubit_manager.py +97 -0
- cirq/ops/qubit_manager_test.py +66 -0
- cirq/ops/raw_types.py +75 -33
- cirq/ops/raw_types_test.py +34 -0
- cirq/ops/three_qubit_gates.py +16 -10
- cirq/ops/three_qubit_gates_test.py +4 -2
- cirq/ops/two_qubit_diagonal_gate.py +3 -3
- cirq/ops/wait_gate.py +1 -1
- cirq/protocols/__init__.py +1 -0
- cirq/protocols/act_on_protocol.py +3 -3
- cirq/protocols/act_on_protocol_test.py +5 -5
- cirq/protocols/apply_channel_protocol.py +9 -8
- cirq/protocols/apply_mixture_protocol.py +8 -8
- cirq/protocols/apply_mixture_protocol_test.py +1 -1
- cirq/protocols/apply_unitary_protocol.py +66 -19
- cirq/protocols/apply_unitary_protocol_test.py +50 -0
- cirq/protocols/circuit_diagram_info_protocol.py +7 -9
- cirq/protocols/decompose_protocol.py +167 -125
- cirq/protocols/decompose_protocol_test.py +132 -2
- cirq/protocols/has_stabilizer_effect_protocol.py +2 -1
- cirq/protocols/inverse_protocol.py +2 -2
- cirq/protocols/json_serialization_test.py +3 -3
- cirq/protocols/json_test_data/Linspace.json +20 -7
- cirq/protocols/json_test_data/Linspace.repr +4 -1
- cirq/protocols/json_test_data/Points.json +19 -8
- cirq/protocols/json_test_data/Points.repr +4 -1
- cirq/protocols/json_test_data/Result.repr_inward +1 -1
- cirq/protocols/json_test_data/ResultDict.repr +1 -1
- cirq/protocols/json_test_data/ResultDict.repr_inward +1 -1
- cirq/protocols/json_test_data/TrialResult.repr_inward +1 -1
- cirq/protocols/json_test_data/XPowGate.json +13 -5
- cirq/protocols/json_test_data/XPowGate.repr +1 -1
- cirq/protocols/json_test_data/ZPowGate.json +13 -5
- cirq/protocols/json_test_data/ZPowGate.repr +1 -1
- cirq/protocols/json_test_data/ZipLongest.json +19 -0
- cirq/protocols/json_test_data/ZipLongest.repr +1 -0
- cirq/protocols/json_test_data/spec.py +1 -0
- cirq/protocols/kraus_protocol.py +3 -4
- cirq/protocols/measurement_key_protocol.py +3 -1
- cirq/protocols/mixture_protocol.py +3 -2
- cirq/protocols/phase_protocol.py +3 -3
- cirq/protocols/pow_protocol.py +1 -2
- cirq/protocols/qasm.py +4 -4
- cirq/protocols/qid_shape_protocol.py +8 -8
- cirq/protocols/resolve_parameters.py +8 -3
- cirq/protocols/resolve_parameters_test.py +3 -3
- cirq/protocols/unitary_protocol.py +19 -11
- cirq/protocols/unitary_protocol_test.py +37 -0
- cirq/qis/channels.py +1 -1
- cirq/qis/clifford_tableau.py +4 -5
- cirq/qis/quantum_state_representation.py +7 -9
- cirq/qis/states.py +21 -13
- cirq/qis/states_test.py +7 -0
- cirq/sim/clifford/clifford_simulator.py +3 -3
- cirq/sim/density_matrix_simulation_state.py +2 -1
- cirq/sim/density_matrix_simulator.py +1 -1
- cirq/sim/density_matrix_simulator_test.py +9 -5
- cirq/sim/density_matrix_utils.py +7 -32
- cirq/sim/mux.py +2 -2
- cirq/sim/simulation_state.py +58 -18
- cirq/sim/simulation_state_base.py +5 -2
- cirq/sim/simulation_state_test.py +121 -9
- cirq/sim/simulation_utils.py +59 -0
- cirq/sim/simulation_utils_test.py +32 -0
- cirq/sim/simulator.py +2 -1
- cirq/sim/simulator_base_test.py +3 -3
- cirq/sim/sparse_simulator.py +1 -1
- cirq/sim/sparse_simulator_test.py +5 -5
- cirq/sim/state_vector.py +7 -36
- cirq/sim/state_vector_simulation_state.py +18 -1
- cirq/sim/state_vector_simulator.py +3 -2
- cirq/sim/state_vector_simulator_test.py +24 -2
- cirq/sim/state_vector_test.py +46 -15
- cirq/study/__init__.py +1 -0
- cirq/study/flatten_expressions.py +2 -2
- cirq/study/resolver.py +2 -0
- cirq/study/resolver_test.py +1 -1
- cirq/study/result.py +1 -1
- cirq/study/sweeps.py +103 -9
- cirq/study/sweeps_test.py +64 -0
- cirq/testing/__init__.py +4 -0
- cirq/testing/circuit_compare.py +15 -18
- cirq/testing/consistent_act_on.py +4 -4
- cirq/testing/consistent_controlled_gate_op_test.py +1 -1
- cirq/testing/consistent_decomposition.py +11 -2
- cirq/testing/consistent_decomposition_test.py +8 -1
- cirq/testing/consistent_protocols.py +2 -0
- cirq/testing/consistent_protocols_test.py +8 -4
- cirq/testing/consistent_qasm.py +8 -15
- cirq/testing/consistent_specified_has_unitary.py +1 -1
- cirq/testing/consistent_unitary.py +85 -0
- cirq/testing/consistent_unitary_test.py +96 -0
- cirq/testing/equivalent_repr_eval.py +10 -10
- cirq/testing/json.py +3 -3
- cirq/testing/logs.py +1 -1
- cirq/testing/order_tester.py +4 -5
- cirq/testing/random_circuit.py +3 -5
- cirq/testing/sample_gates.py +79 -0
- cirq/testing/sample_gates_test.py +59 -0
- cirq/transformers/__init__.py +2 -0
- cirq/transformers/analytical_decompositions/__init__.py +8 -0
- cirq/transformers/analytical_decompositions/pauli_string_decomposition.py +130 -0
- cirq/transformers/analytical_decompositions/pauli_string_decomposition_test.py +58 -0
- cirq/transformers/analytical_decompositions/quantum_shannon_decomposition.py +230 -0
- cirq/transformers/analytical_decompositions/quantum_shannon_decomposition_test.py +112 -0
- cirq/transformers/analytical_decompositions/three_qubit_decomposition_test.py +1 -3
- cirq/transformers/analytical_decompositions/two_qubit_to_fsim.py +1 -1
- cirq/transformers/expand_composite.py +1 -1
- cirq/transformers/heuristic_decompositions/gate_tabulation_math_utils.py +4 -4
- cirq/transformers/measurement_transformers.py +4 -4
- cirq/transformers/merge_single_qubit_gates.py +17 -4
- cirq/transformers/routing/route_circuit_cqc.py +2 -2
- cirq/transformers/stratify.py +125 -62
- cirq/transformers/stratify_test.py +20 -16
- cirq/transformers/transformer_api.py +1 -1
- cirq/transformers/transformer_primitives.py +3 -2
- cirq/transformers/transformer_primitives_test.py +11 -0
- cirq/value/abc_alt.py +3 -2
- cirq/value/abc_alt_test.py +1 -0
- cirq/value/classical_data.py +10 -10
- cirq/value/digits.py +2 -2
- cirq/value/linear_dict.py +18 -19
- cirq/value/product_state.py +7 -6
- cirq/value/value_equality_attr.py +2 -2
- cirq/vis/heatmap.py +1 -1
- cirq/vis/heatmap_test.py +2 -2
- cirq/work/collector.py +2 -2
- cirq/work/observable_measurement_data.py +5 -5
- cirq/work/observable_readout_calibration.py +3 -1
- cirq/work/observable_settings.py +1 -1
- cirq/work/pauli_sum_collector.py +9 -8
- cirq/work/sampler.py +2 -0
- cirq/work/zeros_sampler.py +2 -2
- {cirq_core-1.1.0.dev20221219200817.dist-info → cirq_core-1.2.0.dist-info}/METADATA +7 -15
- {cirq_core-1.1.0.dev20221219200817.dist-info → cirq_core-1.2.0.dist-info}/RECORD +229 -215
- {cirq_core-1.1.0.dev20221219200817.dist-info → cirq_core-1.2.0.dist-info}/WHEEL +1 -1
- {cirq_core-1.1.0.dev20221219200817.dist-info → cirq_core-1.2.0.dist-info}/LICENSE +0 -0
- {cirq_core-1.1.0.dev20221219200817.dist-info → cirq_core-1.2.0.dist-info}/top_level.txt +0 -0
cirq/value/digits.py
CHANGED
|
@@ -182,8 +182,8 @@ def big_endian_int_to_digits(
|
|
|
182
182
|
if val:
|
|
183
183
|
raise ValueError(
|
|
184
184
|
'Out of range. '
|
|
185
|
-
'Extracted digits {!r} but the long division process '
|
|
186
|
-
'left behind {!r} instead of 0.'
|
|
185
|
+
f'Extracted digits {result!r} but the long division process '
|
|
186
|
+
f'left behind {val!r} instead of 0.'
|
|
187
187
|
)
|
|
188
188
|
|
|
189
189
|
return result[::-1]
|
cirq/value/linear_dict.py
CHANGED
|
@@ -18,20 +18,21 @@ from typing import (
|
|
|
18
18
|
Any,
|
|
19
19
|
Callable,
|
|
20
20
|
Dict,
|
|
21
|
+
Generic,
|
|
21
22
|
ItemsView,
|
|
22
23
|
Iterable,
|
|
23
24
|
Iterator,
|
|
24
25
|
KeysView,
|
|
25
26
|
Mapping,
|
|
26
27
|
MutableMapping,
|
|
28
|
+
Optional,
|
|
27
29
|
overload,
|
|
28
30
|
Tuple,
|
|
29
31
|
TypeVar,
|
|
30
32
|
Union,
|
|
31
33
|
ValuesView,
|
|
32
|
-
Generic,
|
|
33
|
-
Optional,
|
|
34
34
|
)
|
|
35
|
+
from typing_extensions import Self
|
|
35
36
|
|
|
36
37
|
Scalar = Union[complex, float, numbers.Complex]
|
|
37
38
|
TVector = TypeVar('TVector')
|
|
@@ -41,8 +42,8 @@ TDefault = TypeVar('TDefault')
|
|
|
41
42
|
|
|
42
43
|
def _format_coefficient(format_spec: str, coefficient: Scalar) -> str:
|
|
43
44
|
coefficient = complex(coefficient)
|
|
44
|
-
real_str = '{:{
|
|
45
|
-
imag_str = '{:{
|
|
45
|
+
real_str = f'{coefficient.real:{format_spec}}'
|
|
46
|
+
imag_str = f'{coefficient.imag:{format_spec}}'
|
|
46
47
|
if float(real_str) == 0 and float(imag_str) == 0:
|
|
47
48
|
return ''
|
|
48
49
|
if float(imag_str) == 0:
|
|
@@ -70,7 +71,7 @@ def _format_terms(terms: Iterable[Tuple[TVector, Scalar]], format_spec: str):
|
|
|
70
71
|
formatted_terms = [_format_term(format_spec, vector, coeff) for vector, coeff in terms]
|
|
71
72
|
s = ''.join(formatted_terms)
|
|
72
73
|
if not s:
|
|
73
|
-
return '{:{
|
|
74
|
+
return f'{0:{format_spec}}'
|
|
74
75
|
if s[0] == '+':
|
|
75
76
|
return s[1:]
|
|
76
77
|
return s
|
|
@@ -94,7 +95,7 @@ class LinearDict(Generic[TVector], MutableMapping[TVector, Scalar]):
|
|
|
94
95
|
def __init__(
|
|
95
96
|
self,
|
|
96
97
|
terms: Optional[Mapping[TVector, Scalar]] = None,
|
|
97
|
-
validator: Callable[[TVector], bool] = None,
|
|
98
|
+
validator: Optional[Callable[[TVector], bool]] = None,
|
|
98
99
|
) -> None:
|
|
99
100
|
"""Initializes linear combination from a collection of terms.
|
|
100
101
|
|
|
@@ -113,8 +114,6 @@ class LinearDict(Generic[TVector], MutableMapping[TVector, Scalar]):
|
|
|
113
114
|
if terms is not None:
|
|
114
115
|
self.update(terms)
|
|
115
116
|
|
|
116
|
-
TSelf = TypeVar('TSelf', bound='LinearDict[TVector]')
|
|
117
|
-
|
|
118
117
|
@classmethod
|
|
119
118
|
def fromkeys(cls, vectors, coefficient=0):
|
|
120
119
|
return LinearDict(dict.fromkeys(vectors, complex(coefficient)))
|
|
@@ -123,14 +122,14 @@ class LinearDict(Generic[TVector], MutableMapping[TVector, Scalar]):
|
|
|
123
122
|
if not self._is_valid(vector):
|
|
124
123
|
raise ValueError(f'{vector} is not compatible with linear combination {self}')
|
|
125
124
|
|
|
126
|
-
def clean(self
|
|
125
|
+
def clean(self, *, atol: float = 1e-9) -> Self:
|
|
127
126
|
"""Remove terms with coefficients of absolute value atol or less."""
|
|
128
127
|
negligible = [v for v, c in self._terms.items() if abs(c) <= atol] # type: ignore[operator]
|
|
129
128
|
for v in negligible:
|
|
130
129
|
del self._terms[v]
|
|
131
130
|
return self
|
|
132
131
|
|
|
133
|
-
def copy(self
|
|
132
|
+
def copy(self) -> Self:
|
|
134
133
|
factory = type(self)
|
|
135
134
|
return factory(self._terms.copy())
|
|
136
135
|
|
|
@@ -206,19 +205,19 @@ class LinearDict(Generic[TVector], MutableMapping[TVector, Scalar]):
|
|
|
206
205
|
def __len__(self) -> int:
|
|
207
206
|
return len([v for v, c in self._terms.items() if c != 0])
|
|
208
207
|
|
|
209
|
-
def __iadd__(self
|
|
208
|
+
def __iadd__(self, other: Self) -> Self:
|
|
210
209
|
for vector, other_coefficient in other.items():
|
|
211
210
|
old_coefficient = self._terms.get(vector, 0)
|
|
212
211
|
new_coefficient = old_coefficient + other_coefficient
|
|
213
212
|
self[vector] = new_coefficient
|
|
214
213
|
return self.clean(atol=0)
|
|
215
214
|
|
|
216
|
-
def __add__(self
|
|
215
|
+
def __add__(self, other: Self) -> Self:
|
|
217
216
|
result = self.copy()
|
|
218
217
|
result += other
|
|
219
218
|
return result
|
|
220
219
|
|
|
221
|
-
def __isub__(self
|
|
220
|
+
def __isub__(self, other: Self) -> Self:
|
|
222
221
|
for vector, other_coefficient in other.items():
|
|
223
222
|
old_coefficient = self._terms.get(vector, 0)
|
|
224
223
|
new_coefficient = old_coefficient - other_coefficient
|
|
@@ -226,30 +225,30 @@ class LinearDict(Generic[TVector], MutableMapping[TVector, Scalar]):
|
|
|
226
225
|
self.clean(atol=0)
|
|
227
226
|
return self
|
|
228
227
|
|
|
229
|
-
def __sub__(self
|
|
228
|
+
def __sub__(self, other: Self) -> Self:
|
|
230
229
|
result = self.copy()
|
|
231
230
|
result -= other
|
|
232
231
|
return result
|
|
233
232
|
|
|
234
|
-
def __neg__(self
|
|
233
|
+
def __neg__(self) -> Self:
|
|
235
234
|
factory = type(self)
|
|
236
235
|
return factory({v: -c for v, c in self.items()})
|
|
237
236
|
|
|
238
|
-
def __imul__(self
|
|
237
|
+
def __imul__(self, a: Scalar) -> Self:
|
|
239
238
|
for vector in self:
|
|
240
239
|
self._terms[vector] *= a
|
|
241
240
|
self.clean(atol=0)
|
|
242
241
|
return self
|
|
243
242
|
|
|
244
|
-
def __mul__(self
|
|
243
|
+
def __mul__(self, a: Scalar) -> Self:
|
|
245
244
|
result = self.copy()
|
|
246
245
|
result *= a
|
|
247
246
|
return result
|
|
248
247
|
|
|
249
|
-
def __rmul__(self
|
|
248
|
+
def __rmul__(self, a: Scalar) -> Self:
|
|
250
249
|
return self.__mul__(a)
|
|
251
250
|
|
|
252
|
-
def __truediv__(self
|
|
251
|
+
def __truediv__(self, a: Scalar) -> Self:
|
|
253
252
|
return self.__mul__(1 / a)
|
|
254
253
|
|
|
255
254
|
def __bool__(self) -> bool:
|
cirq/value/product_state.py
CHANGED
|
@@ -11,9 +11,10 @@
|
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
|
+
|
|
14
15
|
import abc
|
|
15
16
|
from dataclasses import dataclass
|
|
16
|
-
from typing import
|
|
17
|
+
from typing import Dict, Iterator, Optional, Sequence, Tuple, TYPE_CHECKING
|
|
17
18
|
|
|
18
19
|
import numpy as np
|
|
19
20
|
|
|
@@ -77,7 +78,7 @@ class ProductState:
|
|
|
77
78
|
if len(dupe_qubits) != 0:
|
|
78
79
|
raise ValueError(
|
|
79
80
|
"You tried to tensor two states, "
|
|
80
|
-
"but both contain factors for these qubits: {
|
|
81
|
+
f"but both contain factors for these qubits: {sorted(dupe_qubits)}"
|
|
81
82
|
)
|
|
82
83
|
|
|
83
84
|
new_states = self.states.copy()
|
|
@@ -91,7 +92,7 @@ class ProductState:
|
|
|
91
92
|
states_dict_repr = ', '.join(
|
|
92
93
|
f'{repr(key)}: {repr(val)}' for key, val in self.states.items()
|
|
93
94
|
)
|
|
94
|
-
return 'cirq.ProductState({
|
|
95
|
+
return f'cirq.ProductState({{{states_dict_repr}}})'
|
|
95
96
|
|
|
96
97
|
def __getitem__(self, qubit: 'cirq.Qid') -> _NamedOneQubitState:
|
|
97
98
|
"""Return the _NamedOneQubitState at the given qubit."""
|
|
@@ -119,7 +120,7 @@ class ProductState:
|
|
|
119
120
|
def _from_json_dict_(cls, states, **kwargs):
|
|
120
121
|
return cls(states=dict(states))
|
|
121
122
|
|
|
122
|
-
def state_vector(self, qubit_order: 'cirq.QubitOrder' = None) -> np.ndarray:
|
|
123
|
+
def state_vector(self, qubit_order: Optional['cirq.QubitOrder'] = None) -> np.ndarray:
|
|
123
124
|
"""The state-vector representation of this state."""
|
|
124
125
|
from cirq import ops
|
|
125
126
|
|
|
@@ -136,7 +137,7 @@ class ProductState:
|
|
|
136
137
|
|
|
137
138
|
return mat
|
|
138
139
|
|
|
139
|
-
def projector(self, qubit_order: 'cirq.QubitOrder' = None) -> np.ndarray:
|
|
140
|
+
def projector(self, qubit_order: Optional['cirq.QubitOrder'] = None) -> np.ndarray:
|
|
140
141
|
"""The projector associated with this state expressed as a matrix.
|
|
141
142
|
|
|
142
143
|
This is |s⟩⟨s| where |s⟩ is this state.
|
|
@@ -322,4 +323,4 @@ document(
|
|
|
322
323
|
)
|
|
323
324
|
|
|
324
325
|
PAULI_STATES = [KET_PLUS, KET_MINUS, KET_IMAG, KET_MINUS_IMAG, KET_ZERO, KET_ONE]
|
|
325
|
-
document(PAULI_STATES, """All one-qubit states
|
|
326
|
+
document(PAULI_STATES, """All one-qubit states stabilized by the pauli operators.""")
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
"""Defines `@cirq.value_equality`, for easy __eq__/__hash__ methods."""
|
|
15
15
|
|
|
16
|
-
from typing import
|
|
16
|
+
from typing import Any, Callable, Optional, overload, Union
|
|
17
17
|
|
|
18
18
|
from typing_extensions import Protocol
|
|
19
19
|
|
|
@@ -132,7 +132,7 @@ def value_equality(
|
|
|
132
132
|
|
|
133
133
|
|
|
134
134
|
def value_equality(
|
|
135
|
-
cls: type = None,
|
|
135
|
+
cls: Optional[type] = None,
|
|
136
136
|
*,
|
|
137
137
|
unhashable: bool = False,
|
|
138
138
|
distinct_child_types: bool = False,
|
cirq/vis/heatmap.py
CHANGED
|
@@ -316,7 +316,7 @@ class TwoQubitInteractionHeatmap(Heatmap):
|
|
|
316
316
|
|
|
317
317
|
Args:
|
|
318
318
|
value_map: A map from a qubit tuple location to a value.
|
|
319
|
-
**kwargs:
|
|
319
|
+
**kwargs: Optional kwargs including
|
|
320
320
|
coupler_margin: float, default = 0.03
|
|
321
321
|
coupler_width: float, default = 0.6
|
|
322
322
|
"""
|
cirq/vis/heatmap_test.py
CHANGED
|
@@ -97,7 +97,7 @@ def test_cell_colors(ax, colormap_name):
|
|
|
97
97
|
)
|
|
98
98
|
_, mesh = random_heatmap.plot(ax)
|
|
99
99
|
|
|
100
|
-
colormap = mpl.
|
|
100
|
+
colormap = mpl.colormaps[colormap_name]
|
|
101
101
|
for path, facecolor in zip(mesh.get_paths(), mesh.get_facecolors()):
|
|
102
102
|
vertices = path.vertices[0:4]
|
|
103
103
|
row = int(round(np.mean([v[1] for v in vertices])))
|
|
@@ -218,7 +218,7 @@ def test_non_float_values(ax, format_string):
|
|
|
218
218
|
|
|
219
219
|
_, mesh = random_heatmap.plot(ax)
|
|
220
220
|
|
|
221
|
-
colormap = mpl.
|
|
221
|
+
colormap = mpl.colormaps[colormap_name]
|
|
222
222
|
for path, facecolor in zip(mesh.get_paths(), mesh.get_facecolors()):
|
|
223
223
|
vertices = path.vertices[0:4]
|
|
224
224
|
row = int(round(np.mean([v[1] for v in vertices])))
|
cirq/work/collector.py
CHANGED
|
@@ -19,7 +19,7 @@ from typing_extensions import Protocol
|
|
|
19
19
|
import duet
|
|
20
20
|
import numpy as np
|
|
21
21
|
|
|
22
|
-
from cirq import
|
|
22
|
+
from cirq import study, value
|
|
23
23
|
|
|
24
24
|
if TYPE_CHECKING:
|
|
25
25
|
import cirq
|
|
@@ -29,7 +29,7 @@ if TYPE_CHECKING:
|
|
|
29
29
|
class CircuitSampleJob:
|
|
30
30
|
"""Describes a sampling task."""
|
|
31
31
|
|
|
32
|
-
def __init__(self, circuit:
|
|
32
|
+
def __init__(self, circuit: 'cirq.AbstractCircuit', *, repetitions: int, tag: Any = None):
|
|
33
33
|
"""Inits CircuitSampleJob.
|
|
34
34
|
|
|
35
35
|
Args:
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
import dataclasses
|
|
16
16
|
import datetime
|
|
17
|
-
from typing import Any, Dict, Iterable, List, Mapping, Tuple, TYPE_CHECKING, Union
|
|
17
|
+
from typing import Any, Dict, Iterable, List, Mapping, Optional, Tuple, TYPE_CHECKING, Union
|
|
18
18
|
|
|
19
19
|
import numpy as np
|
|
20
20
|
import sympy
|
|
@@ -212,10 +212,10 @@ class BitstringAccumulator:
|
|
|
212
212
|
meas_spec: _MeasurementSpec,
|
|
213
213
|
simul_settings: List[InitObsSetting],
|
|
214
214
|
qubit_to_index: Dict['cirq.Qid', int],
|
|
215
|
-
bitstrings: np.ndarray = None,
|
|
216
|
-
chunksizes: np.ndarray = None,
|
|
217
|
-
timestamps: np.ndarray = None,
|
|
218
|
-
readout_calibration: 'BitstringAccumulator' = None,
|
|
215
|
+
bitstrings: Optional[np.ndarray] = None,
|
|
216
|
+
chunksizes: Optional[np.ndarray] = None,
|
|
217
|
+
timestamps: Optional[np.ndarray] = None,
|
|
218
|
+
readout_calibration: Optional['BitstringAccumulator'] = None,
|
|
219
219
|
):
|
|
220
220
|
self._meas_spec = meas_spec
|
|
221
221
|
self._simul_settings = simul_settings
|
|
@@ -17,7 +17,9 @@ def calibrate_readout_error(
|
|
|
17
17
|
):
|
|
18
18
|
# We know there won't be any fancy sweeps or observables so we can
|
|
19
19
|
# get away with more repetitions per job
|
|
20
|
-
stopping_criteria = dataclasses.replace(
|
|
20
|
+
stopping_criteria = dataclasses.replace(
|
|
21
|
+
stopping_criteria, repetitions_per_chunk=100_000 # type: ignore[type-var]
|
|
22
|
+
)
|
|
21
23
|
|
|
22
24
|
# Simultaneous readout characterization:
|
|
23
25
|
# We can measure all qubits simultaneously (i.e. _max_setting is ZZZ..ZZ
|
cirq/work/observable_settings.py
CHANGED
|
@@ -55,7 +55,7 @@ class InitObsSetting:
|
|
|
55
55
|
raise ValueError(
|
|
56
56
|
"`observable`'s qubits should be a subset of those "
|
|
57
57
|
"found in `init_state`. "
|
|
58
|
-
"observable qubits: {}. init_state qubits: {}"
|
|
58
|
+
f"observable qubits: {obs_qs}. init_state qubits: {init_qs}"
|
|
59
59
|
)
|
|
60
60
|
|
|
61
61
|
def __str__(self):
|
cirq/work/pauli_sum_collector.py
CHANGED
|
@@ -17,7 +17,7 @@ from typing import cast, Dict, Optional, Union, TYPE_CHECKING
|
|
|
17
17
|
|
|
18
18
|
import numpy as np
|
|
19
19
|
|
|
20
|
-
from cirq import
|
|
20
|
+
from cirq import ops
|
|
21
21
|
from cirq.work import collector
|
|
22
22
|
|
|
23
23
|
if TYPE_CHECKING:
|
|
@@ -29,7 +29,7 @@ class PauliSumCollector(collector.Collector):
|
|
|
29
29
|
|
|
30
30
|
def __init__(
|
|
31
31
|
self,
|
|
32
|
-
circuit: 'cirq.
|
|
32
|
+
circuit: 'cirq.AbstractCircuit',
|
|
33
33
|
observable: 'cirq.PauliSumLike',
|
|
34
34
|
*,
|
|
35
35
|
samples_per_term: int,
|
|
@@ -99,11 +99,12 @@ class PauliSumCollector(collector.Collector):
|
|
|
99
99
|
|
|
100
100
|
|
|
101
101
|
def _circuit_plus_pauli_string_measurements(
|
|
102
|
-
circuit: 'cirq.
|
|
103
|
-
) -> 'cirq.
|
|
102
|
+
circuit: 'cirq.AbstractCircuit', pauli_string: 'cirq.PauliString'
|
|
103
|
+
) -> 'cirq.AbstractCircuit':
|
|
104
104
|
"""A circuit measuring the given observable at the end of the given circuit."""
|
|
105
105
|
assert pauli_string
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
106
|
+
return circuit.from_moments(
|
|
107
|
+
*circuit,
|
|
108
|
+
pauli_string.to_z_basis_ops(),
|
|
109
|
+
ops.measure(*sorted(pauli_string.keys()), key='out'),
|
|
110
|
+
)
|
cirq/work/sampler.py
CHANGED
|
@@ -211,6 +211,7 @@ class Sampler(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
211
211
|
Returns:
|
|
212
212
|
Result list for this run; one for each possible parameter resolver.
|
|
213
213
|
"""
|
|
214
|
+
raise NotImplementedError
|
|
214
215
|
|
|
215
216
|
@value.alternative(requires='run_sweep', implementation=_run_sweep_async_impl)
|
|
216
217
|
async def run_sweep_async(
|
|
@@ -230,6 +231,7 @@ class Sampler(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
230
231
|
Returns:
|
|
231
232
|
Result list for this run; one for each possible parameter resolver.
|
|
232
233
|
"""
|
|
234
|
+
raise NotImplementedError
|
|
233
235
|
|
|
234
236
|
def run_batch(
|
|
235
237
|
self,
|
cirq/work/zeros_sampler.py
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
15
|
import abc
|
|
16
|
-
from typing import List, TYPE_CHECKING
|
|
16
|
+
from typing import List, Optional, TYPE_CHECKING
|
|
17
17
|
|
|
18
18
|
import numpy as np
|
|
19
19
|
|
|
@@ -26,7 +26,7 @@ if TYPE_CHECKING:
|
|
|
26
26
|
class ZerosSampler(work.Sampler, metaclass=abc.ABCMeta):
|
|
27
27
|
"""A dummy sampler for testing. Immediately returns zeroes."""
|
|
28
28
|
|
|
29
|
-
def __init__(self, device: devices.Device = None):
|
|
29
|
+
def __init__(self, device: Optional[devices.Device] = None):
|
|
30
30
|
"""Construct a sampler that returns 0 for all measurements.
|
|
31
31
|
|
|
32
32
|
Args:
|
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: cirq-core
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.2.0
|
|
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
|
|
7
7
|
Author-email: cirq-dev@googlegroups.com
|
|
8
8
|
License: Apache 2
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
Requires-Dist: duet (~=0.2.
|
|
9
|
+
Requires-Python: >=3.9.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Dist: duet (~=0.2.8)
|
|
12
12
|
Requires-Dist: matplotlib (~=3.0)
|
|
13
|
-
Requires-Dist: networkx (
|
|
14
|
-
Requires-Dist: numpy (
|
|
13
|
+
Requires-Dist: networkx (>=2.4)
|
|
14
|
+
Requires-Dist: numpy (~=1.16)
|
|
15
15
|
Requires-Dist: pandas
|
|
16
16
|
Requires-Dist: sortedcontainers (~=2.0)
|
|
17
17
|
Requires-Dist: scipy
|
|
18
18
|
Requires-Dist: sympy
|
|
19
|
-
Requires-Dist: typing-extensions
|
|
19
|
+
Requires-Dist: typing-extensions (>=4.2)
|
|
20
20
|
Requires-Dist: tqdm
|
|
21
|
-
Requires-Dist: backports.cached-property (~=1.0.1) ; python_version < "3.8"
|
|
22
21
|
Provides-Extra: contrib
|
|
23
22
|
Requires-Dist: ply (>=3.6) ; extra == 'contrib'
|
|
24
23
|
Requires-Dist: pylatex (~=1.3.0) ; extra == 'contrib'
|
|
@@ -27,11 +26,6 @@ Requires-Dist: opt-einsum ; extra == 'contrib'
|
|
|
27
26
|
Requires-Dist: autoray ; extra == 'contrib'
|
|
28
27
|
Requires-Dist: numba (>=0.53.0) ; extra == 'contrib'
|
|
29
28
|
|
|
30
|
-
**This is a development version of Cirq-core and may be unstable.**
|
|
31
|
-
|
|
32
|
-
**For the latest stable release of Cirq-core see**
|
|
33
|
-
`here <https://pypi.org/project/cirq-core>`__.
|
|
34
|
-
|
|
35
29
|
.. image:: https://raw.githubusercontent.com/quantumlib/Cirq/master/docs/images/Cirq_logo_color.png
|
|
36
30
|
:target: https://github.com/quantumlib/cirq
|
|
37
31
|
:alt: Cirq
|
|
@@ -50,5 +44,3 @@ To install the stable version of only **cirq-core**, use `pip install cirq-core`
|
|
|
50
44
|
To install the pre-release version of only **cirq-core**, use `pip install cirq-core --pre`.
|
|
51
45
|
|
|
52
46
|
To get all the optional modules installed as well, you'll have to use `pip install cirq` or `pip install cirq --pre` for the pre-release version.
|
|
53
|
-
|
|
54
|
-
|