cirq-core 1.6.0.dev20250520054601__py3-none-any.whl → 1.6.0.dev20250520183459__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/_compat.py +15 -17
- cirq/_compat_test.py +6 -9
- cirq/_doc.py +2 -2
- cirq/_import.py +6 -6
- cirq/_version.py +1 -1
- cirq/_version_test.py +1 -1
- cirq/circuits/_block_diagram_drawer.py +9 -10
- cirq/circuits/_box_drawing_character_data.py +6 -8
- cirq/circuits/_bucket_priority_queue.py +7 -7
- cirq/circuits/circuit.py +118 -125
- cirq/circuits/circuit_operation.py +38 -52
- cirq/circuits/circuit_test.py +4 -4
- cirq/circuits/frozen_circuit.py +13 -23
- cirq/circuits/moment.py +23 -29
- cirq/circuits/optimization_pass.py +4 -4
- cirq/circuits/optimization_pass_test.py +4 -6
- cirq/circuits/qasm_output.py +11 -11
- cirq/circuits/text_diagram_drawer.py +21 -36
- cirq/contrib/acquaintance/bipartite.py +5 -8
- cirq/contrib/acquaintance/executor.py +5 -5
- cirq/contrib/acquaintance/executor_test.py +3 -3
- cirq/contrib/acquaintance/gates.py +16 -26
- cirq/contrib/acquaintance/gates_test.py +3 -3
- cirq/contrib/acquaintance/mutation_utils.py +4 -4
- cirq/contrib/acquaintance/optimizers.py +4 -4
- cirq/contrib/acquaintance/permutation.py +15 -27
- cirq/contrib/acquaintance/shift.py +3 -3
- cirq/contrib/acquaintance/shift_swap_network.py +4 -4
- cirq/contrib/acquaintance/strategies/cubic.py +2 -2
- cirq/contrib/acquaintance/strategies/quartic_paired.py +6 -6
- cirq/contrib/bayesian_network/bayesian_network_gate.py +9 -10
- cirq/contrib/circuitdag/circuit_dag.py +2 -2
- cirq/contrib/custom_simulators/custom_state_simulator.py +3 -3
- cirq/contrib/custom_simulators/custom_state_simulator_test.py +4 -4
- cirq/contrib/graph_device/graph_device.py +5 -5
- cirq/contrib/graph_device/hypergraph.py +12 -12
- cirq/contrib/graph_device/uniform_graph_device.py +4 -4
- cirq/contrib/paulistring/clifford_optimize.py +2 -2
- cirq/contrib/paulistring/clifford_target_gateset.py +7 -7
- cirq/contrib/paulistring/pauli_string_measurement_with_readout_mitigation.py +31 -31
- cirq/contrib/paulistring/pauli_string_measurement_with_readout_mitigation_test.py +23 -23
- cirq/contrib/paulistring/recombine.py +3 -3
- cirq/contrib/paulistring/separate.py +2 -2
- cirq/contrib/qasm_import/_parser.py +20 -32
- cirq/contrib/qcircuit/qcircuit_diagram_info.py +3 -5
- cirq/contrib/quantum_volume/quantum_volume.py +24 -24
- cirq/contrib/quimb/density_matrix.py +12 -14
- cirq/contrib/quimb/mps_simulator.py +20 -20
- cirq/contrib/quimb/state_vector.py +6 -10
- cirq/contrib/quirk/export_to_quirk.py +3 -3
- cirq/contrib/quirk/quirk_gate.py +15 -15
- cirq/contrib/routing/device.py +3 -3
- cirq/contrib/routing/greedy.py +10 -21
- cirq/contrib/routing/initialization.py +2 -2
- cirq/contrib/routing/swap_network.py +3 -3
- cirq/contrib/routing/utils.py +2 -2
- cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking.py +8 -8
- cirq/contrib/svg/svg.py +3 -3
- cirq/devices/grid_device_metadata.py +10 -10
- cirq/devices/grid_qubit.py +20 -20
- cirq/devices/insertion_noise_model.py +5 -5
- cirq/devices/line_qubit.py +13 -13
- cirq/devices/named_topologies.py +18 -29
- cirq/devices/noise_model.py +3 -3
- cirq/devices/noise_properties.py +2 -2
- cirq/devices/noise_properties_test.py +1 -3
- cirq/devices/noise_utils.py +7 -7
- cirq/devices/superconducting_qubits_noise_properties.py +21 -21
- cirq/devices/superconducting_qubits_noise_properties_test.py +5 -7
- cirq/devices/thermal_noise_model.py +14 -14
- cirq/devices/unconstrained_device.py +2 -2
- cirq/experiments/benchmarking/parallel_xeb.py +29 -31
- cirq/experiments/n_qubit_tomography.py +5 -7
- cirq/experiments/qubit_characterizations.py +29 -40
- cirq/experiments/qubit_characterizations_test.py +1 -1
- cirq/experiments/random_quantum_circuit_generation.py +19 -33
- cirq/experiments/random_quantum_circuit_generation_test.py +6 -6
- cirq/experiments/readout_confusion_matrix.py +14 -14
- cirq/experiments/single_qubit_readout_calibration.py +12 -12
- cirq/experiments/t2_decay_experiment.py +7 -7
- cirq/experiments/two_qubit_xeb.py +32 -32
- cirq/experiments/two_qubit_xeb_test.py +5 -5
- cirq/experiments/xeb_fitting.py +25 -25
- cirq/experiments/xeb_sampling.py +22 -33
- cirq/experiments/xeb_simulation.py +5 -5
- cirq/experiments/xeb_simulation_test.py +3 -3
- cirq/experiments/z_phase_calibration.py +19 -19
- cirq/interop/quirk/cells/arithmetic_cells.py +23 -36
- cirq/interop/quirk/cells/cell.py +9 -21
- cirq/interop/quirk/cells/composite_cell.py +7 -22
- cirq/interop/quirk/cells/control_cells.py +8 -8
- cirq/interop/quirk/cells/input_cells.py +4 -4
- cirq/interop/quirk/cells/input_rotation_cells.py +5 -5
- cirq/interop/quirk/cells/parse.py +20 -23
- cirq/interop/quirk/cells/qubit_permutation_cells.py +3 -3
- cirq/interop/quirk/cells/swap_cell.py +3 -3
- cirq/interop/quirk/cells/testing.py +5 -7
- cirq/interop/quirk/url_to_circuit.py +17 -33
- cirq/json_resolver_cache.py +6 -6
- cirq/linalg/decompositions.py +20 -31
- cirq/linalg/diagonalize.py +4 -4
- cirq/linalg/diagonalize_test.py +3 -4
- cirq/linalg/operator_spaces.py +5 -5
- cirq/linalg/predicates.py +7 -7
- cirq/linalg/transformations.py +20 -20
- cirq/ops/arithmetic_operation.py +13 -15
- cirq/ops/boolean_hamiltonian.py +17 -17
- cirq/ops/classically_controlled_operation.py +13 -25
- cirq/ops/clifford_gate.py +31 -35
- cirq/ops/clifford_gate_test.py +2 -3
- cirq/ops/common_channels.py +30 -32
- cirq/ops/common_gates.py +64 -74
- cirq/ops/control_values.py +12 -12
- cirq/ops/controlled_gate.py +15 -30
- cirq/ops/controlled_gate_test.py +5 -5
- cirq/ops/controlled_operation.py +12 -25
- cirq/ops/controlled_operation_test.py +5 -5
- cirq/ops/dense_pauli_string.py +23 -34
- cirq/ops/dense_pauli_string_test.py +1 -2
- cirq/ops/diagonal_gate.py +9 -20
- cirq/ops/diagonal_gate_test.py +1 -3
- cirq/ops/eigen_gate.py +11 -23
- cirq/ops/eigen_gate_test.py +6 -8
- cirq/ops/fourier_transform.py +5 -5
- cirq/ops/fsim_gate.py +14 -14
- cirq/ops/gate_operation.py +23 -44
- cirq/ops/gateset.py +23 -37
- cirq/ops/gateset_test.py +2 -2
- cirq/ops/global_phase_op.py +8 -10
- cirq/ops/greedy_qubit_manager.py +6 -6
- cirq/ops/identity.py +9 -9
- cirq/ops/kraus_channel.py +7 -7
- cirq/ops/linear_combinations.py +29 -48
- cirq/ops/matrix_gates.py +8 -8
- cirq/ops/measure_util.py +13 -14
- cirq/ops/measurement_gate.py +18 -29
- cirq/ops/mixed_unitary_channel.py +8 -8
- cirq/ops/named_qubit.py +10 -10
- cirq/ops/op_tree.py +7 -7
- cirq/ops/parallel_gate.py +5 -5
- cirq/ops/parity_gates.py +14 -14
- cirq/ops/pauli_gates.py +8 -10
- cirq/ops/pauli_interaction_gate.py +6 -6
- cirq/ops/pauli_measurement_gate.py +11 -23
- cirq/ops/pauli_string.py +35 -52
- cirq/ops/pauli_string_phasor.py +4 -14
- cirq/ops/pauli_string_raw_types.py +3 -3
- cirq/ops/pauli_sum_exponential.py +2 -2
- cirq/ops/permutation_gate.py +4 -4
- cirq/ops/phased_iswap_gate.py +9 -9
- cirq/ops/phased_x_gate.py +10 -10
- cirq/ops/phased_x_z_gate.py +11 -11
- cirq/ops/projector.py +6 -6
- cirq/ops/qubit_manager.py +6 -6
- cirq/ops/qubit_order.py +3 -3
- cirq/ops/random_gate_channel.py +4 -4
- cirq/ops/raw_types.py +48 -70
- cirq/ops/state_preparation_channel.py +3 -3
- cirq/ops/swap_gates.py +9 -9
- cirq/ops/tags.py +2 -4
- cirq/ops/three_qubit_gates.py +20 -38
- cirq/ops/two_qubit_diagonal_gate.py +5 -5
- cirq/ops/uniform_superposition_gate.py +2 -2
- cirq/ops/wait_gate.py +5 -5
- cirq/protocols/act_on_protocol_test.py +3 -3
- cirq/protocols/apply_channel_protocol.py +8 -14
- cirq/protocols/apply_mixture_protocol.py +14 -16
- cirq/protocols/apply_mixture_protocol_test.py +5 -6
- cirq/protocols/apply_unitary_protocol.py +17 -19
- cirq/protocols/circuit_diagram_info_protocol.py +19 -30
- cirq/protocols/decompose_protocol.py +30 -34
- cirq/protocols/inverse_protocol.py +7 -7
- cirq/protocols/json_serialization.py +32 -51
- cirq/protocols/json_serialization_test.py +9 -10
- cirq/protocols/kraus_protocol.py +4 -4
- cirq/protocols/kraus_protocol_test.py +3 -3
- cirq/protocols/measurement_key_protocol.py +11 -13
- cirq/protocols/mixture_protocol.py +4 -4
- cirq/protocols/qasm.py +11 -13
- cirq/protocols/qid_shape_protocol.py +6 -8
- cirq/qis/clifford_tableau.py +12 -12
- cirq/qis/measures.py +7 -7
- cirq/qis/quantum_state_representation.py +3 -3
- cirq/qis/states.py +51 -51
- cirq/sim/classical_simulator.py +10 -10
- cirq/sim/clifford/clifford_simulator.py +6 -6
- cirq/sim/clifford/clifford_tableau_simulation_state_test.py +1 -3
- cirq/sim/clifford/stabilizer_sampler.py +4 -4
- cirq/sim/clifford/stabilizer_state_ch_form.py +3 -3
- cirq/sim/density_matrix_simulation_state.py +15 -15
- cirq/sim/density_matrix_simulator.py +11 -11
- cirq/sim/density_matrix_utils.py +9 -9
- cirq/sim/mux.py +9 -9
- cirq/sim/simulation_product_state.py +9 -9
- cirq/sim/simulation_product_state_test.py +2 -2
- cirq/sim/simulation_state.py +14 -27
- cirq/sim/simulation_state_base.py +8 -24
- cirq/sim/simulation_utils.py +3 -4
- cirq/sim/simulator.py +28 -43
- cirq/sim/simulator_base.py +12 -25
- cirq/sim/simulator_base_test.py +6 -6
- cirq/sim/simulator_test.py +7 -7
- cirq/sim/sparse_simulator.py +8 -8
- cirq/sim/state_vector.py +8 -8
- cirq/sim/state_vector_simulation_state.py +17 -17
- cirq/sim/state_vector_simulator.py +4 -4
- cirq/study/flatten_expressions.py +12 -14
- cirq/study/resolver.py +9 -11
- cirq/study/result.py +11 -24
- cirq/study/sweepable.py +5 -5
- cirq/study/sweeps.py +27 -40
- cirq/testing/circuit_compare.py +5 -5
- cirq/testing/consistent_controlled_gate_op_test.py +7 -11
- cirq/testing/consistent_protocols.py +10 -10
- cirq/testing/consistent_protocols_test.py +7 -7
- cirq/testing/consistent_qasm.py +4 -4
- cirq/testing/consistent_qasm_test.py +2 -3
- cirq/testing/devices.py +4 -5
- cirq/testing/equals_tester.py +2 -2
- cirq/testing/equivalent_basis_map.py +4 -4
- cirq/testing/equivalent_repr_eval.py +3 -3
- cirq/testing/json.py +14 -14
- cirq/testing/logs.py +3 -3
- cirq/testing/no_identifier_qubit.py +2 -3
- cirq/testing/random_circuit.py +7 -7
- cirq/testing/random_circuit_test.py +3 -3
- cirq/transformers/analytical_decompositions/clifford_decomposition.py +16 -16
- cirq/transformers/analytical_decompositions/controlled_gate_decomposition.py +13 -13
- cirq/transformers/analytical_decompositions/cphase_to_fsim.py +5 -5
- cirq/transformers/analytical_decompositions/cphase_to_fsim_test.py +3 -3
- cirq/transformers/analytical_decompositions/pauli_string_decomposition.py +3 -3
- cirq/transformers/analytical_decompositions/quantum_shannon_decomposition.py +4 -4
- cirq/transformers/analytical_decompositions/single_qubit_decompositions.py +6 -7
- cirq/transformers/analytical_decompositions/single_to_two_qubit_isometry.py +2 -2
- cirq/transformers/analytical_decompositions/three_qubit_decomposition.py +7 -7
- cirq/transformers/analytical_decompositions/two_qubit_state_preparation.py +4 -4
- cirq/transformers/analytical_decompositions/two_qubit_to_cz.py +7 -7
- cirq/transformers/analytical_decompositions/two_qubit_to_fsim.py +11 -11
- cirq/transformers/analytical_decompositions/two_qubit_to_ms.py +5 -5
- cirq/transformers/analytical_decompositions/two_qubit_to_sqrt_iswap.py +14 -14
- cirq/transformers/dynamical_decoupling.py +13 -13
- cirq/transformers/dynamical_decoupling_test.py +4 -4
- cirq/transformers/eject_phased_paulis.py +16 -16
- cirq/transformers/eject_z.py +5 -7
- cirq/transformers/gauge_compiling/gauge_compiling.py +38 -38
- cirq/transformers/gauge_compiling/sqrt_cz_gauge.py +2 -2
- cirq/transformers/heuristic_decompositions/two_qubit_gate_tabulation.py +8 -8
- cirq/transformers/insertion_sort.py +5 -5
- cirq/transformers/measurement_transformers.py +14 -14
- cirq/transformers/merge_k_qubit_gates_test.py +1 -3
- cirq/transformers/merge_single_qubit_gates_test.py +1 -3
- cirq/transformers/qubit_management_transformers.py +5 -5
- cirq/transformers/routing/initial_mapper.py +4 -4
- cirq/transformers/routing/line_initial_mapper.py +9 -9
- cirq/transformers/routing/mapping_manager.py +7 -7
- cirq/transformers/routing/route_circuit_cqc.py +27 -27
- cirq/transformers/routing/visualize_routed_circuit.py +4 -4
- cirq/transformers/stratify.py +8 -8
- cirq/transformers/synchronize_terminal_measurements.py +6 -6
- cirq/transformers/target_gatesets/compilation_target_gateset.py +8 -8
- cirq/transformers/target_gatesets/compilation_target_gateset_test.py +2 -2
- cirq/transformers/target_gatesets/cz_gateset.py +4 -4
- cirq/transformers/target_gatesets/sqrt_iswap_gateset.py +5 -5
- cirq/transformers/transformer_api.py +11 -26
- cirq/transformers/transformer_primitives.py +24 -36
- cirq/transformers/transformer_primitives_test.py +3 -3
- cirq/value/classical_data.py +18 -18
- cirq/value/condition.py +8 -8
- cirq/value/digits.py +7 -7
- cirq/value/duration.py +12 -12
- cirq/value/linear_dict.py +8 -12
- cirq/value/linear_dict_test.py +2 -2
- cirq/value/measurement_key.py +8 -8
- cirq/value/product_state.py +9 -9
- cirq/value/value_equality_attr.py +4 -4
- cirq/vis/heatmap.py +23 -35
- cirq/work/collector.py +9 -17
- cirq/work/observable_grouping.py +4 -7
- cirq/work/observable_measurement.py +29 -41
- cirq/work/observable_measurement_data.py +14 -14
- cirq/work/observable_measurement_test.py +2 -2
- cirq/work/observable_settings.py +9 -10
- cirq/work/pauli_sum_collector.py +5 -5
- cirq/work/sampler.py +17 -17
- cirq/work/zeros_sampler.py +3 -3
- {cirq_core-1.6.0.dev20250520054601.dist-info → cirq_core-1.6.0.dev20250520183459.dist-info}/METADATA +1 -1
- {cirq_core-1.6.0.dev20250520054601.dist-info → cirq_core-1.6.0.dev20250520183459.dist-info}/RECORD +290 -290
- {cirq_core-1.6.0.dev20250520054601.dist-info → cirq_core-1.6.0.dev20250520183459.dist-info}/WHEEL +1 -1
- {cirq_core-1.6.0.dev20250520054601.dist-info → cirq_core-1.6.0.dev20250520183459.dist-info}/licenses/LICENSE +0 -0
- {cirq_core-1.6.0.dev20250520054601.dist-info → cirq_core-1.6.0.dev20250520183459.dist-info}/top_level.txt +0 -0
cirq/protocols/kraus_protocol.py
CHANGED
|
@@ -18,7 +18,7 @@ from __future__ import annotations
|
|
|
18
18
|
|
|
19
19
|
import warnings
|
|
20
20
|
from types import NotImplementedType
|
|
21
|
-
from typing import Any, Sequence,
|
|
21
|
+
from typing import Any, Sequence, TypeVar
|
|
22
22
|
|
|
23
23
|
import numpy as np
|
|
24
24
|
from typing_extensions import Protocol
|
|
@@ -33,7 +33,7 @@ from cirq.protocols.unitary_protocol import unitary
|
|
|
33
33
|
# Sequence[np.ndarray] to ensure the method has the correct type signature in
|
|
34
34
|
# that case. It is checked for using `is`, so it won't have a false positive
|
|
35
35
|
# if the user provides a different (np.array([]),) value.
|
|
36
|
-
RaiseTypeErrorIfNotProvided:
|
|
36
|
+
RaiseTypeErrorIfNotProvided: tuple[np.ndarray] = (np.array([]),)
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
TDefault = TypeVar('TDefault')
|
|
@@ -43,7 +43,7 @@ class SupportsKraus(Protocol):
|
|
|
43
43
|
"""An object that may be describable as a quantum channel."""
|
|
44
44
|
|
|
45
45
|
@doc_private
|
|
46
|
-
def _kraus_(self) ->
|
|
46
|
+
def _kraus_(self) -> Sequence[np.ndarray] | NotImplementedType:
|
|
47
47
|
r"""A list of Kraus matrices describing the quantum channel.
|
|
48
48
|
|
|
49
49
|
These matrices are the terms in the operator sum representation of a
|
|
@@ -96,7 +96,7 @@ class SupportsKraus(Protocol):
|
|
|
96
96
|
|
|
97
97
|
def kraus(
|
|
98
98
|
val: Any, default: Any = RaiseTypeErrorIfNotProvided
|
|
99
|
-
) ->
|
|
99
|
+
) -> tuple[np.ndarray, ...] | TDefault:
|
|
100
100
|
r"""Returns a list of matrices describing the channel for the given value.
|
|
101
101
|
|
|
102
102
|
These matrices are the terms in the operator sum representation of
|
|
@@ -16,14 +16,14 @@
|
|
|
16
16
|
|
|
17
17
|
from __future__ import annotations
|
|
18
18
|
|
|
19
|
-
from typing import Iterable,
|
|
19
|
+
from typing import Iterable, Sequence
|
|
20
20
|
|
|
21
21
|
import numpy as np
|
|
22
22
|
import pytest
|
|
23
23
|
|
|
24
24
|
import cirq
|
|
25
25
|
|
|
26
|
-
LOCAL_DEFAULT:
|
|
26
|
+
LOCAL_DEFAULT: list[np.ndarray] = [np.array([])]
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
def test_kraus_no_methods() -> None:
|
|
@@ -104,7 +104,7 @@ def test_kraus_fallback_to_mixture() -> None:
|
|
|
104
104
|
m = ((0.3, cirq.unitary(cirq.X)), (0.4, cirq.unitary(cirq.Y)), (0.3, cirq.unitary(cirq.Z)))
|
|
105
105
|
|
|
106
106
|
class ReturnsMixture:
|
|
107
|
-
def _mixture_(self) -> Iterable[
|
|
107
|
+
def _mixture_(self) -> Iterable[tuple[float, np.ndarray]]:
|
|
108
108
|
return m
|
|
109
109
|
|
|
110
110
|
c = (
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
from __future__ import annotations
|
|
18
18
|
|
|
19
19
|
from types import NotImplementedType
|
|
20
|
-
from typing import Any,
|
|
20
|
+
from typing import Any, Mapping, TYPE_CHECKING
|
|
21
21
|
|
|
22
22
|
from typing_extensions import Protocol
|
|
23
23
|
|
|
@@ -72,9 +72,7 @@ class SupportsMeasurementKey(Protocol):
|
|
|
72
72
|
"""
|
|
73
73
|
|
|
74
74
|
@doc_private
|
|
75
|
-
def _measurement_key_objs_(
|
|
76
|
-
self,
|
|
77
|
-
) -> Union[FrozenSet[cirq.MeasurementKey], NotImplementedType, None]:
|
|
75
|
+
def _measurement_key_objs_(self) -> frozenset[cirq.MeasurementKey] | NotImplementedType | None:
|
|
78
76
|
"""Return the key objects for measurements performed by the receiving object.
|
|
79
77
|
|
|
80
78
|
When a measurement occurs, either on hardware, or in a simulation,
|
|
@@ -92,7 +90,7 @@ class SupportsMeasurementKey(Protocol):
|
|
|
92
90
|
"""
|
|
93
91
|
|
|
94
92
|
@doc_private
|
|
95
|
-
def _measurement_key_names_(self) ->
|
|
93
|
+
def _measurement_key_names_(self) -> frozenset[str] | NotImplementedType | None:
|
|
96
94
|
"""Return the string keys for measurements performed by the receiving object.
|
|
97
95
|
|
|
98
96
|
When a measurement occurs, either on hardware, or in a simulation,
|
|
@@ -178,7 +176,7 @@ def measurement_key_name(val: Any, default: Any = RaiseTypeErrorIfNotProvided):
|
|
|
178
176
|
|
|
179
177
|
def _measurement_key_objs_from_magic_methods(
|
|
180
178
|
val: Any,
|
|
181
|
-
) ->
|
|
179
|
+
) -> frozenset[cirq.MeasurementKey] | NotImplementedType | None:
|
|
182
180
|
"""Uses the measurement key related magic methods to get the `MeasurementKey`s for this
|
|
183
181
|
object."""
|
|
184
182
|
|
|
@@ -196,7 +194,7 @@ def _measurement_key_objs_from_magic_methods(
|
|
|
196
194
|
|
|
197
195
|
def _measurement_key_names_from_magic_methods(
|
|
198
196
|
val: Any,
|
|
199
|
-
) ->
|
|
197
|
+
) -> frozenset[str] | NotImplementedType | None:
|
|
200
198
|
"""Uses the measurement key related magic methods to get the key strings for this object."""
|
|
201
199
|
|
|
202
200
|
getter = getattr(val, '_measurement_key_names_', None)
|
|
@@ -212,7 +210,7 @@ def _measurement_key_names_from_magic_methods(
|
|
|
212
210
|
return result
|
|
213
211
|
|
|
214
212
|
|
|
215
|
-
def measurement_key_objs(val: Any) ->
|
|
213
|
+
def measurement_key_objs(val: Any) -> frozenset[cirq.MeasurementKey]:
|
|
216
214
|
"""Gets the measurement key objects of measurements within the given value.
|
|
217
215
|
|
|
218
216
|
Args:
|
|
@@ -231,7 +229,7 @@ def measurement_key_objs(val: Any) -> FrozenSet[cirq.MeasurementKey]:
|
|
|
231
229
|
return frozenset()
|
|
232
230
|
|
|
233
231
|
|
|
234
|
-
def measurement_key_names(val: Any) ->
|
|
232
|
+
def measurement_key_names(val: Any) -> frozenset[str]:
|
|
235
233
|
"""Gets the measurement key strings of measurements within the given value.
|
|
236
234
|
|
|
237
235
|
Args:
|
|
@@ -256,7 +254,7 @@ def measurement_key_names(val: Any) -> FrozenSet[str]:
|
|
|
256
254
|
return frozenset()
|
|
257
255
|
|
|
258
256
|
|
|
259
|
-
def _is_measurement_from_magic_method(val: Any) ->
|
|
257
|
+
def _is_measurement_from_magic_method(val: Any) -> bool | None:
|
|
260
258
|
"""Uses `is_measurement` magic method to determine if this object is a measurement."""
|
|
261
259
|
getter = getattr(val, '_is_measurement_', None)
|
|
262
260
|
return NotImplemented if getter is None else getter()
|
|
@@ -292,7 +290,7 @@ def with_measurement_key_mapping(val: Any, key_map: Mapping[str, str]):
|
|
|
292
290
|
return NotImplemented if getter is None else getter(key_map)
|
|
293
291
|
|
|
294
292
|
|
|
295
|
-
def with_key_path(val: Any, path:
|
|
293
|
+
def with_key_path(val: Any, path: tuple[str, ...]):
|
|
296
294
|
"""Adds the path to the target's measurement keys.
|
|
297
295
|
|
|
298
296
|
The path usually refers to an identifier or a list of identifiers from a subcircuit that
|
|
@@ -303,7 +301,7 @@ def with_key_path(val: Any, path: Tuple[str, ...]):
|
|
|
303
301
|
return NotImplemented if getter is None else getter(path)
|
|
304
302
|
|
|
305
303
|
|
|
306
|
-
def with_key_path_prefix(val: Any, prefix:
|
|
304
|
+
def with_key_path_prefix(val: Any, prefix: tuple[str, ...]):
|
|
307
305
|
"""Prefixes the path to the target's measurement keys.
|
|
308
306
|
|
|
309
307
|
The path usually refers to an identifier or a list of identifiers from a subcircuit that
|
|
@@ -319,7 +317,7 @@ def with_key_path_prefix(val: Any, prefix: Tuple[str, ...]):
|
|
|
319
317
|
|
|
320
318
|
|
|
321
319
|
def with_rescoped_keys(
|
|
322
|
-
val: Any, path:
|
|
320
|
+
val: Any, path: tuple[str, ...], bindable_keys: frozenset[cirq.MeasurementKey] | None = None
|
|
323
321
|
):
|
|
324
322
|
"""Rescopes any measurement and control keys to the provided path, given the existing keys.
|
|
325
323
|
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
from __future__ import annotations
|
|
18
18
|
|
|
19
19
|
from types import NotImplementedType
|
|
20
|
-
from typing import Any, Sequence
|
|
20
|
+
from typing import Any, Sequence
|
|
21
21
|
|
|
22
22
|
import numpy as np
|
|
23
23
|
from typing_extensions import Protocol
|
|
@@ -29,14 +29,14 @@ from cirq.protocols.unitary_protocol import unitary
|
|
|
29
29
|
|
|
30
30
|
# This is a special indicator value used by the inverse method to determine
|
|
31
31
|
# whether or not the caller provided a 'default' argument.
|
|
32
|
-
RaiseTypeErrorIfNotProvided: Sequence[
|
|
32
|
+
RaiseTypeErrorIfNotProvided: Sequence[tuple[float, Any]] = ((0.0, []),)
|
|
33
33
|
|
|
34
34
|
|
|
35
35
|
class SupportsMixture(Protocol):
|
|
36
36
|
"""An object that decomposes into a probability distribution of unitaries."""
|
|
37
37
|
|
|
38
38
|
@doc_private
|
|
39
|
-
def _mixture_(self) ->
|
|
39
|
+
def _mixture_(self) -> Sequence[tuple[float, Any]] | NotImplementedType:
|
|
40
40
|
"""Decompose into a probability distribution of unitaries.
|
|
41
41
|
|
|
42
42
|
This method is used by the global `cirq.mixture` method.
|
|
@@ -67,7 +67,7 @@ class SupportsMixture(Protocol):
|
|
|
67
67
|
|
|
68
68
|
def mixture(
|
|
69
69
|
val: Any, default: Any = RaiseTypeErrorIfNotProvided
|
|
70
|
-
) -> Sequence[
|
|
70
|
+
) -> Sequence[tuple[float, np.ndarray]]:
|
|
71
71
|
"""Return a sequence of tuples representing a probabilistic unitary.
|
|
72
72
|
|
|
73
73
|
A mixture is described by an iterable of tuples of the form
|
cirq/protocols/qasm.py
CHANGED
|
@@ -16,7 +16,7 @@ from __future__ import annotations
|
|
|
16
16
|
|
|
17
17
|
import string
|
|
18
18
|
from types import NotImplementedType
|
|
19
|
-
from typing import Any,
|
|
19
|
+
from typing import Any, Iterable, TYPE_CHECKING, TypeVar
|
|
20
20
|
|
|
21
21
|
from typing_extensions import Protocol
|
|
22
22
|
|
|
@@ -38,9 +38,9 @@ class QasmArgs(string.Formatter):
|
|
|
38
38
|
self,
|
|
39
39
|
precision: int = 10,
|
|
40
40
|
version: str = '2.0',
|
|
41
|
-
qubit_id_map:
|
|
42
|
-
meas_key_id_map:
|
|
43
|
-
meas_key_bitcount:
|
|
41
|
+
qubit_id_map: dict[cirq.Qid, str] | None = None,
|
|
42
|
+
meas_key_id_map: dict[str, str] | None = None,
|
|
43
|
+
meas_key_bitcount: dict[str, int] | None = None,
|
|
44
44
|
) -> None:
|
|
45
45
|
"""Inits QasmArgs.
|
|
46
46
|
|
|
@@ -99,7 +99,7 @@ class SupportsQasm(Protocol):
|
|
|
99
99
|
"""
|
|
100
100
|
|
|
101
101
|
@doc_private
|
|
102
|
-
def _qasm_(self) ->
|
|
102
|
+
def _qasm_(self) -> None | NotImplementedType | str:
|
|
103
103
|
pass
|
|
104
104
|
|
|
105
105
|
|
|
@@ -112,7 +112,7 @@ class SupportsQasmWithArgs(Protocol):
|
|
|
112
112
|
"""
|
|
113
113
|
|
|
114
114
|
@doc_private
|
|
115
|
-
def _qasm_(self, args: QasmArgs) ->
|
|
115
|
+
def _qasm_(self, args: QasmArgs) -> None | NotImplementedType | str:
|
|
116
116
|
pass
|
|
117
117
|
|
|
118
118
|
|
|
@@ -125,9 +125,7 @@ class SupportsQasmWithArgsAndQubits(Protocol):
|
|
|
125
125
|
"""
|
|
126
126
|
|
|
127
127
|
@doc_private
|
|
128
|
-
def _qasm_(
|
|
129
|
-
self, qubits: Tuple[cirq.Qid], args: QasmArgs
|
|
130
|
-
) -> Union[None, NotImplementedType, str]:
|
|
128
|
+
def _qasm_(self, qubits: tuple[cirq.Qid], args: QasmArgs) -> None | NotImplementedType | str:
|
|
131
129
|
pass
|
|
132
130
|
|
|
133
131
|
|
|
@@ -135,10 +133,10 @@ class SupportsQasmWithArgsAndQubits(Protocol):
|
|
|
135
133
|
def qasm(
|
|
136
134
|
val: Any,
|
|
137
135
|
*,
|
|
138
|
-
args:
|
|
139
|
-
qubits:
|
|
136
|
+
args: QasmArgs | None = None,
|
|
137
|
+
qubits: Iterable[cirq.Qid] | None = None,
|
|
140
138
|
default: TDefault = RaiseTypeErrorIfNotProvided,
|
|
141
|
-
) ->
|
|
139
|
+
) -> str | TDefault:
|
|
142
140
|
"""Returns QASM code for the given value, if possible.
|
|
143
141
|
|
|
144
142
|
Different values require different sets of arguments. The general rule of
|
|
@@ -171,7 +169,7 @@ def qasm(
|
|
|
171
169
|
method = getattr(val, '_qasm_', None)
|
|
172
170
|
result = NotImplemented
|
|
173
171
|
if method is not None:
|
|
174
|
-
kwargs:
|
|
172
|
+
kwargs: dict[str, Any] = {}
|
|
175
173
|
if args is not None:
|
|
176
174
|
kwargs['args'] = args
|
|
177
175
|
# pylint: disable=not-callable
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
17
|
from types import NotImplementedType
|
|
18
|
-
from typing import Any, Sequence,
|
|
18
|
+
from typing import Any, Sequence, TypeVar
|
|
19
19
|
|
|
20
20
|
from typing_extensions import Protocol
|
|
21
21
|
|
|
@@ -24,7 +24,7 @@ from cirq._doc import doc_private, document
|
|
|
24
24
|
|
|
25
25
|
# This is a special indicator value used by the methods to determine whether or
|
|
26
26
|
# not the caller provided a 'default' argument. It must be of type
|
|
27
|
-
#
|
|
27
|
+
# tuple[int, ...] to ensure the method has the correct type signature in that
|
|
28
28
|
# case. It is checked for using `is`, so it won't have a false positive if the
|
|
29
29
|
# user provides a different (0,) value.
|
|
30
30
|
RaiseTypeErrorIfNotProvided: Any = (0,)
|
|
@@ -39,7 +39,7 @@ class SupportsExplicitQidShape(Protocol):
|
|
|
39
39
|
number qubits/qudits/qids, each with a specific number of quantum levels."""
|
|
40
40
|
|
|
41
41
|
@doc_private
|
|
42
|
-
def _qid_shape_(self) ->
|
|
42
|
+
def _qid_shape_(self) -> tuple[int, ...] | NotImplementedType:
|
|
43
43
|
"""A tuple specifying the number of quantum levels of each qid this
|
|
44
44
|
object operates on, e.g. (2, 2, 2) for a three-qubit gate.
|
|
45
45
|
|
|
@@ -67,7 +67,7 @@ class SupportsExplicitNumQubits(Protocol):
|
|
|
67
67
|
number of qubits."""
|
|
68
68
|
|
|
69
69
|
@document
|
|
70
|
-
def _num_qubits_(self) ->
|
|
70
|
+
def _num_qubits_(self) -> int | NotImplementedType:
|
|
71
71
|
"""The number of qubits, qudits, or qids this object operates on.
|
|
72
72
|
|
|
73
73
|
This method is used by the global `cirq.num_qubits` method (and by
|
|
@@ -82,7 +82,7 @@ class SupportsExplicitNumQubits(Protocol):
|
|
|
82
82
|
|
|
83
83
|
def qid_shape(
|
|
84
84
|
val: Any, default: TDefault = RaiseTypeErrorIfNotProvided
|
|
85
|
-
) ->
|
|
85
|
+
) -> tuple[int, ...] | TDefault:
|
|
86
86
|
"""Returns a tuple describing the number of quantum levels of each
|
|
87
87
|
qubit/qudit/qid `val` operates on.
|
|
88
88
|
|
|
@@ -136,9 +136,7 @@ def qid_shape(
|
|
|
136
136
|
raise TypeError(f"object of type '{type(val)}' has no _num_qubits_ or _qid_shape_ methods.")
|
|
137
137
|
|
|
138
138
|
|
|
139
|
-
def num_qubits(
|
|
140
|
-
val: Any, default: TDefault = RaiseTypeErrorIfNotProvidedInt
|
|
141
|
-
) -> Union[int, TDefault]:
|
|
139
|
+
def num_qubits(val: Any, default: TDefault = RaiseTypeErrorIfNotProvidedInt) -> int | TDefault:
|
|
142
140
|
"""Returns the number of qubits, qudits, or qids `val` operates on.
|
|
143
141
|
|
|
144
142
|
Args:
|
cirq/qis/clifford_tableau.py
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
17
|
import abc
|
|
18
|
-
from typing import Any,
|
|
18
|
+
from typing import Any, Sequence, TYPE_CHECKING
|
|
19
19
|
|
|
20
20
|
import numpy as np
|
|
21
21
|
|
|
@@ -147,9 +147,9 @@ class CliffordTableau(StabilizerState):
|
|
|
147
147
|
self,
|
|
148
148
|
num_qubits,
|
|
149
149
|
initial_state: int = 0,
|
|
150
|
-
rs:
|
|
151
|
-
xs:
|
|
152
|
-
zs:
|
|
150
|
+
rs: np.ndarray | None = None,
|
|
151
|
+
xs: np.ndarray | None = None,
|
|
152
|
+
zs: np.ndarray | None = None,
|
|
153
153
|
):
|
|
154
154
|
"""Initializes CliffordTableau
|
|
155
155
|
Args:
|
|
@@ -166,7 +166,7 @@ class CliffordTableau(StabilizerState):
|
|
|
166
166
|
self._xs = self._reconstruct_xs(xs)
|
|
167
167
|
self._zs = self._reconstruct_zs(zs)
|
|
168
168
|
|
|
169
|
-
def _reconstruct_rs(self, rs:
|
|
169
|
+
def _reconstruct_rs(self, rs: np.ndarray | None) -> np.ndarray:
|
|
170
170
|
if rs is None:
|
|
171
171
|
new_rs = np.zeros(2 * self.n + 1, dtype=bool)
|
|
172
172
|
for i, val in enumerate(
|
|
@@ -185,7 +185,7 @@ class CliffordTableau(StabilizerState):
|
|
|
185
185
|
)
|
|
186
186
|
return new_rs
|
|
187
187
|
|
|
188
|
-
def _reconstruct_xs(self, xs:
|
|
188
|
+
def _reconstruct_xs(self, xs: np.ndarray | None) -> np.ndarray:
|
|
189
189
|
if xs is None:
|
|
190
190
|
new_xs = np.zeros((2 * self.n + 1, self.n), dtype=bool)
|
|
191
191
|
for i in range(self.n):
|
|
@@ -207,7 +207,7 @@ class CliffordTableau(StabilizerState):
|
|
|
207
207
|
)
|
|
208
208
|
return new_xs
|
|
209
209
|
|
|
210
|
-
def _reconstruct_zs(self, zs:
|
|
210
|
+
def _reconstruct_zs(self, zs: np.ndarray | None) -> np.ndarray:
|
|
211
211
|
if zs is None:
|
|
212
212
|
new_zs = np.zeros((2 * self.n + 1, self.n), dtype=bool)
|
|
213
213
|
for i in range(self.n):
|
|
@@ -260,7 +260,7 @@ class CliffordTableau(StabilizerState):
|
|
|
260
260
|
"""Returns the 2n * 2n matrix representation of the Clifford tableau."""
|
|
261
261
|
return np.concatenate([self.xs, self.zs], axis=1)
|
|
262
262
|
|
|
263
|
-
def _json_dict_(self) ->
|
|
263
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
264
264
|
return protocols.obj_to_dict_helper(self, ['n', 'rs', 'xs', 'zs'])
|
|
265
265
|
|
|
266
266
|
@classmethod
|
|
@@ -511,12 +511,12 @@ class CliffordTableau(StabilizerState):
|
|
|
511
511
|
pauli_mask += "I"
|
|
512
512
|
return DensePauliString(pauli_mask, coefficient=coefficient)
|
|
513
513
|
|
|
514
|
-
def stabilizers(self) ->
|
|
514
|
+
def stabilizers(self) -> list[cirq.DensePauliString]:
|
|
515
515
|
"""Returns the stabilizer generators of the state. These
|
|
516
516
|
are n operators {S_1,S_2,...,S_n} such that S_i |psi> = |psi>"""
|
|
517
517
|
return [self._row_to_dense_pauli(i) for i in range(self.n, 2 * self.n)]
|
|
518
518
|
|
|
519
|
-
def destabilizers(self) ->
|
|
519
|
+
def destabilizers(self) -> list[cirq.DensePauliString]:
|
|
520
520
|
"""Returns the destabilizer generators of the state. These
|
|
521
521
|
are n operators {S_1,S_2,...,S_n} such that along with the stabilizer
|
|
522
522
|
generators above generate the full Pauli group on n qubits."""
|
|
@@ -665,14 +665,14 @@ class CliffordTableau(StabilizerState):
|
|
|
665
665
|
|
|
666
666
|
def measure(
|
|
667
667
|
self, axes: Sequence[int], seed: cirq.RANDOM_STATE_OR_SEED_LIKE = None
|
|
668
|
-
) ->
|
|
668
|
+
) -> list[int]:
|
|
669
669
|
return [self._measure(axis, random_state.parse_random_state(seed)) for axis in axes]
|
|
670
670
|
|
|
671
671
|
@cached_method
|
|
672
672
|
def __hash__(self) -> int:
|
|
673
673
|
return hash(self.matrix().tobytes() + self.rs.tobytes())
|
|
674
674
|
|
|
675
|
-
def __getstate__(self) ->
|
|
675
|
+
def __getstate__(self) -> dict[str, Any]:
|
|
676
676
|
# clear cached hash value when pickling, see #6674
|
|
677
677
|
state = self.__dict__
|
|
678
678
|
hash_attr = _method_cache_name(self.__hash__)
|
cirq/qis/measures.py
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
from __future__ import annotations
|
|
18
18
|
|
|
19
|
-
from typing import
|
|
19
|
+
from typing import TYPE_CHECKING
|
|
20
20
|
|
|
21
21
|
import numpy as np
|
|
22
22
|
|
|
@@ -44,7 +44,7 @@ def _sqrt_positive_semidefinite_matrix(mat: np.ndarray) -> np.ndarray:
|
|
|
44
44
|
return vecs @ (np.sqrt(np.abs(eigs)) * vecs).T.conj()
|
|
45
45
|
|
|
46
46
|
|
|
47
|
-
def _validate_int_state(state: int, qid_shape:
|
|
47
|
+
def _validate_int_state(state: int, qid_shape: tuple[int, ...] | None) -> None:
|
|
48
48
|
if state < 0:
|
|
49
49
|
raise ValueError(
|
|
50
50
|
'Invalid state: A state specified as an integer must be non-negative, '
|
|
@@ -60,7 +60,7 @@ def _validate_int_state(state: int, qid_shape: Optional[Tuple[int, ...]]) -> Non
|
|
|
60
60
|
)
|
|
61
61
|
|
|
62
62
|
|
|
63
|
-
def _validate_product_state(state: cirq.ProductState, qid_shape:
|
|
63
|
+
def _validate_product_state(state: cirq.ProductState, qid_shape: tuple[int, ...] | None) -> None:
|
|
64
64
|
if qid_shape is not None and qid_shape != (2,) * len(state):
|
|
65
65
|
raise ValueError(
|
|
66
66
|
'Invalid state for given qid shape: '
|
|
@@ -72,7 +72,7 @@ def _validate_product_state(state: cirq.ProductState, qid_shape: Optional[Tuple[
|
|
|
72
72
|
def fidelity(
|
|
73
73
|
state1: cirq.QUANTUM_STATE_LIKE,
|
|
74
74
|
state2: cirq.QUANTUM_STATE_LIKE,
|
|
75
|
-
qid_shape:
|
|
75
|
+
qid_shape: tuple[int, ...] | None = None,
|
|
76
76
|
validate: bool = True,
|
|
77
77
|
atol: float = 1e-7,
|
|
78
78
|
) -> float:
|
|
@@ -156,10 +156,10 @@ def fidelity(
|
|
|
156
156
|
def _numpy_arrays_to_state_vectors_or_density_matrices(
|
|
157
157
|
state1: np.ndarray,
|
|
158
158
|
state2: np.ndarray,
|
|
159
|
-
qid_shape:
|
|
159
|
+
qid_shape: tuple[int, ...] | None,
|
|
160
160
|
validate: bool,
|
|
161
161
|
atol: float,
|
|
162
|
-
) ->
|
|
162
|
+
) -> tuple[np.ndarray, np.ndarray]:
|
|
163
163
|
if state1.ndim > 2 or (state1.ndim == 2 and state1.shape[0] != state1.shape[1]):
|
|
164
164
|
# State tensor, convert to state vector
|
|
165
165
|
state1 = state1.reshape(-1)
|
|
@@ -256,7 +256,7 @@ def _fidelity_state_vectors_or_density_matrices(state1: np.ndarray, state2: np.n
|
|
|
256
256
|
|
|
257
257
|
def von_neumann_entropy(
|
|
258
258
|
state: cirq.QUANTUM_STATE_LIKE,
|
|
259
|
-
qid_shape:
|
|
259
|
+
qid_shape: tuple[int, ...] | None = None,
|
|
260
260
|
validate: bool = True,
|
|
261
261
|
atol: float = 1e-7,
|
|
262
262
|
) -> float:
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
17
|
import abc
|
|
18
|
-
from typing import
|
|
18
|
+
from typing import Sequence, TYPE_CHECKING
|
|
19
19
|
|
|
20
20
|
import numpy as np
|
|
21
21
|
from typing_extensions import Self
|
|
@@ -41,7 +41,7 @@ class QuantumStateRepresentation(metaclass=abc.ABCMeta):
|
|
|
41
41
|
@abc.abstractmethod
|
|
42
42
|
def measure(
|
|
43
43
|
self, axes: Sequence[int], seed: cirq.RANDOM_STATE_OR_SEED_LIKE = None
|
|
44
|
-
) ->
|
|
44
|
+
) -> list[int]:
|
|
45
45
|
"""Measures the state.
|
|
46
46
|
|
|
47
47
|
Args:
|
|
@@ -74,7 +74,7 @@ class QuantumStateRepresentation(metaclass=abc.ABCMeta):
|
|
|
74
74
|
"""Joins two state spaces together."""
|
|
75
75
|
raise NotImplementedError()
|
|
76
76
|
|
|
77
|
-
def factor(self, axes: Sequence[int], *, validate=True, atol=1e-07) ->
|
|
77
|
+
def factor(self, axes: Sequence[int], *, validate=True, atol=1e-07) -> tuple[Self, Self]:
|
|
78
78
|
"""Splits two state spaces after a measurement or reset."""
|
|
79
79
|
raise NotImplementedError()
|
|
80
80
|
|