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/qis/states.py
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
from __future__ import annotations
|
|
18
18
|
|
|
19
19
|
import itertools
|
|
20
|
-
from typing import Any, cast, Iterable,
|
|
20
|
+
from typing import Any, cast, Iterable, Sequence, TYPE_CHECKING, Union
|
|
21
21
|
|
|
22
22
|
import numpy as np
|
|
23
23
|
|
|
@@ -64,9 +64,9 @@ class QuantumState:
|
|
|
64
64
|
def __init__(
|
|
65
65
|
self,
|
|
66
66
|
data: np.ndarray,
|
|
67
|
-
qid_shape:
|
|
67
|
+
qid_shape: tuple[int, ...] | None = None,
|
|
68
68
|
*, # Force keyword arguments
|
|
69
|
-
dtype:
|
|
69
|
+
dtype: DTypeLike | None = None,
|
|
70
70
|
validate: bool = True,
|
|
71
71
|
atol: float = 1e-7,
|
|
72
72
|
) -> None:
|
|
@@ -99,7 +99,7 @@ class QuantumState:
|
|
|
99
99
|
return self._data
|
|
100
100
|
|
|
101
101
|
@property
|
|
102
|
-
def qid_shape(self) ->
|
|
102
|
+
def qid_shape(self) -> tuple[int, ...]:
|
|
103
103
|
"""The qid shape of the quantum state."""
|
|
104
104
|
return self._qid_shape
|
|
105
105
|
|
|
@@ -108,7 +108,7 @@ class QuantumState:
|
|
|
108
108
|
"""The data type of the quantum state."""
|
|
109
109
|
return self._data.dtype
|
|
110
110
|
|
|
111
|
-
def state_vector(self) ->
|
|
111
|
+
def state_vector(self) -> np.ndarray | None:
|
|
112
112
|
"""Return the state vector of this state.
|
|
113
113
|
|
|
114
114
|
A state vector stores the amplitudes of a pure state as a
|
|
@@ -119,7 +119,7 @@ class QuantumState:
|
|
|
119
119
|
return None
|
|
120
120
|
return np.reshape(self.data, (self._dim,))
|
|
121
121
|
|
|
122
|
-
def state_tensor(self) ->
|
|
122
|
+
def state_tensor(self) -> np.ndarray | None:
|
|
123
123
|
"""Return the state tensor of this state.
|
|
124
124
|
|
|
125
125
|
A state tensor stores the amplitudes of a pure state as an array with
|
|
@@ -158,7 +158,7 @@ class QuantumState:
|
|
|
158
158
|
return self.data.shape == (self._dim, self._dim)
|
|
159
159
|
|
|
160
160
|
def validate(
|
|
161
|
-
self, *, dtype:
|
|
161
|
+
self, *, dtype: DTypeLike | None = None, atol=1e-7 # Force keyword arguments
|
|
162
162
|
) -> None:
|
|
163
163
|
"""Check if this quantum state is valid.
|
|
164
164
|
|
|
@@ -191,11 +191,11 @@ class QuantumState:
|
|
|
191
191
|
|
|
192
192
|
def quantum_state(
|
|
193
193
|
state: cirq.QUANTUM_STATE_LIKE,
|
|
194
|
-
qid_shape:
|
|
194
|
+
qid_shape: tuple[int, ...] | None = None,
|
|
195
195
|
*, # Force keyword arguments
|
|
196
196
|
copy: bool = False,
|
|
197
197
|
validate: bool = True,
|
|
198
|
-
dtype:
|
|
198
|
+
dtype: DTypeLike | None = None,
|
|
199
199
|
atol: float = 1e-7,
|
|
200
200
|
) -> QuantumState:
|
|
201
201
|
"""Create a QuantumState object from a state-like object.
|
|
@@ -295,11 +295,11 @@ def quantum_state(
|
|
|
295
295
|
|
|
296
296
|
def density_matrix(
|
|
297
297
|
state: np.ndarray,
|
|
298
|
-
qid_shape:
|
|
298
|
+
qid_shape: tuple[int, ...] | None = None,
|
|
299
299
|
*, # Force keyword arguments
|
|
300
300
|
copy: bool = False,
|
|
301
301
|
validate: bool = True,
|
|
302
|
-
dtype:
|
|
302
|
+
dtype: DTypeLike | None = None,
|
|
303
303
|
atol: float = 1e-7,
|
|
304
304
|
) -> QuantumState:
|
|
305
305
|
"""Create a QuantumState object from a density matrix.
|
|
@@ -330,7 +330,7 @@ def density_matrix(
|
|
|
330
330
|
)
|
|
331
331
|
|
|
332
332
|
|
|
333
|
-
def _infer_qid_shape_from_dimension(dim: int) ->
|
|
333
|
+
def _infer_qid_shape_from_dimension(dim: int) -> tuple[int, ...]:
|
|
334
334
|
if dim != 0 and dim & dim - 1 == 0:
|
|
335
335
|
# dim is a power of 2, assume qubits
|
|
336
336
|
n_qubits = dim.bit_length() - 1
|
|
@@ -352,7 +352,7 @@ _NON_INT_STATE_LIKE = Union[
|
|
|
352
352
|
]
|
|
353
353
|
|
|
354
354
|
|
|
355
|
-
def infer_qid_shape(*states: cirq.QUANTUM_STATE_LIKE) ->
|
|
355
|
+
def infer_qid_shape(*states: cirq.QUANTUM_STATE_LIKE) -> tuple[int, ...]:
|
|
356
356
|
"""Infer the qid shape of a set of states.
|
|
357
357
|
|
|
358
358
|
This is a heuristic to determine a qid shape compatible with all of the
|
|
@@ -377,8 +377,8 @@ def infer_qid_shape(*states: cirq.QUANTUM_STATE_LIKE) -> Tuple[int, ...]:
|
|
|
377
377
|
if not states:
|
|
378
378
|
raise ValueError('No states were specified.')
|
|
379
379
|
|
|
380
|
-
integer_states:
|
|
381
|
-
non_integer_states:
|
|
380
|
+
integer_states: list[int] = []
|
|
381
|
+
non_integer_states: list[_NON_INT_STATE_LIKE] = []
|
|
382
382
|
for state in states:
|
|
383
383
|
if isinstance(state, int):
|
|
384
384
|
integer_states.append(state)
|
|
@@ -448,9 +448,9 @@ class _QidShapeSet:
|
|
|
448
448
|
def __init__(
|
|
449
449
|
self,
|
|
450
450
|
*,
|
|
451
|
-
explicit_qid_shapes:
|
|
452
|
-
unfactorized_total_dimension:
|
|
453
|
-
min_qudit_dimensions:
|
|
451
|
+
explicit_qid_shapes: set[tuple[int, ...]] | None = None,
|
|
452
|
+
unfactorized_total_dimension: int | None = None,
|
|
453
|
+
min_qudit_dimensions: tuple[int, ...] | None = None,
|
|
454
454
|
) -> None:
|
|
455
455
|
"""Create a qid shape set.
|
|
456
456
|
|
|
@@ -539,7 +539,7 @@ class _QidShapeSet:
|
|
|
539
539
|
f'a Hilbert space dimension of {self.unfactorized_total_dimension}.'
|
|
540
540
|
)
|
|
541
541
|
|
|
542
|
-
def infer_qid_shape(self) ->
|
|
542
|
+
def infer_qid_shape(self) -> tuple[int, ...] | None:
|
|
543
543
|
"""Return a qid shape from this set, or None."""
|
|
544
544
|
self._raise_value_error_if_ambiguous()
|
|
545
545
|
if self.unfactorized_total_dimension is not None:
|
|
@@ -550,8 +550,8 @@ class _QidShapeSet:
|
|
|
550
550
|
|
|
551
551
|
|
|
552
552
|
def _intersection_explicit_with_unfactorized_qid_shapes(
|
|
553
|
-
explicit_qid_shapes:
|
|
554
|
-
) ->
|
|
553
|
+
explicit_qid_shapes: set[tuple[int, ...]], unfactorized_total_dimension: int
|
|
554
|
+
) -> set[tuple[int, ...]]:
|
|
555
555
|
return {
|
|
556
556
|
qid_shape
|
|
557
557
|
for qid_shape in explicit_qid_shapes
|
|
@@ -560,8 +560,8 @@ def _intersection_explicit_with_unfactorized_qid_shapes(
|
|
|
560
560
|
|
|
561
561
|
|
|
562
562
|
def _intersection_explicit_with_min_qudit_dims_qid_shapes(
|
|
563
|
-
explicit_qid_shapes:
|
|
564
|
-
) ->
|
|
563
|
+
explicit_qid_shapes: set[tuple[int, ...]], min_qudit_dimensions: tuple[int, ...]
|
|
564
|
+
) -> set[tuple[int, ...]]:
|
|
565
565
|
return {
|
|
566
566
|
qid_shape
|
|
567
567
|
for qid_shape in explicit_qid_shapes
|
|
@@ -571,8 +571,8 @@ def _intersection_explicit_with_min_qudit_dims_qid_shapes(
|
|
|
571
571
|
|
|
572
572
|
|
|
573
573
|
def _intersection_min_qudit_dims_qid_shapes(
|
|
574
|
-
min_qudit_dimensions1:
|
|
575
|
-
) ->
|
|
574
|
+
min_qudit_dimensions1: tuple[int, ...], min_qudit_dimensions2: tuple[int, ...]
|
|
575
|
+
) -> tuple[int, ...] | None:
|
|
576
576
|
if len(min_qudit_dimensions1) == len(min_qudit_dimensions2):
|
|
577
577
|
return tuple(
|
|
578
578
|
max(dim1, dim2) for dim1, dim2 in zip(min_qudit_dimensions1, min_qudit_dimensions2)
|
|
@@ -581,7 +581,7 @@ def _intersection_min_qudit_dims_qid_shapes(
|
|
|
581
581
|
|
|
582
582
|
|
|
583
583
|
def bloch_vector_from_state_vector(
|
|
584
|
-
state_vector: np.ndarray, index: int, qid_shape:
|
|
584
|
+
state_vector: np.ndarray, index: int, qid_shape: tuple[int, ...] | None = None
|
|
585
585
|
) -> np.ndarray:
|
|
586
586
|
"""Returns the bloch vector of a qubit.
|
|
587
587
|
|
|
@@ -621,8 +621,8 @@ def bloch_vector_from_state_vector(
|
|
|
621
621
|
|
|
622
622
|
def density_matrix_from_state_vector(
|
|
623
623
|
state_vector: np.ndarray,
|
|
624
|
-
indices:
|
|
625
|
-
qid_shape:
|
|
624
|
+
indices: Iterable[int] | None = None,
|
|
625
|
+
qid_shape: tuple[int, ...] | None = None,
|
|
626
626
|
) -> np.ndarray:
|
|
627
627
|
r"""Returns the density matrix of the state vector.
|
|
628
628
|
|
|
@@ -684,8 +684,8 @@ def density_matrix_from_state_vector(
|
|
|
684
684
|
state_vector,
|
|
685
685
|
list(range(n_qubits)),
|
|
686
686
|
np.conj(state_vector),
|
|
687
|
-
cast(
|
|
688
|
-
indices + cast(
|
|
687
|
+
cast(list, sum_inds.tolist()),
|
|
688
|
+
indices + cast(list, sum_inds[indices].tolist()),
|
|
689
689
|
)
|
|
690
690
|
new_shape = np.prod([shape[i] for i in indices], dtype=np.int64)
|
|
691
691
|
|
|
@@ -693,7 +693,7 @@ def density_matrix_from_state_vector(
|
|
|
693
693
|
|
|
694
694
|
|
|
695
695
|
def dirac_notation(
|
|
696
|
-
state_vector: np.ndarray, decimals: int = 2, qid_shape:
|
|
696
|
+
state_vector: np.ndarray, decimals: int = 2, qid_shape: tuple[int, ...] | None = None
|
|
697
697
|
) -> str:
|
|
698
698
|
"""Returns the state vector as a string in Dirac notation.
|
|
699
699
|
|
|
@@ -764,10 +764,10 @@ def dirac_notation(
|
|
|
764
764
|
|
|
765
765
|
def to_valid_state_vector(
|
|
766
766
|
state_rep: cirq.STATE_VECTOR_LIKE,
|
|
767
|
-
num_qubits:
|
|
767
|
+
num_qubits: int | None = None,
|
|
768
768
|
*, # Force keyword arguments
|
|
769
|
-
qid_shape:
|
|
770
|
-
dtype:
|
|
769
|
+
qid_shape: Sequence[int] | None = None,
|
|
770
|
+
dtype: DTypeLike | None = None,
|
|
771
771
|
atol: float = 1e-7,
|
|
772
772
|
) -> np.ndarray:
|
|
773
773
|
"""Verifies the state_rep is valid and converts it to ndarray form.
|
|
@@ -832,7 +832,7 @@ def to_valid_state_vector(
|
|
|
832
832
|
|
|
833
833
|
|
|
834
834
|
def _qudit_values_to_state_tensor(
|
|
835
|
-
*, state_vector: np.ndarray, qid_shape:
|
|
835
|
+
*, state_vector: np.ndarray, qid_shape: tuple[int, ...], dtype: DTypeLike | None
|
|
836
836
|
) -> np.ndarray:
|
|
837
837
|
for i in range(len(qid_shape)):
|
|
838
838
|
s = state_vector[i]
|
|
@@ -864,8 +864,8 @@ def _qudit_values_to_state_tensor(
|
|
|
864
864
|
def validate_normalized_state_vector(
|
|
865
865
|
state_vector: np.ndarray,
|
|
866
866
|
*, # Force keyword arguments
|
|
867
|
-
qid_shape:
|
|
868
|
-
dtype:
|
|
867
|
+
qid_shape: tuple[int, ...],
|
|
868
|
+
dtype: DTypeLike | None = None,
|
|
869
869
|
atol: float = 1e-7,
|
|
870
870
|
) -> None:
|
|
871
871
|
"""Checks that the given state vector is valid.
|
|
@@ -896,8 +896,8 @@ def validate_normalized_state_vector(
|
|
|
896
896
|
|
|
897
897
|
|
|
898
898
|
def validate_qid_shape(
|
|
899
|
-
state_vector: np.ndarray, qid_shape:
|
|
900
|
-
) ->
|
|
899
|
+
state_vector: np.ndarray, qid_shape: tuple[int, ...] | None
|
|
900
|
+
) -> tuple[int, ...]:
|
|
901
901
|
"""Validates the size of the given `state_vector` against the given shape.
|
|
902
902
|
|
|
903
903
|
Returns:
|
|
@@ -930,11 +930,11 @@ def validate_indices(num_qubits: int, indices: Sequence[int]) -> None:
|
|
|
930
930
|
|
|
931
931
|
|
|
932
932
|
def to_valid_density_matrix(
|
|
933
|
-
density_matrix_rep:
|
|
934
|
-
num_qubits:
|
|
933
|
+
density_matrix_rep: np.ndarray | cirq.STATE_VECTOR_LIKE,
|
|
934
|
+
num_qubits: int | None = None,
|
|
935
935
|
*, # Force keyword arguments
|
|
936
|
-
qid_shape:
|
|
937
|
-
dtype:
|
|
936
|
+
qid_shape: tuple[int, ...] | None = None,
|
|
937
|
+
dtype: DTypeLike | None = None,
|
|
938
938
|
atol: float = 1e-7,
|
|
939
939
|
) -> np.ndarray:
|
|
940
940
|
"""Verifies the density_matrix_rep is valid and converts it to ndarray form.
|
|
@@ -982,8 +982,8 @@ def to_valid_density_matrix(
|
|
|
982
982
|
def validate_density_matrix(
|
|
983
983
|
density_matrix: np.ndarray,
|
|
984
984
|
*, # Force keyword arguments
|
|
985
|
-
qid_shape:
|
|
986
|
-
dtype:
|
|
985
|
+
qid_shape: tuple[int, ...],
|
|
986
|
+
dtype: DTypeLike | None = None,
|
|
987
987
|
atol: float = 1e-7,
|
|
988
988
|
) -> None:
|
|
989
989
|
"""Checks that the given density matrix is valid.
|
|
@@ -1023,8 +1023,8 @@ def validate_density_matrix(
|
|
|
1023
1023
|
|
|
1024
1024
|
|
|
1025
1025
|
def _qid_shape_from_args(
|
|
1026
|
-
num_qubits:
|
|
1027
|
-
) ->
|
|
1026
|
+
num_qubits: int | None, qid_shape: tuple[int, ...] | None
|
|
1027
|
+
) -> tuple[int, ...]:
|
|
1028
1028
|
"""Returns either `(2,) * num_qubits` or `qid_shape`.
|
|
1029
1029
|
|
|
1030
1030
|
Raises:
|
|
@@ -1035,7 +1035,7 @@ def _qid_shape_from_args(
|
|
|
1035
1035
|
'Either the num_qubits or qid_shape argument must be specified. Both were None.'
|
|
1036
1036
|
)
|
|
1037
1037
|
if num_qubits is None:
|
|
1038
|
-
return cast(
|
|
1038
|
+
return cast(tuple[int, ...], qid_shape)
|
|
1039
1039
|
if qid_shape is None:
|
|
1040
1040
|
return (2,) * num_qubits
|
|
1041
1041
|
if len(qid_shape) != num_qubits:
|
|
@@ -1048,8 +1048,8 @@ def _qid_shape_from_args(
|
|
|
1048
1048
|
|
|
1049
1049
|
def one_hot(
|
|
1050
1050
|
*,
|
|
1051
|
-
index:
|
|
1052
|
-
shape:
|
|
1051
|
+
index: None | int | Sequence[int] = None,
|
|
1052
|
+
shape: int | Sequence[int],
|
|
1053
1053
|
value: Any = 1,
|
|
1054
1054
|
dtype: DTypeLike,
|
|
1055
1055
|
) -> np.ndarray:
|
|
@@ -1072,7 +1072,7 @@ def one_hot(
|
|
|
1072
1072
|
return result
|
|
1073
1073
|
|
|
1074
1074
|
|
|
1075
|
-
def eye_tensor(half_shape:
|
|
1075
|
+
def eye_tensor(half_shape: tuple[int, ...], *, dtype: DTypeLike) -> np.ndarray:
|
|
1076
1076
|
"""Returns an identity matrix reshaped into a tensor.
|
|
1077
1077
|
|
|
1078
1078
|
Args:
|
cirq/sim/classical_simulator.py
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
17
|
from copy import copy, deepcopy
|
|
18
|
-
from typing import Any,
|
|
18
|
+
from typing import Any, Generic, Sequence, TYPE_CHECKING
|
|
19
19
|
|
|
20
20
|
import numpy as np
|
|
21
21
|
|
|
@@ -38,7 +38,7 @@ def _is_identity(action) -> bool:
|
|
|
38
38
|
class ClassicalBasisState(qis.QuantumStateRepresentation):
|
|
39
39
|
"""Represents a classical basis state for efficient state evolution."""
|
|
40
40
|
|
|
41
|
-
def __init__(self, initial_state:
|
|
41
|
+
def __init__(self, initial_state: list[int] | np.ndarray):
|
|
42
42
|
"""Initializes the ClassicalBasisState object.
|
|
43
43
|
|
|
44
44
|
Args:
|
|
@@ -60,7 +60,7 @@ class ClassicalBasisState(qis.QuantumStateRepresentation):
|
|
|
60
60
|
|
|
61
61
|
def measure(
|
|
62
62
|
self, axes: Sequence[int], seed: cirq.RANDOM_STATE_OR_SEED_LIKE = None
|
|
63
|
-
) ->
|
|
63
|
+
) -> list[int]:
|
|
64
64
|
"""Measures the density matrix.
|
|
65
65
|
|
|
66
66
|
Args:
|
|
@@ -77,9 +77,9 @@ class ClassicalBasisSimState(SimulationState[ClassicalBasisState]):
|
|
|
77
77
|
|
|
78
78
|
def __init__(
|
|
79
79
|
self,
|
|
80
|
-
initial_state:
|
|
81
|
-
qubits:
|
|
82
|
-
classical_data:
|
|
80
|
+
initial_state: int | list[int] = 0,
|
|
81
|
+
qubits: Sequence[cirq.Qid] | None = None,
|
|
82
|
+
classical_data: cirq.ClassicalDataStore | None = None,
|
|
83
83
|
):
|
|
84
84
|
"""Initializes the ClassicalBasisSimState object.
|
|
85
85
|
|
|
@@ -90,20 +90,20 @@ class ClassicalBasisSimState(SimulationState[ClassicalBasisState]):
|
|
|
90
90
|
|
|
91
91
|
Raises:
|
|
92
92
|
ValueError: If qubits not provided and initial_state is int.
|
|
93
|
-
If initial_state is not an int,
|
|
93
|
+
If initial_state is not an int, list[int], or np.ndarray.
|
|
94
94
|
|
|
95
95
|
An initial_state value of type integer is parsed in big endian order.
|
|
96
96
|
"""
|
|
97
97
|
if isinstance(initial_state, int):
|
|
98
98
|
if qubits is None:
|
|
99
|
-
raise ValueError('qubits must be provided if initial_state is not
|
|
99
|
+
raise ValueError('qubits must be provided if initial_state is not list[int]')
|
|
100
100
|
state = ClassicalBasisState(
|
|
101
101
|
big_endian_int_to_bits(initial_state, bit_count=len(qubits))
|
|
102
102
|
)
|
|
103
103
|
elif isinstance(initial_state, (list, np.ndarray)):
|
|
104
104
|
state = ClassicalBasisState(initial_state)
|
|
105
105
|
else:
|
|
106
|
-
raise ValueError('initial_state must be an int or
|
|
106
|
+
raise ValueError('initial_state must be an int or list[int] or np.ndarray')
|
|
107
107
|
super().__init__(state=state, qubits=qubits, classical_data=classical_data)
|
|
108
108
|
|
|
109
109
|
def _act_on_fallback_(self, action, qubits: Sequence[cirq.Qid], allow_decompose: bool = True):
|
|
@@ -201,7 +201,7 @@ class ClassicalStateSimulator(
|
|
|
201
201
|
def _create_simulator_trial_result(
|
|
202
202
|
self,
|
|
203
203
|
params: cirq.ParamResolver,
|
|
204
|
-
measurements:
|
|
204
|
+
measurements: dict[str, np.ndarray],
|
|
205
205
|
final_simulator_state: cirq.SimulationStateBase[ClassicalBasisSimState],
|
|
206
206
|
) -> ClassicalStateTrialResult[ClassicalBasisSimState]:
|
|
207
207
|
"""Creates a trial result for the simulator.
|
|
@@ -32,7 +32,7 @@ The quantum state is specified in two forms:
|
|
|
32
32
|
|
|
33
33
|
from __future__ import annotations
|
|
34
34
|
|
|
35
|
-
from typing import Any,
|
|
35
|
+
from typing import Any, Sequence
|
|
36
36
|
|
|
37
37
|
import numpy as np
|
|
38
38
|
|
|
@@ -72,7 +72,7 @@ class CliffordSimulator(
|
|
|
72
72
|
|
|
73
73
|
def _create_partial_simulation_state(
|
|
74
74
|
self,
|
|
75
|
-
initial_state:
|
|
75
|
+
initial_state: int | cirq.StabilizerChFormSimulationState,
|
|
76
76
|
qubits: Sequence[cirq.Qid],
|
|
77
77
|
classical_data: cirq.ClassicalDataStore,
|
|
78
78
|
) -> cirq.StabilizerChFormSimulationState:
|
|
@@ -110,7 +110,7 @@ class CliffordSimulator(
|
|
|
110
110
|
def _create_simulator_trial_result(
|
|
111
111
|
self,
|
|
112
112
|
params: cirq.ParamResolver,
|
|
113
|
-
measurements:
|
|
113
|
+
measurements: dict[str, np.ndarray],
|
|
114
114
|
final_simulator_state: cirq.SimulationStateBase[cirq.StabilizerChFormSimulationState],
|
|
115
115
|
):
|
|
116
116
|
return CliffordTrialResult(
|
|
@@ -124,7 +124,7 @@ class CliffordTrialResult(
|
|
|
124
124
|
def __init__(
|
|
125
125
|
self,
|
|
126
126
|
params: cirq.ParamResolver,
|
|
127
|
-
measurements:
|
|
127
|
+
measurements: dict[str, np.ndarray],
|
|
128
128
|
final_simulator_state: cirq.SimulationStateBase[cirq.StabilizerChFormSimulationState],
|
|
129
129
|
) -> None:
|
|
130
130
|
super().__init__(
|
|
@@ -201,7 +201,7 @@ class CliffordState:
|
|
|
201
201
|
Gates and measurements are applied to each representation in O(n^2) time.
|
|
202
202
|
"""
|
|
203
203
|
|
|
204
|
-
def __init__(self, qubit_map, initial_state:
|
|
204
|
+
def __init__(self, qubit_map, initial_state: int | cirq.StabilizerStateChForm = 0):
|
|
205
205
|
self.qubit_map = qubit_map
|
|
206
206
|
self.n = len(qubit_map)
|
|
207
207
|
|
|
@@ -256,7 +256,7 @@ class CliffordState:
|
|
|
256
256
|
def apply_measurement(
|
|
257
257
|
self,
|
|
258
258
|
op: cirq.Operation,
|
|
259
|
-
measurements:
|
|
259
|
+
measurements: dict[str, list[int]],
|
|
260
260
|
prng: np.random.RandomState,
|
|
261
261
|
collapse_state_vector=True,
|
|
262
262
|
):
|
|
@@ -14,8 +14,6 @@
|
|
|
14
14
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
|
-
from typing import Tuple
|
|
18
|
-
|
|
19
17
|
import numpy as np
|
|
20
18
|
import pytest
|
|
21
19
|
|
|
@@ -28,7 +26,7 @@ def test_unitary_fallback() -> None:
|
|
|
28
26
|
return np.array([[0, 1], [1, 0]])
|
|
29
27
|
|
|
30
28
|
class UnitaryYGate(cirq.Gate):
|
|
31
|
-
def _qid_shape_(self) ->
|
|
29
|
+
def _qid_shape_(self) -> tuple[int, ...]:
|
|
32
30
|
return (2,)
|
|
33
31
|
|
|
34
32
|
def _unitary_(self):
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
|
-
from typing import
|
|
17
|
+
from typing import Sequence
|
|
18
18
|
|
|
19
19
|
import numpy as np
|
|
20
20
|
|
|
@@ -40,16 +40,16 @@ class StabilizerSampler(sampler.Sampler):
|
|
|
40
40
|
def run_sweep(
|
|
41
41
|
self, program: cirq.AbstractCircuit, params: cirq.Sweepable, repetitions: int = 1
|
|
42
42
|
) -> Sequence[cirq.Result]:
|
|
43
|
-
results:
|
|
43
|
+
results: list[cirq.Result] = []
|
|
44
44
|
for param_resolver in cirq.to_resolvers(params):
|
|
45
45
|
resolved_circuit = cirq.resolve_parameters(program, param_resolver)
|
|
46
46
|
measurements = self._run(resolved_circuit, repetitions=repetitions)
|
|
47
47
|
results.append(cirq.ResultDict(params=param_resolver, measurements=measurements))
|
|
48
48
|
return results
|
|
49
49
|
|
|
50
|
-
def _run(self, circuit: cirq.AbstractCircuit, repetitions: int) ->
|
|
50
|
+
def _run(self, circuit: cirq.AbstractCircuit, repetitions: int) -> dict[str, np.ndarray]:
|
|
51
51
|
|
|
52
|
-
measurements:
|
|
52
|
+
measurements: dict[str, list[np.ndarray]] = {
|
|
53
53
|
key: [] for key in protocols.measurement_key_names(circuit)
|
|
54
54
|
}
|
|
55
55
|
qubits = circuit.all_qubits()
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
|
-
from typing import Any,
|
|
17
|
+
from typing import Any, Sequence
|
|
18
18
|
|
|
19
19
|
import numpy as np
|
|
20
20
|
|
|
@@ -63,7 +63,7 @@ class StabilizerStateChForm(qis.StabilizerState):
|
|
|
63
63
|
if val:
|
|
64
64
|
self.apply_x(i)
|
|
65
65
|
|
|
66
|
-
def _json_dict_(self) ->
|
|
66
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
67
67
|
return protocols.obj_to_dict_helper(self, ['n', 'G', 'F', 'M', 'gamma', 'v', 's', 'omega'])
|
|
68
68
|
|
|
69
69
|
@classmethod
|
|
@@ -390,7 +390,7 @@ class StabilizerStateChForm(qis.StabilizerState):
|
|
|
390
390
|
|
|
391
391
|
def measure(
|
|
392
392
|
self, axes: Sequence[int], seed: cirq.RANDOM_STATE_OR_SEED_LIKE = None
|
|
393
|
-
) ->
|
|
393
|
+
) -> list[int]:
|
|
394
394
|
return [self._measure(axis, random_state.parse_random_state(seed)) for axis in axes]
|
|
395
395
|
|
|
396
396
|
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
from __future__ import annotations
|
|
18
18
|
|
|
19
|
-
from typing import Any, Callable,
|
|
19
|
+
from typing import Any, Callable, Sequence, TYPE_CHECKING
|
|
20
20
|
|
|
21
21
|
import numpy as np
|
|
22
22
|
|
|
@@ -32,7 +32,7 @@ if TYPE_CHECKING:
|
|
|
32
32
|
class _BufferedDensityMatrix(qis.QuantumStateRepresentation):
|
|
33
33
|
"""Contains the density matrix and buffers for efficient state evolution."""
|
|
34
34
|
|
|
35
|
-
def __init__(self, density_matrix: np.ndarray, buffer:
|
|
35
|
+
def __init__(self, density_matrix: np.ndarray, buffer: list[np.ndarray] | None = None):
|
|
36
36
|
"""Initializes the object with the inputs.
|
|
37
37
|
|
|
38
38
|
This initializer creates the buffer if necessary.
|
|
@@ -57,10 +57,10 @@ class _BufferedDensityMatrix(qis.QuantumStateRepresentation):
|
|
|
57
57
|
def create(
|
|
58
58
|
cls,
|
|
59
59
|
*,
|
|
60
|
-
initial_state:
|
|
61
|
-
qid_shape:
|
|
62
|
-
dtype:
|
|
63
|
-
buffer:
|
|
60
|
+
initial_state: np.ndarray | cirq.STATE_VECTOR_LIKE = 0,
|
|
61
|
+
qid_shape: tuple[int, ...] | None = None,
|
|
62
|
+
dtype: type[np.complexfloating] | None = None,
|
|
63
|
+
buffer: list[np.ndarray] | None = None,
|
|
64
64
|
):
|
|
65
65
|
"""Creates a buffered density matrix with the requested state.
|
|
66
66
|
|
|
@@ -121,7 +121,7 @@ class _BufferedDensityMatrix(qis.QuantumStateRepresentation):
|
|
|
121
121
|
|
|
122
122
|
def factor(
|
|
123
123
|
self, axes: Sequence[int], *, validate=True, atol=1e-07
|
|
124
|
-
) ->
|
|
124
|
+
) -> tuple[_BufferedDensityMatrix, _BufferedDensityMatrix]:
|
|
125
125
|
"""Factors out the desired axes.
|
|
126
126
|
|
|
127
127
|
Args:
|
|
@@ -188,7 +188,7 @@ class _BufferedDensityMatrix(qis.QuantumStateRepresentation):
|
|
|
188
188
|
|
|
189
189
|
def measure(
|
|
190
190
|
self, axes: Sequence[int], seed: cirq.RANDOM_STATE_OR_SEED_LIKE = None
|
|
191
|
-
) ->
|
|
191
|
+
) -> list[int]:
|
|
192
192
|
"""Measures the density matrix.
|
|
193
193
|
|
|
194
194
|
Args:
|
|
@@ -245,12 +245,12 @@ class DensityMatrixSimulationState(SimulationState[_BufferedDensityMatrix]):
|
|
|
245
245
|
def __init__(
|
|
246
246
|
self,
|
|
247
247
|
*,
|
|
248
|
-
available_buffer:
|
|
249
|
-
prng:
|
|
250
|
-
qubits:
|
|
251
|
-
initial_state:
|
|
252
|
-
dtype:
|
|
253
|
-
classical_data:
|
|
248
|
+
available_buffer: list[np.ndarray] | None = None,
|
|
249
|
+
prng: np.random.RandomState | None = None,
|
|
250
|
+
qubits: Sequence[cirq.Qid] | None = None,
|
|
251
|
+
initial_state: np.ndarray | cirq.STATE_VECTOR_LIKE = 0,
|
|
252
|
+
dtype: type[np.complexfloating] = np.complex64,
|
|
253
|
+
classical_data: cirq.ClassicalDataStore | None = None,
|
|
254
254
|
):
|
|
255
255
|
"""Inits DensityMatrixSimulationState.
|
|
256
256
|
|
|
@@ -303,7 +303,7 @@ class DensityMatrixSimulationState(SimulationState[_BufferedDensityMatrix]):
|
|
|
303
303
|
def _act_on_fallback_(
|
|
304
304
|
self, action: Any, qubits: Sequence[cirq.Qid], allow_decompose: bool = True
|
|
305
305
|
) -> bool:
|
|
306
|
-
strats:
|
|
306
|
+
strats: list[Callable[[Any, Any, Sequence[cirq.Qid]], bool]] = [
|
|
307
307
|
_strat_apply_channel_to_state
|
|
308
308
|
]
|
|
309
309
|
if allow_decompose:
|