cirq-core 1.6.0.dev20250520054601__py3-none-any.whl → 1.6.0.dev20250520183459__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of cirq-core might be problematic. Click here for more details.
- cirq/_compat.py +15 -17
- cirq/_compat_test.py +6 -9
- cirq/_doc.py +2 -2
- cirq/_import.py +6 -6
- cirq/_version.py +1 -1
- cirq/_version_test.py +1 -1
- cirq/circuits/_block_diagram_drawer.py +9 -10
- cirq/circuits/_box_drawing_character_data.py +6 -8
- cirq/circuits/_bucket_priority_queue.py +7 -7
- cirq/circuits/circuit.py +118 -125
- cirq/circuits/circuit_operation.py +38 -52
- cirq/circuits/circuit_test.py +4 -4
- cirq/circuits/frozen_circuit.py +13 -23
- cirq/circuits/moment.py +23 -29
- cirq/circuits/optimization_pass.py +4 -4
- cirq/circuits/optimization_pass_test.py +4 -6
- cirq/circuits/qasm_output.py +11 -11
- cirq/circuits/text_diagram_drawer.py +21 -36
- cirq/contrib/acquaintance/bipartite.py +5 -8
- cirq/contrib/acquaintance/executor.py +5 -5
- cirq/contrib/acquaintance/executor_test.py +3 -3
- cirq/contrib/acquaintance/gates.py +16 -26
- cirq/contrib/acquaintance/gates_test.py +3 -3
- cirq/contrib/acquaintance/mutation_utils.py +4 -4
- cirq/contrib/acquaintance/optimizers.py +4 -4
- cirq/contrib/acquaintance/permutation.py +15 -27
- cirq/contrib/acquaintance/shift.py +3 -3
- cirq/contrib/acquaintance/shift_swap_network.py +4 -4
- cirq/contrib/acquaintance/strategies/cubic.py +2 -2
- cirq/contrib/acquaintance/strategies/quartic_paired.py +6 -6
- cirq/contrib/bayesian_network/bayesian_network_gate.py +9 -10
- cirq/contrib/circuitdag/circuit_dag.py +2 -2
- cirq/contrib/custom_simulators/custom_state_simulator.py +3 -3
- cirq/contrib/custom_simulators/custom_state_simulator_test.py +4 -4
- cirq/contrib/graph_device/graph_device.py +5 -5
- cirq/contrib/graph_device/hypergraph.py +12 -12
- cirq/contrib/graph_device/uniform_graph_device.py +4 -4
- cirq/contrib/paulistring/clifford_optimize.py +2 -2
- cirq/contrib/paulistring/clifford_target_gateset.py +7 -7
- cirq/contrib/paulistring/pauli_string_measurement_with_readout_mitigation.py +31 -31
- cirq/contrib/paulistring/pauli_string_measurement_with_readout_mitigation_test.py +23 -23
- cirq/contrib/paulistring/recombine.py +3 -3
- cirq/contrib/paulistring/separate.py +2 -2
- cirq/contrib/qasm_import/_parser.py +20 -32
- cirq/contrib/qcircuit/qcircuit_diagram_info.py +3 -5
- cirq/contrib/quantum_volume/quantum_volume.py +24 -24
- cirq/contrib/quimb/density_matrix.py +12 -14
- cirq/contrib/quimb/mps_simulator.py +20 -20
- cirq/contrib/quimb/state_vector.py +6 -10
- cirq/contrib/quirk/export_to_quirk.py +3 -3
- cirq/contrib/quirk/quirk_gate.py +15 -15
- cirq/contrib/routing/device.py +3 -3
- cirq/contrib/routing/greedy.py +10 -21
- cirq/contrib/routing/initialization.py +2 -2
- cirq/contrib/routing/swap_network.py +3 -3
- cirq/contrib/routing/utils.py +2 -2
- cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking.py +8 -8
- cirq/contrib/svg/svg.py +3 -3
- cirq/devices/grid_device_metadata.py +10 -10
- cirq/devices/grid_qubit.py +20 -20
- cirq/devices/insertion_noise_model.py +5 -5
- cirq/devices/line_qubit.py +13 -13
- cirq/devices/named_topologies.py +18 -29
- cirq/devices/noise_model.py +3 -3
- cirq/devices/noise_properties.py +2 -2
- cirq/devices/noise_properties_test.py +1 -3
- cirq/devices/noise_utils.py +7 -7
- cirq/devices/superconducting_qubits_noise_properties.py +21 -21
- cirq/devices/superconducting_qubits_noise_properties_test.py +5 -7
- cirq/devices/thermal_noise_model.py +14 -14
- cirq/devices/unconstrained_device.py +2 -2
- cirq/experiments/benchmarking/parallel_xeb.py +29 -31
- cirq/experiments/n_qubit_tomography.py +5 -7
- cirq/experiments/qubit_characterizations.py +29 -40
- cirq/experiments/qubit_characterizations_test.py +1 -1
- cirq/experiments/random_quantum_circuit_generation.py +19 -33
- cirq/experiments/random_quantum_circuit_generation_test.py +6 -6
- cirq/experiments/readout_confusion_matrix.py +14 -14
- cirq/experiments/single_qubit_readout_calibration.py +12 -12
- cirq/experiments/t2_decay_experiment.py +7 -7
- cirq/experiments/two_qubit_xeb.py +32 -32
- cirq/experiments/two_qubit_xeb_test.py +5 -5
- cirq/experiments/xeb_fitting.py +25 -25
- cirq/experiments/xeb_sampling.py +22 -33
- cirq/experiments/xeb_simulation.py +5 -5
- cirq/experiments/xeb_simulation_test.py +3 -3
- cirq/experiments/z_phase_calibration.py +19 -19
- cirq/interop/quirk/cells/arithmetic_cells.py +23 -36
- cirq/interop/quirk/cells/cell.py +9 -21
- cirq/interop/quirk/cells/composite_cell.py +7 -22
- cirq/interop/quirk/cells/control_cells.py +8 -8
- cirq/interop/quirk/cells/input_cells.py +4 -4
- cirq/interop/quirk/cells/input_rotation_cells.py +5 -5
- cirq/interop/quirk/cells/parse.py +20 -23
- cirq/interop/quirk/cells/qubit_permutation_cells.py +3 -3
- cirq/interop/quirk/cells/swap_cell.py +3 -3
- cirq/interop/quirk/cells/testing.py +5 -7
- cirq/interop/quirk/url_to_circuit.py +17 -33
- cirq/json_resolver_cache.py +6 -6
- cirq/linalg/decompositions.py +20 -31
- cirq/linalg/diagonalize.py +4 -4
- cirq/linalg/diagonalize_test.py +3 -4
- cirq/linalg/operator_spaces.py +5 -5
- cirq/linalg/predicates.py +7 -7
- cirq/linalg/transformations.py +20 -20
- cirq/ops/arithmetic_operation.py +13 -15
- cirq/ops/boolean_hamiltonian.py +17 -17
- cirq/ops/classically_controlled_operation.py +13 -25
- cirq/ops/clifford_gate.py +31 -35
- cirq/ops/clifford_gate_test.py +2 -3
- cirq/ops/common_channels.py +30 -32
- cirq/ops/common_gates.py +64 -74
- cirq/ops/control_values.py +12 -12
- cirq/ops/controlled_gate.py +15 -30
- cirq/ops/controlled_gate_test.py +5 -5
- cirq/ops/controlled_operation.py +12 -25
- cirq/ops/controlled_operation_test.py +5 -5
- cirq/ops/dense_pauli_string.py +23 -34
- cirq/ops/dense_pauli_string_test.py +1 -2
- cirq/ops/diagonal_gate.py +9 -20
- cirq/ops/diagonal_gate_test.py +1 -3
- cirq/ops/eigen_gate.py +11 -23
- cirq/ops/eigen_gate_test.py +6 -8
- cirq/ops/fourier_transform.py +5 -5
- cirq/ops/fsim_gate.py +14 -14
- cirq/ops/gate_operation.py +23 -44
- cirq/ops/gateset.py +23 -37
- cirq/ops/gateset_test.py +2 -2
- cirq/ops/global_phase_op.py +8 -10
- cirq/ops/greedy_qubit_manager.py +6 -6
- cirq/ops/identity.py +9 -9
- cirq/ops/kraus_channel.py +7 -7
- cirq/ops/linear_combinations.py +29 -48
- cirq/ops/matrix_gates.py +8 -8
- cirq/ops/measure_util.py +13 -14
- cirq/ops/measurement_gate.py +18 -29
- cirq/ops/mixed_unitary_channel.py +8 -8
- cirq/ops/named_qubit.py +10 -10
- cirq/ops/op_tree.py +7 -7
- cirq/ops/parallel_gate.py +5 -5
- cirq/ops/parity_gates.py +14 -14
- cirq/ops/pauli_gates.py +8 -10
- cirq/ops/pauli_interaction_gate.py +6 -6
- cirq/ops/pauli_measurement_gate.py +11 -23
- cirq/ops/pauli_string.py +35 -52
- cirq/ops/pauli_string_phasor.py +4 -14
- cirq/ops/pauli_string_raw_types.py +3 -3
- cirq/ops/pauli_sum_exponential.py +2 -2
- cirq/ops/permutation_gate.py +4 -4
- cirq/ops/phased_iswap_gate.py +9 -9
- cirq/ops/phased_x_gate.py +10 -10
- cirq/ops/phased_x_z_gate.py +11 -11
- cirq/ops/projector.py +6 -6
- cirq/ops/qubit_manager.py +6 -6
- cirq/ops/qubit_order.py +3 -3
- cirq/ops/random_gate_channel.py +4 -4
- cirq/ops/raw_types.py +48 -70
- cirq/ops/state_preparation_channel.py +3 -3
- cirq/ops/swap_gates.py +9 -9
- cirq/ops/tags.py +2 -4
- cirq/ops/three_qubit_gates.py +20 -38
- cirq/ops/two_qubit_diagonal_gate.py +5 -5
- cirq/ops/uniform_superposition_gate.py +2 -2
- cirq/ops/wait_gate.py +5 -5
- cirq/protocols/act_on_protocol_test.py +3 -3
- cirq/protocols/apply_channel_protocol.py +8 -14
- cirq/protocols/apply_mixture_protocol.py +14 -16
- cirq/protocols/apply_mixture_protocol_test.py +5 -6
- cirq/protocols/apply_unitary_protocol.py +17 -19
- cirq/protocols/circuit_diagram_info_protocol.py +19 -30
- cirq/protocols/decompose_protocol.py +30 -34
- cirq/protocols/inverse_protocol.py +7 -7
- cirq/protocols/json_serialization.py +32 -51
- cirq/protocols/json_serialization_test.py +9 -10
- cirq/protocols/kraus_protocol.py +4 -4
- cirq/protocols/kraus_protocol_test.py +3 -3
- cirq/protocols/measurement_key_protocol.py +11 -13
- cirq/protocols/mixture_protocol.py +4 -4
- cirq/protocols/qasm.py +11 -13
- cirq/protocols/qid_shape_protocol.py +6 -8
- cirq/qis/clifford_tableau.py +12 -12
- cirq/qis/measures.py +7 -7
- cirq/qis/quantum_state_representation.py +3 -3
- cirq/qis/states.py +51 -51
- cirq/sim/classical_simulator.py +10 -10
- cirq/sim/clifford/clifford_simulator.py +6 -6
- cirq/sim/clifford/clifford_tableau_simulation_state_test.py +1 -3
- cirq/sim/clifford/stabilizer_sampler.py +4 -4
- cirq/sim/clifford/stabilizer_state_ch_form.py +3 -3
- cirq/sim/density_matrix_simulation_state.py +15 -15
- cirq/sim/density_matrix_simulator.py +11 -11
- cirq/sim/density_matrix_utils.py +9 -9
- cirq/sim/mux.py +9 -9
- cirq/sim/simulation_product_state.py +9 -9
- cirq/sim/simulation_product_state_test.py +2 -2
- cirq/sim/simulation_state.py +14 -27
- cirq/sim/simulation_state_base.py +8 -24
- cirq/sim/simulation_utils.py +3 -4
- cirq/sim/simulator.py +28 -43
- cirq/sim/simulator_base.py +12 -25
- cirq/sim/simulator_base_test.py +6 -6
- cirq/sim/simulator_test.py +7 -7
- cirq/sim/sparse_simulator.py +8 -8
- cirq/sim/state_vector.py +8 -8
- cirq/sim/state_vector_simulation_state.py +17 -17
- cirq/sim/state_vector_simulator.py +4 -4
- cirq/study/flatten_expressions.py +12 -14
- cirq/study/resolver.py +9 -11
- cirq/study/result.py +11 -24
- cirq/study/sweepable.py +5 -5
- cirq/study/sweeps.py +27 -40
- cirq/testing/circuit_compare.py +5 -5
- cirq/testing/consistent_controlled_gate_op_test.py +7 -11
- cirq/testing/consistent_protocols.py +10 -10
- cirq/testing/consistent_protocols_test.py +7 -7
- cirq/testing/consistent_qasm.py +4 -4
- cirq/testing/consistent_qasm_test.py +2 -3
- cirq/testing/devices.py +4 -5
- cirq/testing/equals_tester.py +2 -2
- cirq/testing/equivalent_basis_map.py +4 -4
- cirq/testing/equivalent_repr_eval.py +3 -3
- cirq/testing/json.py +14 -14
- cirq/testing/logs.py +3 -3
- cirq/testing/no_identifier_qubit.py +2 -3
- cirq/testing/random_circuit.py +7 -7
- cirq/testing/random_circuit_test.py +3 -3
- cirq/transformers/analytical_decompositions/clifford_decomposition.py +16 -16
- cirq/transformers/analytical_decompositions/controlled_gate_decomposition.py +13 -13
- cirq/transformers/analytical_decompositions/cphase_to_fsim.py +5 -5
- cirq/transformers/analytical_decompositions/cphase_to_fsim_test.py +3 -3
- cirq/transformers/analytical_decompositions/pauli_string_decomposition.py +3 -3
- cirq/transformers/analytical_decompositions/quantum_shannon_decomposition.py +4 -4
- cirq/transformers/analytical_decompositions/single_qubit_decompositions.py +6 -7
- cirq/transformers/analytical_decompositions/single_to_two_qubit_isometry.py +2 -2
- cirq/transformers/analytical_decompositions/three_qubit_decomposition.py +7 -7
- cirq/transformers/analytical_decompositions/two_qubit_state_preparation.py +4 -4
- cirq/transformers/analytical_decompositions/two_qubit_to_cz.py +7 -7
- cirq/transformers/analytical_decompositions/two_qubit_to_fsim.py +11 -11
- cirq/transformers/analytical_decompositions/two_qubit_to_ms.py +5 -5
- cirq/transformers/analytical_decompositions/two_qubit_to_sqrt_iswap.py +14 -14
- cirq/transformers/dynamical_decoupling.py +13 -13
- cirq/transformers/dynamical_decoupling_test.py +4 -4
- cirq/transformers/eject_phased_paulis.py +16 -16
- cirq/transformers/eject_z.py +5 -7
- cirq/transformers/gauge_compiling/gauge_compiling.py +38 -38
- cirq/transformers/gauge_compiling/sqrt_cz_gauge.py +2 -2
- cirq/transformers/heuristic_decompositions/two_qubit_gate_tabulation.py +8 -8
- cirq/transformers/insertion_sort.py +5 -5
- cirq/transformers/measurement_transformers.py +14 -14
- cirq/transformers/merge_k_qubit_gates_test.py +1 -3
- cirq/transformers/merge_single_qubit_gates_test.py +1 -3
- cirq/transformers/qubit_management_transformers.py +5 -5
- cirq/transformers/routing/initial_mapper.py +4 -4
- cirq/transformers/routing/line_initial_mapper.py +9 -9
- cirq/transformers/routing/mapping_manager.py +7 -7
- cirq/transformers/routing/route_circuit_cqc.py +27 -27
- cirq/transformers/routing/visualize_routed_circuit.py +4 -4
- cirq/transformers/stratify.py +8 -8
- cirq/transformers/synchronize_terminal_measurements.py +6 -6
- cirq/transformers/target_gatesets/compilation_target_gateset.py +8 -8
- cirq/transformers/target_gatesets/compilation_target_gateset_test.py +2 -2
- cirq/transformers/target_gatesets/cz_gateset.py +4 -4
- cirq/transformers/target_gatesets/sqrt_iswap_gateset.py +5 -5
- cirq/transformers/transformer_api.py +11 -26
- cirq/transformers/transformer_primitives.py +24 -36
- cirq/transformers/transformer_primitives_test.py +3 -3
- cirq/value/classical_data.py +18 -18
- cirq/value/condition.py +8 -8
- cirq/value/digits.py +7 -7
- cirq/value/duration.py +12 -12
- cirq/value/linear_dict.py +8 -12
- cirq/value/linear_dict_test.py +2 -2
- cirq/value/measurement_key.py +8 -8
- cirq/value/product_state.py +9 -9
- cirq/value/value_equality_attr.py +4 -4
- cirq/vis/heatmap.py +23 -35
- cirq/work/collector.py +9 -17
- cirq/work/observable_grouping.py +4 -7
- cirq/work/observable_measurement.py +29 -41
- cirq/work/observable_measurement_data.py +14 -14
- cirq/work/observable_measurement_test.py +2 -2
- cirq/work/observable_settings.py +9 -10
- cirq/work/pauli_sum_collector.py +5 -5
- cirq/work/sampler.py +17 -17
- cirq/work/zeros_sampler.py +3 -3
- {cirq_core-1.6.0.dev20250520054601.dist-info → cirq_core-1.6.0.dev20250520183459.dist-info}/METADATA +1 -1
- {cirq_core-1.6.0.dev20250520054601.dist-info → cirq_core-1.6.0.dev20250520183459.dist-info}/RECORD +290 -290
- {cirq_core-1.6.0.dev20250520054601.dist-info → cirq_core-1.6.0.dev20250520183459.dist-info}/WHEEL +1 -1
- {cirq_core-1.6.0.dev20250520054601.dist-info → cirq_core-1.6.0.dev20250520183459.dist-info}/licenses/LICENSE +0 -0
- {cirq_core-1.6.0.dev20250520054601.dist-info → cirq_core-1.6.0.dev20250520183459.dist-info}/top_level.txt +0 -0
|
@@ -19,7 +19,7 @@ from __future__ import annotations
|
|
|
19
19
|
import abc
|
|
20
20
|
from dataclasses import dataclass, field
|
|
21
21
|
from functools import cached_property
|
|
22
|
-
from typing import
|
|
22
|
+
from typing import TYPE_CHECKING
|
|
23
23
|
|
|
24
24
|
from cirq import devices, ops, qis
|
|
25
25
|
from cirq.devices import noise_utils
|
|
@@ -34,11 +34,11 @@ class SuperconductingQubitsNoiseProperties(devices.NoiseProperties, abc.ABC):
|
|
|
34
34
|
"""Noise-defining properties for a superconducting-qubit-based device.
|
|
35
35
|
|
|
36
36
|
Args:
|
|
37
|
-
gate_times_ns:
|
|
37
|
+
gate_times_ns: dict[type, float] of gate types to their duration on
|
|
38
38
|
quantum hardware. Used with t(1|phi)_ns to specify thermal noise.
|
|
39
|
-
t1_ns:
|
|
40
|
-
tphi_ns:
|
|
41
|
-
readout_errors:
|
|
39
|
+
t1_ns: dict[cirq.Qid, float] of qubits to their T_1 time, in ns.
|
|
40
|
+
tphi_ns: dict[cirq.Qid, float] of qubits to their T_phi time, in ns.
|
|
41
|
+
readout_errors: dict[cirq.Qid, np.ndarray] of qubits to their readout
|
|
42
42
|
errors in matrix form: [P(read |1> from |0>), P(read |0> from |1>)].
|
|
43
43
|
Used to prepend amplitude damping errors to measurements.
|
|
44
44
|
gate_pauli_errors: dict of noise_utils.OpIdentifiers (a gate and the qubits it
|
|
@@ -49,14 +49,14 @@ class SuperconductingQubitsNoiseProperties(devices.NoiseProperties, abc.ABC):
|
|
|
49
49
|
symmetric over the qubits they affect. Defaults to True.
|
|
50
50
|
"""
|
|
51
51
|
|
|
52
|
-
gate_times_ns:
|
|
53
|
-
t1_ns:
|
|
54
|
-
tphi_ns:
|
|
55
|
-
readout_errors:
|
|
56
|
-
gate_pauli_errors:
|
|
52
|
+
gate_times_ns: dict[type, float]
|
|
53
|
+
t1_ns: dict[cirq.Qid, float]
|
|
54
|
+
tphi_ns: dict[cirq.Qid, float]
|
|
55
|
+
readout_errors: dict[cirq.Qid, list[float]]
|
|
56
|
+
gate_pauli_errors: dict[noise_utils.OpIdentifier, float]
|
|
57
57
|
|
|
58
58
|
validate: bool = True
|
|
59
|
-
_qubits:
|
|
59
|
+
_qubits: list[cirq.Qid] = field(init=False, default_factory=list)
|
|
60
60
|
|
|
61
61
|
def __post_init__(self):
|
|
62
62
|
if not self.validate:
|
|
@@ -96,7 +96,7 @@ class SuperconductingQubitsNoiseProperties(devices.NoiseProperties, abc.ABC):
|
|
|
96
96
|
)
|
|
97
97
|
|
|
98
98
|
@property
|
|
99
|
-
def qubits(self) ->
|
|
99
|
+
def qubits(self) -> list[cirq.Qid]:
|
|
100
100
|
"""Qubits for which we have data"""
|
|
101
101
|
if not self._qubits:
|
|
102
102
|
self._qubits = sorted(self.t1_ns)
|
|
@@ -104,26 +104,26 @@ class SuperconductingQubitsNoiseProperties(devices.NoiseProperties, abc.ABC):
|
|
|
104
104
|
|
|
105
105
|
@classmethod
|
|
106
106
|
@abc.abstractmethod
|
|
107
|
-
def single_qubit_gates(cls) ->
|
|
107
|
+
def single_qubit_gates(cls) -> set[type[ops.Gate]]:
|
|
108
108
|
"""Returns the set of single-qubit gates this class supports."""
|
|
109
109
|
|
|
110
110
|
@classmethod
|
|
111
111
|
@abc.abstractmethod
|
|
112
|
-
def symmetric_two_qubit_gates(cls) ->
|
|
112
|
+
def symmetric_two_qubit_gates(cls) -> set[type[ops.Gate]]:
|
|
113
113
|
"""Returns the set of symmetric two-qubit gates this class supports."""
|
|
114
114
|
|
|
115
115
|
@classmethod
|
|
116
116
|
@abc.abstractmethod
|
|
117
|
-
def asymmetric_two_qubit_gates(cls) ->
|
|
117
|
+
def asymmetric_two_qubit_gates(cls) -> set[type[ops.Gate]]:
|
|
118
118
|
"""Returns the set of asymmetric two-qubit gates this class supports."""
|
|
119
119
|
|
|
120
120
|
@classmethod
|
|
121
|
-
def two_qubit_gates(cls) ->
|
|
121
|
+
def two_qubit_gates(cls) -> set[type[ops.Gate]]:
|
|
122
122
|
"""Returns the set of all two-qubit gates this class supports."""
|
|
123
123
|
return cls.symmetric_two_qubit_gates() | cls.asymmetric_two_qubit_gates()
|
|
124
124
|
|
|
125
125
|
@classmethod
|
|
126
|
-
def expected_gates(cls) ->
|
|
126
|
+
def expected_gates(cls) -> set[type[ops.Gate]]:
|
|
127
127
|
"""Returns the set of all gates this class supports."""
|
|
128
128
|
return cls.single_qubit_gates() | cls.two_qubit_gates()
|
|
129
129
|
|
|
@@ -134,7 +134,7 @@ class SuperconductingQubitsNoiseProperties(devices.NoiseProperties, abc.ABC):
|
|
|
134
134
|
return p_error
|
|
135
135
|
|
|
136
136
|
@cached_property
|
|
137
|
-
def _depolarizing_error(self) ->
|
|
137
|
+
def _depolarizing_error(self) -> dict[noise_utils.OpIdentifier, float]:
|
|
138
138
|
"""Returns the portion of Pauli error from depolarization."""
|
|
139
139
|
depol_errors = {}
|
|
140
140
|
for op_id, p_error in self.gate_pauli_errors.items():
|
|
@@ -151,8 +151,8 @@ class SuperconductingQubitsNoiseProperties(devices.NoiseProperties, abc.ABC):
|
|
|
151
151
|
depol_errors[op_id] = self._get_pauli_error(p_error, op_id)
|
|
152
152
|
return depol_errors
|
|
153
153
|
|
|
154
|
-
def build_noise_models(self) ->
|
|
155
|
-
noise_models:
|
|
154
|
+
def build_noise_models(self) -> list[cirq.NoiseModel]:
|
|
155
|
+
noise_models: list[cirq.NoiseModel] = []
|
|
156
156
|
|
|
157
157
|
if self.t1_ns:
|
|
158
158
|
noise_models.append(
|
|
@@ -176,7 +176,7 @@ class SuperconductingQubitsNoiseProperties(devices.NoiseProperties, abc.ABC):
|
|
|
176
176
|
|
|
177
177
|
# This adds per-qubit measurement error BEFORE measurement on those qubits.
|
|
178
178
|
if self.readout_errors:
|
|
179
|
-
added_measure_errors:
|
|
179
|
+
added_measure_errors: dict[noise_utils.OpIdentifier, cirq.Operation] = {}
|
|
180
180
|
for qubit in self.readout_errors:
|
|
181
181
|
p_00, p_11 = self.readout_errors[qubit]
|
|
182
182
|
p = p_11 / (p_00 + p_11)
|
|
@@ -14,8 +14,6 @@
|
|
|
14
14
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
|
-
from typing import Dict, List, Set, Tuple
|
|
18
|
-
|
|
19
17
|
import numpy as np
|
|
20
18
|
import pytest
|
|
21
19
|
|
|
@@ -26,7 +24,7 @@ from cirq.devices.superconducting_qubits_noise_properties import (
|
|
|
26
24
|
SuperconductingQubitsNoiseProperties,
|
|
27
25
|
)
|
|
28
26
|
|
|
29
|
-
DEFAULT_GATE_NS:
|
|
27
|
+
DEFAULT_GATE_NS: dict[type, float] = {
|
|
30
28
|
cirq.ZPowGate: 25.0,
|
|
31
29
|
cirq.MeasurementGate: 4000.0,
|
|
32
30
|
cirq.ResetChannel: 250.0,
|
|
@@ -39,7 +37,7 @@ DEFAULT_GATE_NS: Dict[type, float] = {
|
|
|
39
37
|
}
|
|
40
38
|
|
|
41
39
|
|
|
42
|
-
def default_props(system_qubits:
|
|
40
|
+
def default_props(system_qubits: list[cirq.Qid], qubit_pairs: list[tuple[cirq.Qid, cirq.Qid]]):
|
|
43
41
|
return {
|
|
44
42
|
'gate_times_ns': DEFAULT_GATE_NS,
|
|
45
43
|
't1_ns': {q: 1e5 for q in system_qubits},
|
|
@@ -65,15 +63,15 @@ class ExampleNoiseProperties(SuperconductingQubitsNoiseProperties):
|
|
|
65
63
|
super().__init__(*args, **kwargs)
|
|
66
64
|
|
|
67
65
|
@classmethod
|
|
68
|
-
def single_qubit_gates(cls) ->
|
|
66
|
+
def single_qubit_gates(cls) -> set[type]:
|
|
69
67
|
return {cirq.ZPowGate, cirq.PhasedXZGate, cirq.MeasurementGate, cirq.ResetChannel}
|
|
70
68
|
|
|
71
69
|
@classmethod
|
|
72
|
-
def symmetric_two_qubit_gates(cls) ->
|
|
70
|
+
def symmetric_two_qubit_gates(cls) -> set[type]:
|
|
73
71
|
return {cirq.FSimGate, cirq.PhasedFSimGate, cirq.ISwapPowGate, cirq.CZPowGate}
|
|
74
72
|
|
|
75
73
|
@classmethod
|
|
76
|
-
def asymmetric_two_qubit_gates(cls) ->
|
|
74
|
+
def asymmetric_two_qubit_gates(cls) -> set[type]:
|
|
77
75
|
return set()
|
|
78
76
|
|
|
79
77
|
|
|
@@ -16,7 +16,7 @@ from __future__ import annotations
|
|
|
16
16
|
|
|
17
17
|
import dataclasses
|
|
18
18
|
import functools
|
|
19
|
-
from typing import
|
|
19
|
+
from typing import Sequence, TYPE_CHECKING
|
|
20
20
|
|
|
21
21
|
import numpy as np
|
|
22
22
|
import sympy
|
|
@@ -81,7 +81,7 @@ def _lindbladian(left_op: np.ndarray) -> np.ndarray:
|
|
|
81
81
|
|
|
82
82
|
@functools.lru_cache(maxsize=256)
|
|
83
83
|
def _kraus_ops_from_rates(
|
|
84
|
-
flat_rates:
|
|
84
|
+
flat_rates: tuple[float, ...], shape: tuple[int, int]
|
|
85
85
|
) -> Sequence[np.ndarray]:
|
|
86
86
|
"""Generate kraus operators from an array of rates.
|
|
87
87
|
|
|
@@ -131,8 +131,8 @@ def _decoherence_matrix(
|
|
|
131
131
|
|
|
132
132
|
|
|
133
133
|
def _as_rate_dict(
|
|
134
|
-
rate_or_dict:
|
|
135
|
-
) ->
|
|
134
|
+
rate_or_dict: float | dict[cirq.Qid, float] | None, qubits: set[cirq.Qid]
|
|
135
|
+
) -> dict[cirq.Qid, float]:
|
|
136
136
|
"""Convert float or None input into dictionary form.
|
|
137
137
|
|
|
138
138
|
This method also ensures that no qubits are missing from dictionary keys.
|
|
@@ -145,7 +145,7 @@ def _as_rate_dict(
|
|
|
145
145
|
return {q: rate_or_dict for q in qubits}
|
|
146
146
|
|
|
147
147
|
|
|
148
|
-
def _validate_rates(qubits:
|
|
148
|
+
def _validate_rates(qubits: set[cirq.Qid], rates: dict[cirq.Qid, np.ndarray]) -> None:
|
|
149
149
|
"""Check all rate matrices are square and of appropriate dimension.
|
|
150
150
|
|
|
151
151
|
We check rates are positive in the class validator.
|
|
@@ -171,11 +171,11 @@ class ThermalNoiseModel(devices.NoiseModel):
|
|
|
171
171
|
|
|
172
172
|
def __init__(
|
|
173
173
|
self,
|
|
174
|
-
qubits:
|
|
175
|
-
gate_durations_ns:
|
|
176
|
-
heat_rate_GHz:
|
|
177
|
-
cool_rate_GHz:
|
|
178
|
-
dephase_rate_GHz:
|
|
174
|
+
qubits: set[cirq.Qid],
|
|
175
|
+
gate_durations_ns: dict[type, float],
|
|
176
|
+
heat_rate_GHz: float | dict[cirq.Qid, float] | None = None,
|
|
177
|
+
cool_rate_GHz: float | dict[cirq.Qid, float] | None = None,
|
|
178
|
+
dephase_rate_GHz: float | dict[cirq.Qid, float] | None = None,
|
|
179
179
|
require_physical_tag: bool = True,
|
|
180
180
|
skip_measurements: bool = True,
|
|
181
181
|
prepend: bool = False,
|
|
@@ -226,8 +226,8 @@ class ThermalNoiseModel(devices.NoiseModel):
|
|
|
226
226
|
rate_dict[q] = _decoherence_matrix(gamma_c, gamma_phi, gamma_h, q.dimension)
|
|
227
227
|
|
|
228
228
|
_validate_rates(qubits, rate_dict)
|
|
229
|
-
self.gate_durations_ns:
|
|
230
|
-
self.rate_matrix_GHz:
|
|
229
|
+
self.gate_durations_ns: dict[type, float] = gate_durations_ns
|
|
230
|
+
self.rate_matrix_GHz: dict[cirq.Qid, np.ndarray] = rate_dict
|
|
231
231
|
self.require_physical_tag: bool = require_physical_tag
|
|
232
232
|
self.skip_measurements: bool = skip_measurements
|
|
233
233
|
self._prepend = prepend
|
|
@@ -247,13 +247,13 @@ class ThermalNoiseModel(devices.NoiseModel):
|
|
|
247
247
|
# Only moments with physical operations should have noise.
|
|
248
248
|
return [moment]
|
|
249
249
|
|
|
250
|
-
noise_ops:
|
|
250
|
+
noise_ops: list[cirq.Operation] = []
|
|
251
251
|
# Some devices (including Google hardware) require that all gates have
|
|
252
252
|
# the same duration, but this does not. Instead, each moment is assumed
|
|
253
253
|
# to be as long as the longest gate it contains.
|
|
254
254
|
moment_ns: float = 0
|
|
255
255
|
for op in moment:
|
|
256
|
-
op_duration:
|
|
256
|
+
op_duration: float | None = None
|
|
257
257
|
for key, duration in self.gate_durations_ns.items():
|
|
258
258
|
if not issubclass(type(op.gate), key):
|
|
259
259
|
continue # gate type doesn't match
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
|
-
from typing import Any,
|
|
17
|
+
from typing import Any, TYPE_CHECKING
|
|
18
18
|
|
|
19
19
|
from cirq import protocols, value
|
|
20
20
|
from cirq._doc import document
|
|
@@ -43,7 +43,7 @@ class _UnconstrainedDevice(device.Device):
|
|
|
43
43
|
def _value_equality_values_(self) -> Any:
|
|
44
44
|
return ()
|
|
45
45
|
|
|
46
|
-
def _json_dict_(self) ->
|
|
46
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
47
47
|
return protocols.obj_to_dict_helper(self, [])
|
|
48
48
|
|
|
49
49
|
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
from __future__ import annotations
|
|
18
18
|
|
|
19
19
|
from concurrent import futures
|
|
20
|
-
from typing import
|
|
20
|
+
from typing import overload, Sequence, TYPE_CHECKING, Union
|
|
21
21
|
|
|
22
22
|
import attrs
|
|
23
23
|
import networkx as nx
|
|
@@ -34,7 +34,7 @@ if TYPE_CHECKING:
|
|
|
34
34
|
|
|
35
35
|
_TARGET_T = Union['cirq.Gate', 'cirq.Operation', 'cirq.AbstractCircuit']
|
|
36
36
|
_QUBIT_PAIR_T = tuple['cirq.GridQubit', 'cirq.GridQubit']
|
|
37
|
-
_CANONICAL_TARGET_T = Union['cirq.Operation',
|
|
37
|
+
_CANONICAL_TARGET_T = Union['cirq.Operation', dict[_QUBIT_PAIR_T, 'cirq.Operation']]
|
|
38
38
|
_PROBABILITIES_DICT_T = dict[_QUBIT_PAIR_T, list[list[np.ndarray]]]
|
|
39
39
|
|
|
40
40
|
|
|
@@ -76,7 +76,7 @@ class XEBWideCircuitInfo:
|
|
|
76
76
|
converter=lambda seq: [_canonize_pair(pair) for pair in seq]
|
|
77
77
|
)
|
|
78
78
|
narrow_template_indices: tuple[int, ...] = attrs.field(converter=tuple)
|
|
79
|
-
cycle_depth:
|
|
79
|
+
cycle_depth: int | None = None
|
|
80
80
|
|
|
81
81
|
@staticmethod
|
|
82
82
|
def from_narrow_circuits(
|
|
@@ -166,9 +166,7 @@ def _target_to_operation(target: _TARGET_T) -> cirq.Operation:
|
|
|
166
166
|
return target
|
|
167
167
|
|
|
168
168
|
|
|
169
|
-
def _canonize_target(
|
|
170
|
-
target: Union[_TARGET_T, Dict[_QUBIT_PAIR_T, _TARGET_T]],
|
|
171
|
-
) -> _CANONICAL_TARGET_T:
|
|
169
|
+
def _canonize_target(target: _TARGET_T | dict[_QUBIT_PAIR_T, _TARGET_T]) -> _CANONICAL_TARGET_T:
|
|
172
170
|
if isinstance(target, (ops.Gate, ops.Operation, circuits.AbstractCircuit)):
|
|
173
171
|
return _target_to_operation(target)
|
|
174
172
|
return {k: _target_to_operation(v) for k, v in target.items()}
|
|
@@ -267,7 +265,7 @@ def simulate_circuit_library(
|
|
|
267
265
|
circuit_templates: Sequence[cirq.Circuit],
|
|
268
266
|
target_or_dict: ops.Operation,
|
|
269
267
|
cycle_depths: Sequence[int],
|
|
270
|
-
pool:
|
|
268
|
+
pool: futures.Executor | None = None,
|
|
271
269
|
) -> Sequence[Sequence[np.ndarray]]: ...
|
|
272
270
|
|
|
273
271
|
|
|
@@ -276,7 +274,7 @@ def simulate_circuit_library(
|
|
|
276
274
|
circuit_templates: Sequence[cirq.Circuit],
|
|
277
275
|
target_or_dict: dict[_QUBIT_PAIR_T, ops.Operation],
|
|
278
276
|
cycle_depths: Sequence[int],
|
|
279
|
-
pool:
|
|
277
|
+
pool: futures.Executor | None = None,
|
|
280
278
|
) -> dict[_QUBIT_PAIR_T, Sequence[Sequence[np.ndarray]]]: ...
|
|
281
279
|
|
|
282
280
|
|
|
@@ -284,8 +282,8 @@ def simulate_circuit_library(
|
|
|
284
282
|
circuit_templates: Sequence[cirq.Circuit],
|
|
285
283
|
target_or_dict: _CANONICAL_TARGET_T,
|
|
286
284
|
cycle_depths: Sequence[int],
|
|
287
|
-
pool:
|
|
288
|
-
) ->
|
|
285
|
+
pool: futures.Executor | None = None,
|
|
286
|
+
) -> Sequence[Sequence[np.ndarray]] | dict[_QUBIT_PAIR_T, Sequence[Sequence[np.ndarray]]]:
|
|
289
287
|
"""Simulate the given sequence of circuits.
|
|
290
288
|
|
|
291
289
|
Args:
|
|
@@ -408,9 +406,9 @@ def _reshape_sampling_results(
|
|
|
408
406
|
|
|
409
407
|
|
|
410
408
|
def _reshape_simulation_results(
|
|
411
|
-
simulation_results:
|
|
412
|
-
Sequence[Sequence[np.ndarray]]
|
|
413
|
-
|
|
409
|
+
simulation_results: (
|
|
410
|
+
Sequence[Sequence[np.ndarray]] | dict[_QUBIT_PAIR_T, Sequence[Sequence[np.ndarray]]]
|
|
411
|
+
),
|
|
414
412
|
cycle_depths: Sequence[int],
|
|
415
413
|
pairs: Sequence[_QUBIT_PAIR_T],
|
|
416
414
|
num_templates: int,
|
|
@@ -464,9 +462,9 @@ def _cross_entropy(p: np.ndarray, q: np.ndarray, eps: float = 1e-60) -> float:
|
|
|
464
462
|
|
|
465
463
|
def estimate_fidelities(
|
|
466
464
|
sampling_results: Sequence[dict[str, np.ndarray]],
|
|
467
|
-
simulation_results:
|
|
468
|
-
Sequence[Sequence[np.ndarray]]
|
|
469
|
-
|
|
465
|
+
simulation_results: (
|
|
466
|
+
Sequence[Sequence[np.ndarray]] | dict[_QUBIT_PAIR_T, Sequence[Sequence[np.ndarray]]]
|
|
467
|
+
),
|
|
470
468
|
cycle_depths: Sequence[int],
|
|
471
469
|
wide_circuits_info: Sequence[XEBWideCircuitInfo],
|
|
472
470
|
pairs: Sequence[_QUBIT_PAIR_T],
|
|
@@ -527,9 +525,9 @@ def estimate_fidelities(
|
|
|
527
525
|
|
|
528
526
|
def _extract_pairs(
|
|
529
527
|
sampler: cirq.Sampler,
|
|
530
|
-
target:
|
|
531
|
-
qubits:
|
|
532
|
-
pairs:
|
|
528
|
+
target: _TARGET_T | dict[_QUBIT_PAIR_T, _TARGET_T],
|
|
529
|
+
qubits: Sequence[cirq.GridQubit] | None,
|
|
530
|
+
pairs: Sequence[_QUBIT_PAIR_T] | None,
|
|
533
531
|
) -> Sequence[_QUBIT_PAIR_T]:
|
|
534
532
|
if isinstance(target, dict):
|
|
535
533
|
if pairs is None:
|
|
@@ -547,13 +545,13 @@ def _extract_pairs(
|
|
|
547
545
|
|
|
548
546
|
def parallel_xeb_workflow(
|
|
549
547
|
sampler: cirq.Sampler,
|
|
550
|
-
target:
|
|
551
|
-
ideal_target:
|
|
552
|
-
qubits:
|
|
553
|
-
pairs:
|
|
548
|
+
target: _TARGET_T | dict[_QUBIT_PAIR_T, _TARGET_T],
|
|
549
|
+
ideal_target: _TARGET_T | dict[_QUBIT_PAIR_T, _TARGET_T] | None = None,
|
|
550
|
+
qubits: Sequence[cirq.GridQubit] | None = None,
|
|
551
|
+
pairs: Sequence[_QUBIT_PAIR_T] | None = None,
|
|
554
552
|
parameters: XEBParameters = XEBParameters(),
|
|
555
|
-
rng:
|
|
556
|
-
pool:
|
|
553
|
+
rng: np.random.Generator | None = None,
|
|
554
|
+
pool: futures.Executor | None = None,
|
|
557
555
|
) -> Sequence[XEBFidelity]:
|
|
558
556
|
"""A utility method that runs the full XEB workflow.
|
|
559
557
|
|
|
@@ -646,13 +644,13 @@ def parallel_xeb_workflow(
|
|
|
646
644
|
|
|
647
645
|
def parallel_two_qubit_xeb(
|
|
648
646
|
sampler: cirq.Sampler,
|
|
649
|
-
target:
|
|
650
|
-
ideal_target:
|
|
651
|
-
qubits:
|
|
652
|
-
pairs:
|
|
647
|
+
target: _TARGET_T | dict[_QUBIT_PAIR_T, _TARGET_T],
|
|
648
|
+
ideal_target: _TARGET_T | dict[_QUBIT_PAIR_T, _TARGET_T] | None = None,
|
|
649
|
+
qubits: Sequence[cirq.GridQubit] | None = None,
|
|
650
|
+
pairs: Sequence[_QUBIT_PAIR_T] | None = None,
|
|
653
651
|
parameters: XEBParameters = XEBParameters(),
|
|
654
|
-
rng:
|
|
655
|
-
pool:
|
|
652
|
+
rng: np.random.Generator | None = None,
|
|
653
|
+
pool: futures.Executor | None = None,
|
|
656
654
|
) -> tqxeb.TwoQubitXEBResult:
|
|
657
655
|
"""A convenience method that runs the full XEB workflow.
|
|
658
656
|
|
|
@@ -20,7 +20,7 @@ so that occurs outside of the StateTomographyExperiment class.
|
|
|
20
20
|
|
|
21
21
|
from __future__ import annotations
|
|
22
22
|
|
|
23
|
-
from typing import
|
|
23
|
+
from typing import Sequence, TYPE_CHECKING
|
|
24
24
|
|
|
25
25
|
import numpy as np
|
|
26
26
|
import sympy
|
|
@@ -51,9 +51,7 @@ class StateTomographyExperiment:
|
|
|
51
51
|
"""
|
|
52
52
|
|
|
53
53
|
def __init__(
|
|
54
|
-
self,
|
|
55
|
-
qubits: Sequence[cirq.Qid],
|
|
56
|
-
prerotations: Optional[Sequence[Tuple[float, float]]] = None,
|
|
54
|
+
self, qubits: Sequence[cirq.Qid], prerotations: Sequence[tuple[float, float]] | None = None
|
|
57
55
|
):
|
|
58
56
|
"""Initializes the rotation protocol and matrix for system.
|
|
59
57
|
|
|
@@ -72,8 +70,8 @@ class StateTomographyExperiment:
|
|
|
72
70
|
|
|
73
71
|
phase_exp_vals, exp_vals = zip(*prerotations)
|
|
74
72
|
|
|
75
|
-
operations:
|
|
76
|
-
sweeps:
|
|
73
|
+
operations: list[cirq.Operation] = []
|
|
74
|
+
sweeps: list[cirq.Sweep] = []
|
|
77
75
|
for i, qubit in enumerate(qubits):
|
|
78
76
|
phase_exp = sympy.Symbol(f'phase_exp_{i}')
|
|
79
77
|
exp = sympy.Symbol(f'exp_{i}')
|
|
@@ -137,7 +135,7 @@ def state_tomography(
|
|
|
137
135
|
qubits: Sequence[cirq.Qid],
|
|
138
136
|
circuit: cirq.Circuit,
|
|
139
137
|
repetitions: int = 1000,
|
|
140
|
-
prerotations:
|
|
138
|
+
prerotations: Sequence[tuple[float, float]] | None = None,
|
|
141
139
|
) -> TomographyResult:
|
|
142
140
|
"""This performs n qubit tomography on a cirq circuit
|
|
143
141
|
|
|
@@ -17,18 +17,7 @@ from __future__ import annotations
|
|
|
17
17
|
import dataclasses
|
|
18
18
|
import functools
|
|
19
19
|
import itertools
|
|
20
|
-
from typing import
|
|
21
|
-
Any,
|
|
22
|
-
cast,
|
|
23
|
-
Dict,
|
|
24
|
-
Iterator,
|
|
25
|
-
List,
|
|
26
|
-
Mapping,
|
|
27
|
-
Optional,
|
|
28
|
-
Sequence,
|
|
29
|
-
Tuple,
|
|
30
|
-
TYPE_CHECKING,
|
|
31
|
-
)
|
|
20
|
+
from typing import Any, cast, Iterator, Mapping, Sequence, TYPE_CHECKING
|
|
32
21
|
|
|
33
22
|
import numpy as np
|
|
34
23
|
from matplotlib import pyplot as plt
|
|
@@ -65,11 +54,11 @@ class Cliffords:
|
|
|
65
54
|
s1_y
|
|
66
55
|
"""
|
|
67
56
|
|
|
68
|
-
c1_in_xy:
|
|
69
|
-
c1_in_xz:
|
|
70
|
-
s1:
|
|
71
|
-
s1_x:
|
|
72
|
-
s1_y:
|
|
57
|
+
c1_in_xy: list[list[ops.SingleQubitCliffordGate]]
|
|
58
|
+
c1_in_xz: list[list[ops.SingleQubitCliffordGate]]
|
|
59
|
+
s1: list[list[ops.SingleQubitCliffordGate]]
|
|
60
|
+
s1_x: list[list[ops.SingleQubitCliffordGate]]
|
|
61
|
+
s1_y: list[list[ops.SingleQubitCliffordGate]]
|
|
73
62
|
|
|
74
63
|
|
|
75
64
|
class RandomizedBenchMarkResult:
|
|
@@ -88,14 +77,14 @@ class RandomizedBenchMarkResult:
|
|
|
88
77
|
self._gnd_state_probs = ground_state_probabilities
|
|
89
78
|
|
|
90
79
|
@property
|
|
91
|
-
def data(self) -> Sequence[
|
|
80
|
+
def data(self) -> Sequence[tuple[int, float]]:
|
|
92
81
|
"""Returns a sequence of tuple pairs with the first item being a
|
|
93
82
|
number of Cliffords and the second item being the corresponding average
|
|
94
83
|
ground state probability.
|
|
95
84
|
"""
|
|
96
85
|
return [(num, prob) for num, prob in zip(self._num_cfds_seq, self._gnd_state_probs)]
|
|
97
86
|
|
|
98
|
-
def plot(self, ax:
|
|
87
|
+
def plot(self, ax: plt.Axes | None = None, **plot_kwargs: Any) -> plt.Axes:
|
|
99
88
|
"""Plots the average ground state probability vs the number of
|
|
100
89
|
Cliffords in the RB study.
|
|
101
90
|
|
|
@@ -138,7 +127,7 @@ class RandomizedBenchMarkResult:
|
|
|
138
127
|
p = opt_params[2]
|
|
139
128
|
return (1.0 - 1.0 / 4.0) * (1.0 - p)
|
|
140
129
|
|
|
141
|
-
def _fit_exponential(self) ->
|
|
130
|
+
def _fit_exponential(self) -> tuple[np.ndarray, np.ndarray]:
|
|
142
131
|
exp_fit = lambda x, A, B, p: A * p**x + B
|
|
143
132
|
return curve_fit(
|
|
144
133
|
f=exp_fit,
|
|
@@ -156,7 +145,7 @@ class ParallelRandomizedBenchmarkingResult:
|
|
|
156
145
|
results_dictionary: Mapping[cirq.Qid, RandomizedBenchMarkResult]
|
|
157
146
|
|
|
158
147
|
def plot_single_qubit(
|
|
159
|
-
self, qubit: cirq.Qid, ax:
|
|
148
|
+
self, qubit: cirq.Qid, ax: plt.Axes | None = None, **plot_kwargs: Any
|
|
160
149
|
) -> plt.Axes:
|
|
161
150
|
"""Plot the raw data for the specified qubit.
|
|
162
151
|
|
|
@@ -183,7 +172,7 @@ class ParallelRandomizedBenchmarkingResult:
|
|
|
183
172
|
|
|
184
173
|
def plot_heatmap(
|
|
185
174
|
self,
|
|
186
|
-
ax:
|
|
175
|
+
ax: plt.Axes | None = None,
|
|
187
176
|
annotation_format: str = '0.1%',
|
|
188
177
|
title: str = 'Single-qubit Pauli error',
|
|
189
178
|
**plot_kwargs: Any,
|
|
@@ -216,16 +205,16 @@ class ParallelRandomizedBenchmarkingResult:
|
|
|
216
205
|
|
|
217
206
|
def plot_integrated_histogram(
|
|
218
207
|
self,
|
|
219
|
-
ax:
|
|
208
|
+
ax: plt.Axes | None = None,
|
|
220
209
|
cdf_on_x: bool = False,
|
|
221
210
|
axis_label: str = 'Pauli error',
|
|
222
211
|
semilog: bool = True,
|
|
223
212
|
median_line: bool = True,
|
|
224
|
-
median_label:
|
|
213
|
+
median_label: str | None = 'median',
|
|
225
214
|
mean_line: bool = False,
|
|
226
|
-
mean_label:
|
|
215
|
+
mean_label: str | None = 'mean',
|
|
227
216
|
show_zero: bool = False,
|
|
228
|
-
title:
|
|
217
|
+
title: str | None = None,
|
|
229
218
|
**kwargs,
|
|
230
219
|
) -> plt.Axes:
|
|
231
220
|
"""Plot the Pauli errors using cirq.integrated_histogram().
|
|
@@ -289,8 +278,8 @@ class TomographyResult:
|
|
|
289
278
|
return self._density_matrix
|
|
290
279
|
|
|
291
280
|
def plot(
|
|
292
|
-
self, axes:
|
|
293
|
-
) ->
|
|
281
|
+
self, axes: list[plt.Axes] | None = None, **plot_kwargs: Any
|
|
282
|
+
) -> list[plt.Axes]: # pragma: no cover
|
|
294
283
|
"""Plots the real and imaginary parts of the density matrix as two 3D bar plots.
|
|
295
284
|
|
|
296
285
|
Args:
|
|
@@ -433,7 +422,7 @@ def parallel_single_qubit_randomized_benchmarking(
|
|
|
433
422
|
c1 = clifford_group.c1_in_xy if use_xy_basis else clifford_group.c1_in_xz
|
|
434
423
|
|
|
435
424
|
# create circuits
|
|
436
|
-
circuits_all:
|
|
425
|
+
circuits_all: list[cirq.AbstractCircuit] = []
|
|
437
426
|
for num_cliffords in num_clifford_range:
|
|
438
427
|
for _ in range(num_circuits):
|
|
439
428
|
circuits_all.append(_create_parallel_rb_circuit(qubits, num_cliffords, c1))
|
|
@@ -443,7 +432,7 @@ def parallel_single_qubit_randomized_benchmarking(
|
|
|
443
432
|
gnd_probs: dict = {q: [] for q in qubits}
|
|
444
433
|
idx = 0
|
|
445
434
|
for num_cliffords in num_clifford_range:
|
|
446
|
-
excited_probs:
|
|
435
|
+
excited_probs: dict[cirq.Qid, list[float]] = {q: [] for q in qubits}
|
|
447
436
|
for _ in range(num_circuits):
|
|
448
437
|
result = results[idx][0]
|
|
449
438
|
for qubit in qubits:
|
|
@@ -702,7 +691,7 @@ def _create_parallel_rb_circuit(
|
|
|
702
691
|
return circuits.Circuit.from_moments(*moments, ops.measure_each(*qubits))
|
|
703
692
|
|
|
704
693
|
|
|
705
|
-
def _indices_after_basis_rot(i: int, j: int) ->
|
|
694
|
+
def _indices_after_basis_rot(i: int, j: int) -> tuple[int, Sequence[int], Sequence[int]]:
|
|
706
695
|
mat_idx = 3 * (3 * i + j)
|
|
707
696
|
q_0_i = 3 - i
|
|
708
697
|
q_1_j = 3 - j
|
|
@@ -742,7 +731,7 @@ def _two_qubit_clifford_matrices(q_0: cirq.Qid, q_1: cirq.Qid, cliffords: Cliffo
|
|
|
742
731
|
|
|
743
732
|
def _random_single_q_clifford(
|
|
744
733
|
qubit: cirq.Qid, num_cfds: int, cfds: Sequence[Sequence[cirq.ops.SingleQubitCliffordGate]]
|
|
745
|
-
) ->
|
|
734
|
+
) -> list[cirq.Operation]:
|
|
746
735
|
clifford_group_size = 24
|
|
747
736
|
operations = [[gate.to_phased_xz_gate()(qubit) for gate in gates] for gates in cfds]
|
|
748
737
|
gate_ids = np.random.choice(clifford_group_size, num_cfds).tolist()
|
|
@@ -776,9 +765,9 @@ def _matrix_bar_plot(
|
|
|
776
765
|
mat: np.ndarray,
|
|
777
766
|
z_label: str,
|
|
778
767
|
ax: mplot3d.axes3d.Axes3D,
|
|
779
|
-
kets:
|
|
780
|
-
title:
|
|
781
|
-
ylim:
|
|
768
|
+
kets: Sequence[str] | None = None,
|
|
769
|
+
title: str | None = None,
|
|
770
|
+
ylim: tuple[int, int] = (-1, 1),
|
|
782
771
|
**bar3d_kwargs: Any,
|
|
783
772
|
) -> None: # pragma: no cover
|
|
784
773
|
num_rows, num_cols = mat.shape
|
|
@@ -927,8 +916,8 @@ def _single_qubit_cliffords() -> Cliffords:
|
|
|
927
916
|
ops.SingleQubitCliffordGate.Z,
|
|
928
917
|
)
|
|
929
918
|
|
|
930
|
-
c1_in_xy:
|
|
931
|
-
c1_in_xz:
|
|
919
|
+
c1_in_xy: list[list[ops.SingleQubitCliffordGate]] = []
|
|
920
|
+
c1_in_xz: list[list[ops.SingleQubitCliffordGate]] = []
|
|
932
921
|
|
|
933
922
|
for phi_0, phi_1 in itertools.product([1.0, 0.5, -0.5], [0.0, 0.5, -0.5]):
|
|
934
923
|
c1_in_xy.append([X**phi_0, Y**phi_1])
|
|
@@ -951,9 +940,9 @@ def _single_qubit_cliffords() -> Cliffords:
|
|
|
951
940
|
for z0, x, z1 in phi_xz:
|
|
952
941
|
c1_in_xz.append([Z**z0, X**x, Z**z1])
|
|
953
942
|
|
|
954
|
-
s1:
|
|
955
|
-
s1_x:
|
|
956
|
-
s1_y:
|
|
943
|
+
s1: list[list[ops.SingleQubitCliffordGate]] = [[X**0.0], [Y**0.5, X**0.5], [X**-0.5, Y**-0.5]]
|
|
944
|
+
s1_x: list[list[ops.SingleQubitCliffordGate]] = [[X**0.5], [X**0.5, Y**0.5, X**0.5], [Y**-0.5]]
|
|
945
|
+
s1_y: list[list[ops.SingleQubitCliffordGate]] = [
|
|
957
946
|
[Y**0.5],
|
|
958
947
|
[X**-0.5, Y**-0.5, X**0.5],
|
|
959
948
|
[Y, X**0.5],
|
|
@@ -221,7 +221,7 @@ def test_tomography_plot_raises_for_incorrect_number_of_axes():
|
|
|
221
221
|
qubit = GridQubit(0, 0)
|
|
222
222
|
circuit = circuits.Circuit(ops.X(qubit) ** 0.5)
|
|
223
223
|
result = single_qubit_state_tomography(simulator, qubit, circuit, 1000)
|
|
224
|
-
with pytest.raises(TypeError): # ax is not a
|
|
224
|
+
with pytest.raises(TypeError): # ax is not a list[plt.Axes]
|
|
225
225
|
ax = plt.subplot()
|
|
226
226
|
result.plot(ax)
|
|
227
227
|
with pytest.raises(ValueError):
|