cirq-core 1.5.0.dev20250409222543__py3-none-any.whl → 1.6.0__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/__init__.py +16 -17
- cirq/_compat.py +21 -20
- cirq/_compat_test.py +14 -34
- cirq/_doc.py +4 -2
- cirq/_import.py +8 -6
- cirq/_import_test.py +4 -2
- cirq/_version.py +6 -6
- cirq/_version_test.py +2 -2
- cirq/circuits/_block_diagram_drawer.py +11 -10
- cirq/circuits/_block_diagram_drawer_test.py +8 -6
- cirq/circuits/_box_drawing_character_data.py +8 -8
- cirq/circuits/_box_drawing_character_data_test.py +3 -1
- cirq/circuits/_bucket_priority_queue.py +9 -7
- cirq/circuits/_bucket_priority_queue_test.py +22 -20
- cirq/circuits/circuit.py +248 -172
- cirq/circuits/circuit_operation.py +73 -83
- cirq/circuits/circuit_operation_test.py +128 -90
- cirq/circuits/circuit_test.py +211 -151
- cirq/circuits/frozen_circuit.py +23 -60
- cirq/circuits/frozen_circuit_test.py +31 -8
- cirq/circuits/insert_strategy.py +7 -5
- cirq/circuits/insert_strategy_test.py +4 -2
- cirq/circuits/moment.py +88 -40
- cirq/circuits/moment_test.py +128 -51
- cirq/circuits/optimization_pass.py +5 -5
- cirq/circuits/optimization_pass_test.py +10 -10
- cirq/circuits/qasm_output.py +11 -11
- cirq/circuits/qasm_output_test.py +25 -22
- cirq/circuits/text_diagram_drawer.py +23 -38
- cirq/circuits/text_diagram_drawer_test.py +19 -17
- cirq/conftest.py +4 -3
- cirq/contrib/__init__.py +4 -4
- cirq/contrib/acquaintance/__init__.py +1 -1
- cirq/contrib/acquaintance/bipartite.py +5 -8
- cirq/contrib/acquaintance/bipartite_test.py +18 -13
- cirq/contrib/acquaintance/devices.py +2 -2
- cirq/contrib/acquaintance/devices_test.py +5 -3
- cirq/contrib/acquaintance/executor.py +5 -5
- cirq/contrib/acquaintance/executor_test.py +13 -9
- cirq/contrib/acquaintance/gates.py +18 -28
- cirq/contrib/acquaintance/gates_test.py +24 -20
- cirq/contrib/acquaintance/inspection_utils.py +8 -4
- cirq/contrib/acquaintance/inspection_utils_test.py +4 -2
- cirq/contrib/acquaintance/mutation_utils.py +4 -4
- cirq/contrib/acquaintance/mutation_utils_test.py +4 -2
- cirq/contrib/acquaintance/optimizers.py +4 -4
- cirq/contrib/acquaintance/optimizers_test.py +4 -1
- cirq/contrib/acquaintance/permutation.py +15 -27
- cirq/contrib/acquaintance/permutation_test.py +26 -17
- cirq/contrib/acquaintance/shift.py +4 -4
- cirq/contrib/acquaintance/shift_swap_network.py +4 -4
- cirq/contrib/acquaintance/shift_swap_network_test.py +9 -6
- cirq/contrib/acquaintance/shift_test.py +8 -6
- cirq/contrib/acquaintance/strategies/cubic.py +2 -2
- cirq/contrib/acquaintance/strategies/cubic_test.py +4 -2
- cirq/contrib/acquaintance/strategies/quartic_paired.py +6 -6
- cirq/contrib/acquaintance/strategies/quartic_paired_test.py +10 -6
- cirq/contrib/acquaintance/testing.py +2 -0
- cirq/contrib/acquaintance/topological_sort.py +2 -2
- cirq/contrib/acquaintance/topological_sort_test.py +3 -1
- cirq/contrib/bayesian_network/bayesian_network_gate.py +9 -10
- cirq/contrib/bayesian_network/bayesian_network_gate_test.py +14 -9
- cirq/contrib/circuitdag/circuit_dag.py +4 -4
- cirq/contrib/circuitdag/circuit_dag_test.py +17 -15
- cirq/contrib/custom_simulators/custom_state_simulator.py +5 -5
- cirq/contrib/custom_simulators/custom_state_simulator_test.py +22 -17
- cirq/contrib/graph_device/graph_device.py +12 -11
- cirq/contrib/graph_device/graph_device_test.py +18 -14
- cirq/contrib/graph_device/hypergraph.py +16 -14
- cirq/contrib/graph_device/hypergraph_test.py +13 -11
- cirq/contrib/graph_device/uniform_graph_device.py +6 -4
- cirq/contrib/graph_device/uniform_graph_device_test.py +11 -3
- cirq/contrib/hacks/disable_validation.py +6 -1
- cirq/contrib/hacks/disable_validation_test.py +3 -1
- cirq/contrib/json.py +31 -5
- cirq/contrib/json_test.py +6 -3
- cirq/contrib/json_test_data/DampedReadoutNoiseModel.json +12 -0
- cirq/contrib/json_test_data/DampedReadoutNoiseModel.repr +4 -0
- cirq/contrib/json_test_data/DepolarizingNoiseModel.json +12 -0
- cirq/contrib/json_test_data/DepolarizingNoiseModel.repr +4 -0
- cirq/contrib/json_test_data/DepolarizingWithDampedReadoutNoiseModel.json +6 -0
- cirq/contrib/json_test_data/DepolarizingWithDampedReadoutNoiseModel.repr +1 -0
- cirq/contrib/json_test_data/DepolarizingWithReadoutNoiseModel.json +5 -0
- cirq/contrib/json_test_data/DepolarizingWithReadoutNoiseModel.repr +1 -0
- cirq/contrib/json_test_data/ReadoutNoiseModel.json +12 -0
- cirq/contrib/json_test_data/ReadoutNoiseModel.repr +4 -0
- cirq/contrib/json_test_data/__init__.py +17 -0
- cirq/contrib/json_test_data/spec.py +32 -0
- cirq/contrib/noise_models/noise_models.py +119 -5
- cirq/contrib/noise_models/noise_models_test.py +37 -9
- cirq/contrib/paulistring/clifford_optimize.py +6 -4
- cirq/contrib/paulistring/clifford_optimize_test.py +6 -5
- cirq/contrib/paulistring/clifford_target_gateset.py +10 -10
- cirq/contrib/paulistring/clifford_target_gateset_test.py +13 -11
- cirq/contrib/paulistring/optimize.py +2 -0
- cirq/contrib/paulistring/optimize_test.py +4 -3
- cirq/contrib/paulistring/pauli_string_dag.py +2 -0
- cirq/contrib/paulistring/pauli_string_dag_test.py +3 -1
- cirq/contrib/paulistring/pauli_string_measurement_with_readout_mitigation.py +255 -120
- cirq/contrib/paulistring/pauli_string_measurement_with_readout_mitigation_test.py +398 -19
- cirq/contrib/paulistring/pauli_string_optimize.py +7 -1
- cirq/contrib/paulistring/pauli_string_optimize_test.py +5 -3
- cirq/contrib/paulistring/recombine.py +6 -4
- cirq/contrib/paulistring/recombine_test.py +3 -1
- cirq/contrib/paulistring/separate.py +9 -6
- cirq/contrib/paulistring/separate_test.py +3 -1
- cirq/contrib/qasm_import/_lexer.py +3 -2
- cirq/contrib/qasm_import/_lexer_test.py +49 -13
- cirq/contrib/qasm_import/_parser.py +547 -83
- cirq/contrib/qasm_import/_parser_test.py +988 -97
- cirq/contrib/qasm_import/exception.py +2 -0
- cirq/contrib/qasm_import/qasm.py +8 -2
- cirq/contrib/qasm_import/qasm_test.py +7 -4
- cirq/contrib/qcircuit/qcircuit_diagram_info.py +5 -5
- cirq/contrib/qcircuit/qcircuit_diagram_info_test.py +4 -1
- cirq/contrib/qcircuit/qcircuit_pdf.py +7 -3
- cirq/contrib/qcircuit/qcircuit_pdf_test.py +3 -1
- cirq/contrib/qcircuit/qcircuit_test.py +10 -8
- cirq/contrib/quantum_volume/quantum_volume.py +31 -27
- cirq/contrib/quantum_volume/quantum_volume_test.py +19 -16
- cirq/contrib/quimb/density_matrix.py +15 -14
- cirq/contrib/quimb/density_matrix_test.py +10 -7
- cirq/contrib/quimb/grid_circuits.py +5 -2
- cirq/contrib/quimb/grid_circuits_test.py +3 -0
- cirq/contrib/quimb/mps_simulator.py +20 -20
- cirq/contrib/quimb/mps_simulator_test.py +3 -0
- cirq/contrib/quimb/state_vector.py +12 -11
- cirq/contrib/quimb/state_vector_test.py +3 -0
- cirq/contrib/quirk/export_to_quirk.py +5 -3
- cirq/contrib/quirk/export_to_quirk_test.py +18 -16
- cirq/contrib/quirk/linearize_circuit.py +2 -0
- cirq/contrib/quirk/quirk_gate.py +18 -17
- cirq/contrib/routing/device.py +5 -3
- cirq/contrib/routing/device_test.py +2 -0
- cirq/contrib/routing/greedy.py +10 -21
- cirq/contrib/routing/greedy_test.py +4 -2
- cirq/contrib/routing/initialization.py +2 -2
- cirq/contrib/routing/initialization_test.py +5 -3
- cirq/contrib/routing/router.py +9 -5
- cirq/contrib/routing/router_test.py +2 -0
- cirq/contrib/routing/swap_network.py +3 -3
- cirq/contrib/routing/swap_network_test.py +3 -1
- cirq/contrib/routing/utils.py +2 -2
- cirq/contrib/routing/utils_test.py +3 -0
- cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking.py +15 -9
- cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking_test.py +3 -0
- cirq/contrib/svg/svg.py +3 -3
- cirq/contrib/svg/svg_test.py +8 -5
- cirq/devices/device.py +4 -4
- cirq/devices/device_test.py +7 -4
- cirq/devices/grid_device_metadata.py +10 -10
- cirq/devices/grid_device_metadata_test.py +3 -0
- cirq/devices/grid_qubit.py +29 -21
- cirq/devices/grid_qubit_test.py +3 -0
- cirq/devices/insertion_noise_model.py +7 -7
- cirq/devices/insertion_noise_model_test.py +7 -5
- cirq/devices/line_qubit.py +13 -13
- cirq/devices/line_qubit_test.py +2 -0
- cirq/devices/named_topologies.py +18 -29
- cirq/devices/named_topologies_test.py +13 -10
- cirq/devices/noise_model.py +3 -3
- cirq/devices/noise_model_test.py +19 -15
- cirq/devices/noise_properties.py +15 -6
- cirq/devices/noise_properties_test.py +34 -3
- cirq/devices/noise_utils.py +11 -9
- cirq/devices/noise_utils_test.py +2 -0
- cirq/devices/superconducting_qubits_noise_properties.py +23 -22
- cirq/devices/superconducting_qubits_noise_properties_test.py +6 -6
- cirq/devices/thermal_noise_model.py +107 -37
- cirq/devices/thermal_noise_model_test.py +21 -0
- cirq/devices/unconstrained_device.py +5 -3
- cirq/devices/unconstrained_device_test.py +2 -0
- cirq/experiments/__init__.py +4 -2
- cirq/experiments/benchmarking/__init__.py +17 -0
- cirq/experiments/benchmarking/parallel_xeb.py +677 -0
- cirq/experiments/benchmarking/parallel_xeb_test.py +447 -0
- cirq/experiments/fidelity_estimation.py +14 -8
- cirq/experiments/fidelity_estimation_test.py +3 -0
- cirq/experiments/n_qubit_tomography.py +17 -16
- cirq/experiments/n_qubit_tomography_test.py +8 -5
- cirq/experiments/purity_estimation.py +2 -0
- cirq/experiments/purity_estimation_test.py +2 -0
- cirq/experiments/qubit_characterizations.py +207 -103
- cirq/experiments/qubit_characterizations_test.py +40 -12
- cirq/experiments/random_quantum_circuit_generation.py +56 -70
- cirq/experiments/random_quantum_circuit_generation_test.py +11 -8
- cirq/experiments/readout_confusion_matrix.py +24 -22
- cirq/experiments/readout_confusion_matrix_test.py +2 -0
- cirq/experiments/single_qubit_readout_calibration.py +30 -15
- cirq/experiments/single_qubit_readout_calibration_test.py +5 -2
- cirq/experiments/t1_decay_experiment.py +9 -7
- cirq/experiments/t1_decay_experiment_test.py +13 -11
- cirq/experiments/t2_decay_experiment.py +16 -13
- cirq/experiments/t2_decay_experiment_test.py +2 -0
- cirq/experiments/two_qubit_xeb.py +64 -57
- cirq/experiments/two_qubit_xeb_test.py +10 -6
- cirq/experiments/xeb_fitting.py +39 -35
- cirq/experiments/xeb_sampling.py +37 -44
- cirq/experiments/xeb_sampling_test.py +3 -0
- cirq/experiments/xeb_simulation.py +14 -10
- cirq/experiments/xeb_simulation_test.py +5 -5
- cirq/experiments/z_phase_calibration.py +32 -29
- cirq/experiments/z_phase_calibration_test.py +3 -4
- cirq/interop/quirk/cells/__init__.py +1 -1
- cirq/interop/quirk/cells/all_cells.py +7 -2
- cirq/interop/quirk/cells/arithmetic_cells.py +29 -41
- cirq/interop/quirk/cells/arithmetic_cells_test.py +17 -14
- cirq/interop/quirk/cells/cell.py +19 -28
- cirq/interop/quirk/cells/cell_test.py +3 -0
- cirq/interop/quirk/cells/composite_cell.py +13 -28
- cirq/interop/quirk/cells/composite_cell_test.py +2 -0
- cirq/interop/quirk/cells/control_cells.py +15 -15
- cirq/interop/quirk/cells/control_cells_test.py +7 -5
- cirq/interop/quirk/cells/frequency_space_cells.py +4 -3
- cirq/interop/quirk/cells/frequency_space_cells_test.py +3 -1
- cirq/interop/quirk/cells/ignored_cells.py +3 -0
- cirq/interop/quirk/cells/ignored_cells_test.py +3 -1
- cirq/interop/quirk/cells/input_cells.py +7 -5
- cirq/interop/quirk/cells/input_cells_test.py +7 -5
- cirq/interop/quirk/cells/input_rotation_cells.py +15 -13
- cirq/interop/quirk/cells/input_rotation_cells_test.py +9 -7
- cirq/interop/quirk/cells/measurement_cells.py +5 -2
- cirq/interop/quirk/cells/measurement_cells_test.py +3 -1
- cirq/interop/quirk/cells/parse.py +22 -23
- cirq/interop/quirk/cells/parse_test.py +12 -10
- cirq/interop/quirk/cells/qubit_permutation_cells.py +5 -3
- cirq/interop/quirk/cells/qubit_permutation_cells_test.py +9 -7
- cirq/interop/quirk/cells/scalar_cells.py +4 -1
- cirq/interop/quirk/cells/scalar_cells_test.py +3 -1
- cirq/interop/quirk/cells/single_qubit_rotation_cells.py +5 -2
- cirq/interop/quirk/cells/single_qubit_rotation_cells_test.py +5 -3
- cirq/interop/quirk/cells/swap_cell.py +8 -6
- cirq/interop/quirk/cells/swap_cell_test.py +6 -4
- cirq/interop/quirk/cells/testing.py +6 -6
- cirq/interop/quirk/cells/testing_test.py +8 -6
- cirq/interop/quirk/cells/unsupported_cells.py +3 -0
- cirq/interop/quirk/cells/unsupported_cells_test.py +4 -2
- cirq/interop/quirk/url_to_circuit.py +23 -36
- cirq/interop/quirk/url_to_circuit_test.py +4 -1
- cirq/json_resolver_cache.py +14 -12
- cirq/linalg/__init__.py +4 -6
- cirq/linalg/combinators.py +7 -5
- cirq/linalg/combinators_test.py +10 -7
- cirq/linalg/decompositions.py +24 -35
- cirq/linalg/decompositions_test.py +3 -1
- cirq/linalg/diagonalize.py +6 -4
- cirq/linalg/diagonalize_test.py +15 -14
- cirq/linalg/operator_spaces.py +14 -14
- cirq/linalg/operator_spaces_test.py +13 -11
- cirq/linalg/predicates.py +18 -9
- cirq/linalg/predicates_test.py +5 -0
- cirq/linalg/tolerance.py +6 -3
- cirq/linalg/tolerance_test.py +6 -4
- cirq/linalg/transformations.py +23 -20
- cirq/linalg/transformations_test.py +73 -43
- cirq/neutral_atoms/convert_to_neutral_atom_gates.py +9 -3
- cirq/neutral_atoms/convert_to_neutral_atom_gates_test.py +3 -1
- cirq/neutral_atoms/neutral_atom_devices.py +2 -0
- cirq/ops/__init__.py +2 -0
- cirq/ops/arithmetic_operation.py +21 -21
- cirq/ops/arithmetic_operation_test.py +7 -8
- cirq/ops/boolean_hamiltonian.py +23 -22
- cirq/ops/boolean_hamiltonian_test.py +12 -9
- cirq/ops/classically_controlled_operation.py +31 -36
- cirq/ops/classically_controlled_operation_test.py +121 -117
- cirq/ops/clifford_gate.py +98 -81
- cirq/ops/clifford_gate_test.py +72 -57
- cirq/ops/common_channels.py +44 -44
- cirq/ops/common_channels_test.py +83 -81
- cirq/ops/common_gate_families.py +9 -7
- cirq/ops/common_gate_families_test.py +11 -7
- cirq/ops/common_gates.py +164 -183
- cirq/ops/common_gates_test.py +135 -95
- cirq/ops/control_values.py +23 -26
- cirq/ops/control_values_test.py +22 -20
- cirq/ops/controlled_gate.py +64 -112
- cirq/ops/controlled_gate_test.py +130 -35
- cirq/ops/controlled_operation.py +24 -35
- cirq/ops/controlled_operation_test.py +8 -6
- cirq/ops/dense_pauli_string.py +38 -49
- cirq/ops/dense_pauli_string_test.py +4 -2
- cirq/ops/diagonal_gate.py +18 -31
- cirq/ops/diagonal_gate_test.py +13 -13
- cirq/ops/eigen_gate.py +29 -29
- cirq/ops/eigen_gate_test.py +45 -28
- cirq/ops/fourier_transform.py +14 -20
- cirq/ops/fourier_transform_test.py +15 -12
- cirq/ops/fsim_gate.py +43 -42
- cirq/ops/fsim_gate_test.py +29 -29
- cirq/ops/gate_features.py +2 -0
- cirq/ops/gate_features_test.py +5 -3
- cirq/ops/gate_operation.py +43 -65
- cirq/ops/gate_operation_test.py +46 -42
- cirq/ops/gateset.py +28 -40
- cirq/ops/gateset_test.py +4 -2
- cirq/ops/global_phase_op.py +45 -20
- cirq/ops/global_phase_op_test.py +44 -20
- cirq/ops/greedy_qubit_manager.py +10 -8
- cirq/ops/greedy_qubit_manager_test.py +5 -3
- cirq/ops/identity.py +14 -12
- cirq/ops/identity_test.py +24 -20
- cirq/ops/kraus_channel.py +11 -8
- cirq/ops/kraus_channel_test.py +14 -11
- cirq/ops/linear_combinations.py +65 -77
- cirq/ops/linear_combinations_test.py +14 -9
- cirq/ops/matrix_gates.py +21 -18
- cirq/ops/matrix_gates_test.py +16 -0
- cirq/ops/measure_util.py +15 -20
- cirq/ops/measure_util_test.py +2 -0
- cirq/ops/measurement_gate.py +26 -37
- cirq/ops/measurement_gate_test.py +2 -0
- cirq/ops/mixed_unitary_channel.py +12 -9
- cirq/ops/mixed_unitary_channel_test.py +14 -11
- cirq/ops/named_qubit.py +16 -13
- cirq/ops/named_qubit_test.py +15 -13
- cirq/ops/op_tree.py +9 -7
- cirq/ops/op_tree_test.py +22 -19
- cirq/ops/parallel_gate.py +15 -17
- cirq/ops/parallel_gate_test.py +18 -16
- cirq/ops/parity_gates.py +23 -25
- cirq/ops/parity_gates_test.py +36 -32
- cirq/ops/pauli_gates.py +22 -21
- cirq/ops/pauli_gates_test.py +29 -20
- cirq/ops/pauli_interaction_gate.py +15 -19
- cirq/ops/pauli_interaction_gate_test.py +10 -8
- cirq/ops/pauli_measurement_gate.py +23 -35
- cirq/ops/pauli_measurement_gate_test.py +2 -0
- cirq/ops/pauli_string.py +92 -120
- cirq/ops/pauli_string_phasor.py +52 -45
- cirq/ops/pauli_string_phasor_test.py +4 -5
- cirq/ops/pauli_string_raw_types.py +9 -7
- cirq/ops/pauli_string_raw_types_test.py +2 -0
- cirq/ops/pauli_string_test.py +31 -154
- cirq/ops/pauli_sum_exponential.py +12 -12
- cirq/ops/pauli_sum_exponential_test.py +12 -10
- cirq/ops/permutation_gate.py +8 -6
- cirq/ops/permutation_gate_test.py +10 -8
- cirq/ops/phased_iswap_gate.py +16 -16
- cirq/ops/phased_iswap_gate_test.py +17 -15
- cirq/ops/phased_x_gate.py +16 -17
- cirq/ops/phased_x_gate_test.py +18 -16
- cirq/ops/phased_x_z_gate.py +24 -22
- cirq/ops/phased_x_z_gate_test.py +17 -11
- cirq/ops/projector.py +16 -11
- cirq/ops/projector_test.py +19 -16
- cirq/ops/qid_util.py +7 -5
- cirq/ops/qid_util_test.py +2 -0
- cirq/ops/qubit_manager.py +11 -9
- cirq/ops/qubit_manager_test.py +6 -4
- cirq/ops/qubit_order.py +11 -14
- cirq/ops/qubit_order_or_list.py +4 -2
- cirq/ops/qubit_order_test.py +12 -10
- cirq/ops/random_gate_channel.py +12 -10
- cirq/ops/random_gate_channel_test.py +14 -11
- cirq/ops/raw_types.py +109 -129
- cirq/ops/raw_types_test.py +63 -57
- cirq/ops/state_preparation_channel.py +7 -7
- cirq/ops/state_preparation_channel_test.py +11 -9
- cirq/ops/swap_gates.py +13 -15
- cirq/ops/swap_gates_test.py +19 -17
- cirq/ops/tags.py +5 -3
- cirq/ops/tags_test.py +4 -2
- cirq/ops/three_qubit_gates.py +43 -76
- cirq/ops/three_qubit_gates_test.py +19 -17
- cirq/ops/two_qubit_diagonal_gate.py +13 -13
- cirq/ops/two_qubit_diagonal_gate_test.py +10 -8
- cirq/ops/uniform_superposition_gate.py +5 -3
- cirq/ops/uniform_superposition_gate_test.py +5 -3
- cirq/ops/wait_gate.py +17 -14
- cirq/ops/wait_gate_test.py +9 -6
- cirq/protocols/__init__.py +0 -3
- cirq/protocols/act_on_protocol.py +8 -6
- cirq/protocols/act_on_protocol_test.py +15 -12
- cirq/protocols/apply_channel_protocol.py +10 -14
- cirq/protocols/apply_channel_protocol_test.py +2 -0
- cirq/protocols/apply_mixture_protocol.py +13 -42
- cirq/protocols/apply_mixture_protocol_test.py +7 -5
- cirq/protocols/apply_unitary_protocol.py +39 -34
- cirq/protocols/apply_unitary_protocol_test.py +4 -1
- cirq/protocols/approximate_equality_protocol.py +2 -0
- cirq/protocols/approximate_equality_protocol_test.py +2 -0
- cirq/protocols/circuit_diagram_info_protocol.py +58 -42
- cirq/protocols/circuit_diagram_info_protocol_test.py +70 -12
- cirq/protocols/commutes_protocol.py +8 -7
- cirq/protocols/commutes_protocol_test.py +2 -0
- cirq/protocols/control_key_protocol.py +6 -4
- cirq/protocols/control_key_protocol_test.py +3 -1
- cirq/protocols/decompose_protocol.py +49 -48
- cirq/protocols/decompose_protocol_test.py +27 -16
- cirq/protocols/equal_up_to_global_phase_protocol.py +2 -0
- cirq/protocols/equal_up_to_global_phase_protocol_test.py +9 -6
- cirq/protocols/has_stabilizer_effect_protocol.py +7 -5
- cirq/protocols/has_stabilizer_effect_protocol_test.py +7 -5
- cirq/protocols/has_unitary_protocol.py +10 -6
- cirq/protocols/has_unitary_protocol_test.py +13 -8
- cirq/protocols/hash_from_pickle_test.py +2 -11
- cirq/protocols/inverse_protocol.py +13 -16
- cirq/protocols/inverse_protocol_test.py +5 -3
- cirq/protocols/json_serialization.py +35 -54
- cirq/protocols/json_serialization_test.py +14 -21
- cirq/protocols/json_test_data/CXSWAP.json +46 -0
- cirq/protocols/json_test_data/CXSWAP.repr +13 -0
- cirq/protocols/json_test_data/CZSWAP.json +46 -0
- cirq/protocols/json_test_data/CZSWAP.repr +13 -0
- cirq/protocols/json_test_data/CircuitOperation.json +6 -3
- cirq/protocols/json_test_data/CircuitOperation.repr_inward +4 -2
- cirq/protocols/json_test_data/Moment.json +24 -1
- cirq/protocols/json_test_data/Moment.repr +6 -1
- cirq/protocols/json_test_data/ThermalNoiseModel.json +32 -0
- cirq/protocols/json_test_data/ThermalNoiseModel.repr +1 -0
- cirq/protocols/json_test_data/spec.py +6 -2
- cirq/protocols/kraus_protocol.py +47 -7
- cirq/protocols/kraus_protocol_test.py +86 -12
- cirq/protocols/measurement_key_protocol.py +15 -16
- cirq/protocols/measurement_key_protocol_test.py +13 -11
- cirq/protocols/mixture_protocol.py +7 -5
- cirq/protocols/mixture_protocol_test.py +4 -2
- cirq/protocols/mul_protocol.py +2 -3
- cirq/protocols/mul_protocol_test.py +2 -0
- cirq/protocols/pauli_expansion_protocol.py +6 -3
- cirq/protocols/pauli_expansion_protocol_test.py +5 -3
- cirq/protocols/phase_protocol.py +2 -0
- cirq/protocols/phase_protocol_test.py +3 -1
- cirq/protocols/pow_protocol.py +11 -16
- cirq/protocols/pow_protocol_test.py +2 -0
- cirq/protocols/qasm.py +14 -20
- cirq/protocols/qasm_test.py +6 -3
- cirq/protocols/qid_shape_protocol.py +8 -8
- cirq/protocols/qid_shape_protocol_test.py +3 -1
- cirq/protocols/resolve_parameters.py +5 -3
- cirq/protocols/resolve_parameters_test.py +8 -7
- cirq/protocols/trace_distance_bound.py +6 -4
- cirq/protocols/trace_distance_bound_test.py +3 -1
- cirq/protocols/unitary_protocol.py +17 -7
- cirq/protocols/unitary_protocol_test.py +12 -2
- cirq/qis/channels.py +6 -2
- cirq/qis/channels_test.py +20 -16
- cirq/qis/clifford_tableau.py +21 -19
- cirq/qis/clifford_tableau_test.py +2 -2
- cirq/qis/entropy.py +14 -3
- cirq/qis/entropy_test.py +3 -1
- cirq/qis/measures.py +13 -13
- cirq/qis/measures_test.py +20 -14
- cirq/qis/noise_utils.py +2 -0
- cirq/qis/noise_utils_test.py +9 -7
- cirq/qis/quantum_state_representation.py +7 -8
- cirq/qis/states.py +58 -56
- cirq/qis/states_test.py +2 -0
- cirq/sim/classical_simulator.py +23 -22
- cirq/sim/classical_simulator_test.py +2 -0
- cirq/sim/clifford/clifford_simulator.py +23 -21
- cirq/sim/clifford/clifford_simulator_test.py +7 -4
- cirq/sim/clifford/clifford_tableau_simulation_state.py +10 -7
- cirq/sim/clifford/clifford_tableau_simulation_state_test.py +5 -5
- cirq/sim/clifford/stabilizer_ch_form_simulation_state.py +8 -6
- cirq/sim/clifford/stabilizer_ch_form_simulation_state_test.py +8 -6
- cirq/sim/clifford/stabilizer_sampler.py +9 -7
- cirq/sim/clifford/stabilizer_sampler_test.py +4 -2
- cirq/sim/clifford/stabilizer_simulation_state.py +14 -13
- cirq/sim/clifford/stabilizer_simulation_state_test.py +6 -4
- cirq/sim/clifford/stabilizer_state_ch_form.py +13 -11
- cirq/sim/clifford/stabilizer_state_ch_form_test.py +4 -2
- cirq/sim/density_matrix_simulation_state.py +26 -27
- cirq/sim/density_matrix_simulation_state_test.py +10 -8
- cirq/sim/density_matrix_simulator.py +30 -28
- cirq/sim/density_matrix_simulator_test.py +48 -48
- cirq/sim/density_matrix_utils.py +13 -11
- cirq/sim/density_matrix_utils_test.py +38 -36
- cirq/sim/mux.py +33 -31
- cirq/sim/mux_test.py +3 -0
- cirq/sim/simulation_product_state.py +15 -15
- cirq/sim/simulation_product_state_test.py +29 -26
- cirq/sim/simulation_state.py +29 -38
- cirq/sim/simulation_state_base.py +21 -32
- cirq/sim/simulation_state_test.py +15 -13
- cirq/sim/simulation_utils.py +5 -2
- cirq/sim/simulation_utils_test.py +5 -2
- cirq/sim/simulator.py +90 -106
- cirq/sim/simulator_base.py +33 -45
- cirq/sim/simulator_base_test.py +20 -15
- cirq/sim/simulator_test.py +23 -14
- cirq/sim/sparse_simulator.py +19 -17
- cirq/sim/sparse_simulator_test.py +41 -40
- cirq/sim/state_vector.py +15 -12
- cirq/sim/state_vector_simulation_state.py +31 -31
- cirq/sim/state_vector_simulation_state_test.py +16 -14
- cirq/sim/state_vector_simulator.py +17 -14
- cirq/sim/state_vector_simulator_test.py +2 -0
- cirq/sim/state_vector_test.py +6 -3
- cirq/study/flatten_expressions.py +16 -15
- cirq/study/flatten_expressions_test.py +13 -11
- cirq/study/resolver.py +18 -17
- cirq/study/resolver_test.py +22 -20
- cirq/study/result.py +17 -27
- cirq/study/result_test.py +2 -0
- cirq/study/sweepable.py +12 -10
- cirq/study/sweepable_test.py +3 -0
- cirq/study/sweeps.py +42 -61
- cirq/study/sweeps_test.py +33 -0
- cirq/testing/__init__.py +7 -11
- cirq/testing/_compat_test_data/module_a/__init__.py +1 -0
- cirq/testing/_compat_test_data/module_a/module_b/__init__.py +1 -0
- cirq/testing/_compat_test_data/module_a/sub/__init__.py +1 -0
- cirq/testing/circuit_compare.py +8 -17
- cirq/testing/circuit_compare_test.py +2 -0
- cirq/testing/consistent_act_on.py +13 -11
- cirq/testing/consistent_act_on_test.py +5 -3
- cirq/testing/consistent_channels.py +2 -0
- cirq/testing/consistent_channels_test.py +10 -8
- cirq/testing/consistent_controlled_gate_op.py +5 -5
- cirq/testing/consistent_controlled_gate_op_test.py +18 -18
- cirq/testing/consistent_decomposition.py +2 -2
- cirq/testing/consistent_decomposition_test.py +4 -2
- cirq/testing/consistent_pauli_expansion.py +2 -0
- cirq/testing/consistent_pauli_expansion_test.py +3 -1
- cirq/testing/consistent_phase_by.py +2 -0
- cirq/testing/consistent_phase_by_test.py +3 -1
- cirq/testing/consistent_protocols.py +14 -20
- cirq/testing/consistent_protocols_test.py +13 -11
- cirq/testing/consistent_qasm.py +6 -4
- cirq/testing/consistent_qasm_test.py +7 -7
- cirq/testing/consistent_resolve_parameters.py +2 -0
- cirq/testing/consistent_specified_has_unitary.py +2 -2
- cirq/testing/consistent_specified_has_unitary_test.py +6 -4
- cirq/testing/consistent_unitary.py +1 -0
- cirq/testing/consistent_unitary_test.py +4 -2
- cirq/testing/deprecation.py +5 -2
- cirq/testing/deprecation_test.py +5 -2
- cirq/testing/devices.py +7 -4
- cirq/testing/devices_test.py +7 -4
- cirq/testing/equals_tester.py +4 -2
- cirq/testing/equals_tester_test.py +21 -17
- cirq/testing/equivalent_basis_map.py +6 -4
- cirq/testing/equivalent_basis_map_test.py +6 -4
- cirq/testing/equivalent_repr_eval.py +6 -4
- cirq/testing/equivalent_repr_eval_test.py +5 -3
- cirq/testing/gate_features.py +2 -0
- cirq/testing/gate_features_test.py +7 -5
- cirq/testing/json.py +19 -15
- cirq/testing/json_test.py +5 -3
- cirq/testing/lin_alg_utils.py +10 -11
- cirq/testing/lin_alg_utils_test.py +14 -12
- cirq/testing/logs.py +7 -6
- cirq/testing/logs_test.py +9 -7
- cirq/testing/no_identifier_qubit.py +4 -2
- cirq/testing/no_identifier_qubit_test.py +5 -3
- cirq/testing/op_tree.py +2 -0
- cirq/testing/op_tree_test.py +4 -1
- cirq/testing/order_tester.py +2 -0
- cirq/testing/order_tester_test.py +8 -6
- cirq/testing/pytest_utils.py +2 -0
- cirq/testing/pytest_utils_test.py +4 -2
- cirq/testing/random_circuit.py +21 -20
- cirq/testing/random_circuit_test.py +12 -9
- cirq/testing/repr_pretty_tester.py +1 -0
- cirq/testing/repr_pretty_tester_test.py +5 -3
- cirq/testing/routing_devices.py +4 -1
- cirq/testing/routing_devices_test.py +9 -6
- cirq/testing/sample_circuits.py +4 -1
- cirq/testing/sample_circuits_test.py +3 -1
- cirq/testing/sample_gates.py +3 -0
- cirq/testing/sample_gates_test.py +5 -2
- cirq/transformers/__init__.py +11 -4
- cirq/transformers/align.py +9 -7
- cirq/transformers/align_test.py +2 -0
- cirq/transformers/analytical_decompositions/__init__.py +3 -6
- cirq/transformers/analytical_decompositions/clifford_decomposition.py +18 -16
- cirq/transformers/analytical_decompositions/clifford_decomposition_test.py +2 -0
- cirq/transformers/analytical_decompositions/controlled_gate_decomposition.py +19 -16
- cirq/transformers/analytical_decompositions/controlled_gate_decomposition_test.py +2 -0
- cirq/transformers/analytical_decompositions/cphase_to_fsim.py +11 -9
- cirq/transformers/analytical_decompositions/cphase_to_fsim_test.py +5 -3
- cirq/transformers/analytical_decompositions/pauli_string_decomposition.py +5 -3
- cirq/transformers/analytical_decompositions/pauli_string_decomposition_test.py +5 -3
- cirq/transformers/analytical_decompositions/quantum_shannon_decomposition.py +141 -44
- cirq/transformers/analytical_decompositions/quantum_shannon_decomposition_test.py +35 -1
- cirq/transformers/analytical_decompositions/single_qubit_decompositions.py +8 -7
- cirq/transformers/analytical_decompositions/single_qubit_decompositions_test.py +2 -0
- cirq/transformers/analytical_decompositions/single_to_two_qubit_isometry.py +7 -4
- cirq/transformers/analytical_decompositions/single_to_two_qubit_isometry_test.py +3 -0
- cirq/transformers/analytical_decompositions/three_qubit_decomposition.py +11 -19
- cirq/transformers/analytical_decompositions/three_qubit_decomposition_test.py +8 -33
- cirq/transformers/analytical_decompositions/two_qubit_state_preparation.py +9 -11
- cirq/transformers/analytical_decompositions/two_qubit_state_preparation_test.py +2 -0
- cirq/transformers/analytical_decompositions/two_qubit_to_cz.py +91 -27
- cirq/transformers/analytical_decompositions/two_qubit_to_cz_test.py +36 -7
- cirq/transformers/analytical_decompositions/two_qubit_to_fsim.py +20 -21
- cirq/transformers/analytical_decompositions/two_qubit_to_fsim_test.py +8 -6
- cirq/transformers/analytical_decompositions/two_qubit_to_ms.py +13 -15
- cirq/transformers/analytical_decompositions/two_qubit_to_ms_test.py +3 -1
- cirq/transformers/analytical_decompositions/two_qubit_to_sqrt_iswap.py +39 -41
- cirq/transformers/analytical_decompositions/two_qubit_to_sqrt_iswap_test.py +2 -0
- cirq/transformers/drop_empty_moments.py +5 -3
- cirq/transformers/drop_empty_moments_test.py +4 -2
- cirq/transformers/drop_negligible_operations.py +7 -5
- cirq/transformers/drop_negligible_operations_test.py +2 -0
- cirq/transformers/dynamical_decoupling.py +49 -42
- cirq/transformers/dynamical_decoupling_test.py +223 -205
- cirq/transformers/eject_phased_paulis.py +28 -26
- cirq/transformers/eject_phased_paulis_test.py +12 -9
- cirq/transformers/eject_z.py +12 -12
- cirq/transformers/eject_z_test.py +2 -2
- cirq/transformers/expand_composite.py +6 -4
- cirq/transformers/expand_composite_test.py +3 -1
- cirq/transformers/gauge_compiling/__init__.py +3 -1
- cirq/transformers/gauge_compiling/cphase_gauge.py +2 -0
- cirq/transformers/gauge_compiling/cphase_gauge_test.py +2 -0
- cirq/transformers/gauge_compiling/cz_gauge.py +2 -0
- cirq/transformers/gauge_compiling/cz_gauge_test.py +1 -0
- cirq/transformers/gauge_compiling/gauge_compiling.py +45 -41
- cirq/transformers/gauge_compiling/gauge_compiling_test.py +2 -0
- cirq/transformers/gauge_compiling/gauge_compiling_test_utils.py +1 -0
- cirq/transformers/gauge_compiling/gauge_compiling_test_utils_test.py +5 -1
- cirq/transformers/gauge_compiling/iswap_gauge.py +2 -0
- cirq/transformers/gauge_compiling/iswap_gauge_test.py +1 -0
- cirq/transformers/gauge_compiling/spin_inversion_gauge.py +2 -0
- cirq/transformers/gauge_compiling/spin_inversion_gauge_test.py +2 -0
- cirq/transformers/gauge_compiling/sqrt_cz_gauge.py +7 -6
- cirq/transformers/gauge_compiling/sqrt_cz_gauge_test.py +2 -0
- cirq/transformers/gauge_compiling/sqrt_iswap_gauge.py +2 -0
- cirq/transformers/gauge_compiling/sqrt_iswap_gauge_test.py +2 -0
- cirq/transformers/heuristic_decompositions/gate_tabulation_math_utils.py +6 -3
- cirq/transformers/heuristic_decompositions/gate_tabulation_math_utils_test.py +3 -0
- cirq/transformers/heuristic_decompositions/two_qubit_gate_tabulation.py +12 -9
- cirq/transformers/heuristic_decompositions/two_qubit_gate_tabulation_test.py +9 -7
- cirq/transformers/insertion_sort.py +8 -6
- cirq/transformers/insertion_sort_test.py +3 -1
- cirq/transformers/measurement_transformers.py +29 -29
- cirq/transformers/measurement_transformers_test.py +2 -0
- cirq/transformers/merge_k_qubit_gates.py +12 -10
- cirq/transformers/merge_k_qubit_gates_test.py +18 -18
- cirq/transformers/merge_single_qubit_gates.py +197 -20
- cirq/transformers/merge_single_qubit_gates_test.py +177 -5
- cirq/transformers/noise_adding.py +5 -3
- cirq/transformers/noise_adding_test.py +2 -0
- cirq/transformers/optimize_for_target_gateset.py +19 -17
- cirq/transformers/optimize_for_target_gateset_test.py +11 -8
- cirq/transformers/qubit_management_transformers.py +13 -11
- cirq/transformers/qubit_management_transformers_test.py +5 -3
- cirq/transformers/randomized_measurements.py +16 -14
- cirq/transformers/randomized_measurements_test.py +10 -4
- cirq/transformers/routing/initial_mapper.py +6 -4
- cirq/transformers/routing/initial_mapper_test.py +2 -0
- cirq/transformers/routing/line_initial_mapper.py +16 -14
- cirq/transformers/routing/line_initial_mapper_test.py +9 -7
- cirq/transformers/routing/mapping_manager.py +10 -10
- cirq/transformers/routing/mapping_manager_test.py +2 -0
- cirq/transformers/routing/route_circuit_cqc.py +33 -31
- cirq/transformers/routing/route_circuit_cqc_test.py +15 -13
- cirq/transformers/routing/visualize_routed_circuit.py +8 -7
- cirq/transformers/routing/visualize_routed_circuit_test.py +4 -2
- cirq/transformers/stratify.py +17 -15
- cirq/transformers/stratify_test.py +3 -0
- cirq/transformers/symbolize.py +103 -0
- cirq/transformers/symbolize_test.py +62 -0
- cirq/transformers/synchronize_terminal_measurements.py +10 -10
- cirq/transformers/synchronize_terminal_measurements_test.py +12 -10
- cirq/transformers/tag_transformers.py +97 -0
- cirq/transformers/tag_transformers_test.py +103 -0
- cirq/transformers/target_gatesets/compilation_target_gateset.py +21 -19
- cirq/transformers/target_gatesets/compilation_target_gateset_test.py +20 -16
- cirq/transformers/target_gatesets/cz_gateset.py +7 -5
- cirq/transformers/target_gatesets/cz_gateset_test.py +21 -19
- cirq/transformers/target_gatesets/sqrt_iswap_gateset.py +9 -7
- cirq/transformers/target_gatesets/sqrt_iswap_gateset_test.py +25 -25
- cirq/transformers/transformer_api.py +34 -47
- cirq/transformers/transformer_api_test.py +9 -8
- cirq/transformers/transformer_primitives.py +39 -49
- cirq/transformers/transformer_primitives_test.py +10 -17
- cirq/value/abc_alt.py +6 -4
- cirq/value/abc_alt_test.py +5 -3
- cirq/value/angle.py +11 -12
- cirq/value/angle_test.py +5 -3
- cirq/value/classical_data.py +27 -27
- cirq/value/classical_data_test.py +11 -8
- cirq/value/condition.py +26 -24
- cirq/value/condition_test.py +2 -0
- cirq/value/digits.py +14 -11
- cirq/value/digits_test.py +2 -0
- cirq/value/duration.py +23 -20
- cirq/value/duration_test.py +2 -0
- cirq/value/linear_dict.py +25 -30
- cirq/value/linear_dict_test.py +10 -8
- cirq/value/measurement_key.py +12 -12
- cirq/value/measurement_key_test.py +2 -0
- cirq/value/periodic_value.py +4 -4
- cirq/value/periodic_value_test.py +11 -7
- cirq/value/probability.py +3 -1
- cirq/value/probability_test.py +4 -2
- cirq/value/product_state.py +15 -13
- cirq/value/product_state_test.py +4 -1
- cirq/value/random_state.py +2 -0
- cirq/value/random_state_test.py +5 -3
- cirq/value/timestamp.py +11 -7
- cirq/value/timestamp_test.py +14 -12
- cirq/value/type_alias.py +4 -4
- cirq/value/value_equality_attr.py +8 -9
- cirq/value/value_equality_attr_test.py +14 -11
- cirq/vis/density_matrix.py +3 -3
- cirq/vis/density_matrix_test.py +20 -17
- cirq/vis/heatmap.py +24 -37
- cirq/vis/heatmap_test.py +3 -0
- cirq/vis/histogram.py +9 -6
- cirq/vis/histogram_test.py +5 -2
- cirq/vis/state_histogram.py +10 -8
- cirq/vis/state_histogram_test.py +7 -5
- cirq/vis/vis_utils.py +4 -1
- cirq/vis/vis_utils_test.py +4 -1
- cirq/work/collector.py +12 -18
- cirq/work/collector_test.py +15 -10
- cirq/work/observable_grouping.py +6 -7
- cirq/work/observable_grouping_test.py +10 -9
- cirq/work/observable_measurement.py +47 -45
- cirq/work/observable_measurement_data.py +22 -17
- cirq/work/observable_measurement_data_test.py +4 -1
- cirq/work/observable_measurement_test.py +48 -29
- cirq/work/observable_readout_calibration.py +5 -2
- cirq/work/observable_readout_calibration_test.py +5 -2
- cirq/work/observable_settings.py +13 -22
- cirq/work/observable_settings_test.py +9 -7
- cirq/work/pauli_sum_collector.py +12 -10
- cirq/work/pauli_sum_collector_test.py +9 -9
- cirq/work/sampler.py +42 -43
- cirq/work/sampler_test.py +31 -24
- cirq/work/zeros_sampler.py +6 -4
- cirq/work/zeros_sampler_test.py +7 -5
- {cirq_core-1.5.0.dev20250409222543.dist-info → cirq_core-1.6.0.dist-info}/METADATA +7 -8
- cirq_core-1.6.0.dist-info/RECORD +1241 -0
- {cirq_core-1.5.0.dev20250409222543.dist-info → cirq_core-1.6.0.dist-info}/WHEEL +1 -1
- cirq_core-1.5.0.dev20250409222543.dist-info/RECORD +0 -1216
- {cirq_core-1.5.0.dev20250409222543.dist-info → cirq_core-1.6.0.dist-info}/licenses/LICENSE +0 -0
- {cirq_core-1.5.0.dev20250409222543.dist-info → cirq_core-1.6.0.dist-info}/top_level.txt +0 -0
|
@@ -12,8 +12,10 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
15
17
|
import abc
|
|
16
|
-
from typing import
|
|
18
|
+
from typing import Sequence, TYPE_CHECKING
|
|
17
19
|
|
|
18
20
|
import numpy as np
|
|
19
21
|
from typing_extensions import Self
|
|
@@ -38,8 +40,8 @@ class QuantumStateRepresentation(metaclass=abc.ABCMeta):
|
|
|
38
40
|
|
|
39
41
|
@abc.abstractmethod
|
|
40
42
|
def measure(
|
|
41
|
-
self, axes: Sequence[int], seed:
|
|
42
|
-
) ->
|
|
43
|
+
self, axes: Sequence[int], seed: cirq.RANDOM_STATE_OR_SEED_LIKE = None
|
|
44
|
+
) -> list[int]:
|
|
43
45
|
"""Measures the state.
|
|
44
46
|
|
|
45
47
|
Args:
|
|
@@ -50,10 +52,7 @@ class QuantumStateRepresentation(metaclass=abc.ABCMeta):
|
|
|
50
52
|
"""
|
|
51
53
|
|
|
52
54
|
def sample(
|
|
53
|
-
self,
|
|
54
|
-
axes: Sequence[int],
|
|
55
|
-
repetitions: int = 1,
|
|
56
|
-
seed: 'cirq.RANDOM_STATE_OR_SEED_LIKE' = None,
|
|
55
|
+
self, axes: Sequence[int], repetitions: int = 1, seed: cirq.RANDOM_STATE_OR_SEED_LIKE = None
|
|
57
56
|
) -> np.ndarray:
|
|
58
57
|
"""Samples the state. Subclasses can override with more performant method.
|
|
59
58
|
|
|
@@ -75,7 +74,7 @@ class QuantumStateRepresentation(metaclass=abc.ABCMeta):
|
|
|
75
74
|
"""Joins two state spaces together."""
|
|
76
75
|
raise NotImplementedError()
|
|
77
76
|
|
|
78
|
-
def factor(self, axes: Sequence[int], *, validate=True, atol=1e-07) ->
|
|
77
|
+
def factor(self, axes: Sequence[int], *, validate=True, atol=1e-07) -> tuple[Self, Self]:
|
|
79
78
|
"""Splits two state spaces after a measurement or reset."""
|
|
80
79
|
raise NotImplementedError()
|
|
81
80
|
|
cirq/qis/states.py
CHANGED
|
@@ -14,8 +14,10 @@
|
|
|
14
14
|
|
|
15
15
|
"""Classes and methods for quantum states."""
|
|
16
16
|
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
17
19
|
import itertools
|
|
18
|
-
from typing import Any, cast, Iterable,
|
|
20
|
+
from typing import Any, cast, Iterable, Sequence, TYPE_CHECKING, Union
|
|
19
21
|
|
|
20
22
|
import numpy as np
|
|
21
23
|
|
|
@@ -62,9 +64,9 @@ class QuantumState:
|
|
|
62
64
|
def __init__(
|
|
63
65
|
self,
|
|
64
66
|
data: np.ndarray,
|
|
65
|
-
qid_shape:
|
|
67
|
+
qid_shape: tuple[int, ...] | None = None,
|
|
66
68
|
*, # Force keyword arguments
|
|
67
|
-
dtype:
|
|
69
|
+
dtype: DTypeLike | None = None,
|
|
68
70
|
validate: bool = True,
|
|
69
71
|
atol: float = 1e-7,
|
|
70
72
|
) -> None:
|
|
@@ -97,7 +99,7 @@ class QuantumState:
|
|
|
97
99
|
return self._data
|
|
98
100
|
|
|
99
101
|
@property
|
|
100
|
-
def qid_shape(self) ->
|
|
102
|
+
def qid_shape(self) -> tuple[int, ...]:
|
|
101
103
|
"""The qid shape of the quantum state."""
|
|
102
104
|
return self._qid_shape
|
|
103
105
|
|
|
@@ -106,7 +108,7 @@ class QuantumState:
|
|
|
106
108
|
"""The data type of the quantum state."""
|
|
107
109
|
return self._data.dtype
|
|
108
110
|
|
|
109
|
-
def state_vector(self) ->
|
|
111
|
+
def state_vector(self) -> np.ndarray | None:
|
|
110
112
|
"""Return the state vector of this state.
|
|
111
113
|
|
|
112
114
|
A state vector stores the amplitudes of a pure state as a
|
|
@@ -117,7 +119,7 @@ class QuantumState:
|
|
|
117
119
|
return None
|
|
118
120
|
return np.reshape(self.data, (self._dim,))
|
|
119
121
|
|
|
120
|
-
def state_tensor(self) ->
|
|
122
|
+
def state_tensor(self) -> np.ndarray | None:
|
|
121
123
|
"""Return the state tensor of this state.
|
|
122
124
|
|
|
123
125
|
A state tensor stores the amplitudes of a pure state as an array with
|
|
@@ -156,7 +158,7 @@ class QuantumState:
|
|
|
156
158
|
return self.data.shape == (self._dim, self._dim)
|
|
157
159
|
|
|
158
160
|
def validate(
|
|
159
|
-
self, *, dtype:
|
|
161
|
+
self, *, dtype: DTypeLike | None = None, atol=1e-7 # Force keyword arguments
|
|
160
162
|
) -> None:
|
|
161
163
|
"""Check if this quantum state is valid.
|
|
162
164
|
|
|
@@ -188,12 +190,12 @@ class QuantumState:
|
|
|
188
190
|
|
|
189
191
|
|
|
190
192
|
def quantum_state(
|
|
191
|
-
state:
|
|
192
|
-
qid_shape:
|
|
193
|
+
state: cirq.QUANTUM_STATE_LIKE,
|
|
194
|
+
qid_shape: tuple[int, ...] | None = None,
|
|
193
195
|
*, # Force keyword arguments
|
|
194
196
|
copy: bool = False,
|
|
195
197
|
validate: bool = True,
|
|
196
|
-
dtype:
|
|
198
|
+
dtype: DTypeLike | None = None,
|
|
197
199
|
atol: float = 1e-7,
|
|
198
200
|
) -> QuantumState:
|
|
199
201
|
"""Create a QuantumState object from a state-like object.
|
|
@@ -293,11 +295,11 @@ def quantum_state(
|
|
|
293
295
|
|
|
294
296
|
def density_matrix(
|
|
295
297
|
state: np.ndarray,
|
|
296
|
-
qid_shape:
|
|
298
|
+
qid_shape: tuple[int, ...] | None = None,
|
|
297
299
|
*, # Force keyword arguments
|
|
298
300
|
copy: bool = False,
|
|
299
301
|
validate: bool = True,
|
|
300
|
-
dtype:
|
|
302
|
+
dtype: DTypeLike | None = None,
|
|
301
303
|
atol: float = 1e-7,
|
|
302
304
|
) -> QuantumState:
|
|
303
305
|
"""Create a QuantumState object from a density matrix.
|
|
@@ -328,7 +330,7 @@ def density_matrix(
|
|
|
328
330
|
)
|
|
329
331
|
|
|
330
332
|
|
|
331
|
-
def _infer_qid_shape_from_dimension(dim: int) ->
|
|
333
|
+
def _infer_qid_shape_from_dimension(dim: int) -> tuple[int, ...]:
|
|
332
334
|
if dim != 0 and dim & dim - 1 == 0:
|
|
333
335
|
# dim is a power of 2, assume qubits
|
|
334
336
|
n_qubits = dim.bit_length() - 1
|
|
@@ -350,7 +352,7 @@ _NON_INT_STATE_LIKE = Union[
|
|
|
350
352
|
]
|
|
351
353
|
|
|
352
354
|
|
|
353
|
-
def infer_qid_shape(*states:
|
|
355
|
+
def infer_qid_shape(*states: cirq.QUANTUM_STATE_LIKE) -> tuple[int, ...]:
|
|
354
356
|
"""Infer the qid shape of a set of states.
|
|
355
357
|
|
|
356
358
|
This is a heuristic to determine a qid shape compatible with all of the
|
|
@@ -375,8 +377,8 @@ def infer_qid_shape(*states: 'cirq.QUANTUM_STATE_LIKE') -> Tuple[int, ...]:
|
|
|
375
377
|
if not states:
|
|
376
378
|
raise ValueError('No states were specified.')
|
|
377
379
|
|
|
378
|
-
integer_states:
|
|
379
|
-
non_integer_states:
|
|
380
|
+
integer_states: list[int] = []
|
|
381
|
+
non_integer_states: list[_NON_INT_STATE_LIKE] = []
|
|
380
382
|
for state in states:
|
|
381
383
|
if isinstance(state, int):
|
|
382
384
|
integer_states.append(state)
|
|
@@ -410,7 +412,7 @@ def infer_qid_shape(*states: 'cirq.QUANTUM_STATE_LIKE') -> Tuple[int, ...]:
|
|
|
410
412
|
return qid_shape
|
|
411
413
|
|
|
412
414
|
|
|
413
|
-
def _potential_qid_shapes(state: _NON_INT_STATE_LIKE) ->
|
|
415
|
+
def _potential_qid_shapes(state: _NON_INT_STATE_LIKE) -> _QidShapeSet:
|
|
414
416
|
"""Return a set of qid shapes compatible with a given state."""
|
|
415
417
|
if isinstance(state, QuantumState):
|
|
416
418
|
return _QidShapeSet(explicit_qid_shapes={state.qid_shape})
|
|
@@ -446,9 +448,9 @@ class _QidShapeSet:
|
|
|
446
448
|
def __init__(
|
|
447
449
|
self,
|
|
448
450
|
*,
|
|
449
|
-
explicit_qid_shapes:
|
|
450
|
-
unfactorized_total_dimension:
|
|
451
|
-
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,
|
|
452
454
|
) -> None:
|
|
453
455
|
"""Create a qid shape set.
|
|
454
456
|
|
|
@@ -472,7 +474,7 @@ class _QidShapeSet:
|
|
|
472
474
|
self.unfactorized_total_dimension = unfactorized_total_dimension
|
|
473
475
|
self.min_qudit_dimensions = min_qudit_dimensions
|
|
474
476
|
|
|
475
|
-
def intersection_subset(self, other:
|
|
477
|
+
def intersection_subset(self, other: _QidShapeSet):
|
|
476
478
|
"""Return a subset of the intersection with other qid shape set."""
|
|
477
479
|
explicit_qid_shapes = self.explicit_qid_shapes & other.explicit_qid_shapes
|
|
478
480
|
unfactorized_total_dimension = None
|
|
@@ -537,7 +539,7 @@ class _QidShapeSet:
|
|
|
537
539
|
f'a Hilbert space dimension of {self.unfactorized_total_dimension}.'
|
|
538
540
|
)
|
|
539
541
|
|
|
540
|
-
def infer_qid_shape(self) ->
|
|
542
|
+
def infer_qid_shape(self) -> tuple[int, ...] | None:
|
|
541
543
|
"""Return a qid shape from this set, or None."""
|
|
542
544
|
self._raise_value_error_if_ambiguous()
|
|
543
545
|
if self.unfactorized_total_dimension is not None:
|
|
@@ -548,8 +550,8 @@ class _QidShapeSet:
|
|
|
548
550
|
|
|
549
551
|
|
|
550
552
|
def _intersection_explicit_with_unfactorized_qid_shapes(
|
|
551
|
-
explicit_qid_shapes:
|
|
552
|
-
) ->
|
|
553
|
+
explicit_qid_shapes: set[tuple[int, ...]], unfactorized_total_dimension: int
|
|
554
|
+
) -> set[tuple[int, ...]]:
|
|
553
555
|
return {
|
|
554
556
|
qid_shape
|
|
555
557
|
for qid_shape in explicit_qid_shapes
|
|
@@ -558,8 +560,8 @@ def _intersection_explicit_with_unfactorized_qid_shapes(
|
|
|
558
560
|
|
|
559
561
|
|
|
560
562
|
def _intersection_explicit_with_min_qudit_dims_qid_shapes(
|
|
561
|
-
explicit_qid_shapes:
|
|
562
|
-
) ->
|
|
563
|
+
explicit_qid_shapes: set[tuple[int, ...]], min_qudit_dimensions: tuple[int, ...]
|
|
564
|
+
) -> set[tuple[int, ...]]:
|
|
563
565
|
return {
|
|
564
566
|
qid_shape
|
|
565
567
|
for qid_shape in explicit_qid_shapes
|
|
@@ -569,8 +571,8 @@ def _intersection_explicit_with_min_qudit_dims_qid_shapes(
|
|
|
569
571
|
|
|
570
572
|
|
|
571
573
|
def _intersection_min_qudit_dims_qid_shapes(
|
|
572
|
-
min_qudit_dimensions1:
|
|
573
|
-
) ->
|
|
574
|
+
min_qudit_dimensions1: tuple[int, ...], min_qudit_dimensions2: tuple[int, ...]
|
|
575
|
+
) -> tuple[int, ...] | None:
|
|
574
576
|
if len(min_qudit_dimensions1) == len(min_qudit_dimensions2):
|
|
575
577
|
return tuple(
|
|
576
578
|
max(dim1, dim2) for dim1, dim2 in zip(min_qudit_dimensions1, min_qudit_dimensions2)
|
|
@@ -579,7 +581,7 @@ def _intersection_min_qudit_dims_qid_shapes(
|
|
|
579
581
|
|
|
580
582
|
|
|
581
583
|
def bloch_vector_from_state_vector(
|
|
582
|
-
state_vector: np.ndarray, index: int, qid_shape:
|
|
584
|
+
state_vector: np.ndarray, index: int, qid_shape: tuple[int, ...] | None = None
|
|
583
585
|
) -> np.ndarray:
|
|
584
586
|
"""Returns the bloch vector of a qubit.
|
|
585
587
|
|
|
@@ -619,8 +621,8 @@ def bloch_vector_from_state_vector(
|
|
|
619
621
|
|
|
620
622
|
def density_matrix_from_state_vector(
|
|
621
623
|
state_vector: np.ndarray,
|
|
622
|
-
indices:
|
|
623
|
-
qid_shape:
|
|
624
|
+
indices: Iterable[int] | None = None,
|
|
625
|
+
qid_shape: tuple[int, ...] | None = None,
|
|
624
626
|
) -> np.ndarray:
|
|
625
627
|
r"""Returns the density matrix of the state vector.
|
|
626
628
|
|
|
@@ -682,8 +684,8 @@ def density_matrix_from_state_vector(
|
|
|
682
684
|
state_vector,
|
|
683
685
|
list(range(n_qubits)),
|
|
684
686
|
np.conj(state_vector),
|
|
685
|
-
cast(
|
|
686
|
-
indices + cast(
|
|
687
|
+
cast(list, sum_inds.tolist()),
|
|
688
|
+
indices + cast(list, sum_inds[indices].tolist()),
|
|
687
689
|
)
|
|
688
690
|
new_shape = np.prod([shape[i] for i in indices], dtype=np.int64)
|
|
689
691
|
|
|
@@ -691,7 +693,7 @@ def density_matrix_from_state_vector(
|
|
|
691
693
|
|
|
692
694
|
|
|
693
695
|
def dirac_notation(
|
|
694
|
-
state_vector: np.ndarray, decimals: int = 2, qid_shape:
|
|
696
|
+
state_vector: np.ndarray, decimals: int = 2, qid_shape: tuple[int, ...] | None = None
|
|
695
697
|
) -> str:
|
|
696
698
|
"""Returns the state vector as a string in Dirac notation.
|
|
697
699
|
|
|
@@ -761,11 +763,11 @@ def dirac_notation(
|
|
|
761
763
|
|
|
762
764
|
|
|
763
765
|
def to_valid_state_vector(
|
|
764
|
-
state_rep:
|
|
765
|
-
num_qubits:
|
|
766
|
+
state_rep: cirq.STATE_VECTOR_LIKE,
|
|
767
|
+
num_qubits: int | None = None,
|
|
766
768
|
*, # Force keyword arguments
|
|
767
|
-
qid_shape:
|
|
768
|
-
dtype:
|
|
769
|
+
qid_shape: Sequence[int] | None = None,
|
|
770
|
+
dtype: DTypeLike | None = None,
|
|
769
771
|
atol: float = 1e-7,
|
|
770
772
|
) -> np.ndarray:
|
|
771
773
|
"""Verifies the state_rep is valid and converts it to ndarray form.
|
|
@@ -830,7 +832,7 @@ def to_valid_state_vector(
|
|
|
830
832
|
|
|
831
833
|
|
|
832
834
|
def _qudit_values_to_state_tensor(
|
|
833
|
-
*, state_vector: np.ndarray, qid_shape:
|
|
835
|
+
*, state_vector: np.ndarray, qid_shape: tuple[int, ...], dtype: DTypeLike | None
|
|
834
836
|
) -> np.ndarray:
|
|
835
837
|
for i in range(len(qid_shape)):
|
|
836
838
|
s = state_vector[i]
|
|
@@ -862,8 +864,8 @@ def _qudit_values_to_state_tensor(
|
|
|
862
864
|
def validate_normalized_state_vector(
|
|
863
865
|
state_vector: np.ndarray,
|
|
864
866
|
*, # Force keyword arguments
|
|
865
|
-
qid_shape:
|
|
866
|
-
dtype:
|
|
867
|
+
qid_shape: tuple[int, ...],
|
|
868
|
+
dtype: DTypeLike | None = None,
|
|
867
869
|
atol: float = 1e-7,
|
|
868
870
|
) -> None:
|
|
869
871
|
"""Checks that the given state vector is valid.
|
|
@@ -894,8 +896,8 @@ def validate_normalized_state_vector(
|
|
|
894
896
|
|
|
895
897
|
|
|
896
898
|
def validate_qid_shape(
|
|
897
|
-
state_vector: np.ndarray, qid_shape:
|
|
898
|
-
) ->
|
|
899
|
+
state_vector: np.ndarray, qid_shape: tuple[int, ...] | None
|
|
900
|
+
) -> tuple[int, ...]:
|
|
899
901
|
"""Validates the size of the given `state_vector` against the given shape.
|
|
900
902
|
|
|
901
903
|
Returns:
|
|
@@ -928,11 +930,11 @@ def validate_indices(num_qubits: int, indices: Sequence[int]) -> None:
|
|
|
928
930
|
|
|
929
931
|
|
|
930
932
|
def to_valid_density_matrix(
|
|
931
|
-
density_matrix_rep:
|
|
932
|
-
num_qubits:
|
|
933
|
+
density_matrix_rep: np.ndarray | cirq.STATE_VECTOR_LIKE,
|
|
934
|
+
num_qubits: int | None = None,
|
|
933
935
|
*, # Force keyword arguments
|
|
934
|
-
qid_shape:
|
|
935
|
-
dtype:
|
|
936
|
+
qid_shape: tuple[int, ...] | None = None,
|
|
937
|
+
dtype: DTypeLike | None = None,
|
|
936
938
|
atol: float = 1e-7,
|
|
937
939
|
) -> np.ndarray:
|
|
938
940
|
"""Verifies the density_matrix_rep is valid and converts it to ndarray form.
|
|
@@ -980,8 +982,8 @@ def to_valid_density_matrix(
|
|
|
980
982
|
def validate_density_matrix(
|
|
981
983
|
density_matrix: np.ndarray,
|
|
982
984
|
*, # Force keyword arguments
|
|
983
|
-
qid_shape:
|
|
984
|
-
dtype:
|
|
985
|
+
qid_shape: tuple[int, ...],
|
|
986
|
+
dtype: DTypeLike | None = None,
|
|
985
987
|
atol: float = 1e-7,
|
|
986
988
|
) -> None:
|
|
987
989
|
"""Checks that the given density matrix is valid.
|
|
@@ -1021,8 +1023,8 @@ def validate_density_matrix(
|
|
|
1021
1023
|
|
|
1022
1024
|
|
|
1023
1025
|
def _qid_shape_from_args(
|
|
1024
|
-
num_qubits:
|
|
1025
|
-
) ->
|
|
1026
|
+
num_qubits: int | None, qid_shape: tuple[int, ...] | None
|
|
1027
|
+
) -> tuple[int, ...]:
|
|
1026
1028
|
"""Returns either `(2,) * num_qubits` or `qid_shape`.
|
|
1027
1029
|
|
|
1028
1030
|
Raises:
|
|
@@ -1033,7 +1035,7 @@ def _qid_shape_from_args(
|
|
|
1033
1035
|
'Either the num_qubits or qid_shape argument must be specified. Both were None.'
|
|
1034
1036
|
)
|
|
1035
1037
|
if num_qubits is None:
|
|
1036
|
-
return cast(
|
|
1038
|
+
return cast(tuple[int, ...], qid_shape)
|
|
1037
1039
|
if qid_shape is None:
|
|
1038
1040
|
return (2,) * num_qubits
|
|
1039
1041
|
if len(qid_shape) != num_qubits:
|
|
@@ -1046,10 +1048,10 @@ def _qid_shape_from_args(
|
|
|
1046
1048
|
|
|
1047
1049
|
def one_hot(
|
|
1048
1050
|
*,
|
|
1049
|
-
index:
|
|
1050
|
-
shape:
|
|
1051
|
+
index: None | int | Sequence[int] = None,
|
|
1052
|
+
shape: int | Sequence[int],
|
|
1051
1053
|
value: Any = 1,
|
|
1052
|
-
dtype:
|
|
1054
|
+
dtype: DTypeLike,
|
|
1053
1055
|
) -> np.ndarray:
|
|
1054
1056
|
"""Returns a numpy array with all 0s and a single non-zero entry(default 1).
|
|
1055
1057
|
|
|
@@ -1070,7 +1072,7 @@ def one_hot(
|
|
|
1070
1072
|
return result
|
|
1071
1073
|
|
|
1072
1074
|
|
|
1073
|
-
def eye_tensor(half_shape:
|
|
1075
|
+
def eye_tensor(half_shape: tuple[int, ...], *, dtype: DTypeLike) -> np.ndarray:
|
|
1074
1076
|
"""Returns an identity matrix reshaped into a tensor.
|
|
1075
1077
|
|
|
1076
1078
|
Args:
|
cirq/qis/states_test.py
CHANGED
cirq/sim/classical_simulator.py
CHANGED
|
@@ -12,9 +12,10 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
+
from __future__ import annotations
|
|
15
16
|
|
|
16
17
|
from copy import copy, deepcopy
|
|
17
|
-
from typing import Any,
|
|
18
|
+
from typing import Any, Generic, Sequence, TYPE_CHECKING
|
|
18
19
|
|
|
19
20
|
import numpy as np
|
|
20
21
|
|
|
@@ -37,7 +38,7 @@ def _is_identity(action) -> bool:
|
|
|
37
38
|
class ClassicalBasisState(qis.QuantumStateRepresentation):
|
|
38
39
|
"""Represents a classical basis state for efficient state evolution."""
|
|
39
40
|
|
|
40
|
-
def __init__(self, initial_state:
|
|
41
|
+
def __init__(self, initial_state: list[int] | np.ndarray):
|
|
41
42
|
"""Initializes the ClassicalBasisState object.
|
|
42
43
|
|
|
43
44
|
Args:
|
|
@@ -45,7 +46,7 @@ class ClassicalBasisState(qis.QuantumStateRepresentation):
|
|
|
45
46
|
"""
|
|
46
47
|
self.basis = initial_state
|
|
47
48
|
|
|
48
|
-
def copy(self, deep_copy_buffers: bool = True) ->
|
|
49
|
+
def copy(self, deep_copy_buffers: bool = True) -> ClassicalBasisState:
|
|
49
50
|
"""Creates a copy of the ClassicalBasisState object.
|
|
50
51
|
|
|
51
52
|
Args:
|
|
@@ -58,8 +59,8 @@ class ClassicalBasisState(qis.QuantumStateRepresentation):
|
|
|
58
59
|
)
|
|
59
60
|
|
|
60
61
|
def measure(
|
|
61
|
-
self, axes: Sequence[int], seed:
|
|
62
|
-
) ->
|
|
62
|
+
self, axes: Sequence[int], seed: cirq.RANDOM_STATE_OR_SEED_LIKE = None
|
|
63
|
+
) -> list[int]:
|
|
63
64
|
"""Measures the density matrix.
|
|
64
65
|
|
|
65
66
|
Args:
|
|
@@ -76,9 +77,9 @@ class ClassicalBasisSimState(SimulationState[ClassicalBasisState]):
|
|
|
76
77
|
|
|
77
78
|
def __init__(
|
|
78
79
|
self,
|
|
79
|
-
initial_state:
|
|
80
|
-
qubits:
|
|
81
|
-
classical_data:
|
|
80
|
+
initial_state: int | list[int] = 0,
|
|
81
|
+
qubits: Sequence[cirq.Qid] | None = None,
|
|
82
|
+
classical_data: cirq.ClassicalDataStore | None = None,
|
|
82
83
|
):
|
|
83
84
|
"""Initializes the ClassicalBasisSimState object.
|
|
84
85
|
|
|
@@ -89,23 +90,23 @@ class ClassicalBasisSimState(SimulationState[ClassicalBasisState]):
|
|
|
89
90
|
|
|
90
91
|
Raises:
|
|
91
92
|
ValueError: If qubits not provided and initial_state is int.
|
|
92
|
-
If initial_state is not an int,
|
|
93
|
+
If initial_state is not an int, list[int], or np.ndarray.
|
|
93
94
|
|
|
94
95
|
An initial_state value of type integer is parsed in big endian order.
|
|
95
96
|
"""
|
|
96
97
|
if isinstance(initial_state, int):
|
|
97
98
|
if qubits is None:
|
|
98
|
-
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]')
|
|
99
100
|
state = ClassicalBasisState(
|
|
100
101
|
big_endian_int_to_bits(initial_state, bit_count=len(qubits))
|
|
101
102
|
)
|
|
102
103
|
elif isinstance(initial_state, (list, np.ndarray)):
|
|
103
104
|
state = ClassicalBasisState(initial_state)
|
|
104
105
|
else:
|
|
105
|
-
raise ValueError('initial_state must be an int or
|
|
106
|
+
raise ValueError('initial_state must be an int or list[int] or np.ndarray')
|
|
106
107
|
super().__init__(state=state, qubits=qubits, classical_data=classical_data)
|
|
107
108
|
|
|
108
|
-
def _act_on_fallback_(self, action, qubits: Sequence[
|
|
109
|
+
def _act_on_fallback_(self, action, qubits: Sequence[cirq.Qid], allow_decompose: bool = True):
|
|
109
110
|
"""Acts on the state with a given operation.
|
|
110
111
|
|
|
111
112
|
Args:
|
|
@@ -182,7 +183,7 @@ class ClassicalStateSimulator(
|
|
|
182
183
|
"""A simulator that accepts only gates with classical counterparts."""
|
|
183
184
|
|
|
184
185
|
def __init__(
|
|
185
|
-
self, *, noise:
|
|
186
|
+
self, *, noise: cirq.NOISE_MODEL_LIKE = None, split_untangled_states: bool = False
|
|
186
187
|
):
|
|
187
188
|
"""Initializes a ClassicalStateSimulator.
|
|
188
189
|
|
|
@@ -199,10 +200,10 @@ class ClassicalStateSimulator(
|
|
|
199
200
|
|
|
200
201
|
def _create_simulator_trial_result(
|
|
201
202
|
self,
|
|
202
|
-
params:
|
|
203
|
-
measurements:
|
|
204
|
-
final_simulator_state:
|
|
205
|
-
) ->
|
|
203
|
+
params: cirq.ParamResolver,
|
|
204
|
+
measurements: dict[str, np.ndarray],
|
|
205
|
+
final_simulator_state: cirq.SimulationStateBase[ClassicalBasisSimState],
|
|
206
|
+
) -> ClassicalStateTrialResult[ClassicalBasisSimState]:
|
|
206
207
|
"""Creates a trial result for the simulator.
|
|
207
208
|
|
|
208
209
|
Args:
|
|
@@ -217,8 +218,8 @@ class ClassicalStateSimulator(
|
|
|
217
218
|
)
|
|
218
219
|
|
|
219
220
|
def _create_step_result(
|
|
220
|
-
self, sim_state:
|
|
221
|
-
) ->
|
|
221
|
+
self, sim_state: cirq.SimulationStateBase[ClassicalBasisSimState]
|
|
222
|
+
) -> ClassicalStateStepResult[ClassicalBasisSimState]:
|
|
222
223
|
"""Creates a step result for the simulator.
|
|
223
224
|
|
|
224
225
|
Args:
|
|
@@ -231,9 +232,9 @@ class ClassicalStateSimulator(
|
|
|
231
232
|
def _create_partial_simulation_state(
|
|
232
233
|
self,
|
|
233
234
|
initial_state: Any,
|
|
234
|
-
qubits: Sequence[
|
|
235
|
-
classical_data:
|
|
236
|
-
) ->
|
|
235
|
+
qubits: Sequence[cirq.Qid],
|
|
236
|
+
classical_data: cirq.ClassicalDataStore,
|
|
237
|
+
) -> ClassicalBasisSimState:
|
|
237
238
|
"""Creates a partial simulation state for the simulator.
|
|
238
239
|
|
|
239
240
|
Args:
|
|
@@ -30,7 +30,9 @@ The quantum state is specified in two forms:
|
|
|
30
30
|
to state vector amplitudes.
|
|
31
31
|
"""
|
|
32
32
|
|
|
33
|
-
from
|
|
33
|
+
from __future__ import annotations
|
|
34
|
+
|
|
35
|
+
from typing import Any, Sequence
|
|
34
36
|
|
|
35
37
|
import numpy as np
|
|
36
38
|
|
|
@@ -50,7 +52,7 @@ class CliffordSimulator(
|
|
|
50
52
|
"""An efficient simulator for Clifford circuits."""
|
|
51
53
|
|
|
52
54
|
def __init__(
|
|
53
|
-
self, seed:
|
|
55
|
+
self, seed: cirq.RANDOM_STATE_OR_SEED_LIKE = None, split_untangled_states: bool = False
|
|
54
56
|
):
|
|
55
57
|
"""Creates instance of `CliffordSimulator`.
|
|
56
58
|
|
|
@@ -63,17 +65,17 @@ class CliffordSimulator(
|
|
|
63
65
|
super().__init__(seed=seed, split_untangled_states=split_untangled_states)
|
|
64
66
|
|
|
65
67
|
@staticmethod
|
|
66
|
-
def is_supported_operation(op:
|
|
68
|
+
def is_supported_operation(op: cirq.Operation) -> bool:
|
|
67
69
|
"""Checks whether given operation can be simulated by this simulator."""
|
|
68
70
|
# TODO: support more general Pauli measurements
|
|
69
71
|
return protocols.has_stabilizer_effect(op)
|
|
70
72
|
|
|
71
73
|
def _create_partial_simulation_state(
|
|
72
74
|
self,
|
|
73
|
-
initial_state:
|
|
74
|
-
qubits: Sequence[
|
|
75
|
-
classical_data:
|
|
76
|
-
) ->
|
|
75
|
+
initial_state: int | cirq.StabilizerChFormSimulationState,
|
|
76
|
+
qubits: Sequence[cirq.Qid],
|
|
77
|
+
classical_data: cirq.ClassicalDataStore,
|
|
78
|
+
) -> cirq.StabilizerChFormSimulationState:
|
|
77
79
|
"""Creates the StabilizerChFormSimulationState for a circuit.
|
|
78
80
|
|
|
79
81
|
Args:
|
|
@@ -101,15 +103,15 @@ class CliffordSimulator(
|
|
|
101
103
|
)
|
|
102
104
|
|
|
103
105
|
def _create_step_result(
|
|
104
|
-
self, sim_state:
|
|
106
|
+
self, sim_state: cirq.SimulationStateBase[clifford.StabilizerChFormSimulationState]
|
|
105
107
|
):
|
|
106
108
|
return CliffordSimulatorStepResult(sim_state=sim_state)
|
|
107
109
|
|
|
108
110
|
def _create_simulator_trial_result(
|
|
109
111
|
self,
|
|
110
|
-
params:
|
|
111
|
-
measurements:
|
|
112
|
-
final_simulator_state:
|
|
112
|
+
params: cirq.ParamResolver,
|
|
113
|
+
measurements: dict[str, np.ndarray],
|
|
114
|
+
final_simulator_state: cirq.SimulationStateBase[cirq.StabilizerChFormSimulationState],
|
|
113
115
|
):
|
|
114
116
|
return CliffordTrialResult(
|
|
115
117
|
params=params, measurements=measurements, final_simulator_state=final_simulator_state
|
|
@@ -121,16 +123,16 @@ class CliffordTrialResult(
|
|
|
121
123
|
):
|
|
122
124
|
def __init__(
|
|
123
125
|
self,
|
|
124
|
-
params:
|
|
125
|
-
measurements:
|
|
126
|
-
final_simulator_state:
|
|
126
|
+
params: cirq.ParamResolver,
|
|
127
|
+
measurements: dict[str, np.ndarray],
|
|
128
|
+
final_simulator_state: cirq.SimulationStateBase[cirq.StabilizerChFormSimulationState],
|
|
127
129
|
) -> None:
|
|
128
130
|
super().__init__(
|
|
129
131
|
params=params, measurements=measurements, final_simulator_state=final_simulator_state
|
|
130
132
|
)
|
|
131
133
|
|
|
132
134
|
@property
|
|
133
|
-
def final_state(self) ->
|
|
135
|
+
def final_state(self) -> cirq.CliffordState:
|
|
134
136
|
state = self._get_merged_sim_state()
|
|
135
137
|
clifford_state = CliffordState(state.qubit_map)
|
|
136
138
|
clifford_state.ch_form = state.state.copy()
|
|
@@ -152,7 +154,7 @@ class CliffordSimulatorStepResult(
|
|
|
152
154
|
"""A `StepResult` that includes `StateVectorMixin` methods."""
|
|
153
155
|
|
|
154
156
|
def __init__(
|
|
155
|
-
self, sim_state:
|
|
157
|
+
self, sim_state: cirq.SimulationStateBase[clifford.StabilizerChFormSimulationState]
|
|
156
158
|
):
|
|
157
159
|
"""Results of a step of the simulator.
|
|
158
160
|
Attributes:
|
|
@@ -199,7 +201,7 @@ class CliffordState:
|
|
|
199
201
|
Gates and measurements are applied to each representation in O(n^2) time.
|
|
200
202
|
"""
|
|
201
203
|
|
|
202
|
-
def __init__(self, qubit_map, initial_state:
|
|
204
|
+
def __init__(self, qubit_map, initial_state: int | cirq.StabilizerStateChForm = 0):
|
|
203
205
|
self.qubit_map = qubit_map
|
|
204
206
|
self.n = len(qubit_map)
|
|
205
207
|
|
|
@@ -222,7 +224,7 @@ class CliffordState:
|
|
|
222
224
|
def _value_equality_values_(self) -> Any:
|
|
223
225
|
return self.qubit_map, self.ch_form
|
|
224
226
|
|
|
225
|
-
def copy(self) ->
|
|
227
|
+
def copy(self) -> cirq.CliffordState:
|
|
226
228
|
state = CliffordState(self.qubit_map)
|
|
227
229
|
state.ch_form = self.ch_form.copy()
|
|
228
230
|
|
|
@@ -241,7 +243,7 @@ class CliffordState:
|
|
|
241
243
|
def state_vector(self):
|
|
242
244
|
return self.ch_form.state_vector()
|
|
243
245
|
|
|
244
|
-
def apply_unitary(self, op:
|
|
246
|
+
def apply_unitary(self, op: cirq.Operation):
|
|
245
247
|
ch_form_args = clifford.StabilizerChFormSimulationState(
|
|
246
248
|
prng=np.random.RandomState(), qubits=self.qubit_map.keys(), initial_state=self.ch_form
|
|
247
249
|
)
|
|
@@ -253,8 +255,8 @@ class CliffordState:
|
|
|
253
255
|
|
|
254
256
|
def apply_measurement(
|
|
255
257
|
self,
|
|
256
|
-
op:
|
|
257
|
-
measurements:
|
|
258
|
+
op: cirq.Operation,
|
|
259
|
+
measurements: dict[str, list[int]],
|
|
258
260
|
prng: np.random.RandomState,
|
|
259
261
|
collapse_state_vector=True,
|
|
260
262
|
):
|