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
cirq/ops/qubit_manager.py
CHANGED
|
@@ -16,7 +16,7 @@ from __future__ import annotations
|
|
|
16
16
|
|
|
17
17
|
import abc
|
|
18
18
|
import dataclasses
|
|
19
|
-
from typing import Iterable,
|
|
19
|
+
from typing import Iterable, TYPE_CHECKING
|
|
20
20
|
|
|
21
21
|
from cirq.ops import raw_types
|
|
22
22
|
|
|
@@ -26,11 +26,11 @@ if TYPE_CHECKING:
|
|
|
26
26
|
|
|
27
27
|
class QubitManager(metaclass=abc.ABCMeta):
|
|
28
28
|
@abc.abstractmethod
|
|
29
|
-
def qalloc(self, n: int, dim: int = 2) ->
|
|
29
|
+
def qalloc(self, n: int, dim: int = 2) -> list[cirq.Qid]:
|
|
30
30
|
"""Allocate `n` clean qubits, i.e. qubits guaranteed to be in state |0>."""
|
|
31
31
|
|
|
32
32
|
@abc.abstractmethod
|
|
33
|
-
def qborrow(self, n: int, dim: int = 2) ->
|
|
33
|
+
def qborrow(self, n: int, dim: int = 2) -> list[cirq.Qid]:
|
|
34
34
|
"""Allocate `n` dirty qubits, i.e. the returned qubits can be in any state."""
|
|
35
35
|
|
|
36
36
|
@abc.abstractmethod
|
|
@@ -44,7 +44,7 @@ class _BaseAncillaQid(raw_types.Qid):
|
|
|
44
44
|
dim: int = 2
|
|
45
45
|
prefix: str = ''
|
|
46
46
|
|
|
47
|
-
def _comparison_key(self) ->
|
|
47
|
+
def _comparison_key(self) -> tuple[str, int]:
|
|
48
48
|
return self.prefix, self.id
|
|
49
49
|
|
|
50
50
|
@property
|
|
@@ -84,11 +84,11 @@ class SimpleQubitManager(QubitManager):
|
|
|
84
84
|
self._borrow_id = 0
|
|
85
85
|
self._prefix = prefix
|
|
86
86
|
|
|
87
|
-
def qalloc(self, n: int, dim: int = 2) ->
|
|
87
|
+
def qalloc(self, n: int, dim: int = 2) -> list[cirq.Qid]:
|
|
88
88
|
self._clean_id += n
|
|
89
89
|
return [CleanQubit(i, dim, self._prefix) for i in range(self._clean_id - n, self._clean_id)]
|
|
90
90
|
|
|
91
|
-
def qborrow(self, n: int, dim: int = 2) ->
|
|
91
|
+
def qborrow(self, n: int, dim: int = 2) -> list[cirq.Qid]:
|
|
92
92
|
self._borrow_id = self._borrow_id + n
|
|
93
93
|
return [
|
|
94
94
|
BorrowableQubit(i, dim, self._prefix)
|
cirq/ops/qubit_order.py
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
from __future__ import annotations
|
|
17
17
|
|
|
18
|
-
from typing import Any, Callable, Iterable, Optional,
|
|
18
|
+
from typing import Any, Callable, Iterable, Optional, TYPE_CHECKING, TypeVar
|
|
19
19
|
|
|
20
20
|
if TYPE_CHECKING:
|
|
21
21
|
import cirq
|
|
@@ -28,7 +28,7 @@ TExternalQubit = TypeVar('TExternalQubit')
|
|
|
28
28
|
class QubitOrder:
|
|
29
29
|
"""Defines the kronecker product order of qubits."""
|
|
30
30
|
|
|
31
|
-
def __init__(self, explicit_func: Callable[[Iterable[cirq.Qid]],
|
|
31
|
+
def __init__(self, explicit_func: Callable[[Iterable[cirq.Qid]], tuple[cirq.Qid, ...]]) -> None:
|
|
32
32
|
self._explicit_func = explicit_func
|
|
33
33
|
|
|
34
34
|
DEFAULT: QubitOrder
|
|
@@ -87,7 +87,7 @@ class QubitOrder:
|
|
|
87
87
|
"""
|
|
88
88
|
return QubitOrder(lambda qubits: tuple(sorted(qubits, key=key)))
|
|
89
89
|
|
|
90
|
-
def order_for(self, qubits: Iterable[cirq.Qid]) ->
|
|
90
|
+
def order_for(self, qubits: Iterable[cirq.Qid]) -> tuple[cirq.Qid, ...]:
|
|
91
91
|
"""Returns a qubit tuple ordered corresponding to the basis.
|
|
92
92
|
|
|
93
93
|
Args:
|
cirq/ops/random_gate_channel.py
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
17
|
import numbers
|
|
18
|
-
from typing import AbstractSet, Any, cast,
|
|
18
|
+
from typing import AbstractSet, Any, cast, SupportsFloat, TYPE_CHECKING
|
|
19
19
|
|
|
20
20
|
import numpy as np
|
|
21
21
|
|
|
@@ -54,7 +54,7 @@ class RandomGateChannel(raw_types.Gate):
|
|
|
54
54
|
def probability(self) -> cirq.TParamVal:
|
|
55
55
|
return self._probability
|
|
56
56
|
|
|
57
|
-
def _qid_shape_(self) ->
|
|
57
|
+
def _qid_shape_(self) -> tuple[int, ...]:
|
|
58
58
|
return protocols.qid_shape(self.sub_gate)
|
|
59
59
|
|
|
60
60
|
def _value_equality_values_(self):
|
|
@@ -123,7 +123,7 @@ class RandomGateChannel(raw_types.Gate):
|
|
|
123
123
|
result *= float(self.probability)
|
|
124
124
|
return result
|
|
125
125
|
|
|
126
|
-
def _json_dict_(self) ->
|
|
126
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
127
127
|
return protocols.obj_to_dict_helper(self, ['sub_gate', 'probability'])
|
|
128
128
|
|
|
129
129
|
@classmethod
|
|
@@ -132,7 +132,7 @@ class RandomGateChannel(raw_types.Gate):
|
|
|
132
132
|
|
|
133
133
|
def _circuit_diagram_info_(
|
|
134
134
|
self, args: cirq.CircuitDiagramInfoArgs
|
|
135
|
-
) ->
|
|
135
|
+
) -> cirq.CircuitDiagramInfo | None:
|
|
136
136
|
result = protocols.circuit_diagram_info(self.sub_gate, args, None)
|
|
137
137
|
if result is None:
|
|
138
138
|
return None
|
cirq/ops/raw_types.py
CHANGED
|
@@ -25,17 +25,11 @@ from typing import (
|
|
|
25
25
|
Callable,
|
|
26
26
|
cast,
|
|
27
27
|
Collection,
|
|
28
|
-
Dict,
|
|
29
|
-
FrozenSet,
|
|
30
28
|
Hashable,
|
|
31
29
|
Iterable,
|
|
32
|
-
List,
|
|
33
30
|
Mapping,
|
|
34
|
-
Optional,
|
|
35
31
|
Sequence,
|
|
36
|
-
Tuple,
|
|
37
32
|
TYPE_CHECKING,
|
|
38
|
-
Union,
|
|
39
33
|
)
|
|
40
34
|
|
|
41
35
|
import numpy as np
|
|
@@ -118,7 +112,7 @@ class Qid(metaclass=abc.ABCMeta):
|
|
|
118
112
|
def __hash__(self) -> int:
|
|
119
113
|
return hash((Qid, self._comparison_key()))
|
|
120
114
|
|
|
121
|
-
def __getstate__(self) ->
|
|
115
|
+
def __getstate__(self) -> dict[str, Any]:
|
|
122
116
|
# clear cached hash value when pickling, see #6674
|
|
123
117
|
state = self.__dict__
|
|
124
118
|
hash_attr = _method_cache_name(self.__hash__)
|
|
@@ -191,7 +185,7 @@ class _QubitAsQid(Qid):
|
|
|
191
185
|
def __str__(self) -> str:
|
|
192
186
|
return f'{self.qubit!s} (d={self.dimension})'
|
|
193
187
|
|
|
194
|
-
def _json_dict_(self) ->
|
|
188
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
195
189
|
return protocols.obj_to_dict_helper(self, ['qubit', 'dimension'])
|
|
196
190
|
|
|
197
191
|
|
|
@@ -244,7 +238,7 @@ class Gate(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
244
238
|
"""
|
|
245
239
|
return ops.gate_operation.GateOperation(self, qubits)
|
|
246
240
|
|
|
247
|
-
def on_each(self, *targets:
|
|
241
|
+
def on_each(self, *targets: Qid | Iterable[Any]) -> list[cirq.Operation]:
|
|
248
242
|
"""Returns a list of operations applying the gate to all targets.
|
|
249
243
|
|
|
250
244
|
Args:
|
|
@@ -262,7 +256,7 @@ class Gate(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
262
256
|
If the gate qubit number is incompatible.
|
|
263
257
|
TypeError: If a single target is supplied and it is not iterable.
|
|
264
258
|
"""
|
|
265
|
-
operations:
|
|
259
|
+
operations: list[cirq.Operation] = []
|
|
266
260
|
if self._num_qubits_() > 1:
|
|
267
261
|
iterator: Iterable = targets
|
|
268
262
|
if len(targets) == 1:
|
|
@@ -323,16 +317,12 @@ class Gate(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
323
317
|
"""
|
|
324
318
|
return ops.linear_combinations.LinearCombinationOfGates({self: coefficient})
|
|
325
319
|
|
|
326
|
-
def __add__(
|
|
327
|
-
self, other: Union[Gate, cirq.LinearCombinationOfGates]
|
|
328
|
-
) -> cirq.LinearCombinationOfGates:
|
|
320
|
+
def __add__(self, other: Gate | cirq.LinearCombinationOfGates) -> cirq.LinearCombinationOfGates:
|
|
329
321
|
if isinstance(other, Gate):
|
|
330
322
|
return self.wrap_in_linear_combination() + other.wrap_in_linear_combination()
|
|
331
323
|
return self.wrap_in_linear_combination() + other
|
|
332
324
|
|
|
333
|
-
def __sub__(
|
|
334
|
-
self, other: Union[Gate, cirq.LinearCombinationOfGates]
|
|
335
|
-
) -> cirq.LinearCombinationOfGates:
|
|
325
|
+
def __sub__(self, other: Gate | cirq.LinearCombinationOfGates) -> cirq.LinearCombinationOfGates:
|
|
336
326
|
if isinstance(other, Gate):
|
|
337
327
|
return self.wrap_in_linear_combination() - other.wrap_in_linear_combination()
|
|
338
328
|
return self.wrap_in_linear_combination() - other
|
|
@@ -388,11 +378,9 @@ class Gate(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
388
378
|
|
|
389
379
|
def controlled(
|
|
390
380
|
self,
|
|
391
|
-
num_controls:
|
|
392
|
-
control_values:
|
|
393
|
-
|
|
394
|
-
] = None,
|
|
395
|
-
control_qid_shape: Optional[Tuple[int, ...]] = None,
|
|
381
|
+
num_controls: int | None = None,
|
|
382
|
+
control_values: cv.AbstractControlValues | Sequence[int | Collection[int]] | None = None,
|
|
383
|
+
control_qid_shape: tuple[int, ...] | None = None,
|
|
396
384
|
) -> Gate:
|
|
397
385
|
"""Returns a controlled version of this gate. If no arguments are
|
|
398
386
|
specified, defaults to a single qubit control.
|
|
@@ -430,7 +418,7 @@ class Gate(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
430
418
|
def _backwards_compatibility_num_qubits(self) -> int:
|
|
431
419
|
return protocols.num_qubits(self)
|
|
432
420
|
|
|
433
|
-
def _has_stabilizer_effect_(self) ->
|
|
421
|
+
def _has_stabilizer_effect_(self) -> bool | None:
|
|
434
422
|
return NotImplemented
|
|
435
423
|
|
|
436
424
|
@value.alternative(requires='_num_qubits_', implementation=_backwards_compatibility_num_qubits)
|
|
@@ -453,14 +441,14 @@ class Gate(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
453
441
|
"""The number of qubits this gate acts on."""
|
|
454
442
|
raise NotImplementedError
|
|
455
443
|
|
|
456
|
-
def _default_shape_from_num_qubits(self) ->
|
|
444
|
+
def _default_shape_from_num_qubits(self) -> tuple[int, ...]:
|
|
457
445
|
num_qubits = self._num_qubits_()
|
|
458
446
|
if num_qubits is NotImplemented:
|
|
459
447
|
return NotImplemented
|
|
460
448
|
return (2,) * num_qubits
|
|
461
449
|
|
|
462
450
|
@value.alternative(requires='_num_qubits_', implementation=_default_shape_from_num_qubits)
|
|
463
|
-
def _qid_shape_(self) ->
|
|
451
|
+
def _qid_shape_(self) -> tuple[int, ...]:
|
|
464
452
|
"""Returns a Tuple containing the number of quantum levels of each qid
|
|
465
453
|
the gate acts on. E.g. (2, 2, 2) for the three-qubit CCZ gate and
|
|
466
454
|
(3, 3) for a 2-qutrit ternary gate.
|
|
@@ -469,7 +457,7 @@ class Gate(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
469
457
|
|
|
470
458
|
def _equal_up_to_global_phase_(
|
|
471
459
|
self, other: Any, atol: float = 1e-8
|
|
472
|
-
) ->
|
|
460
|
+
) -> NotImplementedType | bool:
|
|
473
461
|
"""Default fallback for gates that do not implement this protocol."""
|
|
474
462
|
try:
|
|
475
463
|
return protocols.equal_up_to_global_phase(
|
|
@@ -481,12 +469,10 @@ class Gate(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
481
469
|
|
|
482
470
|
def _commutes_on_qids_(
|
|
483
471
|
self, qids: Sequence[cirq.Qid], other: Any, *, atol: float = 1e-8
|
|
484
|
-
) ->
|
|
472
|
+
) -> bool | NotImplementedType | None:
|
|
485
473
|
return NotImplemented
|
|
486
474
|
|
|
487
|
-
def _commutes_(
|
|
488
|
-
self, other: Any, *, atol: float = 1e-8
|
|
489
|
-
) -> Union[None, NotImplementedType, bool]:
|
|
475
|
+
def _commutes_(self, other: Any, *, atol: float = 1e-8) -> None | NotImplementedType | bool:
|
|
490
476
|
if not isinstance(other, Gate):
|
|
491
477
|
return NotImplemented
|
|
492
478
|
if protocols.qid_shape(self) != protocols.qid_shape(other):
|
|
@@ -495,15 +481,15 @@ class Gate(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
495
481
|
qs = line_qubit.LineQid.for_qid_shape(protocols.qid_shape(self))
|
|
496
482
|
return protocols.commutes(self(*qs), other(*qs))
|
|
497
483
|
|
|
498
|
-
def _mul_with_qubits(self, qubits:
|
|
484
|
+
def _mul_with_qubits(self, qubits: tuple[cirq.Qid, ...], other):
|
|
499
485
|
"""cirq.GateOperation.__mul__ delegates to this method."""
|
|
500
486
|
return NotImplemented
|
|
501
487
|
|
|
502
|
-
def _rmul_with_qubits(self, qubits:
|
|
488
|
+
def _rmul_with_qubits(self, qubits: tuple[cirq.Qid, ...], other):
|
|
503
489
|
"""cirq.GateOperation.__rmul__ delegates to this method."""
|
|
504
490
|
return NotImplemented
|
|
505
491
|
|
|
506
|
-
def _json_dict_(self) ->
|
|
492
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
507
493
|
return protocols.obj_to_dict_helper(self, attribute_names=[])
|
|
508
494
|
|
|
509
495
|
|
|
@@ -515,12 +501,12 @@ class Operation(metaclass=abc.ABCMeta):
|
|
|
515
501
|
"""
|
|
516
502
|
|
|
517
503
|
@property
|
|
518
|
-
def gate(self) ->
|
|
504
|
+
def gate(self) -> cirq.Gate | None:
|
|
519
505
|
return None
|
|
520
506
|
|
|
521
507
|
@property
|
|
522
508
|
@abc.abstractmethod
|
|
523
|
-
def qubits(self) ->
|
|
509
|
+
def qubits(self) -> tuple[cirq.Qid, ...]:
|
|
524
510
|
raise NotImplementedError()
|
|
525
511
|
|
|
526
512
|
def _num_qubits_(self) -> int:
|
|
@@ -531,7 +517,7 @@ class Operation(metaclass=abc.ABCMeta):
|
|
|
531
517
|
return len(self.qubits)
|
|
532
518
|
|
|
533
519
|
@cached_method
|
|
534
|
-
def _qid_shape_(self) ->
|
|
520
|
+
def _qid_shape_(self) -> tuple[int, ...]:
|
|
535
521
|
return protocols.qid_shape(self.qubits)
|
|
536
522
|
|
|
537
523
|
@abc.abstractmethod
|
|
@@ -545,7 +531,7 @@ class Operation(metaclass=abc.ABCMeta):
|
|
|
545
531
|
"""
|
|
546
532
|
|
|
547
533
|
@property
|
|
548
|
-
def tags(self) ->
|
|
534
|
+
def tags(self) -> tuple[Hashable, ...]:
|
|
549
535
|
"""Returns a tuple of the operation's tags."""
|
|
550
536
|
return ()
|
|
551
537
|
|
|
@@ -580,7 +566,7 @@ class Operation(metaclass=abc.ABCMeta):
|
|
|
580
566
|
return TaggedOperation(self, *new_tags)
|
|
581
567
|
|
|
582
568
|
def transform_qubits(
|
|
583
|
-
self, qubit_map:
|
|
569
|
+
self, qubit_map: dict[cirq.Qid, cirq.Qid] | Callable[[cirq.Qid], cirq.Qid]
|
|
584
570
|
) -> Self:
|
|
585
571
|
"""Returns the same operation, but with different qubits.
|
|
586
572
|
|
|
@@ -626,9 +612,7 @@ class Operation(metaclass=abc.ABCMeta):
|
|
|
626
612
|
def controlled_by(
|
|
627
613
|
self,
|
|
628
614
|
*control_qubits: cirq.Qid,
|
|
629
|
-
control_values:
|
|
630
|
-
Union[cv.AbstractControlValues, Sequence[Union[int, Collection[int]]]]
|
|
631
|
-
] = None,
|
|
615
|
+
control_values: cv.AbstractControlValues | Sequence[int | Collection[int]] | None = None,
|
|
632
616
|
) -> cirq.Operation:
|
|
633
617
|
"""Returns a controlled version of this operation. If no control_qubits
|
|
634
618
|
are specified, returns self.
|
|
@@ -685,21 +669,19 @@ class Operation(metaclass=abc.ABCMeta):
|
|
|
685
669
|
if __cirq_debug__.get():
|
|
686
670
|
_validate_qid_shape(self, qubits)
|
|
687
671
|
|
|
688
|
-
def _commutes_(
|
|
689
|
-
self, other: Any, *, atol: float = 1e-8
|
|
690
|
-
) -> Union[bool, NotImplementedType, None]:
|
|
672
|
+
def _commutes_(self, other: Any, *, atol: float = 1e-8) -> bool | NotImplementedType | None:
|
|
691
673
|
"""Determine if this Operation commutes with the object"""
|
|
692
674
|
if not isinstance(other, Operation):
|
|
693
675
|
return NotImplemented
|
|
694
676
|
return _operations_commutes_impl([self], [other], atol=atol)
|
|
695
677
|
|
|
696
678
|
@property
|
|
697
|
-
def classical_controls(self) ->
|
|
679
|
+
def classical_controls(self) -> frozenset[cirq.Condition]:
|
|
698
680
|
"""The classical controls gating this operation."""
|
|
699
681
|
return frozenset()
|
|
700
682
|
|
|
701
683
|
def with_classical_controls(
|
|
702
|
-
self, *conditions:
|
|
684
|
+
self, *conditions: str | cirq.MeasurementKey | cirq.Condition | sympy.Expr
|
|
703
685
|
) -> cirq.Operation:
|
|
704
686
|
"""Returns a classically controlled version of this operation.
|
|
705
687
|
|
|
@@ -780,11 +762,11 @@ class TaggedOperation(Operation):
|
|
|
780
762
|
return self._sub_operation
|
|
781
763
|
|
|
782
764
|
@property
|
|
783
|
-
def qubits(self) ->
|
|
765
|
+
def qubits(self) -> tuple[cirq.Qid, ...]:
|
|
784
766
|
return self.sub_operation.qubits
|
|
785
767
|
|
|
786
768
|
@property
|
|
787
|
-
def gate(self) ->
|
|
769
|
+
def gate(self) -> cirq.Gate | None:
|
|
788
770
|
return self.sub_operation.gate
|
|
789
771
|
|
|
790
772
|
def with_qubits(self, *new_qubits: cirq.Qid):
|
|
@@ -799,16 +781,14 @@ class TaggedOperation(Operation):
|
|
|
799
781
|
def controlled_by(
|
|
800
782
|
self,
|
|
801
783
|
*control_qubits: cirq.Qid,
|
|
802
|
-
control_values:
|
|
803
|
-
Union[cv.AbstractControlValues, Sequence[Union[int, Collection[int]]]]
|
|
804
|
-
] = None,
|
|
784
|
+
control_values: cv.AbstractControlValues | Sequence[int | Collection[int]] | None = None,
|
|
805
785
|
) -> cirq.Operation:
|
|
806
786
|
if len(control_qubits) == 0:
|
|
807
787
|
return self
|
|
808
788
|
return self.sub_operation.controlled_by(*control_qubits, control_values=control_values)
|
|
809
789
|
|
|
810
790
|
@property
|
|
811
|
-
def tags(self) ->
|
|
791
|
+
def tags(self) -> tuple[Hashable, ...]:
|
|
812
792
|
"""Returns a tuple of the operation's tags."""
|
|
813
793
|
return self._tags
|
|
814
794
|
|
|
@@ -845,14 +825,14 @@ class TaggedOperation(Operation):
|
|
|
845
825
|
def _from_json_dict_(cls, sub_operation, tags, **kwargs):
|
|
846
826
|
return cls(sub_operation, *tags)
|
|
847
827
|
|
|
848
|
-
def _json_dict_(self) ->
|
|
828
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
849
829
|
return protocols.obj_to_dict_helper(self, ['sub_operation', 'tags'])
|
|
850
830
|
|
|
851
831
|
def _decompose_(self) -> cirq.OP_TREE:
|
|
852
832
|
return self._decompose_with_context_()
|
|
853
833
|
|
|
854
834
|
def _decompose_with_context_(
|
|
855
|
-
self, context:
|
|
835
|
+
self, context: cirq.DecompositionContext | None = None
|
|
856
836
|
) -> cirq.OP_TREE:
|
|
857
837
|
return protocols.decompose_once(
|
|
858
838
|
self.sub_operation, default=None, flatten=False, context=context
|
|
@@ -863,41 +843,39 @@ class TaggedOperation(Operation):
|
|
|
863
843
|
|
|
864
844
|
def _apply_unitary_(
|
|
865
845
|
self, args: protocols.ApplyUnitaryArgs
|
|
866
|
-
) ->
|
|
846
|
+
) -> np.ndarray | None | NotImplementedType:
|
|
867
847
|
return protocols.apply_unitary(self.sub_operation, args, default=None)
|
|
868
848
|
|
|
869
849
|
@cached_method
|
|
870
850
|
def _has_unitary_(self) -> bool:
|
|
871
851
|
return protocols.has_unitary(self.sub_operation)
|
|
872
852
|
|
|
873
|
-
def _unitary_(self) ->
|
|
853
|
+
def _unitary_(self) -> np.ndarray | NotImplementedType:
|
|
874
854
|
return protocols.unitary(self.sub_operation, NotImplemented)
|
|
875
855
|
|
|
876
|
-
def _commutes_(
|
|
877
|
-
self, other: Any, *, atol: float = 1e-8
|
|
878
|
-
) -> Union[bool, NotImplementedType, None]:
|
|
856
|
+
def _commutes_(self, other: Any, *, atol: float = 1e-8) -> bool | NotImplementedType | None:
|
|
879
857
|
return protocols.commutes(self.sub_operation, other, atol=atol)
|
|
880
858
|
|
|
881
859
|
@cached_method
|
|
882
860
|
def _has_mixture_(self) -> bool:
|
|
883
861
|
return protocols.has_mixture(self.sub_operation)
|
|
884
862
|
|
|
885
|
-
def _mixture_(self) -> Sequence[
|
|
863
|
+
def _mixture_(self) -> Sequence[tuple[float, Any]]:
|
|
886
864
|
return protocols.mixture(self.sub_operation, NotImplemented)
|
|
887
865
|
|
|
888
866
|
@cached_method
|
|
889
867
|
def _has_kraus_(self) -> bool:
|
|
890
868
|
return protocols.has_kraus(self.sub_operation)
|
|
891
869
|
|
|
892
|
-
def _kraus_(self) ->
|
|
870
|
+
def _kraus_(self) -> tuple[np.ndarray, ...] | NotImplementedType:
|
|
893
871
|
return protocols.kraus(self.sub_operation, NotImplemented)
|
|
894
872
|
|
|
895
873
|
@cached_method
|
|
896
|
-
def _measurement_key_names_(self) ->
|
|
874
|
+
def _measurement_key_names_(self) -> frozenset[str]:
|
|
897
875
|
return protocols.measurement_key_names(self.sub_operation)
|
|
898
876
|
|
|
899
877
|
@cached_method
|
|
900
|
-
def _measurement_key_objs_(self) ->
|
|
878
|
+
def _measurement_key_objs_(self) -> frozenset[cirq.MeasurementKey]:
|
|
901
879
|
return protocols.measurement_key_objs(self.sub_operation)
|
|
902
880
|
|
|
903
881
|
@cached_method
|
|
@@ -960,16 +938,16 @@ class TaggedOperation(Operation):
|
|
|
960
938
|
def __rmul__(self, other: Any) -> Any:
|
|
961
939
|
return other * self.sub_operation
|
|
962
940
|
|
|
963
|
-
def _qasm_(self, args: protocols.QasmArgs) ->
|
|
941
|
+
def _qasm_(self, args: protocols.QasmArgs) -> str | None:
|
|
964
942
|
return protocols.qasm(self.sub_operation, args=args, default=None)
|
|
965
943
|
|
|
966
944
|
def _equal_up_to_global_phase_(
|
|
967
945
|
self, other: Any, atol: float = 1e-8
|
|
968
|
-
) ->
|
|
946
|
+
) -> NotImplementedType | bool:
|
|
969
947
|
return protocols.equal_up_to_global_phase(self.sub_operation, other, atol=atol)
|
|
970
948
|
|
|
971
949
|
@property
|
|
972
|
-
def classical_controls(self) ->
|
|
950
|
+
def classical_controls(self) -> frozenset[cirq.Condition]:
|
|
973
951
|
return self.sub_operation.classical_controls
|
|
974
952
|
|
|
975
953
|
def without_classical_controls(self) -> cirq.Operation:
|
|
@@ -977,13 +955,13 @@ class TaggedOperation(Operation):
|
|
|
977
955
|
return self if new_sub_operation is self.sub_operation else new_sub_operation
|
|
978
956
|
|
|
979
957
|
def with_classical_controls(
|
|
980
|
-
self, *conditions:
|
|
958
|
+
self, *conditions: str | cirq.MeasurementKey | cirq.Condition | sympy.Expr
|
|
981
959
|
) -> cirq.Operation:
|
|
982
960
|
if not conditions:
|
|
983
961
|
return self
|
|
984
962
|
return self.sub_operation.with_classical_controls(*conditions)
|
|
985
963
|
|
|
986
|
-
def _control_keys_(self) ->
|
|
964
|
+
def _control_keys_(self) -> frozenset[cirq.MeasurementKey]:
|
|
987
965
|
return protocols.control_keys(self.sub_operation)
|
|
988
966
|
|
|
989
967
|
|
|
@@ -1008,7 +986,7 @@ class _InverseCompositeGate(Gate):
|
|
|
1008
986
|
return self._decompose_with_context_(qubits)
|
|
1009
987
|
|
|
1010
988
|
def _decompose_with_context_(
|
|
1011
|
-
self, qubits: Sequence[cirq.Qid], context:
|
|
989
|
+
self, qubits: Sequence[cirq.Qid], context: cirq.DecompositionContext | None = None
|
|
1012
990
|
) -> cirq.OP_TREE:
|
|
1013
991
|
return protocols.inverse(
|
|
1014
992
|
protocols.decompose_once_with_qubits(self._original, qubits, context=context)
|
|
@@ -1054,7 +1032,7 @@ class _InverseCompositeGate(Gate):
|
|
|
1054
1032
|
def __str__(self) -> str:
|
|
1055
1033
|
return f'{self._original!s}†'
|
|
1056
1034
|
|
|
1057
|
-
def _json_dict_(self) ->
|
|
1035
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
1058
1036
|
return {'original': self._original}
|
|
1059
1037
|
|
|
1060
1038
|
|
|
@@ -1083,7 +1061,7 @@ def _validate_qid_shape(val: Any, qubits: Sequence[cirq.Qid]) -> None:
|
|
|
1083
1061
|
|
|
1084
1062
|
def _operations_commutes_impl(
|
|
1085
1063
|
ops1: Collection[Operation], ops2: Collection[Operation], *, atol: float
|
|
1086
|
-
) ->
|
|
1064
|
+
) -> bool | NotImplementedType:
|
|
1087
1065
|
"""Determine if two collections of non-overlapping Operations commute.
|
|
1088
1066
|
|
|
1089
1067
|
This function implements the commutes protocol for the Operation and Moment classes
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
from __future__ import annotations
|
|
18
18
|
|
|
19
|
-
from typing import Any,
|
|
19
|
+
from typing import Any, Iterable, TYPE_CHECKING
|
|
20
20
|
|
|
21
21
|
import numpy as np
|
|
22
22
|
|
|
@@ -59,7 +59,7 @@ class StatePreparationChannel(raw_types.Gate):
|
|
|
59
59
|
it involves measurement."""
|
|
60
60
|
return False
|
|
61
61
|
|
|
62
|
-
def _json_dict_(self) ->
|
|
62
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
63
63
|
"""Converts the gate object into a serializable dictionary"""
|
|
64
64
|
return {'target_state': self._state.tolist(), 'name': self._name}
|
|
65
65
|
|
|
@@ -79,7 +79,7 @@ class StatePreparationChannel(raw_types.Gate):
|
|
|
79
79
|
def _num_qubits_(self) -> int:
|
|
80
80
|
return self._num_qubits
|
|
81
81
|
|
|
82
|
-
def _qid_shape_(self) ->
|
|
82
|
+
def _qid_shape_(self) -> tuple[int, ...]:
|
|
83
83
|
return self._qid_shape
|
|
84
84
|
|
|
85
85
|
def _circuit_diagram_info_(self, _args: cirq.CircuitDiagramInfoArgs) -> cirq.CircuitDiagramInfo:
|
cirq/ops/swap_gates.py
CHANGED
|
@@ -27,7 +27,7 @@ EigenGate.
|
|
|
27
27
|
|
|
28
28
|
from __future__ import annotations
|
|
29
29
|
|
|
30
|
-
from typing import cast,
|
|
30
|
+
from typing import cast, TYPE_CHECKING
|
|
31
31
|
|
|
32
32
|
import numpy as np
|
|
33
33
|
import sympy
|
|
@@ -83,7 +83,7 @@ class SwapPowGate(gate_features.InterchangeableQubitsGate, eigen_gate.EigenGate)
|
|
|
83
83
|
)
|
|
84
84
|
yield common_gates.CNOT(a, b)
|
|
85
85
|
|
|
86
|
-
def _eigen_components(self) ->
|
|
86
|
+
def _eigen_components(self) -> list[tuple[float, np.ndarray]]:
|
|
87
87
|
# yapf: disable
|
|
88
88
|
return [
|
|
89
89
|
(0, np.array([[1, 0, 0, 0],
|
|
@@ -97,17 +97,17 @@ class SwapPowGate(gate_features.InterchangeableQubitsGate, eigen_gate.EigenGate)
|
|
|
97
97
|
]
|
|
98
98
|
# yapf: enable
|
|
99
99
|
|
|
100
|
-
def _trace_distance_bound_(self) ->
|
|
100
|
+
def _trace_distance_bound_(self) -> float | None:
|
|
101
101
|
if self._is_parameterized_():
|
|
102
102
|
return None
|
|
103
103
|
return abs(np.sin(self._exponent * 0.5 * np.pi))
|
|
104
104
|
|
|
105
|
-
def _has_stabilizer_effect_(self) ->
|
|
105
|
+
def _has_stabilizer_effect_(self) -> bool | None:
|
|
106
106
|
if self._is_parameterized_():
|
|
107
107
|
return None
|
|
108
108
|
return self.exponent % 1 == 0
|
|
109
109
|
|
|
110
|
-
def _apply_unitary_(self, args: protocols.ApplyUnitaryArgs) ->
|
|
110
|
+
def _apply_unitary_(self, args: protocols.ApplyUnitaryArgs) -> np.ndarray | None:
|
|
111
111
|
if self._exponent != 1:
|
|
112
112
|
return NotImplemented
|
|
113
113
|
|
|
@@ -145,7 +145,7 @@ class SwapPowGate(gate_features.InterchangeableQubitsGate, eigen_gate.EigenGate)
|
|
|
145
145
|
wire_symbols=('×', '×'), exponent=self._diagram_exponent(args)
|
|
146
146
|
)
|
|
147
147
|
|
|
148
|
-
def _qasm_(self, args: cirq.QasmArgs, qubits:
|
|
148
|
+
def _qasm_(self, args: cirq.QasmArgs, qubits: tuple[cirq.Qid, ...]) -> str | None:
|
|
149
149
|
if self._exponent != 1:
|
|
150
150
|
return None # Don't have an equivalent gate in QASM
|
|
151
151
|
args.validate_version('2.0', '3.0')
|
|
@@ -204,7 +204,7 @@ class ISwapPowGate(gate_features.InterchangeableQubitsGate, eigen_gate.EigenGate
|
|
|
204
204
|
def _num_qubits_(self) -> int:
|
|
205
205
|
return 2
|
|
206
206
|
|
|
207
|
-
def _eigen_components(self) ->
|
|
207
|
+
def _eigen_components(self) -> list[tuple[float, np.ndarray]]:
|
|
208
208
|
# yapf: disable
|
|
209
209
|
return [
|
|
210
210
|
(0, np.diag([1, 0, 0, 1])),
|
|
@@ -219,7 +219,7 @@ class ISwapPowGate(gate_features.InterchangeableQubitsGate, eigen_gate.EigenGate
|
|
|
219
219
|
]
|
|
220
220
|
# yapf: enable
|
|
221
221
|
|
|
222
|
-
def _has_stabilizer_effect_(self) ->
|
|
222
|
+
def _has_stabilizer_effect_(self) -> bool | None:
|
|
223
223
|
if self._is_parameterized_():
|
|
224
224
|
return None
|
|
225
225
|
return self.exponent % 1 == 0
|
|
@@ -240,7 +240,7 @@ class ISwapPowGate(gate_features.InterchangeableQubitsGate, eigen_gate.EigenGate
|
|
|
240
240
|
yield common_gates.H(a)
|
|
241
241
|
yield common_gates.CNOT(a, b)
|
|
242
242
|
|
|
243
|
-
def _apply_unitary_(self, args: protocols.ApplyUnitaryArgs) ->
|
|
243
|
+
def _apply_unitary_(self, args: protocols.ApplyUnitaryArgs) -> np.ndarray | None:
|
|
244
244
|
if self._exponent != 1:
|
|
245
245
|
return NotImplemented
|
|
246
246
|
|
cirq/ops/tags.py
CHANGED
|
@@ -16,8 +16,6 @@
|
|
|
16
16
|
|
|
17
17
|
from __future__ import annotations
|
|
18
18
|
|
|
19
|
-
from typing import Dict
|
|
20
|
-
|
|
21
19
|
|
|
22
20
|
class VirtualTag:
|
|
23
21
|
"""A `cirq.TaggedOperation` tag indicating that the operation is virtual.
|
|
@@ -42,7 +40,7 @@ class VirtualTag:
|
|
|
42
40
|
def __repr__(self) -> str:
|
|
43
41
|
return 'cirq.VirtualTag()'
|
|
44
42
|
|
|
45
|
-
def _json_dict_(self) ->
|
|
43
|
+
def _json_dict_(self) -> dict[str, str]:
|
|
46
44
|
return {}
|
|
47
45
|
|
|
48
46
|
def __hash__(self):
|
|
@@ -65,7 +63,7 @@ class RoutingSwapTag:
|
|
|
65
63
|
def __repr__(self) -> str:
|
|
66
64
|
return 'cirq.RoutingSwapTag()'
|
|
67
65
|
|
|
68
|
-
def _json_dict_(self) ->
|
|
66
|
+
def _json_dict_(self) -> dict[str, str]:
|
|
69
67
|
return {}
|
|
70
68
|
|
|
71
69
|
def __hash__(self):
|