cirq-core 1.6.0.dev20250520054601__py3-none-any.whl → 1.6.0.dev20250520181654__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/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.dev20250520181654.dist-info}/METADATA +1 -1
- {cirq_core-1.6.0.dev20250520054601.dist-info → cirq_core-1.6.0.dev20250520181654.dist-info}/RECORD +289 -289
- {cirq_core-1.6.0.dev20250520054601.dist-info → cirq_core-1.6.0.dev20250520181654.dist-info}/WHEEL +1 -1
- {cirq_core-1.6.0.dev20250520054601.dist-info → cirq_core-1.6.0.dev20250520181654.dist-info}/licenses/LICENSE +0 -0
- {cirq_core-1.6.0.dev20250520054601.dist-info → cirq_core-1.6.0.dev20250520181654.dist-info}/top_level.txt +0 -0
|
@@ -14,19 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
|
-
from typing import
|
|
18
|
-
AbstractSet,
|
|
19
|
-
Any,
|
|
20
|
-
Dict,
|
|
21
|
-
FrozenSet,
|
|
22
|
-
List,
|
|
23
|
-
Mapping,
|
|
24
|
-
Optional,
|
|
25
|
-
Sequence,
|
|
26
|
-
Tuple,
|
|
27
|
-
TYPE_CHECKING,
|
|
28
|
-
Union,
|
|
29
|
-
)
|
|
17
|
+
from typing import AbstractSet, Any, Mapping, Sequence, TYPE_CHECKING
|
|
30
18
|
|
|
31
19
|
import sympy
|
|
32
20
|
|
|
@@ -83,7 +71,7 @@ class ClassicallyControlledOperation(raw_types.Operation):
|
|
|
83
71
|
def __init__(
|
|
84
72
|
self,
|
|
85
73
|
sub_operation: cirq.Operation,
|
|
86
|
-
conditions: Sequence[
|
|
74
|
+
conditions: Sequence[str | cirq.MeasurementKey | cirq.Condition | sympy.Basic],
|
|
87
75
|
):
|
|
88
76
|
"""Initializes a `ClassicallyControlledOperation`.
|
|
89
77
|
|
|
@@ -109,7 +97,7 @@ class ClassicallyControlledOperation(raw_types.Operation):
|
|
|
109
97
|
if isinstance(sub_operation, ClassicallyControlledOperation):
|
|
110
98
|
conditions += sub_operation._conditions
|
|
111
99
|
sub_operation = sub_operation._sub_operation
|
|
112
|
-
conds:
|
|
100
|
+
conds: list[cirq.Condition] = []
|
|
113
101
|
for c in conditions:
|
|
114
102
|
if isinstance(c, str):
|
|
115
103
|
c = value.MeasurementKey.parse_serialized(c)
|
|
@@ -118,11 +106,11 @@ class ClassicallyControlledOperation(raw_types.Operation):
|
|
|
118
106
|
if isinstance(c, sympy.Basic):
|
|
119
107
|
c = value.SympyCondition(c)
|
|
120
108
|
conds.append(c)
|
|
121
|
-
self._conditions:
|
|
109
|
+
self._conditions: tuple[cirq.Condition, ...] = tuple(conds)
|
|
122
110
|
self._sub_operation: cirq.Operation = sub_operation
|
|
123
111
|
|
|
124
112
|
@property
|
|
125
|
-
def classical_controls(self) ->
|
|
113
|
+
def classical_controls(self) -> frozenset[cirq.Condition]:
|
|
126
114
|
return frozenset(self._conditions).union(self._sub_operation.classical_controls)
|
|
127
115
|
|
|
128
116
|
def without_classical_controls(self) -> cirq.Operation:
|
|
@@ -140,7 +128,7 @@ class ClassicallyControlledOperation(raw_types.Operation):
|
|
|
140
128
|
def _decompose_(self):
|
|
141
129
|
return self._decompose_with_context_()
|
|
142
130
|
|
|
143
|
-
def _decompose_with_context_(self, context:
|
|
131
|
+
def _decompose_with_context_(self, context: cirq.DecompositionContext | None = None):
|
|
144
132
|
result = protocols.decompose_once(
|
|
145
133
|
self._sub_operation, NotImplemented, flatten=False, context=context
|
|
146
134
|
)
|
|
@@ -178,7 +166,7 @@ class ClassicallyControlledOperation(raw_types.Operation):
|
|
|
178
166
|
|
|
179
167
|
def _circuit_diagram_info_(
|
|
180
168
|
self, args: cirq.CircuitDiagramInfoArgs
|
|
181
|
-
) ->
|
|
169
|
+
) -> protocols.CircuitDiagramInfo | None:
|
|
182
170
|
sub_args = protocols.CircuitDiagramInfoArgs(
|
|
183
171
|
known_qubit_count=args.known_qubit_count,
|
|
184
172
|
known_qubits=args.known_qubits,
|
|
@@ -210,7 +198,7 @@ class ClassicallyControlledOperation(raw_types.Operation):
|
|
|
210
198
|
wire_symbols=wire_symbols, exponent=sub_info.exponent, exponent_qubit_index=exp_index
|
|
211
199
|
)
|
|
212
200
|
|
|
213
|
-
def _json_dict_(self) ->
|
|
201
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
214
202
|
return {'conditions': self._conditions, 'sub_operation': self._sub_operation}
|
|
215
203
|
|
|
216
204
|
def _act_on_(self, sim_state: cirq.SimulationStateBase) -> bool:
|
|
@@ -226,26 +214,26 @@ class ClassicallyControlledOperation(raw_types.Operation):
|
|
|
226
214
|
sub_operation = self._sub_operation if sub_operation is NotImplemented else sub_operation
|
|
227
215
|
return sub_operation.with_classical_controls(*conditions)
|
|
228
216
|
|
|
229
|
-
def _with_key_path_prefix_(self, prefix:
|
|
217
|
+
def _with_key_path_prefix_(self, prefix: tuple[str, ...]) -> ClassicallyControlledOperation:
|
|
230
218
|
conditions = [protocols.with_key_path_prefix(c, prefix) for c in self._conditions]
|
|
231
219
|
sub_operation = protocols.with_key_path_prefix(self._sub_operation, prefix)
|
|
232
220
|
sub_operation = self._sub_operation if sub_operation is NotImplemented else sub_operation
|
|
233
221
|
return sub_operation.with_classical_controls(*conditions)
|
|
234
222
|
|
|
235
223
|
def _with_rescoped_keys_(
|
|
236
|
-
self, path:
|
|
224
|
+
self, path: tuple[str, ...], bindable_keys: frozenset[cirq.MeasurementKey]
|
|
237
225
|
) -> ClassicallyControlledOperation:
|
|
238
226
|
conds = [protocols.with_rescoped_keys(c, path, bindable_keys) for c in self._conditions]
|
|
239
227
|
sub_operation = protocols.with_rescoped_keys(self._sub_operation, path, bindable_keys)
|
|
240
228
|
return sub_operation.with_classical_controls(*conds)
|
|
241
229
|
|
|
242
|
-
def _control_keys_(self) ->
|
|
243
|
-
local_keys:
|
|
230
|
+
def _control_keys_(self) -> frozenset[cirq.MeasurementKey]:
|
|
231
|
+
local_keys: frozenset[cirq.MeasurementKey] = frozenset(
|
|
244
232
|
k for condition in self._conditions for k in condition.keys
|
|
245
233
|
)
|
|
246
234
|
return local_keys.union(protocols.control_keys(self._sub_operation))
|
|
247
235
|
|
|
248
|
-
def _qasm_(self, args: cirq.QasmArgs) ->
|
|
236
|
+
def _qasm_(self, args: cirq.QasmArgs) -> str | None:
|
|
249
237
|
args.validate_version('2.0', '3.0')
|
|
250
238
|
if len(self._conditions) > 1:
|
|
251
239
|
raise ValueError('QASM does not support multiple conditions.')
|
cirq/ops/clifford_gate.py
CHANGED
|
@@ -17,7 +17,7 @@ from __future__ import annotations
|
|
|
17
17
|
import functools
|
|
18
18
|
from dataclasses import dataclass
|
|
19
19
|
from types import NotImplementedType
|
|
20
|
-
from typing import Any,
|
|
20
|
+
from typing import Any, Sequence, TYPE_CHECKING
|
|
21
21
|
|
|
22
22
|
import numpy as np
|
|
23
23
|
|
|
@@ -36,7 +36,7 @@ sim = LazyLoader("sim", globals(), "cirq.sim")
|
|
|
36
36
|
transformers = LazyLoader("transformers", globals(), "cirq.transformers")
|
|
37
37
|
|
|
38
38
|
|
|
39
|
-
def _to_pauli_tuple(matrix: np.ndarray) ->
|
|
39
|
+
def _to_pauli_tuple(matrix: np.ndarray) -> tuple[Pauli, bool] | None:
|
|
40
40
|
"""Converts matrix to Pauli gate.
|
|
41
41
|
|
|
42
42
|
If matrix is not ±Pauli matrix, returns None.
|
|
@@ -51,10 +51,10 @@ def _to_pauli_tuple(matrix: np.ndarray) -> Optional[Tuple[Pauli, bool]]:
|
|
|
51
51
|
|
|
52
52
|
|
|
53
53
|
def _to_clifford_tableau(
|
|
54
|
-
rotation_map:
|
|
54
|
+
rotation_map: dict[Pauli, tuple[Pauli, bool]] | None = None,
|
|
55
55
|
*,
|
|
56
|
-
x_to:
|
|
57
|
-
z_to:
|
|
56
|
+
x_to: tuple[Pauli, bool] | None = None,
|
|
57
|
+
z_to: tuple[Pauli, bool] | None = None,
|
|
58
58
|
) -> qis.CliffordTableau:
|
|
59
59
|
"""Transfer the rotation map to clifford tableau representation"""
|
|
60
60
|
if x_to is None and z_to is None and rotation_map is None:
|
|
@@ -81,11 +81,11 @@ def _to_clifford_tableau(
|
|
|
81
81
|
|
|
82
82
|
def _validate_map_input(
|
|
83
83
|
required_transform_count: int,
|
|
84
|
-
pauli_map_to:
|
|
85
|
-
x_to:
|
|
86
|
-
y_to:
|
|
87
|
-
z_to:
|
|
88
|
-
) ->
|
|
84
|
+
pauli_map_to: dict[Pauli, tuple[Pauli, bool]] | None,
|
|
85
|
+
x_to: tuple[Pauli, bool] | None,
|
|
86
|
+
y_to: tuple[Pauli, bool] | None,
|
|
87
|
+
z_to: tuple[Pauli, bool] | None,
|
|
88
|
+
) -> dict[Pauli, tuple[Pauli, bool]]:
|
|
89
89
|
if pauli_map_to is None:
|
|
90
90
|
xyz_to = {pauli_gates.X: x_to, pauli_gates.Y: y_to, pauli_gates.Z: z_to}
|
|
91
91
|
pauli_map_to = {p: trans for p, trans in xyz_to.items() if trans is not None}
|
|
@@ -110,7 +110,7 @@ def _validate_map_input(
|
|
|
110
110
|
|
|
111
111
|
|
|
112
112
|
def _pad_tableau(
|
|
113
|
-
clifford_tableau: qis.CliffordTableau, num_qubits_after_padding: int, axes:
|
|
113
|
+
clifford_tableau: qis.CliffordTableau, num_qubits_after_padding: int, axes: list[int]
|
|
114
114
|
) -> qis.CliffordTableau:
|
|
115
115
|
"""Roughly, this function copies self.tableau into the "identity" matrix."""
|
|
116
116
|
# Sanity check
|
|
@@ -334,7 +334,7 @@ class CommonCliffordGates(metaclass=CommonCliffordGateMetaClass):
|
|
|
334
334
|
return cls(_clifford_tableau=_clifford_tableau)
|
|
335
335
|
|
|
336
336
|
@classmethod
|
|
337
|
-
def _get_sqrt_map(cls) ->
|
|
337
|
+
def _get_sqrt_map(cls) -> dict[float, dict[SingleQubitCliffordGate, SingleQubitCliffordGate]]:
|
|
338
338
|
"""Returns a map containing two keys 0.5 and -0.5 for the sqrt mapping of Pauli gates."""
|
|
339
339
|
return {
|
|
340
340
|
0.5: {cls.X: cls.X_sqrt, cls.Y: cls.Y_sqrt, cls.Z: cls.Z_sqrt},
|
|
@@ -377,7 +377,7 @@ class CliffordGate(raw_types.Gate, CommonCliffordGates):
|
|
|
377
377
|
def clifford_tableau(self):
|
|
378
378
|
return self._clifford_tableau
|
|
379
379
|
|
|
380
|
-
def _json_dict_(self) ->
|
|
380
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
381
381
|
json_dict = self._clifford_tableau._json_dict_()
|
|
382
382
|
return json_dict
|
|
383
383
|
|
|
@@ -387,7 +387,7 @@ class CliffordGate(raw_types.Gate, CommonCliffordGates):
|
|
|
387
387
|
def _num_qubits_(self):
|
|
388
388
|
return self.clifford_tableau.n
|
|
389
389
|
|
|
390
|
-
def _has_stabilizer_effect_(self) ->
|
|
390
|
+
def _has_stabilizer_effect_(self) -> bool | None:
|
|
391
391
|
# By definition, Clifford Gate should always return True.
|
|
392
392
|
return True
|
|
393
393
|
|
|
@@ -426,9 +426,7 @@ class CliffordGate(raw_types.Gate, CommonCliffordGates):
|
|
|
426
426
|
def __repr__(self) -> str:
|
|
427
427
|
return f"Clifford Gate with Tableau:\n{self.clifford_tableau._str_full_()}"
|
|
428
428
|
|
|
429
|
-
def _commutes_(
|
|
430
|
-
self, other: Any, *, atol: float = 1e-8
|
|
431
|
-
) -> Union[bool, NotImplementedType, None]:
|
|
429
|
+
def _commutes_(self, other: Any, *, atol: float = 1e-8) -> bool | NotImplementedType | None:
|
|
432
430
|
# Note even if we assume two gates define the tableau based on the same qubit order,
|
|
433
431
|
# the following approach cannot judge it:
|
|
434
432
|
# self.clifford_tableau.then(other.clifford_tableau) == other.clifford_tableau.then(
|
|
@@ -445,7 +443,7 @@ class CliffordGate(raw_types.Gate, CommonCliffordGates):
|
|
|
445
443
|
|
|
446
444
|
def _act_on_(
|
|
447
445
|
self, sim_state: cirq.SimulationStateBase, qubits: Sequence[cirq.Qid]
|
|
448
|
-
) ->
|
|
446
|
+
) -> NotImplementedType | bool:
|
|
449
447
|
# Note the computation complexity difference between _decompose_ and _act_on_.
|
|
450
448
|
# Suppose this Gate has `m` qubits, args has `n` qubits, and the decomposition of
|
|
451
449
|
# this operation into `k` operations:
|
|
@@ -493,7 +491,7 @@ class SingleQubitCliffordGate(CliffordGate):
|
|
|
493
491
|
return SingleQubitCliffordGate(_clifford_tableau=tableau)
|
|
494
492
|
|
|
495
493
|
@staticmethod
|
|
496
|
-
def from_xz_map(x_to:
|
|
494
|
+
def from_xz_map(x_to: tuple[Pauli, bool], z_to: tuple[Pauli, bool]) -> SingleQubitCliffordGate:
|
|
497
495
|
"""Returns a SingleQubitCliffordGate for the specified transforms.
|
|
498
496
|
The Y transform is derived from the X and Z.
|
|
499
497
|
|
|
@@ -507,11 +505,11 @@ class SingleQubitCliffordGate(CliffordGate):
|
|
|
507
505
|
|
|
508
506
|
@staticmethod
|
|
509
507
|
def from_single_map(
|
|
510
|
-
pauli_map_to:
|
|
508
|
+
pauli_map_to: dict[Pauli, tuple[Pauli, bool]] | None = None,
|
|
511
509
|
*,
|
|
512
|
-
x_to:
|
|
513
|
-
y_to:
|
|
514
|
-
z_to:
|
|
510
|
+
x_to: tuple[Pauli, bool] | None = None,
|
|
511
|
+
y_to: tuple[Pauli, bool] | None = None,
|
|
512
|
+
z_to: tuple[Pauli, bool] | None = None,
|
|
515
513
|
) -> SingleQubitCliffordGate:
|
|
516
514
|
"""Returns a SingleQubitCliffordGate for the
|
|
517
515
|
specified transform with a 90 or 180 degree rotation.
|
|
@@ -540,11 +538,11 @@ class SingleQubitCliffordGate(CliffordGate):
|
|
|
540
538
|
|
|
541
539
|
@staticmethod
|
|
542
540
|
def from_double_map(
|
|
543
|
-
pauli_map_to:
|
|
541
|
+
pauli_map_to: dict[Pauli, tuple[Pauli, bool]] | None = None,
|
|
544
542
|
*,
|
|
545
|
-
x_to:
|
|
546
|
-
y_to:
|
|
547
|
-
z_to:
|
|
543
|
+
x_to: tuple[Pauli, bool] | None = None,
|
|
544
|
+
y_to: tuple[Pauli, bool] | None = None,
|
|
545
|
+
z_to: tuple[Pauli, bool] | None = None,
|
|
548
546
|
) -> SingleQubitCliffordGate:
|
|
549
547
|
"""Returns a SingleQubitCliffordGate for the
|
|
550
548
|
specified transform with a 90 or 180 degree rotation.
|
|
@@ -598,7 +596,7 @@ class SingleQubitCliffordGate(CliffordGate):
|
|
|
598
596
|
return SingleQubitCliffordGate.from_pauli(pauli, True) ** -1
|
|
599
597
|
|
|
600
598
|
@staticmethod
|
|
601
|
-
def from_unitary(u: np.ndarray) ->
|
|
599
|
+
def from_unitary(u: np.ndarray) -> SingleQubitCliffordGate | None:
|
|
602
600
|
"""Creates Clifford gate with given unitary (up to global phase).
|
|
603
601
|
|
|
604
602
|
Args:
|
|
@@ -624,7 +622,7 @@ class SingleQubitCliffordGate(CliffordGate):
|
|
|
624
622
|
@classmethod
|
|
625
623
|
def from_unitary_with_global_phase(
|
|
626
624
|
cls, u: np.ndarray
|
|
627
|
-
) ->
|
|
625
|
+
) -> tuple[SingleQubitCliffordGate, complex] | None:
|
|
628
626
|
"""Creates Clifford gate with given unitary, including global phase.
|
|
629
627
|
|
|
630
628
|
Args:
|
|
@@ -644,7 +642,7 @@ class SingleQubitCliffordGate(CliffordGate):
|
|
|
644
642
|
k = max(np.ndindex(*u.shape), key=lambda t: abs(u[t]))
|
|
645
643
|
return gate, u[k] / protocols.unitary(gate)[k]
|
|
646
644
|
|
|
647
|
-
def pauli_tuple(self, pauli: Pauli) ->
|
|
645
|
+
def pauli_tuple(self, pauli: Pauli) -> tuple[Pauli, bool]:
|
|
648
646
|
"""Returns a tuple of a Pauli operator and a boolean.
|
|
649
647
|
|
|
650
648
|
The pauli is the operator of the transform and the boolean
|
|
@@ -762,9 +760,7 @@ class SingleQubitCliffordGate(CliffordGate):
|
|
|
762
760
|
(qubit,) = qubits
|
|
763
761
|
return tuple(gate.on(qubit) for gate in self.decompose_gate())
|
|
764
762
|
|
|
765
|
-
def _commutes_(
|
|
766
|
-
self, other: Any, *, atol: float = 1e-8
|
|
767
|
-
) -> Union[bool, NotImplementedType, None]:
|
|
763
|
+
def _commutes_(self, other: Any, *, atol: float = 1e-8) -> bool | NotImplementedType | None:
|
|
768
764
|
if isinstance(other, SingleQubitCliffordGate):
|
|
769
765
|
return self.commutes_with_single_qubit_gate(other)
|
|
770
766
|
if isinstance(other, Pauli):
|
|
@@ -822,7 +818,7 @@ class SingleQubitCliffordGate(CliffordGate):
|
|
|
822
818
|
rotations = self.decompose_rotation()
|
|
823
819
|
return [r ** (qt / 2) for r, qt in rotations]
|
|
824
820
|
|
|
825
|
-
def decompose_rotation(self) -> Sequence[
|
|
821
|
+
def decompose_rotation(self) -> Sequence[tuple[Pauli, int]]:
|
|
826
822
|
"""Decomposes this clifford into a series of pauli rotations.
|
|
827
823
|
|
|
828
824
|
Each rotation is given as a tuple of (axis, quarter_turns),
|
|
@@ -835,7 +831,7 @@ class SingleQubitCliffordGate(CliffordGate):
|
|
|
835
831
|
return self._decompose_rotation
|
|
836
832
|
|
|
837
833
|
@functools.cached_property
|
|
838
|
-
def _decompose_rotation(self) -> Sequence[
|
|
834
|
+
def _decompose_rotation(self) -> Sequence[tuple[Pauli, int]]:
|
|
839
835
|
x_rot = self.pauli_tuple(pauli_gates.X)
|
|
840
836
|
y_rot = self.pauli_tuple(pauli_gates.Y)
|
|
841
837
|
z_rot = self.pauli_tuple(pauli_gates.Z)
|
cirq/ops/clifford_gate_test.py
CHANGED
|
@@ -16,7 +16,6 @@ from __future__ import annotations
|
|
|
16
16
|
|
|
17
17
|
import functools
|
|
18
18
|
import itertools
|
|
19
|
-
from typing import Tuple, Type
|
|
20
19
|
|
|
21
20
|
import numpy as np
|
|
22
21
|
import pytest
|
|
@@ -61,7 +60,7 @@ def _all_rotation_pairs():
|
|
|
61
60
|
|
|
62
61
|
|
|
63
62
|
@functools.lru_cache()
|
|
64
|
-
def _all_clifford_gates() ->
|
|
63
|
+
def _all_clifford_gates() -> tuple[cirq.SingleQubitCliffordGate, ...]:
|
|
65
64
|
return tuple(
|
|
66
65
|
cirq.SingleQubitCliffordGate.from_xz_map(trans_x, trans_z)
|
|
67
66
|
for trans_x, trans_z in _all_rotation_pairs()
|
|
@@ -430,7 +429,7 @@ def test_known_matrix(gate, gate_equiv):
|
|
|
430
429
|
('SWAP', cirq.CliffordGate),
|
|
431
430
|
],
|
|
432
431
|
)
|
|
433
|
-
def test_common_clifford_types(name: str, expected_cls:
|
|
432
|
+
def test_common_clifford_types(name: str, expected_cls: type) -> None:
|
|
434
433
|
assert isinstance(getattr(cirq.CliffordGate, name), expected_cls)
|
|
435
434
|
assert isinstance(getattr(cirq.SingleQubitCliffordGate, name), expected_cls)
|
|
436
435
|
|
cirq/ops/common_channels.py
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
from __future__ import annotations
|
|
18
18
|
|
|
19
19
|
import itertools
|
|
20
|
-
from typing import Any,
|
|
20
|
+
from typing import Any, Iterable, Sequence, TYPE_CHECKING
|
|
21
21
|
|
|
22
22
|
import numpy as np
|
|
23
23
|
|
|
@@ -53,10 +53,10 @@ class AsymmetricDepolarizingChannel(raw_types.Gate):
|
|
|
53
53
|
|
|
54
54
|
def __init__(
|
|
55
55
|
self,
|
|
56
|
-
p_x:
|
|
57
|
-
p_y:
|
|
58
|
-
p_z:
|
|
59
|
-
error_probabilities:
|
|
56
|
+
p_x: float | None = None,
|
|
57
|
+
p_y: float | None = None,
|
|
58
|
+
p_z: float | None = None,
|
|
59
|
+
error_probabilities: dict[str, float] | None = None,
|
|
60
60
|
tol: float = 1e-8,
|
|
61
61
|
) -> None:
|
|
62
62
|
r"""The asymmetric depolarizing channel.
|
|
@@ -110,7 +110,7 @@ class AsymmetricDepolarizingChannel(raw_types.Gate):
|
|
|
110
110
|
self._num_qubits = 1
|
|
111
111
|
self._error_probabilities = {'I': p_i, 'X': p_x, 'Y': p_y, 'Z': p_z}
|
|
112
112
|
|
|
113
|
-
def _mixture_(self) -> Sequence[
|
|
113
|
+
def _mixture_(self) -> Sequence[tuple[float, np.ndarray]]:
|
|
114
114
|
ps = []
|
|
115
115
|
for pauli in self._error_probabilities:
|
|
116
116
|
Pi = np.identity(1)
|
|
@@ -141,9 +141,7 @@ class AsymmetricDepolarizingChannel(raw_types.Gate):
|
|
|
141
141
|
def __str__(self) -> str:
|
|
142
142
|
return 'asymmetric_depolarize(' + f"error_probabilities={self._error_probabilities})"
|
|
143
143
|
|
|
144
|
-
def _circuit_diagram_info_(
|
|
145
|
-
self, args: protocols.CircuitDiagramInfoArgs
|
|
146
|
-
) -> Union[str, Iterable[str]]:
|
|
144
|
+
def _circuit_diagram_info_(self, args: protocols.CircuitDiagramInfoArgs) -> str | Iterable[str]:
|
|
147
145
|
if self._num_qubits == 1:
|
|
148
146
|
if args.precision is not None:
|
|
149
147
|
return (
|
|
@@ -191,19 +189,19 @@ class AsymmetricDepolarizingChannel(raw_types.Gate):
|
|
|
191
189
|
return self._error_probabilities.get('Z', 0.0)
|
|
192
190
|
|
|
193
191
|
@property
|
|
194
|
-
def error_probabilities(self) ->
|
|
192
|
+
def error_probabilities(self) -> dict[str, float]:
|
|
195
193
|
"""A dictionary from Pauli gates to probability"""
|
|
196
194
|
return self._error_probabilities
|
|
197
195
|
|
|
198
|
-
def _json_dict_(self) ->
|
|
196
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
199
197
|
return protocols.obj_to_dict_helper(self, ['error_probabilities'])
|
|
200
198
|
|
|
201
199
|
|
|
202
200
|
def asymmetric_depolarize(
|
|
203
|
-
p_x:
|
|
204
|
-
p_y:
|
|
205
|
-
p_z:
|
|
206
|
-
error_probabilities:
|
|
201
|
+
p_x: float | None = None,
|
|
202
|
+
p_y: float | None = None,
|
|
203
|
+
p_z: float | None = None,
|
|
204
|
+
error_probabilities: dict[str, float] | None = None,
|
|
207
205
|
tol: float = 1e-8,
|
|
208
206
|
) -> AsymmetricDepolarizingChannel:
|
|
209
207
|
r"""Returns an `AsymmetricDepolarizingChannel` with the given parameters.
|
|
@@ -296,7 +294,7 @@ class DepolarizingChannel(raw_types.Gate):
|
|
|
296
294
|
def _qid_shape_(self):
|
|
297
295
|
return (2,) * self._n_qubits
|
|
298
296
|
|
|
299
|
-
def _mixture_(self) -> Sequence[
|
|
297
|
+
def _mixture_(self) -> Sequence[tuple[float, np.ndarray]]:
|
|
300
298
|
return self._delegate._mixture_()
|
|
301
299
|
|
|
302
300
|
def _has_mixture_(self) -> bool:
|
|
@@ -315,8 +313,8 @@ class DepolarizingChannel(raw_types.Gate):
|
|
|
315
313
|
return f"depolarize(p={self._p})"
|
|
316
314
|
return f"depolarize(p={self._p},n_qubits={self._n_qubits})"
|
|
317
315
|
|
|
318
|
-
def _circuit_diagram_info_(self, args: protocols.CircuitDiagramInfoArgs) ->
|
|
319
|
-
result:
|
|
316
|
+
def _circuit_diagram_info_(self, args: protocols.CircuitDiagramInfoArgs) -> tuple[str, ...]:
|
|
317
|
+
result: tuple[str, ...]
|
|
320
318
|
if args.precision is not None:
|
|
321
319
|
result = (f"D({self._p:.{args.precision}g})",)
|
|
322
320
|
else:
|
|
@@ -339,7 +337,7 @@ class DepolarizingChannel(raw_types.Gate):
|
|
|
339
337
|
"""The number of qubits"""
|
|
340
338
|
return self._n_qubits
|
|
341
339
|
|
|
342
|
-
def _json_dict_(self) ->
|
|
340
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
343
341
|
if self._n_qubits == 1:
|
|
344
342
|
return protocols.obj_to_dict_helper(self, ['p'])
|
|
345
343
|
return protocols.obj_to_dict_helper(self, ['p', 'n_qubits'])
|
|
@@ -480,7 +478,7 @@ class GeneralizedAmplitudeDampingChannel(raw_types.Gate):
|
|
|
480
478
|
"""The probability of energy transfer."""
|
|
481
479
|
return self._gamma
|
|
482
480
|
|
|
483
|
-
def _json_dict_(self) ->
|
|
481
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
484
482
|
return protocols.obj_to_dict_helper(self, ['p', 'gamma'])
|
|
485
483
|
|
|
486
484
|
|
|
@@ -604,7 +602,7 @@ class AmplitudeDampingChannel(raw_types.Gate):
|
|
|
604
602
|
"""The probability of the interaction being dissipative."""
|
|
605
603
|
return self._gamma
|
|
606
604
|
|
|
607
|
-
def _json_dict_(self) ->
|
|
605
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
608
606
|
return protocols.obj_to_dict_helper(self, ['gamma'])
|
|
609
607
|
|
|
610
608
|
|
|
@@ -683,10 +681,10 @@ class ResetChannel(raw_types.Gate):
|
|
|
683
681
|
"""
|
|
684
682
|
self._dimension = dimension
|
|
685
683
|
|
|
686
|
-
def _has_stabilizer_effect_(self) ->
|
|
684
|
+
def _has_stabilizer_effect_(self) -> bool | None:
|
|
687
685
|
return True
|
|
688
686
|
|
|
689
|
-
def _qasm_(self, args: cirq.QasmArgs, qubits:
|
|
687
|
+
def _qasm_(self, args: cirq.QasmArgs, qubits: tuple[cirq.Qid, ...]) -> str | None:
|
|
690
688
|
args.validate_version('2.0', '3.0')
|
|
691
689
|
return args.format('reset {0};\n', qubits[0])
|
|
692
690
|
|
|
@@ -752,7 +750,7 @@ class ResetChannel(raw_types.Gate):
|
|
|
752
750
|
"""The dimension of the qudit being reset."""
|
|
753
751
|
return self._dimension
|
|
754
752
|
|
|
755
|
-
def _json_dict_(self) ->
|
|
753
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
756
754
|
return protocols.obj_to_dict_helper(self, ['dimension'])
|
|
757
755
|
|
|
758
756
|
|
|
@@ -767,7 +765,7 @@ def reset(qubit: cirq.Qid) -> raw_types.Operation:
|
|
|
767
765
|
R = reset
|
|
768
766
|
|
|
769
767
|
|
|
770
|
-
def reset_each(*qubits: cirq.Qid) ->
|
|
768
|
+
def reset_each(*qubits: cirq.Qid) -> list[raw_types.Operation]:
|
|
771
769
|
"""Returns a list of `cirq.ResetChannel` instances on the given qubits."""
|
|
772
770
|
return [ResetChannel(q.dimension).on(q) for q in qubits]
|
|
773
771
|
|
|
@@ -863,7 +861,7 @@ class PhaseDampingChannel(raw_types.Gate):
|
|
|
863
861
|
"""The damping constant."""
|
|
864
862
|
return self._gamma
|
|
865
863
|
|
|
866
|
-
def _json_dict_(self) ->
|
|
864
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
867
865
|
return protocols.obj_to_dict_helper(self, ['gamma'])
|
|
868
866
|
|
|
869
867
|
|
|
@@ -942,7 +940,7 @@ class PhaseFlipChannel(raw_types.Gate):
|
|
|
942
940
|
def _num_qubits_(self) -> int:
|
|
943
941
|
return 1
|
|
944
942
|
|
|
945
|
-
def _mixture_(self) -> Sequence[
|
|
943
|
+
def _mixture_(self) -> Sequence[tuple[float, np.ndarray]]:
|
|
946
944
|
mixture = self._delegate._mixture_()
|
|
947
945
|
# just return identity and z term
|
|
948
946
|
return (mixture[0], mixture[3])
|
|
@@ -970,7 +968,7 @@ class PhaseFlipChannel(raw_types.Gate):
|
|
|
970
968
|
"""The probability of a phase flip."""
|
|
971
969
|
return self._p
|
|
972
970
|
|
|
973
|
-
def _json_dict_(self) ->
|
|
971
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
974
972
|
return protocols.obj_to_dict_helper(self, ['p'])
|
|
975
973
|
|
|
976
974
|
|
|
@@ -1013,7 +1011,7 @@ def _phase_flip(p: float) -> PhaseFlipChannel:
|
|
|
1013
1011
|
return PhaseFlipChannel(p)
|
|
1014
1012
|
|
|
1015
1013
|
|
|
1016
|
-
def phase_flip(p:
|
|
1014
|
+
def phase_flip(p: float | None = None) -> common_gates.ZPowGate | PhaseFlipChannel:
|
|
1017
1015
|
r"""Returns a PhaseFlipChannel that flips a qubit's phase with probability p.
|
|
1018
1016
|
|
|
1019
1017
|
If `p` is None, return a guaranteed phase flip in the form of a Z operation.
|
|
@@ -1095,7 +1093,7 @@ class BitFlipChannel(raw_types.Gate):
|
|
|
1095
1093
|
def _num_qubits_(self) -> int:
|
|
1096
1094
|
return 1
|
|
1097
1095
|
|
|
1098
|
-
def _mixture_(self) -> Sequence[
|
|
1096
|
+
def _mixture_(self) -> Sequence[tuple[float, Any]]:
|
|
1099
1097
|
return ((1 - self._p, identity.I), (self._p, pauli_gates.X))
|
|
1100
1098
|
|
|
1101
1099
|
def _has_mixture_(self) -> bool:
|
|
@@ -1121,7 +1119,7 @@ class BitFlipChannel(raw_types.Gate):
|
|
|
1121
1119
|
"""The probability of a bit flip."""
|
|
1122
1120
|
return self._p
|
|
1123
1121
|
|
|
1124
|
-
def _json_dict_(self) ->
|
|
1122
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
1125
1123
|
return protocols.obj_to_dict_helper(self, ['p'])
|
|
1126
1124
|
|
|
1127
1125
|
|
|
@@ -1159,7 +1157,7 @@ def _bit_flip(p: float) -> BitFlipChannel:
|
|
|
1159
1157
|
return BitFlipChannel(p)
|
|
1160
1158
|
|
|
1161
1159
|
|
|
1162
|
-
def bit_flip(p:
|
|
1160
|
+
def bit_flip(p: float | None = None) -> common_gates.XPowGate | BitFlipChannel:
|
|
1163
1161
|
r"""Construct a BitFlipChannel that flips a qubit state with probability p.
|
|
1164
1162
|
|
|
1165
1163
|
If p is None, this returns a guaranteed flip in the form of an X operation.
|