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/ops/pauli_string.py
CHANGED
|
@@ -23,18 +23,14 @@ from typing import (
|
|
|
23
23
|
Any,
|
|
24
24
|
Callable,
|
|
25
25
|
cast,
|
|
26
|
-
Dict,
|
|
27
26
|
Generic,
|
|
28
27
|
ItemsView,
|
|
29
28
|
Iterable,
|
|
30
29
|
Iterator,
|
|
31
30
|
KeysView,
|
|
32
|
-
List,
|
|
33
31
|
Mapping,
|
|
34
|
-
Optional,
|
|
35
32
|
overload,
|
|
36
33
|
Sequence,
|
|
37
|
-
Tuple,
|
|
38
34
|
TYPE_CHECKING,
|
|
39
35
|
TypeVar,
|
|
40
36
|
Union,
|
|
@@ -164,7 +160,7 @@ class PauliString(raw_types.Operation, Generic[TKey]):
|
|
|
164
160
|
def __init__(
|
|
165
161
|
self,
|
|
166
162
|
*contents: cirq.PAULI_STRING_LIKE,
|
|
167
|
-
qubit_pauli_map:
|
|
163
|
+
qubit_pauli_map: dict[TKey, cirq.Pauli] | None = None,
|
|
168
164
|
coefficient: cirq.TParamValComplex = 1,
|
|
169
165
|
):
|
|
170
166
|
"""Initializes a new `PauliString` operation.
|
|
@@ -192,8 +188,8 @@ class PauliString(raw_types.Operation, Generic[TKey]):
|
|
|
192
188
|
if not isinstance(v, pauli_gates.Pauli):
|
|
193
189
|
raise TypeError(f'{v} is not a Pauli')
|
|
194
190
|
|
|
195
|
-
self._qubit_pauli_map:
|
|
196
|
-
self._coefficient:
|
|
191
|
+
self._qubit_pauli_map: dict[TKey, cirq.Pauli] = qubit_pauli_map or {}
|
|
192
|
+
self._coefficient: cirq.TParamValComplex | sympy.Expr = (
|
|
197
193
|
coefficient if isinstance(coefficient, sympy.Expr) else complex(coefficient)
|
|
198
194
|
)
|
|
199
195
|
if contents:
|
|
@@ -213,7 +209,7 @@ class PauliString(raw_types.Operation, Generic[TKey]):
|
|
|
213
209
|
|
|
214
210
|
return (frozenset(self._qubit_pauli_map.items()), self._coefficient)
|
|
215
211
|
|
|
216
|
-
def _json_dict_(self) ->
|
|
212
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
217
213
|
return {
|
|
218
214
|
# JSON requires mappings to have string keys.
|
|
219
215
|
'qubit_pauli_map': list(self._qubit_pauli_map.items()),
|
|
@@ -238,39 +234,33 @@ class PauliString(raw_types.Operation, Generic[TKey]):
|
|
|
238
234
|
|
|
239
235
|
# pylint: disable=function-redefined
|
|
240
236
|
@overload
|
|
241
|
-
def get(self, key: Any, default: None = None) ->
|
|
237
|
+
def get(self, key: Any, default: None = None) -> pauli_gates.Pauli | None:
|
|
242
238
|
pass
|
|
243
239
|
|
|
244
240
|
@overload
|
|
245
|
-
def get(self, key: Any, default: TDefault) ->
|
|
241
|
+
def get(self, key: Any, default: TDefault) -> pauli_gates.Pauli | TDefault:
|
|
246
242
|
pass
|
|
247
243
|
|
|
248
|
-
def get(
|
|
249
|
-
self, key: Any, default: Optional[TDefault] = None
|
|
250
|
-
) -> Union[pauli_gates.Pauli, TDefault, None]:
|
|
244
|
+
def get(self, key: Any, default: TDefault | None = None) -> pauli_gates.Pauli | TDefault | None:
|
|
251
245
|
"""Returns the `cirq.Pauli` operation acting on qubit `key` or `default` if none exists."""
|
|
252
246
|
return self._qubit_pauli_map.get(key, default)
|
|
253
247
|
|
|
254
248
|
@overload
|
|
255
|
-
def __mul__(
|
|
256
|
-
self, other: cirq.PauliString[TKeyOther]
|
|
257
|
-
) -> cirq.PauliString[Union[TKey, TKeyOther]]:
|
|
249
|
+
def __mul__(self, other: cirq.PauliString[TKeyOther]) -> cirq.PauliString[TKey | TKeyOther]:
|
|
258
250
|
pass
|
|
259
251
|
|
|
260
252
|
@overload
|
|
261
253
|
def __mul__(
|
|
262
254
|
self, other: Mapping[TKeyOther, cirq.PAULI_GATE_LIKE]
|
|
263
|
-
) -> cirq.PauliString[
|
|
255
|
+
) -> cirq.PauliString[TKey | TKeyOther]:
|
|
264
256
|
pass
|
|
265
257
|
|
|
266
258
|
@overload
|
|
267
|
-
def __mul__(
|
|
268
|
-
self, other: Iterable[cirq.PAULI_STRING_LIKE]
|
|
269
|
-
) -> cirq.PauliString[Union[TKey, cirq.Qid]]:
|
|
259
|
+
def __mul__(self, other: Iterable[cirq.PAULI_STRING_LIKE]) -> cirq.PauliString[TKey | cirq.Qid]:
|
|
270
260
|
pass
|
|
271
261
|
|
|
272
262
|
@overload
|
|
273
|
-
def __mul__(self, other: cirq.Operation) -> cirq.PauliString[
|
|
263
|
+
def __mul__(self, other: cirq.Operation) -> cirq.PauliString[TKey | cirq.Qid]:
|
|
274
264
|
pass
|
|
275
265
|
|
|
276
266
|
@overload
|
|
@@ -296,12 +286,7 @@ class PauliString(raw_types.Operation, Generic[TKey]):
|
|
|
296
286
|
@property
|
|
297
287
|
def gate(self) -> cirq.DensePauliString:
|
|
298
288
|
"""Returns a `cirq.DensePauliString`"""
|
|
299
|
-
order:
|
|
300
|
-
None,
|
|
301
|
-
pauli_gates.X,
|
|
302
|
-
pauli_gates.Y,
|
|
303
|
-
pauli_gates.Z,
|
|
304
|
-
]
|
|
289
|
+
order: list[pauli_gates.Pauli | None] = [None, pauli_gates.X, pauli_gates.Y, pauli_gates.Z]
|
|
305
290
|
from cirq.ops.dense_pauli_string import DensePauliString
|
|
306
291
|
|
|
307
292
|
return DensePauliString(
|
|
@@ -359,11 +344,11 @@ class PauliString(raw_types.Operation, Generic[TKey]):
|
|
|
359
344
|
return self._qubit_pauli_map.keys()
|
|
360
345
|
|
|
361
346
|
@property
|
|
362
|
-
def qubits(self) ->
|
|
347
|
+
def qubits(self) -> tuple[TKey, ...]:
|
|
363
348
|
"""Returns a tuple of qubits on which this pauli string acts."""
|
|
364
349
|
return tuple(self.keys())
|
|
365
350
|
|
|
366
|
-
def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs) ->
|
|
351
|
+
def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs) -> list[str]:
|
|
367
352
|
if not len(self._qubit_pauli_map):
|
|
368
353
|
return NotImplemented
|
|
369
354
|
|
|
@@ -485,7 +470,7 @@ class PauliString(raw_types.Operation, Generic[TKey]):
|
|
|
485
470
|
|
|
486
471
|
return prefix + '*'.join(factors)
|
|
487
472
|
|
|
488
|
-
def matrix(self, qubits:
|
|
473
|
+
def matrix(self, qubits: Iterable[TKey] | None = None) -> np.ndarray:
|
|
489
474
|
"""Returns the matrix of self in computational basis of qubits.
|
|
490
475
|
|
|
491
476
|
Args:
|
|
@@ -509,7 +494,7 @@ class PauliString(raw_types.Operation, Generic[TKey]):
|
|
|
509
494
|
return False
|
|
510
495
|
return abs(1 - abs(cast(complex, self.coefficient))) < 1e-6
|
|
511
496
|
|
|
512
|
-
def _unitary_(self) ->
|
|
497
|
+
def _unitary_(self) -> np.ndarray | None:
|
|
513
498
|
if not self._has_unitary_():
|
|
514
499
|
return None
|
|
515
500
|
return self.matrix()
|
|
@@ -743,7 +728,7 @@ class PauliString(raw_types.Operation, Generic[TKey]):
|
|
|
743
728
|
|
|
744
729
|
def zip_items(
|
|
745
730
|
self, other: cirq.PauliString[TKey]
|
|
746
|
-
) -> Iterator[
|
|
731
|
+
) -> Iterator[tuple[TKey, tuple[pauli_gates.Pauli, pauli_gates.Pauli]]]:
|
|
747
732
|
"""Combines pauli operations from pauli strings in a qubit-by-qubit fashion.
|
|
748
733
|
|
|
749
734
|
For every qubit that has a `cirq.Pauli` operation acting on it in both `self` and `other`,
|
|
@@ -762,7 +747,7 @@ class PauliString(raw_types.Operation, Generic[TKey]):
|
|
|
762
747
|
|
|
763
748
|
def zip_paulis(
|
|
764
749
|
self, other: cirq.PauliString
|
|
765
|
-
) -> Iterator[
|
|
750
|
+
) -> Iterator[tuple[pauli_gates.Pauli, pauli_gates.Pauli]]:
|
|
766
751
|
"""Combines pauli operations from pauli strings in a qubit-by-qubit fashion.
|
|
767
752
|
|
|
768
753
|
For every qubit that has a `cirq.Pauli` operation acting on it in both `self` and `other`,
|
|
@@ -777,9 +762,7 @@ class PauliString(raw_types.Operation, Generic[TKey]):
|
|
|
777
762
|
"""
|
|
778
763
|
return (paulis for qubit, paulis in self.zip_items(other))
|
|
779
764
|
|
|
780
|
-
def _commutes_(
|
|
781
|
-
self, other: Any, *, atol: float = 1e-8
|
|
782
|
-
) -> Union[bool, NotImplementedType, None]:
|
|
765
|
+
def _commutes_(self, other: Any, *, atol: float = 1e-8) -> bool | NotImplementedType | None:
|
|
783
766
|
if not isinstance(other, PauliString):
|
|
784
767
|
return NotImplemented
|
|
785
768
|
return sum(not protocols.commutes(p0, p1) for p0, p1 in self.zip_paulis(other)) % 2 == 0
|
|
@@ -865,7 +848,7 @@ class PauliString(raw_types.Operation, Generic[TKey]):
|
|
|
865
848
|
)
|
|
866
849
|
return NotImplemented
|
|
867
850
|
|
|
868
|
-
def map_qubits(self, qubit_map:
|
|
851
|
+
def map_qubits(self, qubit_map: dict[TKey, TKeyNew]) -> cirq.PauliString[TKeyNew]:
|
|
869
852
|
"""Replaces every qubit `q` in `self.qubits` with `qubit_map[q]`.
|
|
870
853
|
|
|
871
854
|
Args:
|
|
@@ -1124,7 +1107,7 @@ class PauliString(raw_types.Operation, Generic[TKey]):
|
|
|
1124
1107
|
|
|
1125
1108
|
|
|
1126
1109
|
def _validate_qubit_mapping(
|
|
1127
|
-
qubit_map: Mapping[TKey, int], pauli_qubits:
|
|
1110
|
+
qubit_map: Mapping[TKey, int], pauli_qubits: tuple[TKey, ...], num_state_qubits: int
|
|
1128
1111
|
) -> None:
|
|
1129
1112
|
"""Validates that a qubit map is a valid mapping.
|
|
1130
1113
|
|
|
@@ -1233,7 +1216,7 @@ class SingleQubitPauliStringGateOperation( # type: ignore
|
|
|
1233
1216
|
def __neg__(self):
|
|
1234
1217
|
return -self._as_pauli_string()
|
|
1235
1218
|
|
|
1236
|
-
def _json_dict_(self) ->
|
|
1219
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
1237
1220
|
return protocols.obj_to_dict_helper(self, ['pauli', 'qubit'])
|
|
1238
1221
|
|
|
1239
1222
|
@classmethod
|
|
@@ -1260,7 +1243,7 @@ class MutablePauliString(Generic[TKey]):
|
|
|
1260
1243
|
self,
|
|
1261
1244
|
*contents: cirq.PAULI_STRING_LIKE,
|
|
1262
1245
|
coefficient: cirq.TParamValComplex = 1,
|
|
1263
|
-
pauli_int_dict:
|
|
1246
|
+
pauli_int_dict: dict[TKey, int] | None = None,
|
|
1264
1247
|
):
|
|
1265
1248
|
"""Initializes a new `MutablePauliString`.
|
|
1266
1249
|
|
|
@@ -1282,14 +1265,14 @@ class MutablePauliString(Generic[TKey]):
|
|
|
1282
1265
|
Raises:
|
|
1283
1266
|
ValueError: If the `pauli_int_dict` has integer values `v` not satisfying `1 <= v <= 3`.
|
|
1284
1267
|
"""
|
|
1285
|
-
self.coefficient:
|
|
1268
|
+
self.coefficient: sympy.Expr | cirq.TParamValComplex = (
|
|
1286
1269
|
coefficient if isinstance(coefficient, sympy.Expr) else complex(coefficient)
|
|
1287
1270
|
)
|
|
1288
1271
|
if pauli_int_dict is not None:
|
|
1289
1272
|
for v in pauli_int_dict.values():
|
|
1290
1273
|
if not 1 <= v <= 3:
|
|
1291
1274
|
raise ValueError(f"Value {v} of pauli_int_dict must be between 1 and 3.")
|
|
1292
|
-
self.pauli_int_dict:
|
|
1275
|
+
self.pauli_int_dict: dict[TKey, int] = {} if pauli_int_dict is None else pauli_int_dict
|
|
1293
1276
|
if contents:
|
|
1294
1277
|
self.inplace_left_multiply_by(contents)
|
|
1295
1278
|
|
|
@@ -1345,7 +1328,7 @@ class MutablePauliString(Generic[TKey]):
|
|
|
1345
1328
|
coefficient=self.coefficient, pauli_int_dict=dict(self.pauli_int_dict)
|
|
1346
1329
|
)
|
|
1347
1330
|
|
|
1348
|
-
def items(self) -> Iterator[
|
|
1331
|
+
def items(self) -> Iterator[tuple[TKey, cirq.Pauli]]:
|
|
1349
1332
|
"""Returns (cirq.Qid, cirq.Pauli) pairs representing 1-qubit operations of pauli string."""
|
|
1350
1333
|
for k, v in self.pauli_int_dict.items():
|
|
1351
1334
|
yield k, _INT_TO_PAULI[v - 1]
|
|
@@ -1368,14 +1351,14 @@ class MutablePauliString(Generic[TKey]):
|
|
|
1368
1351
|
|
|
1369
1352
|
# pylint: disable=function-redefined
|
|
1370
1353
|
@overload
|
|
1371
|
-
def get(self, key: TKey, default: None = None) ->
|
|
1354
|
+
def get(self, key: TKey, default: None = None) -> cirq.Pauli | None:
|
|
1372
1355
|
pass
|
|
1373
1356
|
|
|
1374
1357
|
@overload
|
|
1375
|
-
def get(self, key: TKey, default: TDefault) ->
|
|
1358
|
+
def get(self, key: TKey, default: TDefault) -> cirq.Pauli | TDefault:
|
|
1376
1359
|
pass
|
|
1377
1360
|
|
|
1378
|
-
def get(self, key: TKey, default=None) ->
|
|
1361
|
+
def get(self, key: TKey, default=None) -> cirq.Pauli | TDefault | None:
|
|
1379
1362
|
"""Returns the `cirq.Pauli` operation acting on qubit `key` or `default` if none exists."""
|
|
1380
1363
|
result = self.pauli_int_dict.get(key, None)
|
|
1381
1364
|
return default if result is None else _INT_TO_PAULI[result - 1]
|
|
@@ -1519,7 +1502,7 @@ class MutablePauliString(Generic[TKey]):
|
|
|
1519
1502
|
raise TypeError(f"{other!r} is not cirq.PAULI_STRING_LIKE.")
|
|
1520
1503
|
return self
|
|
1521
1504
|
|
|
1522
|
-
def _json_dict_(self) ->
|
|
1505
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
1523
1506
|
return {
|
|
1524
1507
|
# JSON requires mappings to have string keys.
|
|
1525
1508
|
'pauli_int_dict': list(self.pauli_int_dict.items()),
|
|
@@ -1618,7 +1601,7 @@ class MutablePauliString(Generic[TKey]):
|
|
|
1618
1601
|
return f'{self.frozen()!r}.mutable_copy()'
|
|
1619
1602
|
|
|
1620
1603
|
|
|
1621
|
-
def _decompose_into_cliffords(op: cirq.Operation) ->
|
|
1604
|
+
def _decompose_into_cliffords(op: cirq.Operation) -> list[cirq.Operation]:
|
|
1622
1605
|
# An operation that can be ignored?
|
|
1623
1606
|
if isinstance(op.gate, global_phase_op.GlobalPhaseGate):
|
|
1624
1607
|
return []
|
|
@@ -1653,7 +1636,7 @@ _x = cast(pauli_gates.Pauli, pauli_gates.X) # type: ignore
|
|
|
1653
1636
|
_y = cast(pauli_gates.Pauli, pauli_gates.Y) # type: ignore
|
|
1654
1637
|
_z = cast(pauli_gates.Pauli, pauli_gates.Z) # type: ignore
|
|
1655
1638
|
|
|
1656
|
-
PAULI_GATE_LIKE_TO_INDEX_MAP:
|
|
1639
|
+
PAULI_GATE_LIKE_TO_INDEX_MAP: dict[cirq.PAULI_GATE_LIKE, int] = {
|
|
1657
1640
|
_i: 0,
|
|
1658
1641
|
_x: 1,
|
|
1659
1642
|
_y: 2,
|
|
@@ -1672,11 +1655,11 @@ PAULI_GATE_LIKE_TO_INDEX_MAP: Dict[cirq.PAULI_GATE_LIKE, int] = {
|
|
|
1672
1655
|
3: 3,
|
|
1673
1656
|
}
|
|
1674
1657
|
|
|
1675
|
-
_INT_TO_PAULI_OR_IDENTITY:
|
|
1676
|
-
_INT_TO_PAULI:
|
|
1658
|
+
_INT_TO_PAULI_OR_IDENTITY: list[cirq.Pauli | cirq.IdentityGate] = [_i, _x, _y, _z]
|
|
1659
|
+
_INT_TO_PAULI: list[cirq.Pauli] = [_x, _y, _z]
|
|
1677
1660
|
|
|
1678
1661
|
|
|
1679
|
-
PAULI_GATE_LIKE_TO_GATE_MAP:
|
|
1662
|
+
PAULI_GATE_LIKE_TO_GATE_MAP: dict[cirq.PAULI_GATE_LIKE, cirq.Pauli | cirq.IdentityGate] = {
|
|
1680
1663
|
k: _INT_TO_PAULI_OR_IDENTITY[v] for k, v in PAULI_GATE_LIKE_TO_INDEX_MAP.items()
|
|
1681
1664
|
}
|
|
1682
1665
|
|
cirq/ops/pauli_string_phasor.py
CHANGED
|
@@ -15,17 +15,7 @@
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
17
|
import numbers
|
|
18
|
-
from typing import
|
|
19
|
-
AbstractSet,
|
|
20
|
-
cast,
|
|
21
|
-
Dict,
|
|
22
|
-
Iterable,
|
|
23
|
-
Iterator,
|
|
24
|
-
Optional,
|
|
25
|
-
Sequence,
|
|
26
|
-
TYPE_CHECKING,
|
|
27
|
-
Union,
|
|
28
|
-
)
|
|
18
|
+
from typing import AbstractSet, cast, Iterable, Iterator, Sequence, TYPE_CHECKING
|
|
29
19
|
|
|
30
20
|
from cirq import protocols, value
|
|
31
21
|
from cirq._compat import deprecated, proper_repr
|
|
@@ -65,7 +55,7 @@ class PauliStringPhasor(gate_operation.GateOperation):
|
|
|
65
55
|
def __init__(
|
|
66
56
|
self,
|
|
67
57
|
pauli_string: ps.PauliString,
|
|
68
|
-
qubits:
|
|
58
|
+
qubits: Sequence[cirq.Qid] | None = None,
|
|
69
59
|
*,
|
|
70
60
|
exponent_neg: cirq.TParamVal = 1,
|
|
71
61
|
exponent_pos: cirq.TParamVal = 0,
|
|
@@ -145,7 +135,7 @@ class PauliStringPhasor(gate_operation.GateOperation):
|
|
|
145
135
|
)
|
|
146
136
|
return False
|
|
147
137
|
|
|
148
|
-
def map_qubits(self, qubit_map:
|
|
138
|
+
def map_qubits(self, qubit_map: dict[raw_types.Qid, raw_types.Qid]) -> PauliStringPhasor:
|
|
149
139
|
"""Maps the qubits inside the PauliStringPhasor.
|
|
150
140
|
|
|
151
141
|
Args:
|
|
@@ -355,7 +345,7 @@ class PauliStringPhasorGate(raw_types.Gate):
|
|
|
355
345
|
return rel1 == rel2 and self.dense_pauli_string == other.dense_pauli_string
|
|
356
346
|
return False
|
|
357
347
|
|
|
358
|
-
def __pow__(self, exponent:
|
|
348
|
+
def __pow__(self, exponent: float | sympy.Symbol) -> PauliStringPhasorGate:
|
|
359
349
|
pn = protocols.mul(self.exponent_neg, exponent, None)
|
|
360
350
|
pp = protocols.mul(self.exponent_pos, exponent, None)
|
|
361
351
|
if pn is None or pp is None:
|
|
@@ -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
|
from typing_extensions import Self
|
|
21
21
|
|
|
@@ -43,7 +43,7 @@ class PauliStringGateOperation(raw_types.Operation, metaclass=abc.ABCMeta):
|
|
|
43
43
|
return self.map_qubits(dict(zip(self.pauli_string.qubits, new_qubits)))
|
|
44
44
|
|
|
45
45
|
@abc.abstractmethod
|
|
46
|
-
def map_qubits(self, qubit_map:
|
|
46
|
+
def map_qubits(self, qubit_map: dict[raw_types.Qid, raw_types.Qid]) -> Self:
|
|
47
47
|
"""Return an equivalent operation on new qubits with its Pauli string
|
|
48
48
|
mapped to new qubits.
|
|
49
49
|
|
|
@@ -51,7 +51,7 @@ class PauliStringGateOperation(raw_types.Operation, metaclass=abc.ABCMeta):
|
|
|
51
51
|
"""
|
|
52
52
|
|
|
53
53
|
@property
|
|
54
|
-
def qubits(self) ->
|
|
54
|
+
def qubits(self) -> tuple[raw_types.Qid, ...]:
|
|
55
55
|
return tuple(self.pauli_string)
|
|
56
56
|
|
|
57
57
|
def _pauli_string_diagram_info(
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
|
-
from typing import Any, Iterator,
|
|
17
|
+
from typing import Any, Iterator, TYPE_CHECKING
|
|
18
18
|
|
|
19
19
|
import numpy as np
|
|
20
20
|
|
|
@@ -68,7 +68,7 @@ class PauliSumExponential:
|
|
|
68
68
|
self._pauli_sum = pauli_sum
|
|
69
69
|
|
|
70
70
|
@property
|
|
71
|
-
def qubits(self) ->
|
|
71
|
+
def qubits(self) -> tuple[cirq.Qid, ...]:
|
|
72
72
|
return self._pauli_sum.qubits
|
|
73
73
|
|
|
74
74
|
def _value_equality_values_(self) -> Any:
|
cirq/ops/permutation_gate.py
CHANGED
|
@@ -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
|
from cirq import protocols, value
|
|
20
20
|
from cirq.ops import raw_types, swap_gates
|
|
@@ -63,7 +63,7 @@ class QubitPermutationGate(raw_types.Gate):
|
|
|
63
63
|
self._permutation = tuple(permutation)
|
|
64
64
|
|
|
65
65
|
@property
|
|
66
|
-
def permutation(self) ->
|
|
66
|
+
def permutation(self) -> tuple[int, ...]:
|
|
67
67
|
return self._permutation
|
|
68
68
|
|
|
69
69
|
def _value_equality_values_(self):
|
|
@@ -106,13 +106,13 @@ class QubitPermutationGate(raw_types.Gate):
|
|
|
106
106
|
args.available_buffer[...] = args.target_tensor.transpose(permuted_axes)
|
|
107
107
|
return args.available_buffer
|
|
108
108
|
|
|
109
|
-
def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs) ->
|
|
109
|
+
def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs) -> tuple[str, ...]:
|
|
110
110
|
return tuple(f'[{i}>{self.permutation[i]}]' for i in range(len(self.permutation)))
|
|
111
111
|
|
|
112
112
|
def __repr__(self) -> str:
|
|
113
113
|
return f'cirq.QubitPermutationGate(permutation={self.permutation!r})'
|
|
114
114
|
|
|
115
|
-
def _json_dict_(self) ->
|
|
115
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
116
116
|
return protocols.obj_to_dict_helper(self, attribute_names=['permutation'])
|
|
117
117
|
|
|
118
118
|
@classmethod
|
cirq/ops/phased_iswap_gate.py
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
from __future__ import annotations
|
|
17
17
|
|
|
18
|
-
from typing import AbstractSet, Any, cast,
|
|
18
|
+
from typing import AbstractSet, Any, cast, Iterator, Sequence
|
|
19
19
|
|
|
20
20
|
import numpy as np
|
|
21
21
|
import sympy
|
|
@@ -62,8 +62,8 @@ class PhasedISwapPowGate(eigen_gate.EigenGate):
|
|
|
62
62
|
def __init__(
|
|
63
63
|
self,
|
|
64
64
|
*,
|
|
65
|
-
phase_exponent:
|
|
66
|
-
exponent:
|
|
65
|
+
phase_exponent: float | sympy.Expr = 0.25,
|
|
66
|
+
exponent: float | sympy.Expr = 1.0,
|
|
67
67
|
global_shift: float = 0.0,
|
|
68
68
|
):
|
|
69
69
|
"""Inits PhasedISwapPowGate.
|
|
@@ -81,13 +81,13 @@ class PhasedISwapPowGate(eigen_gate.EigenGate):
|
|
|
81
81
|
super().__init__(exponent=exponent, global_shift=global_shift)
|
|
82
82
|
|
|
83
83
|
@property
|
|
84
|
-
def phase_exponent(self) ->
|
|
84
|
+
def phase_exponent(self) -> float | sympy.Expr:
|
|
85
85
|
return self._phase_exponent
|
|
86
86
|
|
|
87
87
|
def _num_qubits_(self) -> int:
|
|
88
88
|
return 2
|
|
89
89
|
|
|
90
|
-
def _json_dict_(self) ->
|
|
90
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
91
91
|
return {
|
|
92
92
|
'phase_exponent': self._phase_exponent,
|
|
93
93
|
'exponent': self._exponent,
|
|
@@ -126,20 +126,20 @@ class PhasedISwapPowGate(eigen_gate.EigenGate):
|
|
|
126
126
|
phase_exponent=self.phase_exponent, exponent=exponent, global_shift=self.global_shift
|
|
127
127
|
)
|
|
128
128
|
|
|
129
|
-
def _eigen_shifts(self) ->
|
|
129
|
+
def _eigen_shifts(self) -> list[float]:
|
|
130
130
|
return [0.0, +0.5, -0.5]
|
|
131
131
|
|
|
132
|
-
def _eigen_components(self) ->
|
|
132
|
+
def _eigen_components(self) -> list[tuple[float, np.ndarray]]:
|
|
133
133
|
phase = np.exp(1j * np.pi * self.phase_exponent)
|
|
134
134
|
phase_matrix = np.diag([1, phase, phase.conjugate(), 1])
|
|
135
135
|
inverse_phase_matrix = np.conjugate(phase_matrix)
|
|
136
|
-
eigen_components:
|
|
136
|
+
eigen_components: list[tuple[float, np.ndarray]] = []
|
|
137
137
|
for eigenvalue, projector in self._iswap._eigen_components():
|
|
138
138
|
new_projector = phase_matrix @ projector @ inverse_phase_matrix
|
|
139
139
|
eigen_components.append((eigenvalue, new_projector))
|
|
140
140
|
return eigen_components
|
|
141
141
|
|
|
142
|
-
def _apply_unitary_(self, args: protocols.ApplyUnitaryArgs) ->
|
|
142
|
+
def _apply_unitary_(self, args: protocols.ApplyUnitaryArgs) -> np.ndarray | None:
|
|
143
143
|
if protocols.is_parameterized(self):
|
|
144
144
|
return NotImplemented
|
|
145
145
|
|
cirq/ops/phased_x_gate.py
CHANGED
|
@@ -19,7 +19,7 @@ from __future__ import annotations
|
|
|
19
19
|
import math
|
|
20
20
|
import numbers
|
|
21
21
|
from types import NotImplementedType
|
|
22
|
-
from typing import AbstractSet, Any, cast,
|
|
22
|
+
from typing import AbstractSet, Any, cast, Sequence
|
|
23
23
|
|
|
24
24
|
import numpy as np
|
|
25
25
|
import sympy
|
|
@@ -51,8 +51,8 @@ class PhasedXPowGate(raw_types.Gate):
|
|
|
51
51
|
def __init__(
|
|
52
52
|
self,
|
|
53
53
|
*,
|
|
54
|
-
phase_exponent:
|
|
55
|
-
exponent:
|
|
54
|
+
phase_exponent: float | sympy.Expr,
|
|
55
|
+
exponent: float | sympy.Expr = 1.0,
|
|
56
56
|
global_shift: float = 0.0,
|
|
57
57
|
) -> None:
|
|
58
58
|
"""Inits PhasedXPowGate.
|
|
@@ -67,7 +67,7 @@ class PhasedXPowGate(raw_types.Gate):
|
|
|
67
67
|
self._exponent = exponent
|
|
68
68
|
self._global_shift = global_shift
|
|
69
69
|
|
|
70
|
-
def _qasm_(self, args: cirq.QasmArgs, qubits:
|
|
70
|
+
def _qasm_(self, args: cirq.QasmArgs, qubits: tuple[cirq.Qid, ...]) -> str | None:
|
|
71
71
|
if cirq.is_parameterized(self):
|
|
72
72
|
return None
|
|
73
73
|
|
|
@@ -103,12 +103,12 @@ class PhasedXPowGate(raw_types.Gate):
|
|
|
103
103
|
return z**-1, x, z
|
|
104
104
|
|
|
105
105
|
@property
|
|
106
|
-
def exponent(self) ->
|
|
106
|
+
def exponent(self) -> float | sympy.Expr:
|
|
107
107
|
"""The exponent on the central X gate conjugated by the Z gates."""
|
|
108
108
|
return self._exponent
|
|
109
109
|
|
|
110
110
|
@property
|
|
111
|
-
def phase_exponent(self) ->
|
|
111
|
+
def phase_exponent(self) -> float | sympy.Expr:
|
|
112
112
|
"""The exponent on the Z gates conjugating the X gate."""
|
|
113
113
|
return self._phase_exponent
|
|
114
114
|
|
|
@@ -116,7 +116,7 @@ class PhasedXPowGate(raw_types.Gate):
|
|
|
116
116
|
def global_shift(self) -> float:
|
|
117
117
|
return self._global_shift
|
|
118
118
|
|
|
119
|
-
def __pow__(self, exponent:
|
|
119
|
+
def __pow__(self, exponent: float | sympy.Expr) -> PhasedXPowGate:
|
|
120
120
|
new_exponent = protocols.mul(self._exponent, exponent, NotImplemented)
|
|
121
121
|
if new_exponent is NotImplemented:
|
|
122
122
|
return NotImplemented # pragma: no cover
|
|
@@ -126,7 +126,7 @@ class PhasedXPowGate(raw_types.Gate):
|
|
|
126
126
|
global_shift=self._global_shift,
|
|
127
127
|
)
|
|
128
128
|
|
|
129
|
-
def _trace_distance_bound_(self) ->
|
|
129
|
+
def _trace_distance_bound_(self) -> float | None:
|
|
130
130
|
if self._is_parameterized_():
|
|
131
131
|
return None
|
|
132
132
|
return abs(np.sin(self._exponent * 0.5 * np.pi))
|
|
@@ -134,7 +134,7 @@ class PhasedXPowGate(raw_types.Gate):
|
|
|
134
134
|
def _has_unitary_(self):
|
|
135
135
|
return not self._is_parameterized_()
|
|
136
136
|
|
|
137
|
-
def _unitary_(self) ->
|
|
137
|
+
def _unitary_(self) -> np.ndarray | NotImplementedType | None:
|
|
138
138
|
"""See `cirq.SupportsUnitary`."""
|
|
139
139
|
if self._is_parameterized_():
|
|
140
140
|
return None
|
|
@@ -243,5 +243,5 @@ class PhasedXPowGate(raw_types.Gate):
|
|
|
243
243
|
def _value_equality_values_(self):
|
|
244
244
|
return self.phase_exponent, self._canonical_exponent, self._global_shift
|
|
245
245
|
|
|
246
|
-
def _json_dict_(self) ->
|
|
246
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
247
247
|
return protocols.obj_to_dict_helper(self, ['phase_exponent', 'exponent', 'global_shift'])
|
cirq/ops/phased_x_z_gate.py
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
17
|
import numbers
|
|
18
|
-
from typing import AbstractSet, Any,
|
|
18
|
+
from typing import AbstractSet, Any, Iterator, Sequence, TYPE_CHECKING
|
|
19
19
|
|
|
20
20
|
import numpy as np
|
|
21
21
|
import sympy
|
|
@@ -52,9 +52,9 @@ class PhasedXZGate(raw_types.Gate):
|
|
|
52
52
|
def __init__(
|
|
53
53
|
self,
|
|
54
54
|
*,
|
|
55
|
-
x_exponent:
|
|
56
|
-
z_exponent:
|
|
57
|
-
axis_phase_exponent:
|
|
55
|
+
x_exponent: float | sympy.Expr,
|
|
56
|
+
z_exponent: float | sympy.Expr,
|
|
57
|
+
axis_phase_exponent: float | sympy.Expr,
|
|
58
58
|
) -> None:
|
|
59
59
|
"""Inits PhasedXZGate.
|
|
60
60
|
|
|
@@ -128,15 +128,15 @@ class PhasedXZGate(raw_types.Gate):
|
|
|
128
128
|
return PhasedXZGate(x_exponent=x, z_exponent=z, axis_phase_exponent=a)
|
|
129
129
|
|
|
130
130
|
@property
|
|
131
|
-
def x_exponent(self) ->
|
|
131
|
+
def x_exponent(self) -> float | sympy.Expr:
|
|
132
132
|
return self._x_exponent
|
|
133
133
|
|
|
134
134
|
@property
|
|
135
|
-
def z_exponent(self) ->
|
|
135
|
+
def z_exponent(self) -> float | sympy.Expr:
|
|
136
136
|
return self._z_exponent
|
|
137
137
|
|
|
138
138
|
@property
|
|
139
|
-
def axis_phase_exponent(self) ->
|
|
139
|
+
def axis_phase_exponent(self) -> float | sympy.Expr:
|
|
140
140
|
return self._axis_phase_exponent
|
|
141
141
|
|
|
142
142
|
def _value_equality_values_(self):
|
|
@@ -159,14 +159,14 @@ class PhasedXZGate(raw_types.Gate):
|
|
|
159
159
|
x_exponent=rotation, axis_phase_exponent=-pre_phase, z_exponent=post_phase + pre_phase
|
|
160
160
|
)._canonical()
|
|
161
161
|
|
|
162
|
-
def with_z_exponent(self, z_exponent:
|
|
162
|
+
def with_z_exponent(self, z_exponent: float | sympy.Expr) -> cirq.PhasedXZGate:
|
|
163
163
|
return PhasedXZGate(
|
|
164
164
|
axis_phase_exponent=self._axis_phase_exponent,
|
|
165
165
|
x_exponent=self._x_exponent,
|
|
166
166
|
z_exponent=z_exponent,
|
|
167
167
|
)
|
|
168
168
|
|
|
169
|
-
def _qasm_(self, args: cirq.QasmArgs, qubits:
|
|
169
|
+
def _qasm_(self, args: cirq.QasmArgs, qubits: tuple[cirq.Qid, ...]) -> str | None:
|
|
170
170
|
from cirq.circuits import qasm_output
|
|
171
171
|
|
|
172
172
|
qasm_gate = qasm_output.QasmUGate(
|
|
@@ -182,7 +182,7 @@ class PhasedXZGate(raw_types.Gate):
|
|
|
182
182
|
def _has_unitary_(self) -> bool:
|
|
183
183
|
return not self._is_parameterized_()
|
|
184
184
|
|
|
185
|
-
def _unitary_(self) ->
|
|
185
|
+
def _unitary_(self) -> np.ndarray | None:
|
|
186
186
|
"""See `cirq.SupportsUnitary`."""
|
|
187
187
|
if self._is_parameterized_():
|
|
188
188
|
return None
|
|
@@ -300,7 +300,7 @@ class PhasedXZGate(raw_types.Gate):
|
|
|
300
300
|
f'z_exponent={proper_repr(self._z_exponent)})'
|
|
301
301
|
)
|
|
302
302
|
|
|
303
|
-
def _json_dict_(self) ->
|
|
303
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
304
304
|
return protocols.obj_to_dict_helper(
|
|
305
305
|
self, ['axis_phase_exponent', 'x_exponent', 'z_exponent']
|
|
306
306
|
)
|
cirq/ops/projector.py
CHANGED
|
@@ -4,7 +4,7 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
import itertools
|
|
6
6
|
import math
|
|
7
|
-
from typing import Any,
|
|
7
|
+
from typing import Any, Iterable, Mapping, TYPE_CHECKING
|
|
8
8
|
|
|
9
9
|
import numpy as np
|
|
10
10
|
from scipy.sparse import csr_matrix
|
|
@@ -26,7 +26,7 @@ def _check_qids_dimension(qids):
|
|
|
26
26
|
class ProjectorString:
|
|
27
27
|
"""Mapping of `cirq.Qid` to measurement values (with a coefficient) representing a projector."""
|
|
28
28
|
|
|
29
|
-
def __init__(self, projector_dict:
|
|
29
|
+
def __init__(self, projector_dict: dict[cirq.Qid, int], coefficient: complex = 1):
|
|
30
30
|
"""Constructor for ProjectorString
|
|
31
31
|
|
|
32
32
|
Args:
|
|
@@ -39,14 +39,14 @@ class ProjectorString:
|
|
|
39
39
|
self._coefficient = complex(coefficient)
|
|
40
40
|
|
|
41
41
|
@property
|
|
42
|
-
def projector_dict(self) ->
|
|
42
|
+
def projector_dict(self) -> dict[cirq.Qid, int]:
|
|
43
43
|
return self._projector_dict
|
|
44
44
|
|
|
45
45
|
@property
|
|
46
46
|
def coefficient(self) -> complex:
|
|
47
47
|
return self._coefficient
|
|
48
48
|
|
|
49
|
-
def matrix(self, projector_qids:
|
|
49
|
+
def matrix(self, projector_qids: Iterable[cirq.Qid] | None = None) -> csr_matrix:
|
|
50
50
|
"""Returns the matrix of self in computational basis of qubits.
|
|
51
51
|
|
|
52
52
|
Args:
|
|
@@ -82,7 +82,7 @@ class ProjectorString:
|
|
|
82
82
|
|
|
83
83
|
def _get_idx_to_keep(self, qid_map: Mapping[cirq.Qid, int]):
|
|
84
84
|
num_qubits = len(qid_map)
|
|
85
|
-
idx_to_keep:
|
|
85
|
+
idx_to_keep: list[Any] = [slice(0, 2)] * num_qubits
|
|
86
86
|
for q in self.projector_dict.keys():
|
|
87
87
|
idx_to_keep[qid_map[q]] = self.projector_dict[q]
|
|
88
88
|
return tuple(idx_to_keep)
|
|
@@ -138,7 +138,7 @@ class ProjectorString:
|
|
|
138
138
|
+ f"coefficient={self._coefficient})"
|
|
139
139
|
)
|
|
140
140
|
|
|
141
|
-
def _json_dict_(self) ->
|
|
141
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
142
142
|
return {
|
|
143
143
|
'projector_dict': list(self._projector_dict.items()),
|
|
144
144
|
'coefficient': self._coefficient,
|