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/fourier_transform.py
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
|
-
from typing import AbstractSet, Any
|
|
17
|
+
from typing import AbstractSet, Any
|
|
18
18
|
|
|
19
19
|
import numpy as np
|
|
20
20
|
import sympy
|
|
@@ -54,7 +54,7 @@ class QuantumFourierTransformGate(raw_types.Gate):
|
|
|
54
54
|
self._num_qubits = num_qubits
|
|
55
55
|
self._without_reverse = without_reverse
|
|
56
56
|
|
|
57
|
-
def _json_dict_(self) ->
|
|
57
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
58
58
|
return {'num_qubits': self._num_qubits, 'without_reverse': self._without_reverse}
|
|
59
59
|
|
|
60
60
|
def _value_equality_values_(self):
|
|
@@ -112,15 +112,15 @@ class PhaseGradientGate(raw_types.Gate):
|
|
|
112
112
|
This gate makes up a portion of the quantum fourier transform.
|
|
113
113
|
"""
|
|
114
114
|
|
|
115
|
-
def __init__(self, *, num_qubits: int, exponent:
|
|
115
|
+
def __init__(self, *, num_qubits: int, exponent: float | sympy.Basic):
|
|
116
116
|
self._num_qubits = num_qubits
|
|
117
117
|
self._exponent = exponent
|
|
118
118
|
|
|
119
119
|
@property
|
|
120
|
-
def exponent(self) ->
|
|
120
|
+
def exponent(self) -> float | sympy.Basic:
|
|
121
121
|
return self._exponent
|
|
122
122
|
|
|
123
|
-
def _json_dict_(self) ->
|
|
123
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
124
124
|
return {'num_qubits': self._num_qubits, 'exponent': self.exponent}
|
|
125
125
|
|
|
126
126
|
def _value_equality_values_(self):
|
cirq/ops/fsim_gate.py
CHANGED
|
@@ -26,7 +26,7 @@ from __future__ import annotations
|
|
|
26
26
|
|
|
27
27
|
import cmath
|
|
28
28
|
import math
|
|
29
|
-
from typing import AbstractSet, Any,
|
|
29
|
+
from typing import AbstractSet, Any, Iterator
|
|
30
30
|
|
|
31
31
|
import numpy as np
|
|
32
32
|
import sympy
|
|
@@ -131,7 +131,7 @@ class FSimGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
|
|
|
131
131
|
def _has_unitary_(self):
|
|
132
132
|
return not self._is_parameterized_()
|
|
133
133
|
|
|
134
|
-
def _unitary_(self) ->
|
|
134
|
+
def _unitary_(self) -> np.ndarray | None:
|
|
135
135
|
if self._is_parameterized_():
|
|
136
136
|
return None
|
|
137
137
|
a = math.cos(self.theta)
|
|
@@ -171,7 +171,7 @@ class FSimGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
|
|
|
171
171
|
protocols.resolve_parameters(self.phi, resolver, recursive),
|
|
172
172
|
)
|
|
173
173
|
|
|
174
|
-
def _apply_unitary_(self, args: cirq.ApplyUnitaryArgs) ->
|
|
174
|
+
def _apply_unitary_(self, args: cirq.ApplyUnitaryArgs) -> np.ndarray | None:
|
|
175
175
|
if cirq.is_parameterized(self):
|
|
176
176
|
return None
|
|
177
177
|
if self.theta != 0:
|
|
@@ -196,7 +196,7 @@ class FSimGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
|
|
|
196
196
|
yield yy(a, b)
|
|
197
197
|
yield cirq.CZ(a, b) ** (-self.phi / np.pi)
|
|
198
198
|
|
|
199
|
-
def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs) ->
|
|
199
|
+
def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs) -> tuple[str, ...]:
|
|
200
200
|
t = args.format_radians(self.theta)
|
|
201
201
|
p = args.format_radians(self.phi)
|
|
202
202
|
return f'FSim({t}, {p})', f'FSim({t}, {p})'
|
|
@@ -209,7 +209,7 @@ class FSimGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
|
|
|
209
209
|
p = proper_repr(self.phi)
|
|
210
210
|
return f'cirq.FSimGate(theta={t}, phi={p})'
|
|
211
211
|
|
|
212
|
-
def _json_dict_(self) ->
|
|
212
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
213
213
|
return protocols.obj_to_dict_helper(self, ['theta', 'phi'])
|
|
214
214
|
|
|
215
215
|
|
|
@@ -326,8 +326,8 @@ class PhasedFSimGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
|
|
|
326
326
|
def from_fsim_rz(
|
|
327
327
|
theta: cirq.TParamVal,
|
|
328
328
|
phi: cirq.TParamVal,
|
|
329
|
-
rz_angles_before:
|
|
330
|
-
rz_angles_after:
|
|
329
|
+
rz_angles_before: tuple[cirq.TParamVal, cirq.TParamVal],
|
|
330
|
+
rz_angles_after: tuple[cirq.TParamVal, cirq.TParamVal],
|
|
331
331
|
) -> PhasedFSimGate:
|
|
332
332
|
"""Creates PhasedFSimGate using an alternate parametrization.
|
|
333
333
|
|
|
@@ -349,7 +349,7 @@ class PhasedFSimGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
|
|
|
349
349
|
return PhasedFSimGate(theta, zeta, chi, gamma, phi)
|
|
350
350
|
|
|
351
351
|
@staticmethod
|
|
352
|
-
def from_matrix(u: np.ndarray) ->
|
|
352
|
+
def from_matrix(u: np.ndarray) -> PhasedFSimGate | None:
|
|
353
353
|
"""Contruct a PhasedFSimGate from unitary.
|
|
354
354
|
|
|
355
355
|
Args:
|
|
@@ -388,14 +388,14 @@ class PhasedFSimGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
|
|
|
388
388
|
return None
|
|
389
389
|
|
|
390
390
|
@property
|
|
391
|
-
def rz_angles_before(self) ->
|
|
391
|
+
def rz_angles_before(self) -> tuple[cirq.TParamVal, cirq.TParamVal]:
|
|
392
392
|
"""Returns 2-tuple of phase angles applied to qubits before FSimGate."""
|
|
393
393
|
b0 = (-self.gamma + self.zeta + self.chi) / 2.0
|
|
394
394
|
b1 = (-self.gamma - self.zeta - self.chi) / 2.0
|
|
395
395
|
return b0, b1
|
|
396
396
|
|
|
397
397
|
@property
|
|
398
|
-
def rz_angles_after(self) ->
|
|
398
|
+
def rz_angles_after(self) -> tuple[cirq.TParamVal, cirq.TParamVal]:
|
|
399
399
|
"""Returns 2-tuple of phase angles applied to qubits after FSimGate."""
|
|
400
400
|
a0 = (-self.gamma + self.zeta - self.chi) / 2.0
|
|
401
401
|
a1 = (-self.gamma - self.zeta + self.chi) / 2.0
|
|
@@ -434,7 +434,7 @@ class PhasedFSimGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
|
|
|
434
434
|
def _has_unitary_(self):
|
|
435
435
|
return not self._is_parameterized_()
|
|
436
436
|
|
|
437
|
-
def _unitary_(self) ->
|
|
437
|
+
def _unitary_(self) -> np.ndarray | None:
|
|
438
438
|
if self._is_parameterized_():
|
|
439
439
|
return None
|
|
440
440
|
a = math.cos(self.theta)
|
|
@@ -467,7 +467,7 @@ class PhasedFSimGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
|
|
|
467
467
|
protocols.resolve_parameters(self.phi, resolver, recursive),
|
|
468
468
|
)
|
|
469
469
|
|
|
470
|
-
def _apply_unitary_(self, args: cirq.ApplyUnitaryArgs) ->
|
|
470
|
+
def _apply_unitary_(self, args: cirq.ApplyUnitaryArgs) -> np.ndarray | None:
|
|
471
471
|
if cirq.is_parameterized(self):
|
|
472
472
|
return None
|
|
473
473
|
oi = args.subspace_index(0b01)
|
|
@@ -515,7 +515,7 @@ class PhasedFSimGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
|
|
|
515
515
|
yield cirq.Z(q0) ** to_exponent(after[0])
|
|
516
516
|
yield cirq.Z(q1) ** to_exponent(after[1])
|
|
517
517
|
|
|
518
|
-
def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs) ->
|
|
518
|
+
def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs) -> tuple[str, ...]:
|
|
519
519
|
theta = args.format_radians(self.theta)
|
|
520
520
|
zeta = args.format_radians(self.zeta)
|
|
521
521
|
chi = args.format_radians(self.chi)
|
|
@@ -537,7 +537,7 @@ class PhasedFSimGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
|
|
|
537
537
|
f'gamma={gamma}, phi={phi})'
|
|
538
538
|
)
|
|
539
539
|
|
|
540
|
-
def _json_dict_(self) ->
|
|
540
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
541
541
|
return protocols.obj_to_dict_helper(self, ['theta', 'zeta', 'chi', 'gamma', 'phi'])
|
|
542
542
|
|
|
543
543
|
def _num_qubits_(self) -> int:
|
cirq/ops/gate_operation.py
CHANGED
|
@@ -19,22 +19,7 @@ from __future__ import annotations
|
|
|
19
19
|
import re
|
|
20
20
|
import warnings
|
|
21
21
|
from types import NotImplementedType
|
|
22
|
-
from typing import
|
|
23
|
-
AbstractSet,
|
|
24
|
-
Any,
|
|
25
|
-
cast,
|
|
26
|
-
Collection,
|
|
27
|
-
Dict,
|
|
28
|
-
FrozenSet,
|
|
29
|
-
List,
|
|
30
|
-
Mapping,
|
|
31
|
-
Optional,
|
|
32
|
-
Sequence,
|
|
33
|
-
Tuple,
|
|
34
|
-
TYPE_CHECKING,
|
|
35
|
-
TypeVar,
|
|
36
|
-
Union,
|
|
37
|
-
)
|
|
22
|
+
from typing import AbstractSet, Any, cast, Collection, Mapping, Sequence, TYPE_CHECKING, TypeVar
|
|
38
23
|
|
|
39
24
|
from typing_extensions import Self
|
|
40
25
|
|
|
@@ -71,7 +56,7 @@ class GateOperation(raw_types.Operation):
|
|
|
71
56
|
return self._gate
|
|
72
57
|
|
|
73
58
|
@property
|
|
74
|
-
def qubits(self) ->
|
|
59
|
+
def qubits(self) -> tuple[cirq.Qid, ...]:
|
|
75
60
|
"""The qubits targeted by the operation."""
|
|
76
61
|
return self._qubits
|
|
77
62
|
|
|
@@ -93,7 +78,7 @@ class GateOperation(raw_types.Operation):
|
|
|
93
78
|
return self
|
|
94
79
|
return new_gate.on(*self.qubits)
|
|
95
80
|
|
|
96
|
-
def _with_key_path_(self, path:
|
|
81
|
+
def _with_key_path_(self, path: tuple[str, ...]):
|
|
97
82
|
new_gate = protocols.with_key_path(self.gate, path)
|
|
98
83
|
if new_gate is NotImplemented:
|
|
99
84
|
return NotImplemented
|
|
@@ -102,7 +87,7 @@ class GateOperation(raw_types.Operation):
|
|
|
102
87
|
return self
|
|
103
88
|
return new_gate.on(*self.qubits)
|
|
104
89
|
|
|
105
|
-
def _with_key_path_prefix_(self, prefix:
|
|
90
|
+
def _with_key_path_prefix_(self, prefix: tuple[str, ...]):
|
|
106
91
|
new_gate = protocols.with_key_path_prefix(self.gate, prefix)
|
|
107
92
|
if new_gate is NotImplemented:
|
|
108
93
|
return NotImplemented
|
|
@@ -112,7 +97,7 @@ class GateOperation(raw_types.Operation):
|
|
|
112
97
|
return new_gate.on(*self.qubits)
|
|
113
98
|
|
|
114
99
|
def _with_rescoped_keys_(
|
|
115
|
-
self, path:
|
|
100
|
+
self, path: tuple[str, ...], bindable_keys: frozenset[cirq.MeasurementKey]
|
|
116
101
|
):
|
|
117
102
|
new_gate = protocols.with_rescoped_keys(self.gate, path, bindable_keys)
|
|
118
103
|
if new_gate is self.gate:
|
|
@@ -140,15 +125,15 @@ class GateOperation(raw_types.Operation):
|
|
|
140
125
|
qubits = ', '.join(str(e) for e in self.qubits)
|
|
141
126
|
return f'{self.gate}({qubits})' if qubits else str(self.gate)
|
|
142
127
|
|
|
143
|
-
def _json_dict_(self) ->
|
|
128
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
144
129
|
return protocols.obj_to_dict_helper(self, ['gate', 'qubits'])
|
|
145
130
|
|
|
146
131
|
def _group_interchangeable_qubits(
|
|
147
132
|
self,
|
|
148
|
-
) ->
|
|
133
|
+
) -> tuple[cirq.Qid | tuple[int, frozenset[cirq.Qid]], ...]:
|
|
149
134
|
if not isinstance(self.gate, gate_features.InterchangeableQubitsGate):
|
|
150
135
|
return self.qubits
|
|
151
|
-
groups:
|
|
136
|
+
groups: dict[int, list[cirq.Qid]] = {}
|
|
152
137
|
for i, q in enumerate(self.qubits):
|
|
153
138
|
k = self.gate.qubit_index_to_equivalence_group_key(i)
|
|
154
139
|
groups.setdefault(k, []).append(q)
|
|
@@ -167,7 +152,7 @@ class GateOperation(raw_types.Operation):
|
|
|
167
152
|
return self._decompose_with_context_()
|
|
168
153
|
|
|
169
154
|
def _decompose_with_context_(
|
|
170
|
-
self, context:
|
|
155
|
+
self, context: cirq.DecompositionContext | None = None
|
|
171
156
|
) -> cirq.OP_TREE:
|
|
172
157
|
return protocols.decompose_once_with_qubits(
|
|
173
158
|
self.gate, self.qubits, NotImplemented, flatten=False, context=context
|
|
@@ -181,7 +166,7 @@ class GateOperation(raw_types.Operation):
|
|
|
181
166
|
|
|
182
167
|
def _apply_unitary_(
|
|
183
168
|
self, args: protocols.ApplyUnitaryArgs
|
|
184
|
-
) ->
|
|
169
|
+
) -> np.ndarray | None | NotImplementedType:
|
|
185
170
|
getter = getattr(self.gate, '_apply_unitary_', None)
|
|
186
171
|
if getter is not None:
|
|
187
172
|
return getter(args)
|
|
@@ -193,15 +178,13 @@ class GateOperation(raw_types.Operation):
|
|
|
193
178
|
return getter()
|
|
194
179
|
return NotImplemented
|
|
195
180
|
|
|
196
|
-
def _unitary_(self) ->
|
|
181
|
+
def _unitary_(self) -> np.ndarray | NotImplementedType:
|
|
197
182
|
getter = getattr(self.gate, '_unitary_', None)
|
|
198
183
|
if getter is not None:
|
|
199
184
|
return getter()
|
|
200
185
|
return NotImplemented
|
|
201
186
|
|
|
202
|
-
def _commutes_(
|
|
203
|
-
self, other: Any, *, atol: float = 1e-8
|
|
204
|
-
) -> Union[bool, NotImplementedType, None]:
|
|
187
|
+
def _commutes_(self, other: Any, *, atol: float = 1e-8) -> bool | NotImplementedType | None:
|
|
205
188
|
commutes = self.gate._commutes_on_qids_(self.qubits, other, atol=atol)
|
|
206
189
|
if commutes is not NotImplemented:
|
|
207
190
|
return commutes
|
|
@@ -214,7 +197,7 @@ class GateOperation(raw_types.Operation):
|
|
|
214
197
|
return getter()
|
|
215
198
|
return NotImplemented
|
|
216
199
|
|
|
217
|
-
def _mixture_(self) -> Sequence[
|
|
200
|
+
def _mixture_(self) -> Sequence[tuple[float, Any]]:
|
|
218
201
|
getter = getattr(self.gate, '_mixture_', None)
|
|
219
202
|
if getter is not None:
|
|
220
203
|
return getter()
|
|
@@ -222,7 +205,7 @@ class GateOperation(raw_types.Operation):
|
|
|
222
205
|
|
|
223
206
|
def _apply_channel_(
|
|
224
207
|
self, args: protocols.ApplyChannelArgs
|
|
225
|
-
) ->
|
|
208
|
+
) -> np.ndarray | None | NotImplementedType:
|
|
226
209
|
getter = getattr(self.gate, '_apply_channel_', None)
|
|
227
210
|
if getter is not None:
|
|
228
211
|
return getter(args)
|
|
@@ -234,40 +217,38 @@ class GateOperation(raw_types.Operation):
|
|
|
234
217
|
return getter()
|
|
235
218
|
return NotImplemented
|
|
236
219
|
|
|
237
|
-
def _kraus_(self) ->
|
|
220
|
+
def _kraus_(self) -> tuple[np.ndarray] | NotImplementedType:
|
|
238
221
|
getter = getattr(self.gate, '_kraus_', None)
|
|
239
222
|
if getter is not None:
|
|
240
223
|
return getter()
|
|
241
224
|
return NotImplemented
|
|
242
225
|
|
|
243
|
-
def _is_measurement_(self) ->
|
|
226
|
+
def _is_measurement_(self) -> bool | None:
|
|
244
227
|
getter = getattr(self.gate, '_is_measurement_', None)
|
|
245
228
|
if getter is not None:
|
|
246
229
|
return getter()
|
|
247
230
|
# Let the protocol handle the fallback.
|
|
248
231
|
return NotImplemented
|
|
249
232
|
|
|
250
|
-
def _measurement_key_name_(self) ->
|
|
233
|
+
def _measurement_key_name_(self) -> str | None:
|
|
251
234
|
getter = getattr(self.gate, '_measurement_key_name_', None)
|
|
252
235
|
if getter is not None:
|
|
253
236
|
return getter()
|
|
254
237
|
return NotImplemented
|
|
255
238
|
|
|
256
|
-
def _measurement_key_names_(self) ->
|
|
239
|
+
def _measurement_key_names_(self) -> frozenset[str] | NotImplementedType | None:
|
|
257
240
|
getter = getattr(self.gate, '_measurement_key_names_', None)
|
|
258
241
|
if getter is not None:
|
|
259
242
|
return getter()
|
|
260
243
|
return NotImplemented
|
|
261
244
|
|
|
262
|
-
def _measurement_key_obj_(self) ->
|
|
245
|
+
def _measurement_key_obj_(self) -> cirq.MeasurementKey | None:
|
|
263
246
|
getter = getattr(self.gate, '_measurement_key_obj_', None)
|
|
264
247
|
if getter is not None:
|
|
265
248
|
return getter()
|
|
266
249
|
return NotImplemented
|
|
267
250
|
|
|
268
|
-
def _measurement_key_objs_(
|
|
269
|
-
self,
|
|
270
|
-
) -> Union[FrozenSet[cirq.MeasurementKey], NotImplementedType, None]:
|
|
251
|
+
def _measurement_key_objs_(self) -> frozenset[cirq.MeasurementKey] | NotImplementedType | None:
|
|
271
252
|
getter = getattr(self.gate, '_measurement_key_objs_', None)
|
|
272
253
|
if getter is not None:
|
|
273
254
|
return getter()
|
|
@@ -347,7 +328,7 @@ class GateOperation(raw_types.Operation):
|
|
|
347
328
|
def __rmul__(self, other: Any) -> Any:
|
|
348
329
|
return self.gate._rmul_with_qubits(self._qubits, other)
|
|
349
330
|
|
|
350
|
-
def _qasm_(self, args: protocols.QasmArgs) ->
|
|
331
|
+
def _qasm_(self, args: protocols.QasmArgs) -> str | None:
|
|
351
332
|
if isinstance(self.gate, ops.GlobalPhaseGate):
|
|
352
333
|
warnings.warn(
|
|
353
334
|
"OpenQASM 2.0 does not support global phase."
|
|
@@ -360,7 +341,7 @@ class GateOperation(raw_types.Operation):
|
|
|
360
341
|
|
|
361
342
|
def _equal_up_to_global_phase_(
|
|
362
343
|
self, other: Any, atol: float = 1e-8
|
|
363
|
-
) ->
|
|
344
|
+
) -> NotImplementedType | bool:
|
|
364
345
|
if not isinstance(other, type(self)):
|
|
365
346
|
return NotImplemented
|
|
366
347
|
if self._group_interchangeable_qubits() != other._group_interchangeable_qubits():
|
|
@@ -370,9 +351,7 @@ class GateOperation(raw_types.Operation):
|
|
|
370
351
|
def controlled_by(
|
|
371
352
|
self,
|
|
372
353
|
*control_qubits: cirq.Qid,
|
|
373
|
-
control_values:
|
|
374
|
-
Union[cv.AbstractControlValues, Sequence[Union[int, Collection[int]]]]
|
|
375
|
-
] = None,
|
|
354
|
+
control_values: cv.AbstractControlValues | Sequence[int | Collection[int]] | None = None,
|
|
376
355
|
) -> cirq.Operation:
|
|
377
356
|
if len(control_qubits) == 0:
|
|
378
357
|
return self
|
cirq/ops/gateset.py
CHANGED
|
@@ -16,20 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
from __future__ import annotations
|
|
18
18
|
|
|
19
|
-
from typing import
|
|
20
|
-
Any,
|
|
21
|
-
Callable,
|
|
22
|
-
cast,
|
|
23
|
-
Dict,
|
|
24
|
-
FrozenSet,
|
|
25
|
-
Hashable,
|
|
26
|
-
List,
|
|
27
|
-
Optional,
|
|
28
|
-
Sequence,
|
|
29
|
-
Type,
|
|
30
|
-
TYPE_CHECKING,
|
|
31
|
-
Union,
|
|
32
|
-
)
|
|
19
|
+
from typing import Any, Callable, cast, Hashable, Sequence, TYPE_CHECKING
|
|
33
20
|
|
|
34
21
|
from cirq import protocols, value
|
|
35
22
|
from cirq.ops import global_phase_op, op_tree, raw_types
|
|
@@ -39,8 +26,7 @@ if TYPE_CHECKING:
|
|
|
39
26
|
|
|
40
27
|
|
|
41
28
|
def _gate_str(
|
|
42
|
-
gate:
|
|
43
|
-
gettr: Callable[[Any], str] = str,
|
|
29
|
+
gate: raw_types.Gate | type[raw_types.Gate] | cirq.GateFamily, gettr: Callable[[Any], str] = str
|
|
44
30
|
) -> str:
|
|
45
31
|
return gettr(gate) if not isinstance(gate, type) else f'{gate.__module__}.{gate.__name__}'
|
|
46
32
|
|
|
@@ -114,10 +100,10 @@ class GateFamily:
|
|
|
114
100
|
|
|
115
101
|
def __init__(
|
|
116
102
|
self,
|
|
117
|
-
gate:
|
|
103
|
+
gate: type[raw_types.Gate] | raw_types.Gate,
|
|
118
104
|
*,
|
|
119
|
-
name:
|
|
120
|
-
description:
|
|
105
|
+
name: str | None = None,
|
|
106
|
+
description: str | None = None,
|
|
121
107
|
ignore_global_phase: bool = True,
|
|
122
108
|
tags_to_accept: Sequence[Hashable] = (),
|
|
123
109
|
tags_to_ignore: Sequence[Hashable] = (),
|
|
@@ -166,7 +152,7 @@ class GateFamily:
|
|
|
166
152
|
def _gate_str(self, gettr: Callable[[Any], str] = str) -> str:
|
|
167
153
|
return _gate_str(self.gate, gettr)
|
|
168
154
|
|
|
169
|
-
def _gate_json(self) ->
|
|
155
|
+
def _gate_json(self) -> raw_types.Gate | str:
|
|
170
156
|
return self.gate if not isinstance(self.gate, type) else protocols.json_cirq_type(self.gate)
|
|
171
157
|
|
|
172
158
|
def _default_name(self) -> str:
|
|
@@ -188,7 +174,7 @@ class GateFamily:
|
|
|
188
174
|
)
|
|
189
175
|
|
|
190
176
|
@property
|
|
191
|
-
def gate(self) ->
|
|
177
|
+
def gate(self) -> type[raw_types.Gate] | raw_types.Gate:
|
|
192
178
|
return self._gate
|
|
193
179
|
|
|
194
180
|
@property
|
|
@@ -200,11 +186,11 @@ class GateFamily:
|
|
|
200
186
|
return self._description
|
|
201
187
|
|
|
202
188
|
@property
|
|
203
|
-
def tags_to_accept(self) ->
|
|
189
|
+
def tags_to_accept(self) -> frozenset[Hashable]:
|
|
204
190
|
return self._tags_to_accept
|
|
205
191
|
|
|
206
192
|
@property
|
|
207
|
-
def tags_to_ignore(self) ->
|
|
193
|
+
def tags_to_ignore(self) -> frozenset[Hashable]:
|
|
208
194
|
return self._tags_to_ignore
|
|
209
195
|
|
|
210
196
|
def _predicate(self, gate: raw_types.Gate) -> bool:
|
|
@@ -227,7 +213,7 @@ class GateFamily:
|
|
|
227
213
|
)
|
|
228
214
|
return isinstance(gate, self.gate)
|
|
229
215
|
|
|
230
|
-
def __contains__(self, item:
|
|
216
|
+
def __contains__(self, item: raw_types.Gate | raw_types.Operation) -> bool:
|
|
231
217
|
if self._tags_to_accept and (
|
|
232
218
|
not isinstance(item, raw_types.Operation) or self._tags_to_accept.isdisjoint(item.tags)
|
|
233
219
|
):
|
|
@@ -270,8 +256,8 @@ class GateFamily:
|
|
|
270
256
|
self._tags_to_ignore,
|
|
271
257
|
)
|
|
272
258
|
|
|
273
|
-
def _json_dict_(self) ->
|
|
274
|
-
d:
|
|
259
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
260
|
+
d: dict[str, Any] = {
|
|
275
261
|
'gate': self._gate_json(),
|
|
276
262
|
'name': self.name,
|
|
277
263
|
'description': self.description,
|
|
@@ -321,8 +307,8 @@ class Gateset:
|
|
|
321
307
|
|
|
322
308
|
def __init__(
|
|
323
309
|
self,
|
|
324
|
-
*gates:
|
|
325
|
-
name:
|
|
310
|
+
*gates: type[raw_types.Gate] | raw_types.Gate | GateFamily,
|
|
311
|
+
name: str | None = None,
|
|
326
312
|
unroll_circuit_op: bool = True,
|
|
327
313
|
) -> None:
|
|
328
314
|
"""Init Gateset.
|
|
@@ -346,10 +332,10 @@ class Gateset:
|
|
|
346
332
|
"""
|
|
347
333
|
self._name = name
|
|
348
334
|
self._unroll_circuit_op = unroll_circuit_op
|
|
349
|
-
self._instance_gate_families:
|
|
350
|
-
self._type_gate_families:
|
|
335
|
+
self._instance_gate_families: dict[raw_types.Gate, GateFamily] = {}
|
|
336
|
+
self._type_gate_families: dict[type[raw_types.Gate], GateFamily] = {}
|
|
351
337
|
self._gates_repr_str = ", ".join([_gate_str(g, repr) for g in gates])
|
|
352
|
-
unique_gate_list:
|
|
338
|
+
unique_gate_list: list[GateFamily] = list(
|
|
353
339
|
dict.fromkeys(g if isinstance(g, GateFamily) else GateFamily(gate=g) for g in gates)
|
|
354
340
|
)
|
|
355
341
|
|
|
@@ -363,15 +349,15 @@ class Gateset:
|
|
|
363
349
|
self._gates = frozenset(unique_gate_list)
|
|
364
350
|
|
|
365
351
|
@property
|
|
366
|
-
def name(self) ->
|
|
352
|
+
def name(self) -> str | None:
|
|
367
353
|
return self._name
|
|
368
354
|
|
|
369
355
|
@property
|
|
370
|
-
def gates(self) ->
|
|
356
|
+
def gates(self) -> frozenset[GateFamily]:
|
|
371
357
|
return self._gates
|
|
372
358
|
|
|
373
359
|
def with_params(
|
|
374
|
-
self, *, name:
|
|
360
|
+
self, *, name: str | None = None, unroll_circuit_op: bool | None = None
|
|
375
361
|
) -> Gateset:
|
|
376
362
|
"""Returns a copy of this Gateset with identical gates and new values for named arguments.
|
|
377
363
|
|
|
@@ -397,7 +383,7 @@ class Gateset:
|
|
|
397
383
|
gates = self.gates
|
|
398
384
|
return Gateset(*gates, name=name, unroll_circuit_op=cast(bool, unroll_circuit_op))
|
|
399
385
|
|
|
400
|
-
def __contains__(self, item:
|
|
386
|
+
def __contains__(self, item: raw_types.Gate | raw_types.Operation) -> bool:
|
|
401
387
|
r"""Check for containment of a given Gate/Operation in this Gateset.
|
|
402
388
|
|
|
403
389
|
Containment checks are handled as follows:
|
|
@@ -447,7 +433,7 @@ class Gateset:
|
|
|
447
433
|
|
|
448
434
|
return any(item in gate_family for gate_family in self._gates)
|
|
449
435
|
|
|
450
|
-
def validate(self, circuit_or_optree:
|
|
436
|
+
def validate(self, circuit_or_optree: cirq.AbstractCircuit | op_tree.OP_TREE) -> bool:
|
|
451
437
|
"""Validates gates forming `circuit_or_optree` should be contained in Gateset.
|
|
452
438
|
|
|
453
439
|
Args:
|
|
@@ -512,7 +498,7 @@ class Gateset:
|
|
|
512
498
|
header += self.name
|
|
513
499
|
return f'{header}\n' + "\n\n".join([str(g) for g in self._unique_gate_list])
|
|
514
500
|
|
|
515
|
-
def _json_dict_(self) ->
|
|
501
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
516
502
|
return {
|
|
517
503
|
'gates': self._unique_gate_list,
|
|
518
504
|
'name': self.name,
|
cirq/ops/gateset_test.py
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
17
|
import re
|
|
18
|
-
from typing import cast
|
|
18
|
+
from typing import cast
|
|
19
19
|
|
|
20
20
|
import numpy as np
|
|
21
21
|
import pytest
|
|
@@ -26,7 +26,7 @@ from cirq._compat import proper_repr
|
|
|
26
26
|
|
|
27
27
|
|
|
28
28
|
class CustomXPowGate(cirq.EigenGate):
|
|
29
|
-
def _eigen_components(self) ->
|
|
29
|
+
def _eigen_components(self) -> list[tuple[float, np.ndarray]]:
|
|
30
30
|
return [(0, np.array([[0.5, 0.5], [0.5, 0.5]])), (1, np.array([[0.5, -0.5], [-0.5, 0.5]]))]
|
|
31
31
|
|
|
32
32
|
def __str__(self) -> str:
|
cirq/ops/global_phase_op.py
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
from __future__ import annotations
|
|
17
17
|
|
|
18
18
|
from types import NotImplementedType
|
|
19
|
-
from typing import AbstractSet, Any, cast, Collection,
|
|
19
|
+
from typing import AbstractSet, Any, cast, Collection, Sequence
|
|
20
20
|
|
|
21
21
|
import numpy as np
|
|
22
22
|
import sympy
|
|
@@ -50,12 +50,12 @@ class GlobalPhaseGate(raw_types.Gate):
|
|
|
50
50
|
return GlobalPhaseGate(self.coefficient**power)
|
|
51
51
|
return NotImplemented
|
|
52
52
|
|
|
53
|
-
def _unitary_(self) ->
|
|
53
|
+
def _unitary_(self) -> np.ndarray | NotImplementedType:
|
|
54
54
|
if not self._has_unitary_():
|
|
55
55
|
return NotImplemented
|
|
56
56
|
return np.array([[self.coefficient]])
|
|
57
57
|
|
|
58
|
-
def _apply_unitary_(self, args: cirq.ApplyUnitaryArgs) ->
|
|
58
|
+
def _apply_unitary_(self, args: cirq.ApplyUnitaryArgs) -> np.ndarray | NotImplementedType:
|
|
59
59
|
if not self._has_unitary_():
|
|
60
60
|
return NotImplemented
|
|
61
61
|
assert not cirq.is_parameterized(self)
|
|
@@ -74,10 +74,10 @@ class GlobalPhaseGate(raw_types.Gate):
|
|
|
74
74
|
def _op_repr_(self, qubits: Sequence[cirq.Qid]) -> str:
|
|
75
75
|
return f'cirq.global_phase_operation({proper_repr(self.coefficient)})'
|
|
76
76
|
|
|
77
|
-
def _json_dict_(self) ->
|
|
77
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
78
78
|
return protocols.obj_to_dict_helper(self, ['coefficient'])
|
|
79
79
|
|
|
80
|
-
def _qid_shape_(self) ->
|
|
80
|
+
def _qid_shape_(self) -> tuple[int, ...]:
|
|
81
81
|
return tuple()
|
|
82
82
|
|
|
83
83
|
def _is_parameterized_(self) -> bool:
|
|
@@ -94,11 +94,9 @@ class GlobalPhaseGate(raw_types.Gate):
|
|
|
94
94
|
|
|
95
95
|
def controlled(
|
|
96
96
|
self,
|
|
97
|
-
num_controls:
|
|
98
|
-
control_values:
|
|
99
|
-
|
|
100
|
-
] = None,
|
|
101
|
-
control_qid_shape: Optional[Tuple[int, ...]] = None,
|
|
97
|
+
num_controls: int | None = None,
|
|
98
|
+
control_values: cv.AbstractControlValues | Sequence[int | Collection[int]] | None = None,
|
|
99
|
+
control_qid_shape: tuple[int, ...] | None = None,
|
|
102
100
|
) -> raw_types.Gate:
|
|
103
101
|
result = super().controlled(num_controls, control_values, control_qid_shape)
|
|
104
102
|
if (
|
cirq/ops/greedy_qubit_manager.py
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
|
-
from typing import Iterable,
|
|
17
|
+
from typing import Iterable, TYPE_CHECKING
|
|
18
18
|
|
|
19
19
|
from cirq.ops import named_qubit, qid_util, qubit_manager
|
|
20
20
|
|
|
@@ -51,8 +51,8 @@ class GreedyQubitManager(qubit_manager.QubitManager):
|
|
|
51
51
|
maximize_reuse: Flag to control a FIFO vs LIFO strategy, defaults to False (FIFO).
|
|
52
52
|
"""
|
|
53
53
|
self._prefix = prefix
|
|
54
|
-
self._used_qubits:
|
|
55
|
-
self._free_qubits:
|
|
54
|
+
self._used_qubits: set[cirq.Qid] = set()
|
|
55
|
+
self._free_qubits: list[cirq.Qid] = []
|
|
56
56
|
self._size = 0
|
|
57
57
|
self.maximize_reuse = maximize_reuse
|
|
58
58
|
self.resize(size)
|
|
@@ -63,13 +63,13 @@ class GreedyQubitManager(qubit_manager.QubitManager):
|
|
|
63
63
|
def resize(self, new_size: int, dim: int = 2) -> None:
|
|
64
64
|
if new_size <= self._size:
|
|
65
65
|
return
|
|
66
|
-
new_qubits:
|
|
66
|
+
new_qubits: list[cirq.Qid] = [
|
|
67
67
|
self._allocate_qid(f'{self._prefix}_{s}', dim) for s in range(self._size, new_size)
|
|
68
68
|
]
|
|
69
69
|
self._free_qubits = new_qubits + self._free_qubits
|
|
70
70
|
self._size = new_size
|
|
71
71
|
|
|
72
|
-
def qalloc(self, n: int, dim: int = 2) ->
|
|
72
|
+
def qalloc(self, n: int, dim: int = 2) -> list[cirq.Qid]:
|
|
73
73
|
if not n:
|
|
74
74
|
return []
|
|
75
75
|
self.resize(self._size + n - len(self._free_qubits), dim=dim)
|
|
@@ -84,5 +84,5 @@ class GreedyQubitManager(qubit_manager.QubitManager):
|
|
|
84
84
|
self._used_qubits = self._used_qubits.difference(qs)
|
|
85
85
|
self._free_qubits.extend(qs)
|
|
86
86
|
|
|
87
|
-
def qborrow(self, n: int, dim: int = 2) ->
|
|
87
|
+
def qborrow(self, n: int, dim: int = 2) -> list[cirq.Qid]:
|
|
88
88
|
return self.qalloc(n, dim)
|