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
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
from typing import Any,
|
|
5
|
+
from typing import Any, Iterable, Mapping, TYPE_CHECKING
|
|
6
6
|
|
|
7
7
|
import numpy as np
|
|
8
8
|
|
|
@@ -30,8 +30,8 @@ class MixedUnitaryChannel(raw_types.Gate):
|
|
|
30
30
|
|
|
31
31
|
def __init__(
|
|
32
32
|
self,
|
|
33
|
-
mixture: Iterable[
|
|
34
|
-
key:
|
|
33
|
+
mixture: Iterable[tuple[float, np.ndarray]],
|
|
34
|
+
key: str | cirq.MeasurementKey | None = None,
|
|
35
35
|
validate: bool = False,
|
|
36
36
|
):
|
|
37
37
|
mixture = list(mixture)
|
|
@@ -61,7 +61,7 @@ class MixedUnitaryChannel(raw_types.Gate):
|
|
|
61
61
|
|
|
62
62
|
@staticmethod
|
|
63
63
|
def from_mixture(
|
|
64
|
-
mixture: protocols.SupportsMixture, key:
|
|
64
|
+
mixture: protocols.SupportsMixture, key: str | cirq.MeasurementKey | None = None
|
|
65
65
|
):
|
|
66
66
|
"""Creates a copy of a mixture with the given measurement key."""
|
|
67
67
|
return MixedUnitaryChannel(mixture=list(protocols.mixture(mixture)), key=key)
|
|
@@ -100,18 +100,18 @@ class MixedUnitaryChannel(raw_types.Gate):
|
|
|
100
100
|
return self
|
|
101
101
|
return MixedUnitaryChannel(mixture=self._mixture, key=key_map[str(self._key)])
|
|
102
102
|
|
|
103
|
-
def _with_key_path_(self, path:
|
|
103
|
+
def _with_key_path_(self, path: tuple[str, ...]):
|
|
104
104
|
return MixedUnitaryChannel(
|
|
105
105
|
mixture=self._mixture, key=protocols.with_key_path(self._key, path)
|
|
106
106
|
)
|
|
107
107
|
|
|
108
|
-
def _with_key_path_prefix_(self, prefix:
|
|
108
|
+
def _with_key_path_prefix_(self, prefix: tuple[str, ...]):
|
|
109
109
|
return MixedUnitaryChannel(
|
|
110
110
|
mixture=self._mixture, key=protocols.with_key_path_prefix(self._key, prefix)
|
|
111
111
|
)
|
|
112
112
|
|
|
113
113
|
def _with_rescoped_keys_(
|
|
114
|
-
self, path:
|
|
114
|
+
self, path: tuple[str, ...], bindable_keys: frozenset[cirq.MeasurementKey]
|
|
115
115
|
):
|
|
116
116
|
return MixedUnitaryChannel(
|
|
117
117
|
mixture=self._mixture, key=protocols.with_rescoped_keys(self._key, path, bindable_keys)
|
|
@@ -131,7 +131,7 @@ class MixedUnitaryChannel(raw_types.Gate):
|
|
|
131
131
|
args.append(f'key=\'{self._key}\'')
|
|
132
132
|
return f'cirq.MixedUnitaryChannel({", ".join(args)})'
|
|
133
133
|
|
|
134
|
-
def _json_dict_(self) ->
|
|
134
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
135
135
|
return protocols.obj_to_dict_helper(self, ['_mixture', '_key'])
|
|
136
136
|
|
|
137
137
|
@classmethod
|
cirq/ops/named_qubit.py
CHANGED
|
@@ -16,7 +16,7 @@ from __future__ import annotations
|
|
|
16
16
|
|
|
17
17
|
import functools
|
|
18
18
|
import weakref
|
|
19
|
-
from typing import Any,
|
|
19
|
+
from typing import Any, TYPE_CHECKING
|
|
20
20
|
|
|
21
21
|
from cirq import protocols
|
|
22
22
|
from cirq.ops import raw_types
|
|
@@ -31,8 +31,8 @@ class _BaseNamedQid(raw_types.Qid):
|
|
|
31
31
|
|
|
32
32
|
_name: str
|
|
33
33
|
_dimension: int
|
|
34
|
-
_comp_key:
|
|
35
|
-
_hash:
|
|
34
|
+
_comp_key: str | None = None
|
|
35
|
+
_hash: int | None = None
|
|
36
36
|
|
|
37
37
|
def __hash__(self) -> int:
|
|
38
38
|
if self._hash is None:
|
|
@@ -112,7 +112,7 @@ class NamedQid(_BaseNamedQid):
|
|
|
112
112
|
|
|
113
113
|
# Cache of existing NamedQid instances, returned by __new__ if available.
|
|
114
114
|
# Holds weak references so instances can still be garbage collected.
|
|
115
|
-
_cache = weakref.WeakValueDictionary[
|
|
115
|
+
_cache = weakref.WeakValueDictionary[tuple[str, int], 'cirq.NamedQid']()
|
|
116
116
|
|
|
117
117
|
def __new__(cls, name: str, dimension: int) -> cirq.NamedQid:
|
|
118
118
|
"""Initializes a `NamedQid` with a given name and dimension.
|
|
@@ -137,7 +137,7 @@ class NamedQid(_BaseNamedQid):
|
|
|
137
137
|
return (self._name, self._dimension)
|
|
138
138
|
|
|
139
139
|
# avoid pickling the _hash value, attributes are already stored with __getnewargs__
|
|
140
|
-
def __getstate__(self) ->
|
|
140
|
+
def __getstate__(self) -> dict[str, Any]:
|
|
141
141
|
return {}
|
|
142
142
|
|
|
143
143
|
def __repr__(self) -> str:
|
|
@@ -147,7 +147,7 @@ class NamedQid(_BaseNamedQid):
|
|
|
147
147
|
return f'{self._name} (d={self._dimension})'
|
|
148
148
|
|
|
149
149
|
@staticmethod
|
|
150
|
-
def range(*args, prefix: str, dimension: int) ->
|
|
150
|
+
def range(*args, prefix: str, dimension: int) -> list[NamedQid]:
|
|
151
151
|
"""Returns a range of ``NamedQid``\\s.
|
|
152
152
|
|
|
153
153
|
The range returned starts with the prefix, and followed by a qid for
|
|
@@ -170,7 +170,7 @@ class NamedQid(_BaseNamedQid):
|
|
|
170
170
|
"""
|
|
171
171
|
return [NamedQid(f"{prefix}{i}", dimension=dimension) for i in range(*args)]
|
|
172
172
|
|
|
173
|
-
def _json_dict_(self) ->
|
|
173
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
174
174
|
return protocols.obj_to_dict_helper(self, ['name', 'dimension'])
|
|
175
175
|
|
|
176
176
|
|
|
@@ -209,7 +209,7 @@ class NamedQubit(_BaseNamedQid):
|
|
|
209
209
|
return (self._name,)
|
|
210
210
|
|
|
211
211
|
# avoid pickling the _hash value, attributes are already stored with __getnewargs__
|
|
212
|
-
def __getstate__(self) ->
|
|
212
|
+
def __getstate__(self) -> dict[str, Any]:
|
|
213
213
|
return {}
|
|
214
214
|
|
|
215
215
|
def __str__(self) -> str:
|
|
@@ -219,7 +219,7 @@ class NamedQubit(_BaseNamedQid):
|
|
|
219
219
|
return f'cirq.NamedQubit({self._name!r})'
|
|
220
220
|
|
|
221
221
|
@staticmethod
|
|
222
|
-
def range(*args, prefix: str) ->
|
|
222
|
+
def range(*args, prefix: str) -> list[NamedQubit]:
|
|
223
223
|
r"""Returns a range of `cirq.NamedQubit`s.
|
|
224
224
|
|
|
225
225
|
The range returned starts with the prefix, and followed by a qubit for
|
|
@@ -241,7 +241,7 @@ class NamedQubit(_BaseNamedQid):
|
|
|
241
241
|
"""
|
|
242
242
|
return [NamedQubit(f"{prefix}{i}") for i in range(*args)]
|
|
243
243
|
|
|
244
|
-
def _json_dict_(self) ->
|
|
244
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
245
245
|
return protocols.obj_to_dict_helper(self, ['name'])
|
|
246
246
|
|
|
247
247
|
|
cirq/ops/op_tree.py
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
from __future__ import annotations
|
|
18
18
|
|
|
19
|
-
from typing import Callable, Iterable, Iterator, NoReturn, TYPE_CHECKING
|
|
19
|
+
from typing import Callable, Iterable, Iterator, NoReturn, TYPE_CHECKING
|
|
20
20
|
|
|
21
21
|
from cirq._doc import document
|
|
22
22
|
from cirq._import import LazyLoader
|
|
@@ -28,7 +28,7 @@ if TYPE_CHECKING:
|
|
|
28
28
|
moment = LazyLoader("moment", globals(), "cirq.circuits.moment")
|
|
29
29
|
|
|
30
30
|
|
|
31
|
-
OP_TREE =
|
|
31
|
+
OP_TREE = Operation | Iterable['OP_TREE']
|
|
32
32
|
document(
|
|
33
33
|
OP_TREE,
|
|
34
34
|
"""An operation or nested collections of operations.
|
|
@@ -37,10 +37,10 @@ document(
|
|
|
37
37
|
`cirq.OP_TREE` argument:
|
|
38
38
|
|
|
39
39
|
- A single operation (a `cirq.Operation`).
|
|
40
|
-
- A list of operations (a `
|
|
41
|
-
- A list of lists of operations (a `
|
|
40
|
+
- A list of operations (a `list[cirq.Operation]`).
|
|
41
|
+
- A list of lists of operations (a `list[list[cirq.Operation]]`).
|
|
42
42
|
- A list mixing operations and generators of operations
|
|
43
|
-
(a `
|
|
43
|
+
(a `list[Union[cirq.Operation, Iterator[cirq.Operation]]]`).
|
|
44
44
|
- Generally anything that can be iterated, and its items iterated, and
|
|
45
45
|
so forth recursively until a bottom layer of operations is found.
|
|
46
46
|
""",
|
|
@@ -49,7 +49,7 @@ document(
|
|
|
49
49
|
|
|
50
50
|
def flatten_op_tree(
|
|
51
51
|
root: OP_TREE, preserve_moments: bool = False
|
|
52
|
-
) -> Iterator[
|
|
52
|
+
) -> Iterator[Operation | cirq.Moment]:
|
|
53
53
|
"""Performs an in-order iteration of the operations (leaves) in an OP_TREE.
|
|
54
54
|
|
|
55
55
|
Args:
|
|
@@ -90,7 +90,7 @@ def flatten_to_ops(root: OP_TREE) -> Iterator[Operation]:
|
|
|
90
90
|
_bad_op_tree(root)
|
|
91
91
|
|
|
92
92
|
|
|
93
|
-
def flatten_to_ops_or_moments(root: OP_TREE) -> Iterator[
|
|
93
|
+
def flatten_to_ops_or_moments(root: OP_TREE) -> Iterator[Operation | cirq.Moment]:
|
|
94
94
|
"""Performs an in-order iteration OP_TREE, yielding ops and moments.
|
|
95
95
|
|
|
96
96
|
Args:
|
cirq/ops/parallel_gate.py
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
17
|
from types import NotImplementedType
|
|
18
|
-
from typing import AbstractSet, Any,
|
|
18
|
+
from typing import AbstractSet, Any, TYPE_CHECKING
|
|
19
19
|
|
|
20
20
|
import numpy as np
|
|
21
21
|
|
|
@@ -61,7 +61,7 @@ class ParallelGate(raw_types.Gate):
|
|
|
61
61
|
def num_copies(self) -> int:
|
|
62
62
|
return self._num_copies
|
|
63
63
|
|
|
64
|
-
def _decompose_(self, qubits:
|
|
64
|
+
def _decompose_(self, qubits: tuple[cirq.Qid, ...]) -> DecomposeResult:
|
|
65
65
|
if len(qubits) != self.num_qubits():
|
|
66
66
|
raise ValueError(f"len(qubits)={len(qubits)} should be {self.num_qubits()}")
|
|
67
67
|
step = self.sub_gate.num_qubits()
|
|
@@ -98,7 +98,7 @@ class ParallelGate(raw_types.Gate):
|
|
|
98
98
|
sub_gate=protocols.resolve_parameters(self.sub_gate, resolver, recursive)
|
|
99
99
|
)
|
|
100
100
|
|
|
101
|
-
def _unitary_(self) ->
|
|
101
|
+
def _unitary_(self) -> np.ndarray | NotImplementedType:
|
|
102
102
|
# Obtain the unitary for the single qubit gate
|
|
103
103
|
single_unitary = protocols.unitary(self.sub_gate, NotImplemented)
|
|
104
104
|
|
|
@@ -114,7 +114,7 @@ class ParallelGate(raw_types.Gate):
|
|
|
114
114
|
|
|
115
115
|
return unitary
|
|
116
116
|
|
|
117
|
-
def _trace_distance_bound_(self) ->
|
|
117
|
+
def _trace_distance_bound_(self) -> float | None:
|
|
118
118
|
if protocols.is_parameterized(self.sub_gate):
|
|
119
119
|
return None
|
|
120
120
|
angle = self._num_copies * np.arcsin(protocols.trace_distance_bound(self.sub_gate))
|
|
@@ -152,7 +152,7 @@ class ParallelGate(raw_types.Gate):
|
|
|
152
152
|
return NotImplemented
|
|
153
153
|
return self.with_gate(new_gate)
|
|
154
154
|
|
|
155
|
-
def _json_dict_(self) ->
|
|
155
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
156
156
|
return protocols.obj_to_dict_helper(self, attribute_names=["sub_gate", "num_copies"])
|
|
157
157
|
|
|
158
158
|
|
cirq/ops/parity_gates.py
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
from __future__ import annotations
|
|
18
18
|
|
|
19
|
-
from typing import Any,
|
|
19
|
+
from typing import Any, Iterator, Sequence, TYPE_CHECKING
|
|
20
20
|
|
|
21
21
|
import numpy as np
|
|
22
22
|
from typing_extensions import Self
|
|
@@ -73,7 +73,7 @@ class XXPowGate(gate_features.InterchangeableQubitsGate, eigen_gate.EigenGate):
|
|
|
73
73
|
def _num_qubits_(self) -> int:
|
|
74
74
|
return 2
|
|
75
75
|
|
|
76
|
-
def _eigen_components(self) ->
|
|
76
|
+
def _eigen_components(self) -> list[tuple[float, np.ndarray]]:
|
|
77
77
|
return [
|
|
78
78
|
(
|
|
79
79
|
0.0,
|
|
@@ -90,7 +90,7 @@ class XXPowGate(gate_features.InterchangeableQubitsGate, eigen_gate.EigenGate):
|
|
|
90
90
|
def _eigen_shifts(self):
|
|
91
91
|
return [0, 1]
|
|
92
92
|
|
|
93
|
-
def _trace_distance_bound_(self) ->
|
|
93
|
+
def _trace_distance_bound_(self) -> float | None:
|
|
94
94
|
if self._is_parameterized_():
|
|
95
95
|
return None
|
|
96
96
|
return abs(np.sin(self._exponent * 0.5 * np.pi))
|
|
@@ -119,14 +119,14 @@ class XXPowGate(gate_features.InterchangeableQubitsGate, eigen_gate.EigenGate):
|
|
|
119
119
|
def _has_stabilizer_effect_(self) -> bool:
|
|
120
120
|
return self.exponent % 2 in (0, 0.5, 1, 1.5)
|
|
121
121
|
|
|
122
|
-
def _decompose_(self, qubits:
|
|
122
|
+
def _decompose_(self, qubits: tuple[cirq.Qid, ...]) -> Iterator[cirq.OP_TREE]:
|
|
123
123
|
yield common_gates.YPowGate(exponent=-0.5).on_each(*qubits)
|
|
124
124
|
yield ZZPowGate(exponent=self.exponent, global_shift=self.global_shift)(*qubits)
|
|
125
125
|
yield common_gates.YPowGate(exponent=0.5).on_each(*qubits)
|
|
126
126
|
|
|
127
127
|
def _circuit_diagram_info_(
|
|
128
128
|
self, args: cirq.CircuitDiagramInfoArgs
|
|
129
|
-
) ->
|
|
129
|
+
) -> str | protocols.CircuitDiagramInfo:
|
|
130
130
|
return protocols.CircuitDiagramInfo(
|
|
131
131
|
wire_symbols=('XX', 'XX'), exponent=self._diagram_exponent(args)
|
|
132
132
|
)
|
|
@@ -180,7 +180,7 @@ class YYPowGate(gate_features.InterchangeableQubitsGate, eigen_gate.EigenGate):
|
|
|
180
180
|
def _num_qubits_(self) -> int:
|
|
181
181
|
return 2
|
|
182
182
|
|
|
183
|
-
def _eigen_components(self) ->
|
|
183
|
+
def _eigen_components(self) -> list[tuple[float, np.ndarray]]:
|
|
184
184
|
return [
|
|
185
185
|
(
|
|
186
186
|
0.0,
|
|
@@ -199,7 +199,7 @@ class YYPowGate(gate_features.InterchangeableQubitsGate, eigen_gate.EigenGate):
|
|
|
199
199
|
def _eigen_shifts(self):
|
|
200
200
|
return [0, 1]
|
|
201
201
|
|
|
202
|
-
def _trace_distance_bound_(self) ->
|
|
202
|
+
def _trace_distance_bound_(self) -> float | None:
|
|
203
203
|
if self._is_parameterized_():
|
|
204
204
|
return None
|
|
205
205
|
return abs(np.sin(self._exponent * 0.5 * np.pi))
|
|
@@ -228,7 +228,7 @@ class YYPowGate(gate_features.InterchangeableQubitsGate, eigen_gate.EigenGate):
|
|
|
228
228
|
def _has_stabilizer_effect_(self) -> bool:
|
|
229
229
|
return self.exponent % 2 in (0, 0.5, 1, 1.5)
|
|
230
230
|
|
|
231
|
-
def _decompose_(self, qubits:
|
|
231
|
+
def _decompose_(self, qubits: tuple[cirq.Qid, ...]) -> Iterator[cirq.OP_TREE]:
|
|
232
232
|
yield common_gates.XPowGate(exponent=0.5).on_each(*qubits)
|
|
233
233
|
yield ZZPowGate(exponent=self.exponent, global_shift=self.global_shift)(*qubits)
|
|
234
234
|
yield common_gates.XPowGate(exponent=-0.5).on_each(*qubits)
|
|
@@ -282,7 +282,7 @@ class ZZPowGate(gate_features.InterchangeableQubitsGate, eigen_gate.EigenGate):
|
|
|
282
282
|
|
|
283
283
|
def _decompose_into_clifford_with_qubits_(
|
|
284
284
|
self, qubits: Sequence[cirq.Qid]
|
|
285
|
-
) -> Sequence[
|
|
285
|
+
) -> Sequence[cirq.Operation | Sequence[cirq.Operation]]:
|
|
286
286
|
if not self._has_stabilizer_effect_():
|
|
287
287
|
return NotImplemented
|
|
288
288
|
if self.exponent % 2 == 0:
|
|
@@ -308,13 +308,13 @@ class ZZPowGate(gate_features.InterchangeableQubitsGate, eigen_gate.EigenGate):
|
|
|
308
308
|
def _has_stabilizer_effect_(self) -> bool:
|
|
309
309
|
return self.exponent % 2 in (0, 0.5, 1, 1.5)
|
|
310
310
|
|
|
311
|
-
def _eigen_components(self) ->
|
|
311
|
+
def _eigen_components(self) -> list[tuple[float, np.ndarray]]:
|
|
312
312
|
return [(0, np.diag([1, 0, 0, 1])), (1, np.diag([0, 1, 1, 0]))]
|
|
313
313
|
|
|
314
314
|
def _eigen_shifts(self):
|
|
315
315
|
return [0, 1]
|
|
316
316
|
|
|
317
|
-
def _trace_distance_bound_(self) ->
|
|
317
|
+
def _trace_distance_bound_(self) -> float | None:
|
|
318
318
|
if self._is_parameterized_():
|
|
319
319
|
return None
|
|
320
320
|
return abs(np.sin(self._exponent * 0.5 * np.pi))
|
|
@@ -324,7 +324,7 @@ class ZZPowGate(gate_features.InterchangeableQubitsGate, eigen_gate.EigenGate):
|
|
|
324
324
|
wire_symbols=('ZZ', 'ZZ'), exponent=self._diagram_exponent(args)
|
|
325
325
|
)
|
|
326
326
|
|
|
327
|
-
def _apply_unitary_(self, args: protocols.ApplyUnitaryArgs) ->
|
|
327
|
+
def _apply_unitary_(self, args: protocols.ApplyUnitaryArgs) -> np.ndarray | None:
|
|
328
328
|
if protocols.is_parameterized(self):
|
|
329
329
|
return None
|
|
330
330
|
|
|
@@ -381,7 +381,7 @@ class MSGate(XXPowGate):
|
|
|
381
381
|
|
|
382
382
|
def _circuit_diagram_info_(
|
|
383
383
|
self, args: cirq.CircuitDiagramInfoArgs
|
|
384
|
-
) ->
|
|
384
|
+
) -> str | protocols.CircuitDiagramInfo:
|
|
385
385
|
angle_str = self._format_exponent_as_angle(args, order=4)
|
|
386
386
|
symbol = f'MS({angle_str})'
|
|
387
387
|
return protocols.CircuitDiagramInfo(wire_symbols=(symbol, symbol))
|
|
@@ -401,7 +401,7 @@ class MSGate(XXPowGate):
|
|
|
401
401
|
def _json_namespace_(cls) -> str:
|
|
402
402
|
return 'cirq'
|
|
403
403
|
|
|
404
|
-
def _json_dict_(self) ->
|
|
404
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
405
405
|
return protocols.obj_to_dict_helper(self, ["rads"])
|
|
406
406
|
|
|
407
407
|
@classmethod
|
cirq/ops/pauli_gates.py
CHANGED
|
@@ -16,7 +16,7 @@ from __future__ import annotations
|
|
|
16
16
|
|
|
17
17
|
import abc
|
|
18
18
|
from types import NotImplementedType
|
|
19
|
-
from typing import Any, cast,
|
|
19
|
+
from typing import Any, cast, TYPE_CHECKING
|
|
20
20
|
|
|
21
21
|
from cirq._doc import document
|
|
22
22
|
from cirq._import import LazyLoader
|
|
@@ -42,7 +42,7 @@ class Pauli(raw_types.Gate, metaclass=abc.ABCMeta):
|
|
|
42
42
|
of private subclasses are the X, Y, or Z Pauli gates defined below.
|
|
43
43
|
"""
|
|
44
44
|
|
|
45
|
-
_XYZ:
|
|
45
|
+
_XYZ: tuple[Pauli, Pauli, Pauli]
|
|
46
46
|
|
|
47
47
|
@staticmethod
|
|
48
48
|
def by_index(index: int) -> Pauli:
|
|
@@ -59,9 +59,7 @@ class Pauli(raw_types.Gate, metaclass=abc.ABCMeta):
|
|
|
59
59
|
def num_qubits(self):
|
|
60
60
|
return 1
|
|
61
61
|
|
|
62
|
-
def _commutes_(
|
|
63
|
-
self, other: Any, *, atol: float = 1e-8
|
|
64
|
-
) -> Union[bool, NotImplementedType, None]:
|
|
62
|
+
def _commutes_(self, other: Any, *, atol: float = 1e-8) -> bool | NotImplementedType | None:
|
|
65
63
|
if not isinstance(other, Pauli):
|
|
66
64
|
return NotImplemented
|
|
67
65
|
return self is other
|
|
@@ -74,8 +72,8 @@ class Pauli(raw_types.Gate, metaclass=abc.ABCMeta):
|
|
|
74
72
|
return (self._index - second._index + 1) % 3 - 1
|
|
75
73
|
|
|
76
74
|
def phased_pauli_product(
|
|
77
|
-
self, other:
|
|
78
|
-
) ->
|
|
75
|
+
self, other: cirq.Pauli | identity.IdentityGate
|
|
76
|
+
) -> tuple[complex, cirq.Pauli | identity.IdentityGate]:
|
|
79
77
|
if self == other:
|
|
80
78
|
return 1, identity.I
|
|
81
79
|
if other is identity.I:
|
|
@@ -125,7 +123,7 @@ class _PauliX(Pauli, common_gates.XPowGate):
|
|
|
125
123
|
return Pauli._XYZ[0]
|
|
126
124
|
|
|
127
125
|
@property
|
|
128
|
-
def basis(self) ->
|
|
126
|
+
def basis(self) -> dict[int, _XEigenState]:
|
|
129
127
|
from cirq.value.product_state import _XEigenState
|
|
130
128
|
|
|
131
129
|
return {+1: _XEigenState(+1), -1: _XEigenState(-1)}
|
|
@@ -149,7 +147,7 @@ class _PauliY(Pauli, common_gates.YPowGate):
|
|
|
149
147
|
return Pauli._XYZ[1]
|
|
150
148
|
|
|
151
149
|
@property
|
|
152
|
-
def basis(self) ->
|
|
150
|
+
def basis(self) -> dict[int, _YEigenState]:
|
|
153
151
|
from cirq.value.product_state import _YEigenState
|
|
154
152
|
|
|
155
153
|
return {+1: _YEigenState(+1), -1: _YEigenState(-1)}
|
|
@@ -173,7 +171,7 @@ class _PauliZ(Pauli, common_gates.ZPowGate):
|
|
|
173
171
|
return Pauli._XYZ[2]
|
|
174
172
|
|
|
175
173
|
@property
|
|
176
|
-
def basis(self) ->
|
|
174
|
+
def basis(self) -> dict[int, _ZEigenState]:
|
|
177
175
|
from cirq.value.product_state import _ZEigenState
|
|
178
176
|
|
|
179
177
|
return {+1: _ZEigenState(+1), -1: _ZEigenState(-1)}
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
|
-
from typing import Any,
|
|
17
|
+
from typing import Any, Iterator, Sequence, TYPE_CHECKING
|
|
18
18
|
|
|
19
19
|
import numpy as np
|
|
20
20
|
|
|
@@ -26,7 +26,7 @@ from cirq.ops.clifford_gate import SingleQubitCliffordGate
|
|
|
26
26
|
if TYPE_CHECKING:
|
|
27
27
|
import cirq
|
|
28
28
|
|
|
29
|
-
PAULI_EIGEN_MAP:
|
|
29
|
+
PAULI_EIGEN_MAP: dict[pauli_gates.Pauli, tuple[np.ndarray, np.ndarray]] = {
|
|
30
30
|
pauli_gates.X: (np.array([[0.5, 0.5], [0.5, 0.5]]), np.array([[0.5, -0.5], [-0.5, 0.5]])),
|
|
31
31
|
pauli_gates.Y: (np.array([[0.5, -0.5j], [0.5j, 0.5]]), np.array([[0.5, 0.5j], [-0.5j, 0.5]])),
|
|
32
32
|
pauli_gates.Z: (np.diag([1, 0]), np.diag([0, 1])),
|
|
@@ -105,10 +105,10 @@ class PauliInteractionGate(gate_features.InterchangeableQubitsGate, eigen_gate.E
|
|
|
105
105
|
self.pauli0, self.invert0, self.pauli1, self.invert1, exponent=exponent
|
|
106
106
|
)
|
|
107
107
|
|
|
108
|
-
def _eigen_shifts(self) ->
|
|
108
|
+
def _eigen_shifts(self) -> list[float]:
|
|
109
109
|
return [0.0, 1.0]
|
|
110
110
|
|
|
111
|
-
def _eigen_components(self) ->
|
|
111
|
+
def _eigen_components(self) -> list[tuple[float, np.ndarray]]:
|
|
112
112
|
comp1 = np.kron(
|
|
113
113
|
PAULI_EIGEN_MAP[self.pauli0][not self.invert0],
|
|
114
114
|
PAULI_EIGEN_MAP[self.pauli1][not self.invert1],
|
|
@@ -130,7 +130,7 @@ class PauliInteractionGate(gate_features.InterchangeableQubitsGate, eigen_gate.E
|
|
|
130
130
|
yield right_gate1(q1)
|
|
131
131
|
|
|
132
132
|
def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs) -> cirq.CircuitDiagramInfo:
|
|
133
|
-
labels:
|
|
133
|
+
labels: dict[cirq.Pauli, str] = {pauli_gates.X: 'X', pauli_gates.Y: 'Y', pauli_gates.Z: '@'}
|
|
134
134
|
l0 = labels[self.pauli0]
|
|
135
135
|
l1 = labels[self.pauli1]
|
|
136
136
|
# Add brackets around letter if inverted
|
|
@@ -149,7 +149,7 @@ class PauliInteractionGate(gate_features.InterchangeableQubitsGate, eigen_gate.E
|
|
|
149
149
|
return base
|
|
150
150
|
return f'({base}**{proper_repr(self._exponent)})'
|
|
151
151
|
|
|
152
|
-
def _json_dict_(self) ->
|
|
152
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
153
153
|
return protocols.obj_to_dict_helper(self, ["pauli0", "invert0", "pauli1", "invert1"])
|
|
154
154
|
|
|
155
155
|
|
|
@@ -14,19 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
|
-
from typing import
|
|
18
|
-
Any,
|
|
19
|
-
cast,
|
|
20
|
-
Dict,
|
|
21
|
-
FrozenSet,
|
|
22
|
-
Iterable,
|
|
23
|
-
Iterator,
|
|
24
|
-
Mapping,
|
|
25
|
-
Sequence,
|
|
26
|
-
Tuple,
|
|
27
|
-
TYPE_CHECKING,
|
|
28
|
-
Union,
|
|
29
|
-
)
|
|
17
|
+
from typing import Any, cast, Iterable, Iterator, Mapping, Sequence, TYPE_CHECKING
|
|
30
18
|
|
|
31
19
|
from cirq import protocols, value
|
|
32
20
|
from cirq.ops import (
|
|
@@ -52,8 +40,8 @@ class PauliMeasurementGate(raw_types.Gate):
|
|
|
52
40
|
|
|
53
41
|
def __init__(
|
|
54
42
|
self,
|
|
55
|
-
observable:
|
|
56
|
-
key:
|
|
43
|
+
observable: cirq.BaseDensePauliString | Iterable[cirq.Pauli],
|
|
44
|
+
key: str | cirq.MeasurementKey = '',
|
|
57
45
|
) -> None:
|
|
58
46
|
"""Inits PauliMeasurementGate.
|
|
59
47
|
|
|
@@ -94,26 +82,26 @@ class PauliMeasurementGate(raw_types.Gate):
|
|
|
94
82
|
def mkey(self) -> cirq.MeasurementKey:
|
|
95
83
|
return self._mkey
|
|
96
84
|
|
|
97
|
-
def _qid_shape_(self) ->
|
|
85
|
+
def _qid_shape_(self) -> tuple[int, ...]:
|
|
98
86
|
return (2,) * len(self._observable)
|
|
99
87
|
|
|
100
88
|
def _has_unitary_(self) -> bool:
|
|
101
89
|
return False
|
|
102
90
|
|
|
103
|
-
def with_key(self, key:
|
|
91
|
+
def with_key(self, key: str | cirq.MeasurementKey) -> PauliMeasurementGate:
|
|
104
92
|
"""Creates a pauli measurement gate with a new key but otherwise identical."""
|
|
105
93
|
if key == self.key:
|
|
106
94
|
return self
|
|
107
95
|
return PauliMeasurementGate(self._observable, key=key)
|
|
108
96
|
|
|
109
|
-
def _with_key_path_(self, path:
|
|
97
|
+
def _with_key_path_(self, path: tuple[str, ...]) -> PauliMeasurementGate:
|
|
110
98
|
return self.with_key(self.mkey._with_key_path_(path))
|
|
111
99
|
|
|
112
|
-
def _with_key_path_prefix_(self, prefix:
|
|
100
|
+
def _with_key_path_prefix_(self, prefix: tuple[str, ...]) -> PauliMeasurementGate:
|
|
113
101
|
return self.with_key(self.mkey._with_key_path_prefix_(prefix))
|
|
114
102
|
|
|
115
103
|
def _with_rescoped_keys_(
|
|
116
|
-
self, path:
|
|
104
|
+
self, path: tuple[str, ...], bindable_keys: frozenset[cirq.MeasurementKey]
|
|
117
105
|
) -> PauliMeasurementGate:
|
|
118
106
|
return self.with_key(protocols.with_rescoped_keys(self.mkey, path, bindable_keys))
|
|
119
107
|
|
|
@@ -121,7 +109,7 @@ class PauliMeasurementGate(raw_types.Gate):
|
|
|
121
109
|
return self.with_key(protocols.with_measurement_key_mapping(self.mkey, key_map))
|
|
122
110
|
|
|
123
111
|
def with_observable(
|
|
124
|
-
self, observable:
|
|
112
|
+
self, observable: cirq.BaseDensePauliString | Iterable[cirq.Pauli]
|
|
125
113
|
) -> PauliMeasurementGate:
|
|
126
114
|
"""Creates a pauli measurement gate with the new observable and same key."""
|
|
127
115
|
if (
|
|
@@ -146,7 +134,7 @@ class PauliMeasurementGate(raw_types.Gate):
|
|
|
146
134
|
return self._observable
|
|
147
135
|
|
|
148
136
|
def _decompose_(
|
|
149
|
-
self, qubits:
|
|
137
|
+
self, qubits: tuple[cirq.Qid, ...]
|
|
150
138
|
) -> Iterator[protocols.decompose_protocol.DecomposeResult]:
|
|
151
139
|
any_qubit = qubits[0]
|
|
152
140
|
to_z_ops = op_tree.freeze_op_tree(self._observable.on(*qubits).to_z_basis_ops())
|
|
@@ -189,7 +177,7 @@ class PauliMeasurementGate(raw_types.Gate):
|
|
|
189
177
|
def _value_equality_values_(self) -> Any:
|
|
190
178
|
return self.key, self._observable
|
|
191
179
|
|
|
192
|
-
def _json_dict_(self) ->
|
|
180
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
193
181
|
return {'observable': self._observable, 'key': self.key}
|
|
194
182
|
|
|
195
183
|
@classmethod
|