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
|
@@ -20,19 +20,7 @@ import itertools
|
|
|
20
20
|
import os
|
|
21
21
|
import tempfile
|
|
22
22
|
import warnings
|
|
23
|
-
from typing import
|
|
24
|
-
Any,
|
|
25
|
-
Dict,
|
|
26
|
-
Iterable,
|
|
27
|
-
List,
|
|
28
|
-
Mapping,
|
|
29
|
-
Optional,
|
|
30
|
-
Sequence,
|
|
31
|
-
Set,
|
|
32
|
-
Tuple,
|
|
33
|
-
TYPE_CHECKING,
|
|
34
|
-
Union,
|
|
35
|
-
)
|
|
23
|
+
from typing import Any, Iterable, Mapping, Sequence, TYPE_CHECKING
|
|
36
24
|
|
|
37
25
|
import numpy as np
|
|
38
26
|
import pandas as pd
|
|
@@ -150,7 +138,7 @@ class RepetitionsStoppingCriteria(StoppingCriteria):
|
|
|
150
138
|
return protocols.dataclass_json_dict(self)
|
|
151
139
|
|
|
152
140
|
|
|
153
|
-
_OBS_TO_PARAM_VAL:
|
|
141
|
+
_OBS_TO_PARAM_VAL: dict[tuple[cirq.Pauli, bool], tuple[float, float]] = {
|
|
154
142
|
(ops.X, False): (0, -1 / 2),
|
|
155
143
|
(ops.X, True): (0, +1 / 2),
|
|
156
144
|
(ops.Y, False): (1 / 2, 0),
|
|
@@ -162,7 +150,7 @@ _OBS_TO_PARAM_VAL: Dict[Tuple[cirq.Pauli, bool], Tuple[float, float]] = {
|
|
|
162
150
|
second element in the key is whether to measure in the positive or negative (flipped) basis
|
|
163
151
|
for readout symmetrization."""
|
|
164
152
|
|
|
165
|
-
_STATE_TO_PARAM_VAL:
|
|
153
|
+
_STATE_TO_PARAM_VAL: dict[_NamedOneQubitState, tuple[float, float]] = {
|
|
166
154
|
value.KET_PLUS: (0, +1 / 2),
|
|
167
155
|
value.KET_MINUS: (0, -1 / 2),
|
|
168
156
|
value.KET_IMAG: (-1 / 2, 0),
|
|
@@ -178,7 +166,7 @@ def _get_params_for_setting(
|
|
|
178
166
|
flips: Iterable[bool],
|
|
179
167
|
qubits: Sequence[cirq.Qid],
|
|
180
168
|
needs_init_layer: bool,
|
|
181
|
-
) ->
|
|
169
|
+
) -> dict[str, float]:
|
|
182
170
|
"""Return the parameter dictionary for the given setting.
|
|
183
171
|
|
|
184
172
|
This must be used in conjunction with a circuit generated by
|
|
@@ -241,7 +229,7 @@ def _pad_setting(
|
|
|
241
229
|
return InitObsSetting(init_state=init_state, observable=obs)
|
|
242
230
|
|
|
243
231
|
|
|
244
|
-
def _aggregate_n_repetitions(next_chunk_repetitions:
|
|
232
|
+
def _aggregate_n_repetitions(next_chunk_repetitions: set[int]) -> int:
|
|
245
233
|
"""A stopping criteria can request a different number of more_repetitions for each
|
|
246
234
|
measurement spec. For batching efficiency, we take the max and issue a warning in this case."""
|
|
247
235
|
if len(next_chunk_repetitions) == 1:
|
|
@@ -257,10 +245,10 @@ def _aggregate_n_repetitions(next_chunk_repetitions: Set[int]) -> int:
|
|
|
257
245
|
|
|
258
246
|
|
|
259
247
|
def _check_meas_specs_still_todo(
|
|
260
|
-
meas_specs:
|
|
248
|
+
meas_specs: list[_MeasurementSpec],
|
|
261
249
|
accumulators: Mapping[_MeasurementSpec, BitstringAccumulator],
|
|
262
250
|
stopping_criteria: StoppingCriteria,
|
|
263
|
-
) ->
|
|
251
|
+
) -> tuple[list[_MeasurementSpec], int]:
|
|
264
252
|
"""Filter `meas_specs` in case some are done.
|
|
265
253
|
|
|
266
254
|
In the sampling loop in `measure_grouped_settings`, we submit
|
|
@@ -268,7 +256,7 @@ def _check_meas_specs_still_todo(
|
|
|
268
256
|
removing `meas_spec`s from the loop if they are done.
|
|
269
257
|
"""
|
|
270
258
|
still_todo = []
|
|
271
|
-
repetitions_set:
|
|
259
|
+
repetitions_set: set[int] = set()
|
|
272
260
|
for meas_spec in meas_specs:
|
|
273
261
|
accumulator = accumulators[meas_spec]
|
|
274
262
|
more_repetitions = stopping_criteria.more_repetitions(accumulator)
|
|
@@ -334,7 +322,7 @@ def _subdivide_meas_specs(
|
|
|
334
322
|
repetitions: int,
|
|
335
323
|
qubits: Sequence[cirq.Qid],
|
|
336
324
|
readout_symmetrization: bool,
|
|
337
|
-
) ->
|
|
325
|
+
) -> tuple[list[_FlippyMeasSpec], int]:
|
|
338
326
|
"""Split measurement specs into sub-jobs for readout symmetrization
|
|
339
327
|
|
|
340
328
|
In readout symmetrization, we first run the "normal" circuit followed
|
|
@@ -368,8 +356,8 @@ def _to_sweep(param_tuples):
|
|
|
368
356
|
|
|
369
357
|
|
|
370
358
|
def _parse_checkpoint_options(
|
|
371
|
-
checkpoint: bool, checkpoint_fn:
|
|
372
|
-
) ->
|
|
359
|
+
checkpoint: bool, checkpoint_fn: str | None, checkpoint_other_fn: str | None
|
|
360
|
+
) -> tuple[str | None, str | None]:
|
|
373
361
|
"""Parse the checkpoint-oriented options in `measure_grouped_settings`.
|
|
374
362
|
|
|
375
363
|
This function contains the validation and defaults logic. Please see
|
|
@@ -447,8 +435,8 @@ class CheckpointFileOptions:
|
|
|
447
435
|
"""
|
|
448
436
|
|
|
449
437
|
checkpoint: bool = False
|
|
450
|
-
checkpoint_fn:
|
|
451
|
-
checkpoint_other_fn:
|
|
438
|
+
checkpoint_fn: str | None = None
|
|
439
|
+
checkpoint_other_fn: str | None = None
|
|
452
440
|
|
|
453
441
|
def __post_init__(self):
|
|
454
442
|
fn, other_fn = _parse_checkpoint_options(
|
|
@@ -472,7 +460,7 @@ class CheckpointFileOptions:
|
|
|
472
460
|
protocols.to_json(obj, self.checkpoint_fn)
|
|
473
461
|
|
|
474
462
|
|
|
475
|
-
def _needs_init_layer(grouped_settings:
|
|
463
|
+
def _needs_init_layer(grouped_settings: dict[InitObsSetting, list[InitObsSetting]]) -> bool:
|
|
476
464
|
"""Helper function to go through init_states and determine if any of them need an
|
|
477
465
|
initialization layer of single-qubit gates."""
|
|
478
466
|
for max_setting in grouped_settings.keys():
|
|
@@ -483,15 +471,15 @@ def _needs_init_layer(grouped_settings: Dict[InitObsSetting, List[InitObsSetting
|
|
|
483
471
|
|
|
484
472
|
def measure_grouped_settings(
|
|
485
473
|
circuit: cirq.AbstractCircuit,
|
|
486
|
-
grouped_settings:
|
|
474
|
+
grouped_settings: dict[InitObsSetting, list[InitObsSetting]],
|
|
487
475
|
sampler: cirq.Sampler,
|
|
488
476
|
stopping_criteria: StoppingCriteria,
|
|
489
477
|
*,
|
|
490
478
|
readout_symmetrization: bool = False,
|
|
491
479
|
circuit_sweep: cirq.Sweepable = None,
|
|
492
|
-
readout_calibrations:
|
|
480
|
+
readout_calibrations: BitstringAccumulator | None = None,
|
|
493
481
|
checkpoint: CheckpointFileOptions = CheckpointFileOptions(),
|
|
494
|
-
) ->
|
|
482
|
+
) -> list[BitstringAccumulator]:
|
|
495
483
|
"""Measure a suite of grouped InitObsSetting settings.
|
|
496
484
|
|
|
497
485
|
This is a low-level API for accessing the observable measurement
|
|
@@ -596,10 +584,10 @@ def measure_grouped_settings(
|
|
|
596
584
|
return list(accumulators.values())
|
|
597
585
|
|
|
598
586
|
|
|
599
|
-
_GROUPING_FUNCS:
|
|
587
|
+
_GROUPING_FUNCS: dict[str, GROUPER_T] = {'greedy': group_settings_greedy}
|
|
600
588
|
|
|
601
589
|
|
|
602
|
-
def _parse_grouper(grouper:
|
|
590
|
+
def _parse_grouper(grouper: str | GROUPER_T = group_settings_greedy) -> GROUPER_T:
|
|
603
591
|
"""Logic for turning a named grouper into one of the build-in groupers in support of the
|
|
604
592
|
high-level `measure_observables` API."""
|
|
605
593
|
if isinstance(grouper, str):
|
|
@@ -612,7 +600,7 @@ def _parse_grouper(grouper: Union[str, GROUPER_T] = group_settings_greedy) -> GR
|
|
|
612
600
|
|
|
613
601
|
def _get_all_qubits(
|
|
614
602
|
circuit: cirq.AbstractCircuit, observables: Iterable[cirq.PauliString]
|
|
615
|
-
) ->
|
|
603
|
+
) -> list[cirq.Qid]:
|
|
616
604
|
"""Helper function for `measure_observables` to get all qubits from a circuit and a
|
|
617
605
|
collection of observables."""
|
|
618
606
|
qubit_set = set()
|
|
@@ -625,15 +613,15 @@ def _get_all_qubits(
|
|
|
625
613
|
def measure_observables(
|
|
626
614
|
circuit: cirq.AbstractCircuit,
|
|
627
615
|
observables: Iterable[cirq.PauliString],
|
|
628
|
-
sampler:
|
|
616
|
+
sampler: cirq.Simulator | cirq.Sampler,
|
|
629
617
|
stopping_criteria: StoppingCriteria,
|
|
630
618
|
*,
|
|
631
619
|
readout_symmetrization: bool = False,
|
|
632
|
-
circuit_sweep:
|
|
633
|
-
grouper:
|
|
634
|
-
readout_calibrations:
|
|
620
|
+
circuit_sweep: cirq.Sweepable | None = None,
|
|
621
|
+
grouper: str | GROUPER_T = group_settings_greedy,
|
|
622
|
+
readout_calibrations: BitstringAccumulator | None = None,
|
|
635
623
|
checkpoint: CheckpointFileOptions = CheckpointFileOptions(),
|
|
636
|
-
) ->
|
|
624
|
+
) -> list[ObservableMeasuredResult]:
|
|
637
625
|
"""Measure a collection of PauliString observables for a state prepared by a Circuit.
|
|
638
626
|
|
|
639
627
|
If you need more control over the process, please see `measure_grouped_settings` for a
|
|
@@ -687,13 +675,13 @@ def measure_observables(
|
|
|
687
675
|
def measure_observables_df(
|
|
688
676
|
circuit: cirq.AbstractCircuit,
|
|
689
677
|
observables: Iterable[cirq.PauliString],
|
|
690
|
-
sampler:
|
|
678
|
+
sampler: cirq.Simulator | cirq.Sampler,
|
|
691
679
|
stopping_criteria: StoppingCriteria,
|
|
692
680
|
*,
|
|
693
681
|
readout_symmetrization: bool = False,
|
|
694
|
-
circuit_sweep:
|
|
695
|
-
grouper:
|
|
696
|
-
readout_calibrations:
|
|
682
|
+
circuit_sweep: cirq.Sweepable | None = None,
|
|
683
|
+
grouper: str | GROUPER_T = group_settings_greedy,
|
|
684
|
+
readout_calibrations: BitstringAccumulator | None = None,
|
|
697
685
|
checkpoint: CheckpointFileOptions = CheckpointFileOptions(),
|
|
698
686
|
):
|
|
699
687
|
"""Measure observables and return resulting data as a Pandas dataframe.
|
|
@@ -16,7 +16,7 @@ from __future__ import annotations
|
|
|
16
16
|
|
|
17
17
|
import dataclasses
|
|
18
18
|
import datetime
|
|
19
|
-
from typing import Any,
|
|
19
|
+
from typing import Any, Iterable, Mapping, TYPE_CHECKING
|
|
20
20
|
|
|
21
21
|
import numpy as np
|
|
22
22
|
import sympy
|
|
@@ -66,7 +66,7 @@ def _stats_from_measurements(
|
|
|
66
66
|
qubit_to_index: Mapping[cirq.Qid, int],
|
|
67
67
|
observable: cirq.PauliString,
|
|
68
68
|
atol: float,
|
|
69
|
-
) ->
|
|
69
|
+
) -> tuple[float, float]:
|
|
70
70
|
"""Return the mean and squared standard error of the mean for the given
|
|
71
71
|
observable according to the measurements in `bitstrings`."""
|
|
72
72
|
obs_vals = _obs_vals_from_measurements(bitstrings, qubit_to_index, observable, atol=atol)
|
|
@@ -109,7 +109,7 @@ class ObservableMeasuredResult:
|
|
|
109
109
|
mean: float
|
|
110
110
|
variance: float
|
|
111
111
|
repetitions: int
|
|
112
|
-
circuit_params: Mapping[
|
|
112
|
+
circuit_params: Mapping[str | sympy.Expr, value.Scalar | sympy.Expr]
|
|
113
113
|
|
|
114
114
|
# unhashable because of the mapping-type circuit_params attribute
|
|
115
115
|
__hash__ = None # type: ignore
|
|
@@ -138,7 +138,7 @@ class ObservableMeasuredResult:
|
|
|
138
138
|
def stddev(self):
|
|
139
139
|
return np.sqrt(self.variance)
|
|
140
140
|
|
|
141
|
-
def as_dict(self) ->
|
|
141
|
+
def as_dict(self) -> dict[str, Any]:
|
|
142
142
|
"""Return the contents of this class as a dictionary.
|
|
143
143
|
|
|
144
144
|
This makes records suitable for construction of a Pandas dataframe. The circuit parameters
|
|
@@ -215,32 +215,32 @@ class BitstringAccumulator:
|
|
|
215
215
|
def __init__(
|
|
216
216
|
self,
|
|
217
217
|
meas_spec: _MeasurementSpec,
|
|
218
|
-
simul_settings:
|
|
218
|
+
simul_settings: list[InitObsSetting],
|
|
219
219
|
qubit_to_index: Mapping[cirq.Qid, int],
|
|
220
|
-
bitstrings:
|
|
221
|
-
chunksizes:
|
|
222
|
-
timestamps:
|
|
223
|
-
readout_calibration:
|
|
220
|
+
bitstrings: np.ndarray | None = None,
|
|
221
|
+
chunksizes: np.ndarray | None = None,
|
|
222
|
+
timestamps: np.ndarray | None = None,
|
|
223
|
+
readout_calibration: BitstringAccumulator | None = None,
|
|
224
224
|
):
|
|
225
225
|
self._meas_spec = meas_spec
|
|
226
226
|
self._simul_settings = simul_settings
|
|
227
227
|
self._qubit_to_index = qubit_to_index
|
|
228
228
|
self._readout_calibration = readout_calibration
|
|
229
229
|
|
|
230
|
-
self.bitstrings: np.ndarray[
|
|
230
|
+
self.bitstrings: np.ndarray[tuple[int, ...], np.dtype[np.uint8]]
|
|
231
231
|
if bitstrings is None:
|
|
232
232
|
n_bits = len(qubit_to_index)
|
|
233
233
|
self.bitstrings = np.zeros((0, n_bits), dtype=np.uint8)
|
|
234
234
|
else:
|
|
235
235
|
self.bitstrings = np.asarray(bitstrings, dtype=np.uint8)
|
|
236
236
|
|
|
237
|
-
self.chunksizes: np.ndarray[
|
|
237
|
+
self.chunksizes: np.ndarray[tuple[int, ...], np.dtype[np.int64]]
|
|
238
238
|
if chunksizes is None:
|
|
239
239
|
self.chunksizes = np.zeros((0,), dtype=np.int64)
|
|
240
240
|
else:
|
|
241
241
|
self.chunksizes = np.asarray(chunksizes, dtype=np.int64)
|
|
242
242
|
|
|
243
|
-
self.timestamps: np.ndarray[
|
|
243
|
+
self.timestamps: np.ndarray[tuple[int, ...], np.dtype[np.datetime64]]
|
|
244
244
|
if timestamps is None:
|
|
245
245
|
self.timestamps = np.zeros((0,), dtype='datetime64[us]')
|
|
246
246
|
else:
|
|
@@ -528,8 +528,8 @@ class BitstringAccumulator:
|
|
|
528
528
|
|
|
529
529
|
|
|
530
530
|
def flatten_grouped_results(
|
|
531
|
-
grouped_results:
|
|
532
|
-
) ->
|
|
531
|
+
grouped_results: list[BitstringAccumulator],
|
|
532
|
+
) -> list[ObservableMeasuredResult]:
|
|
533
533
|
"""Flatten a collection of BitstringAccumulators into a list of ObservableMeasuredResult.
|
|
534
534
|
|
|
535
535
|
Raw results are contained in BitstringAccumulator which contains
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
17
|
import tempfile
|
|
18
|
-
from typing import
|
|
18
|
+
from typing import Iterable
|
|
19
19
|
|
|
20
20
|
import numpy as np
|
|
21
21
|
import pytest
|
|
@@ -529,7 +529,7 @@ def test_XYZ_point8(circuit, observable) -> None:
|
|
|
529
529
|
|
|
530
530
|
def _each_in_its_own_group_grouper(
|
|
531
531
|
settings: Iterable[InitObsSetting],
|
|
532
|
-
) ->
|
|
532
|
+
) -> dict[InitObsSetting, list[InitObsSetting]]:
|
|
533
533
|
return {setting: [setting] for setting in settings}
|
|
534
534
|
|
|
535
535
|
|
cirq/work/observable_settings.py
CHANGED
|
@@ -16,7 +16,7 @@ from __future__ import annotations
|
|
|
16
16
|
|
|
17
17
|
import dataclasses
|
|
18
18
|
import numbers
|
|
19
|
-
from typing import
|
|
19
|
+
from typing import Iterable, Mapping, TYPE_CHECKING
|
|
20
20
|
|
|
21
21
|
import sympy
|
|
22
22
|
|
|
@@ -64,7 +64,7 @@ class InitObsSetting:
|
|
|
64
64
|
return protocols.dataclass_json_dict(self)
|
|
65
65
|
|
|
66
66
|
|
|
67
|
-
def _max_weight_observable(observables: Iterable[ops.PauliString]) ->
|
|
67
|
+
def _max_weight_observable(observables: Iterable[ops.PauliString]) -> ops.PauliString | None:
|
|
68
68
|
"""Create a new observable that is compatible with all input observables
|
|
69
69
|
and has the maximum non-identity elements.
|
|
70
70
|
|
|
@@ -80,7 +80,7 @@ def _max_weight_observable(observables: Iterable[ops.PauliString]) -> Optional[o
|
|
|
80
80
|
The returned value need not actually be present in the input observables.
|
|
81
81
|
Coefficients from input observables will be dropped.
|
|
82
82
|
"""
|
|
83
|
-
qubit_pauli_map:
|
|
83
|
+
qubit_pauli_map: dict[ops.Qid, ops.Pauli] = {}
|
|
84
84
|
for observable in observables:
|
|
85
85
|
for qubit, pauli in observable.items():
|
|
86
86
|
if qubit in qubit_pauli_map:
|
|
@@ -91,7 +91,7 @@ def _max_weight_observable(observables: Iterable[ops.PauliString]) -> Optional[o
|
|
|
91
91
|
return ops.PauliString(qubit_pauli_map)
|
|
92
92
|
|
|
93
93
|
|
|
94
|
-
def _max_weight_state(states: Iterable[value.ProductState]) ->
|
|
94
|
+
def _max_weight_state(states: Iterable[value.ProductState]) -> value.ProductState | None:
|
|
95
95
|
"""Create a new state that is compatible with all input states
|
|
96
96
|
and has the maximum weight.
|
|
97
97
|
|
|
@@ -104,7 +104,7 @@ def _max_weight_state(states: Iterable[value.ProductState]) -> Optional[value.Pr
|
|
|
104
104
|
"+X(0) * -Z(1)". Asking for the max weight state of something like
|
|
105
105
|
[+X(0), +Z(0)] will return None.
|
|
106
106
|
"""
|
|
107
|
-
qubit_state_map:
|
|
107
|
+
qubit_state_map: dict[ops.Qid, _NamedOneQubitState] = {}
|
|
108
108
|
for state in states:
|
|
109
109
|
for qubit, named_state in state:
|
|
110
110
|
if qubit in qubit_state_map:
|
|
@@ -130,7 +130,7 @@ def observables_to_settings(
|
|
|
130
130
|
yield InitObsSetting(init_state=zeros_state(qubits), observable=observable)
|
|
131
131
|
|
|
132
132
|
|
|
133
|
-
def _fix_precision(val:
|
|
133
|
+
def _fix_precision(val: value.Scalar | sympy.Expr, precision) -> int | tuple[int, int]:
|
|
134
134
|
"""Convert floating point or complex numbers to (implicitly) fixed point
|
|
135
135
|
integers. Complex numbers will return fixed-point (real, imag) tuples.
|
|
136
136
|
|
|
@@ -146,9 +146,8 @@ def _fix_precision(val: Union[value.Scalar, sympy.Expr], precision) -> Union[int
|
|
|
146
146
|
|
|
147
147
|
|
|
148
148
|
def _hashable_param(
|
|
149
|
-
param_tuples: Iterable[
|
|
150
|
-
|
|
151
|
-
) -> FrozenSet[Tuple[str, Union[int, Tuple[int, int]]]]:
|
|
149
|
+
param_tuples: Iterable[tuple[str | sympy.Expr, value.Scalar | sympy.Expr]], precision=1e7
|
|
150
|
+
) -> frozenset[tuple[str, int | tuple[int, int]]]:
|
|
152
151
|
"""Hash circuit parameters using fixed precision.
|
|
153
152
|
|
|
154
153
|
Circuit parameters can be complex but we also need to use them as
|
|
@@ -170,7 +169,7 @@ class _MeasurementSpec:
|
|
|
170
169
|
"""
|
|
171
170
|
|
|
172
171
|
max_setting: InitObsSetting
|
|
173
|
-
circuit_params: Mapping[
|
|
172
|
+
circuit_params: Mapping[str | sympy.Expr, value.Scalar | sympy.Expr]
|
|
174
173
|
|
|
175
174
|
def __hash__(self):
|
|
176
175
|
return hash((self.max_setting, _hashable_param(self.circuit_params.items())))
|
cirq/work/pauli_sum_collector.py
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
17
|
import collections
|
|
18
|
-
from typing import cast,
|
|
18
|
+
from typing import cast, TYPE_CHECKING
|
|
19
19
|
|
|
20
20
|
import numpy as np
|
|
21
21
|
|
|
@@ -60,12 +60,12 @@ class PauliSumCollector(collector.Collector):
|
|
|
60
60
|
if not p:
|
|
61
61
|
self._identity_offset += p.coefficient
|
|
62
62
|
|
|
63
|
-
self._zeros:
|
|
64
|
-
self._ones:
|
|
63
|
+
self._zeros: dict[ops.PauliString, int] = collections.defaultdict(lambda: 0)
|
|
64
|
+
self._ones: dict[ops.PauliString, int] = collections.defaultdict(lambda: 0)
|
|
65
65
|
self._samples_per_term = samples_per_term
|
|
66
66
|
self._total_samples_requested = 0
|
|
67
67
|
|
|
68
|
-
def next_job(self) ->
|
|
68
|
+
def next_job(self) -> cirq.CircuitSampleJob | None:
|
|
69
69
|
i = self._total_samples_requested // self._samples_per_term
|
|
70
70
|
if i >= len(self._pauli_coef_terms):
|
|
71
71
|
return None
|
|
@@ -85,7 +85,7 @@ class PauliSumCollector(collector.Collector):
|
|
|
85
85
|
self._zeros[job_id] += parities[0]
|
|
86
86
|
self._ones[job_id] += parities[1]
|
|
87
87
|
|
|
88
|
-
def estimated_energy(self) ->
|
|
88
|
+
def estimated_energy(self) -> float | complex:
|
|
89
89
|
"""Sums up the sampled expectations, weighted by their coefficients."""
|
|
90
90
|
energy = 0j
|
|
91
91
|
for pauli_string, coef in self._pauli_coef_terms:
|
cirq/work/sampler.py
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
from __future__ import annotations
|
|
18
18
|
|
|
19
19
|
import collections
|
|
20
|
-
from typing import
|
|
20
|
+
from typing import Sequence, TYPE_CHECKING, TypeVar
|
|
21
21
|
|
|
22
22
|
import duet
|
|
23
23
|
import pandas as pd
|
|
@@ -237,8 +237,8 @@ class Sampler(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
237
237
|
async def run_batch_async(
|
|
238
238
|
self,
|
|
239
239
|
programs: Sequence[cirq.AbstractCircuit],
|
|
240
|
-
params_list:
|
|
241
|
-
repetitions:
|
|
240
|
+
params_list: Sequence[cirq.Sweepable] | None = None,
|
|
241
|
+
repetitions: int | Sequence[int] = 1,
|
|
242
242
|
) -> Sequence[Sequence[cirq.Result]]:
|
|
243
243
|
"""Runs the supplied circuits asynchronously.
|
|
244
244
|
|
|
@@ -288,9 +288,9 @@ class Sampler(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
288
288
|
def _normalize_batch_args(
|
|
289
289
|
self,
|
|
290
290
|
programs: Sequence[cirq.AbstractCircuit],
|
|
291
|
-
params_list:
|
|
292
|
-
repetitions:
|
|
293
|
-
) ->
|
|
291
|
+
params_list: Sequence[cirq.Sweepable] | None = None,
|
|
292
|
+
repetitions: int | Sequence[int] = 1,
|
|
293
|
+
) -> tuple[Sequence[cirq.Sweepable], Sequence[int]]:
|
|
294
294
|
if params_list is None:
|
|
295
295
|
params_list = [None] * len(programs)
|
|
296
296
|
if len(programs) != len(params_list):
|
|
@@ -310,7 +310,7 @@ class Sampler(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
310
310
|
def sample_expectation_values(
|
|
311
311
|
self,
|
|
312
312
|
program: cirq.AbstractCircuit,
|
|
313
|
-
observables:
|
|
313
|
+
observables: cirq.PauliSumLike | list[cirq.PauliSumLike],
|
|
314
314
|
*,
|
|
315
315
|
num_samples: int,
|
|
316
316
|
params: cirq.Sweepable = None,
|
|
@@ -359,17 +359,17 @@ class Sampler(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
359
359
|
)
|
|
360
360
|
|
|
361
361
|
# Wrap input into a list of pauli sum
|
|
362
|
-
pauli_sums:
|
|
362
|
+
pauli_sums: list[cirq.PauliSum] = (
|
|
363
363
|
[ops.PauliSum.wrap(o) for o in observables]
|
|
364
|
-
if isinstance(observables,
|
|
364
|
+
if isinstance(observables, list)
|
|
365
365
|
else [ops.PauliSum.wrap(observables)]
|
|
366
366
|
)
|
|
367
367
|
del observables
|
|
368
368
|
|
|
369
369
|
# Flatten Pauli Sum into one big list of Pauli String
|
|
370
370
|
# Keep track of which Pauli Sum each one was from.
|
|
371
|
-
flat_pstrings:
|
|
372
|
-
pstring_to_psum_i:
|
|
371
|
+
flat_pstrings: list[cirq.PauliString] = []
|
|
372
|
+
pstring_to_psum_i: dict[cirq.PauliString, int] = {}
|
|
373
373
|
for psum_i, pauli_sum in enumerate(pauli_sums):
|
|
374
374
|
for pstring in pauli_sum:
|
|
375
375
|
flat_pstrings.append(pstring)
|
|
@@ -377,10 +377,10 @@ class Sampler(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
377
377
|
|
|
378
378
|
# Flatten Circuit Sweep into one big list of Params.
|
|
379
379
|
# Keep track of their indices so we can map back.
|
|
380
|
-
flat_params:
|
|
380
|
+
flat_params: list[cirq.ParamMappingType] = [
|
|
381
381
|
pr.param_dict for pr in study.to_resolvers(params)
|
|
382
382
|
]
|
|
383
|
-
circuit_param_to_sweep_i:
|
|
383
|
+
circuit_param_to_sweep_i: dict[frozenset[tuple[str, int | tuple[int, int]]], int] = {
|
|
384
384
|
_hashable_param(param.items()): i for i, param in enumerate(flat_params)
|
|
385
385
|
}
|
|
386
386
|
|
|
@@ -398,7 +398,7 @@ class Sampler(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
398
398
|
# nesting structure, we place the measured values according to the back-mappings we set up
|
|
399
399
|
# above. We also do the sum operation to aggregate multiple PauliString measured values
|
|
400
400
|
# for a given PauliSum.
|
|
401
|
-
nested_results:
|
|
401
|
+
nested_results: list[list[float]] = [[0] * len(pauli_sums) for _ in range(len(flat_params))]
|
|
402
402
|
for res in obs_meas_results:
|
|
403
403
|
param_i = circuit_param_to_sweep_i[_hashable_param(res.circuit_params.items())]
|
|
404
404
|
psum_i = pstring_to_psum_i[res.setting.observable]
|
|
@@ -409,7 +409,7 @@ class Sampler(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
409
409
|
@staticmethod
|
|
410
410
|
def _get_measurement_shapes(
|
|
411
411
|
circuit: cirq.AbstractCircuit,
|
|
412
|
-
) ->
|
|
412
|
+
) -> dict[str, tuple[int, tuple[int, ...]]]:
|
|
413
413
|
"""Gets the shapes of measurements in the given circuit.
|
|
414
414
|
|
|
415
415
|
Returns:
|
|
@@ -422,8 +422,8 @@ class Sampler(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
422
422
|
ValueError: if the qid_shape of different instances of the same measurement
|
|
423
423
|
key disagree.
|
|
424
424
|
"""
|
|
425
|
-
qid_shapes:
|
|
426
|
-
num_instances:
|
|
425
|
+
qid_shapes: dict[str, tuple[int, ...]] = {}
|
|
426
|
+
num_instances: dict[str, int] = collections.Counter()
|
|
427
427
|
for op in circuit.all_operations():
|
|
428
428
|
key = protocols.measurement_key_name(op, default=None)
|
|
429
429
|
if key is not None:
|
cirq/work/zeros_sampler.py
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
17
|
import abc
|
|
18
|
-
from typing import
|
|
18
|
+
from typing import TYPE_CHECKING
|
|
19
19
|
|
|
20
20
|
import numpy as np
|
|
21
21
|
|
|
@@ -28,7 +28,7 @@ if TYPE_CHECKING:
|
|
|
28
28
|
class ZerosSampler(work.Sampler, metaclass=abc.ABCMeta):
|
|
29
29
|
"""A mock sampler for testing. Immediately returns zeroes."""
|
|
30
30
|
|
|
31
|
-
def __init__(self, device:
|
|
31
|
+
def __init__(self, device: devices.Device | None = None):
|
|
32
32
|
"""Construct a sampler that returns 0 for all measurements.
|
|
33
33
|
|
|
34
34
|
Args:
|
|
@@ -39,7 +39,7 @@ class ZerosSampler(work.Sampler, metaclass=abc.ABCMeta):
|
|
|
39
39
|
|
|
40
40
|
def run_sweep(
|
|
41
41
|
self, program: cirq.AbstractCircuit, params: study.Sweepable, repetitions: int = 1
|
|
42
|
-
) ->
|
|
42
|
+
) -> list[study.Result]:
|
|
43
43
|
"""Samples circuit as if every measurement resulted in zero.
|
|
44
44
|
|
|
45
45
|
Args:
|
{cirq_core-1.6.0.dev20250520054601.dist-info → cirq_core-1.6.0.dev20250520181654.dist-info}/METADATA
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cirq-core
|
|
3
|
-
Version: 1.6.0.
|
|
3
|
+
Version: 1.6.0.dev20250520181654
|
|
4
4
|
Summary: A framework for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits.
|
|
5
5
|
Home-page: http://github.com/quantumlib/cirq
|
|
6
6
|
Author: The Cirq Developers
|