cirq-core 1.5.0.dev20250409225226__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.dev20250409225226.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.dev20250409225226.dist-info → cirq_core-1.6.0.dist-info}/WHEEL +1 -1
- cirq_core-1.5.0.dev20250409225226.dist-info/RECORD +0 -1216
- {cirq_core-1.5.0.dev20250409225226.dist-info → cirq_core-1.6.0.dist-info}/licenses/LICENSE +0 -0
- {cirq_core-1.5.0.dev20250409225226.dist-info → cirq_core-1.6.0.dist-info}/top_level.txt +0 -0
|
@@ -11,7 +11,10 @@
|
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
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
|
+
|
|
17
|
+
from typing import Any, Sequence
|
|
15
18
|
|
|
16
19
|
import cirq
|
|
17
20
|
|
|
@@ -42,7 +45,7 @@ class EmptySimulationState(cirq.SimulationState):
|
|
|
42
45
|
super().__init__(state=EmptyQuantumState(), qubits=qubits, classical_data=classical_data)
|
|
43
46
|
|
|
44
47
|
def _act_on_fallback_(
|
|
45
|
-
self, action: Any, qubits: Sequence[
|
|
48
|
+
self, action: Any, qubits: Sequence[cirq.Qid], allow_decompose: bool = True
|
|
46
49
|
) -> bool:
|
|
47
50
|
return True
|
|
48
51
|
|
|
@@ -52,9 +55,9 @@ qs2 = cirq.LineQubit.range(2)
|
|
|
52
55
|
|
|
53
56
|
|
|
54
57
|
def create_container(
|
|
55
|
-
qubits: Sequence[
|
|
58
|
+
qubits: Sequence[cirq.Qid], split_untangled_states=True
|
|
56
59
|
) -> cirq.SimulationProductState[EmptySimulationState]:
|
|
57
|
-
state_map:
|
|
60
|
+
state_map: dict[cirq.Qid | None, EmptySimulationState] = {}
|
|
58
61
|
log = cirq.ClassicalDataDictionaryStore()
|
|
59
62
|
if split_untangled_states:
|
|
60
63
|
for q in reversed(qubits):
|
|
@@ -70,7 +73,7 @@ def create_container(
|
|
|
70
73
|
)
|
|
71
74
|
|
|
72
75
|
|
|
73
|
-
def test_entanglement_causes_join():
|
|
76
|
+
def test_entanglement_causes_join() -> None:
|
|
74
77
|
state = create_container(qs2)
|
|
75
78
|
assert len(set(state.values())) == 3
|
|
76
79
|
state.apply_operation(cirq.CNOT(q0, q1))
|
|
@@ -79,7 +82,7 @@ def test_entanglement_causes_join():
|
|
|
79
82
|
assert state[None] is not state[q0]
|
|
80
83
|
|
|
81
84
|
|
|
82
|
-
def test_subcircuit_entanglement_causes_join():
|
|
85
|
+
def test_subcircuit_entanglement_causes_join() -> None:
|
|
83
86
|
state = create_container(qs2)
|
|
84
87
|
assert len(set(state.values())) == 3
|
|
85
88
|
state.apply_operation(cirq.CircuitOperation(cirq.FrozenCircuit(cirq.CNOT(q0, q1))))
|
|
@@ -87,7 +90,7 @@ def test_subcircuit_entanglement_causes_join():
|
|
|
87
90
|
assert state[q0] is state[q1]
|
|
88
91
|
|
|
89
92
|
|
|
90
|
-
def test_subcircuit_entanglement_causes_join_in_subset():
|
|
93
|
+
def test_subcircuit_entanglement_causes_join_in_subset() -> None:
|
|
91
94
|
state = create_container(qs3)
|
|
92
95
|
assert len(set(state.values())) == 4
|
|
93
96
|
state.apply_operation(cirq.CircuitOperation(cirq.FrozenCircuit(cirq.CNOT(q0, q1))))
|
|
@@ -98,7 +101,7 @@ def test_subcircuit_entanglement_causes_join_in_subset():
|
|
|
98
101
|
assert state[q0] is state[q1] is state[q2]
|
|
99
102
|
|
|
100
103
|
|
|
101
|
-
def test_identity_does_not_join():
|
|
104
|
+
def test_identity_does_not_join() -> None:
|
|
102
105
|
state = create_container(qs2)
|
|
103
106
|
assert len(set(state.values())) == 3
|
|
104
107
|
state.apply_operation(cirq.IdentityGate(2)(q0, q1))
|
|
@@ -107,7 +110,7 @@ def test_identity_does_not_join():
|
|
|
107
110
|
assert state[q0] is not state[None]
|
|
108
111
|
|
|
109
112
|
|
|
110
|
-
def test_identity_fallback_does_not_join():
|
|
113
|
+
def test_identity_fallback_does_not_join() -> None:
|
|
111
114
|
state = create_container(qs2)
|
|
112
115
|
assert len(set(state.values())) == 3
|
|
113
116
|
state._act_on_fallback_(cirq.I, (q0, q1))
|
|
@@ -116,7 +119,7 @@ def test_identity_fallback_does_not_join():
|
|
|
116
119
|
assert state[q0] is not state[None]
|
|
117
120
|
|
|
118
121
|
|
|
119
|
-
def test_subcircuit_identity_does_not_join():
|
|
122
|
+
def test_subcircuit_identity_does_not_join() -> None:
|
|
120
123
|
state = create_container(qs2)
|
|
121
124
|
assert len(set(state.values())) == 3
|
|
122
125
|
state.apply_operation(cirq.CircuitOperation(cirq.FrozenCircuit(cirq.IdentityGate(2)(q0, q1))))
|
|
@@ -124,7 +127,7 @@ def test_subcircuit_identity_does_not_join():
|
|
|
124
127
|
assert state[q0] is not state[q1]
|
|
125
128
|
|
|
126
129
|
|
|
127
|
-
def test_measurement_causes_split():
|
|
130
|
+
def test_measurement_causes_split() -> None:
|
|
128
131
|
state = create_container(qs2)
|
|
129
132
|
state.apply_operation(cirq.CNOT(q0, q1))
|
|
130
133
|
assert len(set(state.values())) == 2
|
|
@@ -134,7 +137,7 @@ def test_measurement_causes_split():
|
|
|
134
137
|
assert state[q0] is not state[None]
|
|
135
138
|
|
|
136
139
|
|
|
137
|
-
def test_subcircuit_measurement_causes_split():
|
|
140
|
+
def test_subcircuit_measurement_causes_split() -> None:
|
|
138
141
|
state = create_container(qs2)
|
|
139
142
|
state.apply_operation(cirq.CNOT(q0, q1))
|
|
140
143
|
assert len(set(state.values())) == 2
|
|
@@ -143,7 +146,7 @@ def test_subcircuit_measurement_causes_split():
|
|
|
143
146
|
assert state[q0] is not state[q1]
|
|
144
147
|
|
|
145
148
|
|
|
146
|
-
def test_subcircuit_measurement_causes_split_in_subset():
|
|
149
|
+
def test_subcircuit_measurement_causes_split_in_subset() -> None:
|
|
147
150
|
state = create_container(qs3)
|
|
148
151
|
state.apply_operation(cirq.CNOT(q0, q1))
|
|
149
152
|
state.apply_operation(cirq.CNOT(q0, q2))
|
|
@@ -158,7 +161,7 @@ def test_subcircuit_measurement_causes_split_in_subset():
|
|
|
158
161
|
assert state[q1] is not state[q2]
|
|
159
162
|
|
|
160
163
|
|
|
161
|
-
def test_reset_causes_split():
|
|
164
|
+
def test_reset_causes_split() -> None:
|
|
162
165
|
state = create_container(qs2)
|
|
163
166
|
state.apply_operation(cirq.CNOT(q0, q1))
|
|
164
167
|
assert len(set(state.values())) == 2
|
|
@@ -168,7 +171,7 @@ def test_reset_causes_split():
|
|
|
168
171
|
assert state[q0] is not state[None]
|
|
169
172
|
|
|
170
173
|
|
|
171
|
-
def test_measurement_does_not_split_if_disabled():
|
|
174
|
+
def test_measurement_does_not_split_if_disabled() -> None:
|
|
172
175
|
state = create_container(qs2, False)
|
|
173
176
|
state.apply_operation(cirq.CNOT(q0, q1))
|
|
174
177
|
assert len(set(state.values())) == 1
|
|
@@ -178,7 +181,7 @@ def test_measurement_does_not_split_if_disabled():
|
|
|
178
181
|
assert state[None] is state[q0]
|
|
179
182
|
|
|
180
183
|
|
|
181
|
-
def test_reset_does_not_split_if_disabled():
|
|
184
|
+
def test_reset_does_not_split_if_disabled() -> None:
|
|
182
185
|
state = create_container(qs2, False)
|
|
183
186
|
state.apply_operation(cirq.CNOT(q0, q1))
|
|
184
187
|
assert len(set(state.values())) == 1
|
|
@@ -188,7 +191,7 @@ def test_reset_does_not_split_if_disabled():
|
|
|
188
191
|
assert state[None] is state[q0]
|
|
189
192
|
|
|
190
193
|
|
|
191
|
-
def test_measurement_of_all_qubits_causes_split():
|
|
194
|
+
def test_measurement_of_all_qubits_causes_split() -> None:
|
|
192
195
|
state = create_container(qs2)
|
|
193
196
|
state.apply_operation(cirq.CNOT(q0, q1))
|
|
194
197
|
assert len(set(state.values())) == 2
|
|
@@ -198,7 +201,7 @@ def test_measurement_of_all_qubits_causes_split():
|
|
|
198
201
|
assert state[q0] is not state[None]
|
|
199
202
|
|
|
200
203
|
|
|
201
|
-
def test_measurement_in_single_qubit_circuit_passes():
|
|
204
|
+
def test_measurement_in_single_qubit_circuit_passes() -> None:
|
|
202
205
|
state = create_container([q0])
|
|
203
206
|
assert len(set(state.values())) == 2
|
|
204
207
|
state.apply_operation(cirq.measure(q0))
|
|
@@ -206,25 +209,25 @@ def test_measurement_in_single_qubit_circuit_passes():
|
|
|
206
209
|
assert state[q0] is not state[None]
|
|
207
210
|
|
|
208
211
|
|
|
209
|
-
def test_reorder_succeeds():
|
|
212
|
+
def test_reorder_succeeds() -> None:
|
|
210
213
|
state = create_container(qs2, False)
|
|
211
214
|
reordered = state[q0].transpose_to_qubit_order([q1, q0])
|
|
212
215
|
assert reordered.qubits == (q1, q0)
|
|
213
216
|
|
|
214
217
|
|
|
215
|
-
def test_copy_succeeds():
|
|
218
|
+
def test_copy_succeeds() -> None:
|
|
216
219
|
state = create_container(qs2, False)
|
|
217
220
|
copied = state[q0].copy()
|
|
218
221
|
assert copied.qubits == (q0, q1)
|
|
219
222
|
|
|
220
223
|
|
|
221
|
-
def test_merge_succeeds():
|
|
224
|
+
def test_merge_succeeds() -> None:
|
|
222
225
|
state = create_container(qs2, False)
|
|
223
226
|
merged = state.create_merged_state()
|
|
224
227
|
assert merged.qubits == (q0, q1)
|
|
225
228
|
|
|
226
229
|
|
|
227
|
-
def test_swap_does_not_merge():
|
|
230
|
+
def test_swap_does_not_merge() -> None:
|
|
228
231
|
state = create_container(qs2)
|
|
229
232
|
old_q0 = state[q0]
|
|
230
233
|
old_q1 = state[q1]
|
|
@@ -238,14 +241,14 @@ def test_swap_does_not_merge():
|
|
|
238
241
|
assert state[q1].qubits == (q1,)
|
|
239
242
|
|
|
240
243
|
|
|
241
|
-
def test_half_swap_does_merge():
|
|
244
|
+
def test_half_swap_does_merge() -> None:
|
|
242
245
|
state = create_container(qs2)
|
|
243
246
|
state.apply_operation(cirq.SWAP(q0, q1) ** 0.5)
|
|
244
247
|
assert len(set(state.values())) == 2
|
|
245
248
|
assert state[q0] is state[q1]
|
|
246
249
|
|
|
247
250
|
|
|
248
|
-
def test_swap_after_entangle_reorders():
|
|
251
|
+
def test_swap_after_entangle_reorders() -> None:
|
|
249
252
|
state = create_container(qs2)
|
|
250
253
|
state.apply_operation(cirq.CX(q0, q1))
|
|
251
254
|
assert len(set(state.values())) == 2
|
|
@@ -256,7 +259,7 @@ def test_swap_after_entangle_reorders():
|
|
|
256
259
|
assert state[q0].qubits == (q1, q0)
|
|
257
260
|
|
|
258
261
|
|
|
259
|
-
def test_act_on_gate_does_not_join():
|
|
262
|
+
def test_act_on_gate_does_not_join() -> None:
|
|
260
263
|
state = create_container(qs2)
|
|
261
264
|
assert len(set(state.values())) == 3
|
|
262
265
|
cirq.act_on(cirq.X, state, [q0])
|
|
@@ -265,7 +268,7 @@ def test_act_on_gate_does_not_join():
|
|
|
265
268
|
assert state[q0] is not state[None]
|
|
266
269
|
|
|
267
270
|
|
|
268
|
-
def test_field_getters():
|
|
271
|
+
def test_field_getters() -> None:
|
|
269
272
|
state = create_container(qs2)
|
|
270
273
|
assert state.sim_states.keys() == set(qs2) | {None}
|
|
271
274
|
assert state.split_untangled_states
|
cirq/sim/simulation_state.py
CHANGED
|
@@ -11,23 +11,14 @@
|
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
|
+
|
|
14
15
|
"""Objects and methods for acting efficiently on a state tensor."""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
15
19
|
import abc
|
|
16
20
|
import copy
|
|
17
|
-
from typing import
|
|
18
|
-
Any,
|
|
19
|
-
cast,
|
|
20
|
-
Dict,
|
|
21
|
-
Generic,
|
|
22
|
-
Iterator,
|
|
23
|
-
List,
|
|
24
|
-
Optional,
|
|
25
|
-
Sequence,
|
|
26
|
-
Set,
|
|
27
|
-
Tuple,
|
|
28
|
-
TYPE_CHECKING,
|
|
29
|
-
TypeVar,
|
|
30
|
-
)
|
|
21
|
+
from typing import Any, cast, Generic, Iterator, Sequence, TYPE_CHECKING, TypeVar
|
|
31
22
|
|
|
32
23
|
import numpy as np
|
|
33
24
|
from typing_extensions import Self
|
|
@@ -48,9 +39,9 @@ class SimulationState(SimulationStateBase, Generic[TState], metaclass=abc.ABCMet
|
|
|
48
39
|
self,
|
|
49
40
|
*,
|
|
50
41
|
state: TState,
|
|
51
|
-
prng:
|
|
52
|
-
qubits:
|
|
53
|
-
classical_data:
|
|
42
|
+
prng: np.random.RandomState | None = None,
|
|
43
|
+
qubits: Sequence[cirq.Qid] | None = None,
|
|
44
|
+
classical_data: cirq.ClassicalDataStore | None = None,
|
|
54
45
|
):
|
|
55
46
|
"""Inits SimulationState.
|
|
56
47
|
|
|
@@ -79,10 +70,10 @@ class SimulationState(SimulationStateBase, Generic[TState], metaclass=abc.ABCMet
|
|
|
79
70
|
|
|
80
71
|
def measure(
|
|
81
72
|
self,
|
|
82
|
-
qubits: Sequence[
|
|
73
|
+
qubits: Sequence[cirq.Qid],
|
|
83
74
|
key: str,
|
|
84
75
|
invert_mask: Sequence[bool],
|
|
85
|
-
confusion_map:
|
|
76
|
+
confusion_map: dict[tuple[int, ...], np.ndarray],
|
|
86
77
|
):
|
|
87
78
|
"""Measures the qubits and records to `log_of_measurement_results`.
|
|
88
79
|
|
|
@@ -106,10 +97,10 @@ class SimulationState(SimulationStateBase, Generic[TState], metaclass=abc.ABCMet
|
|
|
106
97
|
value.MeasurementKey.parse_serialized(key), corrected, qubits
|
|
107
98
|
)
|
|
108
99
|
|
|
109
|
-
def get_axes(self, qubits: Sequence[
|
|
100
|
+
def get_axes(self, qubits: Sequence[cirq.Qid]) -> list[int]:
|
|
110
101
|
return [self.qubit_map[q] for q in qubits]
|
|
111
102
|
|
|
112
|
-
def _perform_measurement(self, qubits: Sequence[
|
|
103
|
+
def _perform_measurement(self, qubits: Sequence[cirq.Qid]) -> list[int]:
|
|
113
104
|
"""Delegates the call to measure the `QuantumStateRepresentation`."""
|
|
114
105
|
if self._state is not None:
|
|
115
106
|
return self._state.measure(self.get_axes(qubits), self.prng)
|
|
@@ -117,9 +108,9 @@ class SimulationState(SimulationStateBase, Generic[TState], metaclass=abc.ABCMet
|
|
|
117
108
|
|
|
118
109
|
def _confuse_result(
|
|
119
110
|
self,
|
|
120
|
-
bits:
|
|
121
|
-
qubits: Sequence[
|
|
122
|
-
confusion_map:
|
|
111
|
+
bits: list[int],
|
|
112
|
+
qubits: Sequence[cirq.Qid],
|
|
113
|
+
confusion_map: dict[tuple[int, ...], np.ndarray],
|
|
123
114
|
):
|
|
124
115
|
"""Applies confusion matrices to measured results.
|
|
125
116
|
|
|
@@ -138,9 +129,9 @@ class SimulationState(SimulationStateBase, Generic[TState], metaclass=abc.ABCMet
|
|
|
138
129
|
|
|
139
130
|
def sample(
|
|
140
131
|
self,
|
|
141
|
-
qubits: Sequence[
|
|
132
|
+
qubits: Sequence[cirq.Qid],
|
|
142
133
|
repetitions: int = 1,
|
|
143
|
-
seed:
|
|
134
|
+
seed: cirq.RANDOM_STATE_OR_SEED_LIKE = None,
|
|
144
135
|
) -> np.ndarray:
|
|
145
136
|
if self._state is not None:
|
|
146
137
|
return self._state.sample(self.get_axes(qubits), repetitions, seed)
|
|
@@ -166,7 +157,7 @@ class SimulationState(SimulationStateBase, Generic[TState], metaclass=abc.ABCMet
|
|
|
166
157
|
"""Creates a final merged state."""
|
|
167
158
|
return self
|
|
168
159
|
|
|
169
|
-
def add_qubits(self: Self, qubits: Sequence[
|
|
160
|
+
def add_qubits(self: Self, qubits: Sequence[cirq.Qid]) -> Self:
|
|
170
161
|
"""Add `qubits` in the `|0>` state to a new state space and take the kron product.
|
|
171
162
|
|
|
172
163
|
Args:
|
|
@@ -181,7 +172,7 @@ class SimulationState(SimulationStateBase, Generic[TState], metaclass=abc.ABCMet
|
|
|
181
172
|
return self
|
|
182
173
|
return NotImplemented
|
|
183
174
|
|
|
184
|
-
def remove_qubits(self: Self, qubits: Sequence[
|
|
175
|
+
def remove_qubits(self: Self, qubits: Sequence[cirq.Qid]) -> Self:
|
|
185
176
|
"""Remove `qubits` from the state space.
|
|
186
177
|
|
|
187
178
|
The qubits to be removed should be untangled from rest of the system and in the |0> state.
|
|
@@ -206,8 +197,8 @@ class SimulationState(SimulationStateBase, Generic[TState], metaclass=abc.ABCMet
|
|
|
206
197
|
return args
|
|
207
198
|
|
|
208
199
|
def factor(
|
|
209
|
-
self, qubits: Sequence[
|
|
210
|
-
) ->
|
|
200
|
+
self, qubits: Sequence[cirq.Qid], *, validate=True, atol=1e-07, inplace=False
|
|
201
|
+
) -> tuple[Self, Self]:
|
|
211
202
|
"""Splits two state spaces after a measurement or reset."""
|
|
212
203
|
extracted = copy.copy(self)
|
|
213
204
|
remainder = self if inplace else copy.copy(self)
|
|
@@ -223,7 +214,7 @@ class SimulationState(SimulationStateBase, Generic[TState], metaclass=abc.ABCMet
|
|
|
223
214
|
"""Subclasses that allow factorization should override this."""
|
|
224
215
|
return self._state.supports_factor if self._state is not None else False
|
|
225
216
|
|
|
226
|
-
def transpose_to_qubit_order(self, qubits: Sequence[
|
|
217
|
+
def transpose_to_qubit_order(self, qubits: Sequence[cirq.Qid], *, inplace=False) -> Self:
|
|
227
218
|
"""Physically reindexes the state by the new basis.
|
|
228
219
|
|
|
229
220
|
Args:
|
|
@@ -245,10 +236,10 @@ class SimulationState(SimulationStateBase, Generic[TState], metaclass=abc.ABCMet
|
|
|
245
236
|
return args
|
|
246
237
|
|
|
247
238
|
@property
|
|
248
|
-
def qubits(self) ->
|
|
239
|
+
def qubits(self) -> tuple[cirq.Qid, ...]:
|
|
249
240
|
return self._qubits
|
|
250
241
|
|
|
251
|
-
def swap(self, q1:
|
|
242
|
+
def swap(self, q1: cirq.Qid, q2: cirq.Qid, *, inplace=False):
|
|
252
243
|
"""Swaps two qubits.
|
|
253
244
|
|
|
254
245
|
This only affects the index, and does not modify the underlying
|
|
@@ -279,7 +270,7 @@ class SimulationState(SimulationStateBase, Generic[TState], metaclass=abc.ABCMet
|
|
|
279
270
|
args._set_qubits(qubits)
|
|
280
271
|
return args
|
|
281
272
|
|
|
282
|
-
def rename(self, q1:
|
|
273
|
+
def rename(self, q1: cirq.Qid, q2: cirq.Qid, *, inplace=False):
|
|
283
274
|
"""Renames `q1` to `q2`.
|
|
284
275
|
|
|
285
276
|
Args:
|
|
@@ -306,7 +297,7 @@ class SimulationState(SimulationStateBase, Generic[TState], metaclass=abc.ABCMet
|
|
|
306
297
|
args._set_qubits(qubits)
|
|
307
298
|
return args
|
|
308
299
|
|
|
309
|
-
def __getitem__(self, item:
|
|
300
|
+
def __getitem__(self, item: cirq.Qid | None) -> Self:
|
|
310
301
|
if item not in self.qubit_map:
|
|
311
302
|
raise IndexError(f'{item} not in {self.qubits}')
|
|
312
303
|
return self
|
|
@@ -314,7 +305,7 @@ class SimulationState(SimulationStateBase, Generic[TState], metaclass=abc.ABCMet
|
|
|
314
305
|
def __len__(self) -> int:
|
|
315
306
|
return len(self.qubits)
|
|
316
307
|
|
|
317
|
-
def __iter__(self) -> Iterator[
|
|
308
|
+
def __iter__(self) -> Iterator[cirq.Qid | None]:
|
|
318
309
|
return iter(self.qubits)
|
|
319
310
|
|
|
320
311
|
@property
|
|
@@ -323,7 +314,7 @@ class SimulationState(SimulationStateBase, Generic[TState], metaclass=abc.ABCMet
|
|
|
323
314
|
|
|
324
315
|
|
|
325
316
|
def strat_act_on_from_apply_decompose(
|
|
326
|
-
val: Any, args:
|
|
317
|
+
val: Any, args: cirq.SimulationState, qubits: Sequence[cirq.Qid]
|
|
327
318
|
) -> bool:
|
|
328
319
|
if isinstance(val, ops.Gate):
|
|
329
320
|
decomposed = protocols.decompose_once_with_qubits(val, qubits, flatten=False, default=None)
|
|
@@ -331,7 +322,7 @@ def strat_act_on_from_apply_decompose(
|
|
|
331
322
|
decomposed = protocols.decompose_once(val, flatten=False, default=None)
|
|
332
323
|
if decomposed is None:
|
|
333
324
|
return NotImplemented
|
|
334
|
-
all_ancilla:
|
|
325
|
+
all_ancilla: set[cirq.Qid] = set()
|
|
335
326
|
for operation in ops.flatten_to_ops(decomposed):
|
|
336
327
|
curr_ancilla = tuple(q for q in operation.qubits if q not in args.qubits)
|
|
337
328
|
args = args.add_qubits(curr_ancilla)
|
|
@@ -11,30 +11,22 @@
|
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
|
+
|
|
14
15
|
"""An interface for quantum states as targets for operations."""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
15
19
|
import abc
|
|
16
20
|
from types import NotImplementedType
|
|
17
|
-
from typing import
|
|
18
|
-
|
|
19
|
-
Dict,
|
|
20
|
-
Generic,
|
|
21
|
-
Iterator,
|
|
22
|
-
List,
|
|
23
|
-
Mapping,
|
|
24
|
-
Optional,
|
|
25
|
-
Sequence,
|
|
26
|
-
Tuple,
|
|
27
|
-
TYPE_CHECKING,
|
|
28
|
-
TypeVar,
|
|
29
|
-
Union,
|
|
30
|
-
)
|
|
31
|
-
|
|
32
|
-
import numpy as np
|
|
21
|
+
from typing import Any, Generic, Iterator, Mapping, Sequence, TYPE_CHECKING, TypeVar
|
|
22
|
+
|
|
33
23
|
from typing_extensions import Self
|
|
34
24
|
|
|
35
25
|
from cirq import protocols, value
|
|
36
26
|
|
|
37
27
|
if TYPE_CHECKING:
|
|
28
|
+
import numpy as np
|
|
29
|
+
|
|
38
30
|
import cirq
|
|
39
31
|
|
|
40
32
|
|
|
@@ -45,10 +37,7 @@ class SimulationStateBase(Generic[TSimulationState], metaclass=abc.ABCMeta):
|
|
|
45
37
|
"""An interface for quantum states as targets for operations."""
|
|
46
38
|
|
|
47
39
|
def __init__(
|
|
48
|
-
self,
|
|
49
|
-
*,
|
|
50
|
-
qubits: Sequence['cirq.Qid'],
|
|
51
|
-
classical_data: Optional['cirq.ClassicalDataStore'] = None,
|
|
40
|
+
self, *, qubits: Sequence[cirq.Qid], classical_data: cirq.ClassicalDataStore | None = None
|
|
52
41
|
):
|
|
53
42
|
"""Initializes the class.
|
|
54
43
|
|
|
@@ -61,19 +50,19 @@ class SimulationStateBase(Generic[TSimulationState], metaclass=abc.ABCMeta):
|
|
|
61
50
|
self._classical_data = classical_data or value.ClassicalDataDictionaryStore()
|
|
62
51
|
|
|
63
52
|
@property
|
|
64
|
-
def qubits(self) ->
|
|
53
|
+
def qubits(self) -> tuple[cirq.Qid, ...]:
|
|
65
54
|
return self._qubits
|
|
66
55
|
|
|
67
56
|
@property
|
|
68
|
-
def qubit_map(self) -> Mapping[
|
|
57
|
+
def qubit_map(self) -> Mapping[cirq.Qid, int]:
|
|
69
58
|
return self._qubit_map
|
|
70
59
|
|
|
71
|
-
def _set_qubits(self, qubits: Sequence[
|
|
60
|
+
def _set_qubits(self, qubits: Sequence[cirq.Qid]):
|
|
72
61
|
self._qubits = tuple(qubits)
|
|
73
62
|
self._qubit_map = {q: i for i, q in enumerate(self.qubits)}
|
|
74
63
|
|
|
75
64
|
@property
|
|
76
|
-
def classical_data(self) ->
|
|
65
|
+
def classical_data(self) -> cirq.ClassicalDataStoreReader:
|
|
77
66
|
return self._classical_data
|
|
78
67
|
|
|
79
68
|
@abc.abstractmethod
|
|
@@ -82,8 +71,8 @@ class SimulationStateBase(Generic[TSimulationState], metaclass=abc.ABCMeta):
|
|
|
82
71
|
|
|
83
72
|
@abc.abstractmethod
|
|
84
73
|
def _act_on_fallback_(
|
|
85
|
-
self, action: Any, qubits: Sequence[
|
|
86
|
-
) ->
|
|
74
|
+
self, action: Any, qubits: Sequence[cirq.Qid], allow_decompose: bool = True
|
|
75
|
+
) -> bool | NotImplementedType:
|
|
87
76
|
"""Handles the act_on protocol fallback implementation.
|
|
88
77
|
|
|
89
78
|
Args:
|
|
@@ -94,7 +83,7 @@ class SimulationStateBase(Generic[TSimulationState], metaclass=abc.ABCMeta):
|
|
|
94
83
|
Returns:
|
|
95
84
|
True if the fallback applies, else NotImplemented."""
|
|
96
85
|
|
|
97
|
-
def apply_operation(self, op:
|
|
86
|
+
def apply_operation(self, op: cirq.Operation):
|
|
98
87
|
protocols.act_on(op, self)
|
|
99
88
|
|
|
100
89
|
@abc.abstractmethod
|
|
@@ -111,21 +100,21 @@ class SimulationStateBase(Generic[TSimulationState], metaclass=abc.ABCMeta):
|
|
|
111
100
|
"""
|
|
112
101
|
|
|
113
102
|
@property
|
|
114
|
-
def log_of_measurement_results(self) ->
|
|
103
|
+
def log_of_measurement_results(self) -> dict[str, list[int]]:
|
|
115
104
|
"""Gets the log of measurement results."""
|
|
116
105
|
return {str(k): list(self.classical_data.get_digits(k)) for k in self.classical_data.keys()}
|
|
117
106
|
|
|
118
107
|
@abc.abstractmethod
|
|
119
108
|
def sample(
|
|
120
109
|
self,
|
|
121
|
-
qubits:
|
|
110
|
+
qubits: list[cirq.Qid],
|
|
122
111
|
repetitions: int = 1,
|
|
123
|
-
seed:
|
|
112
|
+
seed: cirq.RANDOM_STATE_OR_SEED_LIKE = None,
|
|
124
113
|
) -> np.ndarray:
|
|
125
114
|
"""Samples the state value."""
|
|
126
115
|
|
|
127
116
|
@abc.abstractmethod
|
|
128
|
-
def __getitem__(self, item:
|
|
117
|
+
def __getitem__(self, item: cirq.Qid | None) -> TSimulationState:
|
|
129
118
|
"""Gets the item associated with the qubit."""
|
|
130
119
|
|
|
131
120
|
@abc.abstractmethod
|
|
@@ -133,5 +122,5 @@ class SimulationStateBase(Generic[TSimulationState], metaclass=abc.ABCMeta):
|
|
|
133
122
|
"""Gets the number of items in the mapping."""
|
|
134
123
|
|
|
135
124
|
@abc.abstractmethod
|
|
136
|
-
def __iter__(self) -> Iterator[
|
|
125
|
+
def __iter__(self) -> Iterator[cirq.Qid | None]:
|
|
137
126
|
"""Iterates the keys of the mapping."""
|
|
@@ -12,6 +12,8 @@
|
|
|
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
|
from typing import Any, Sequence
|
|
16
18
|
|
|
17
19
|
import numpy as np
|
|
@@ -38,7 +40,7 @@ class ExampleSimulationState(cirq.SimulationState):
|
|
|
38
40
|
super().__init__(state=ExampleQuantumState(), qubits=qubits)
|
|
39
41
|
|
|
40
42
|
def _act_on_fallback_(
|
|
41
|
-
self, action: Any, qubits: Sequence[
|
|
43
|
+
self, action: Any, qubits: Sequence[cirq.Qid], allow_decompose: bool = True
|
|
42
44
|
) -> bool:
|
|
43
45
|
return True
|
|
44
46
|
|
|
@@ -72,20 +74,20 @@ class Composite(cirq.Gate):
|
|
|
72
74
|
yield cirq.X(*qubits)
|
|
73
75
|
|
|
74
76
|
|
|
75
|
-
def test_measurements():
|
|
77
|
+
def test_measurements() -> None:
|
|
76
78
|
args = ExampleSimulationState()
|
|
77
79
|
args.measure([cirq.LineQubit(0)], "test", [False], {})
|
|
78
80
|
assert args.log_of_measurement_results["test"] == [5]
|
|
79
81
|
|
|
80
82
|
|
|
81
|
-
def test_decompose():
|
|
83
|
+
def test_decompose() -> None:
|
|
82
84
|
args = ExampleSimulationState()
|
|
83
85
|
assert simulation_state.strat_act_on_from_apply_decompose(
|
|
84
86
|
Composite(), args, [cirq.LineQubit(0)]
|
|
85
87
|
)
|
|
86
88
|
|
|
87
89
|
|
|
88
|
-
def test_decompose_for_gate_allocating_qubits_raises():
|
|
90
|
+
def test_decompose_for_gate_allocating_qubits_raises() -> None:
|
|
89
91
|
class Composite(cirq.testing.SingleQubitGate):
|
|
90
92
|
def _decompose_(self, qubits):
|
|
91
93
|
anc = cirq.NamedQubit("anc")
|
|
@@ -97,7 +99,7 @@ def test_decompose_for_gate_allocating_qubits_raises():
|
|
|
97
99
|
simulation_state.strat_act_on_from_apply_decompose(Composite(), args, [cirq.LineQubit(0)])
|
|
98
100
|
|
|
99
101
|
|
|
100
|
-
def test_mapping():
|
|
102
|
+
def test_mapping() -> None:
|
|
101
103
|
args = ExampleSimulationState()
|
|
102
104
|
assert list(iter(args)) == cirq.LineQubit.range(2)
|
|
103
105
|
r1 = args[cirq.LineQubit(0)]
|
|
@@ -106,7 +108,7 @@ def test_mapping():
|
|
|
106
108
|
_ = args[cirq.LineQubit(2)]
|
|
107
109
|
|
|
108
110
|
|
|
109
|
-
def test_swap_bad_dimensions():
|
|
111
|
+
def test_swap_bad_dimensions() -> None:
|
|
110
112
|
q0 = cirq.LineQubit(0)
|
|
111
113
|
q1 = cirq.LineQid(1, 3)
|
|
112
114
|
args = ExampleSimulationState()
|
|
@@ -114,7 +116,7 @@ def test_swap_bad_dimensions():
|
|
|
114
116
|
args.swap(q0, q1)
|
|
115
117
|
|
|
116
118
|
|
|
117
|
-
def test_rename_bad_dimensions():
|
|
119
|
+
def test_rename_bad_dimensions() -> None:
|
|
118
120
|
q0 = cirq.LineQubit(0)
|
|
119
121
|
q1 = cirq.LineQid(1, 3)
|
|
120
122
|
args = ExampleSimulationState()
|
|
@@ -122,7 +124,7 @@ def test_rename_bad_dimensions():
|
|
|
122
124
|
args.rename(q0, q1)
|
|
123
125
|
|
|
124
126
|
|
|
125
|
-
def test_transpose_qubits():
|
|
127
|
+
def test_transpose_qubits() -> None:
|
|
126
128
|
q0, q1, q2 = cirq.LineQubit.range(3)
|
|
127
129
|
args = ExampleSimulationState()
|
|
128
130
|
assert args.transpose_to_qubit_order((q1, q0)).qubits == (q1, q0)
|
|
@@ -132,14 +134,14 @@ def test_transpose_qubits():
|
|
|
132
134
|
args.transpose_to_qubit_order((q0, q1, q1))
|
|
133
135
|
|
|
134
136
|
|
|
135
|
-
def test_field_getters():
|
|
137
|
+
def test_field_getters() -> None:
|
|
136
138
|
args = ExampleSimulationState()
|
|
137
139
|
assert args.prng is np.random
|
|
138
140
|
assert args.qubit_map == {q: i for i, q in enumerate(cirq.LineQubit.range(2))}
|
|
139
141
|
|
|
140
142
|
|
|
141
143
|
@pytest.mark.parametrize('exp', np.linspace(0, 2 * np.pi, 10))
|
|
142
|
-
def test_delegating_gate_unitary(exp):
|
|
144
|
+
def test_delegating_gate_unitary(exp) -> None:
|
|
143
145
|
q = cirq.LineQubit(0)
|
|
144
146
|
|
|
145
147
|
test_circuit = cirq.Circuit()
|
|
@@ -154,7 +156,7 @@ def test_delegating_gate_unitary(exp):
|
|
|
154
156
|
|
|
155
157
|
|
|
156
158
|
@pytest.mark.parametrize('exp', np.linspace(0, 2 * np.pi, 10))
|
|
157
|
-
def test_delegating_gate_channel(exp):
|
|
159
|
+
def test_delegating_gate_channel(exp) -> None:
|
|
158
160
|
q = cirq.LineQubit(0)
|
|
159
161
|
|
|
160
162
|
test_circuit = cirq.Circuit()
|
|
@@ -169,7 +171,7 @@ def test_delegating_gate_channel(exp):
|
|
|
169
171
|
|
|
170
172
|
|
|
171
173
|
@pytest.mark.parametrize('num_ancilla', [1, 2, 3])
|
|
172
|
-
def test_phase_using_dirty_ancilla(num_ancilla: int):
|
|
174
|
+
def test_phase_using_dirty_ancilla(num_ancilla: int) -> None:
|
|
173
175
|
q = cirq.LineQubit(0)
|
|
174
176
|
anc = cirq.NamedQubit.range(num_ancilla, prefix='anc')
|
|
175
177
|
|
|
@@ -184,7 +186,7 @@ def test_phase_using_dirty_ancilla(num_ancilla: int):
|
|
|
184
186
|
|
|
185
187
|
@pytest.mark.parametrize('num_ancilla', [1, 2, 3])
|
|
186
188
|
@pytest.mark.parametrize('theta', np.linspace(0, 2 * np.pi, 10))
|
|
187
|
-
def test_phase_using_clean_ancilla(num_ancilla: int, theta: float):
|
|
189
|
+
def test_phase_using_clean_ancilla(num_ancilla: int, theta: float) -> None:
|
|
188
190
|
q = cirq.LineQubit(0)
|
|
189
191
|
u = cirq.MatrixGate(cirq.testing.random_unitary(2))
|
|
190
192
|
test_circuit = cirq.Circuit(
|
cirq/sim/simulation_utils.py
CHANGED
|
@@ -11,7 +11,9 @@
|
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
|
-
from
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
from typing import Any, Sequence
|
|
15
17
|
|
|
16
18
|
import numpy as np
|
|
17
19
|
|
|
@@ -19,7 +21,7 @@ from cirq import linalg
|
|
|
19
21
|
|
|
20
22
|
|
|
21
23
|
def state_probabilities_by_indices(
|
|
22
|
-
state_probability: np.ndarray, indices: Sequence[int], qid_shape:
|
|
24
|
+
state_probability: np.ndarray, indices: Sequence[int], qid_shape: tuple[int, ...]
|
|
23
25
|
) -> np.ndarray:
|
|
24
26
|
"""Returns the probabilities for a state/measurement on the given indices.
|
|
25
27
|
|
|
@@ -37,6 +39,7 @@ def state_probabilities_by_indices(
|
|
|
37
39
|
Returns:
|
|
38
40
|
State probabilities.
|
|
39
41
|
"""
|
|
42
|
+
probs: np.ndarray[tuple[int, ...], Any]
|
|
40
43
|
probs = state_probability.reshape((-1,))
|
|
41
44
|
not_measured = [i for i in range(len(qid_shape)) if i not in indices]
|
|
42
45
|
if linalg.can_numpy_support_shape(qid_shape):
|