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
cirq/study/sweeps.py
CHANGED
|
@@ -11,23 +11,13 @@
|
|
|
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
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
14
17
|
import abc
|
|
15
18
|
import collections
|
|
16
19
|
import itertools
|
|
17
|
-
from typing import
|
|
18
|
-
Any,
|
|
19
|
-
cast,
|
|
20
|
-
Dict,
|
|
21
|
-
Iterable,
|
|
22
|
-
Iterator,
|
|
23
|
-
List,
|
|
24
|
-
Optional,
|
|
25
|
-
overload,
|
|
26
|
-
Sequence,
|
|
27
|
-
Tuple,
|
|
28
|
-
TYPE_CHECKING,
|
|
29
|
-
Union,
|
|
30
|
-
)
|
|
20
|
+
from typing import Any, cast, Iterable, Iterator, overload, Sequence, TYPE_CHECKING, Union
|
|
31
21
|
|
|
32
22
|
import sympy
|
|
33
23
|
|
|
@@ -38,8 +28,8 @@ from cirq.study import resolver
|
|
|
38
28
|
if TYPE_CHECKING:
|
|
39
29
|
import cirq
|
|
40
30
|
|
|
41
|
-
Params = Iterable[
|
|
42
|
-
ProductOrZipSweepLike =
|
|
31
|
+
Params = Iterable[tuple['cirq.TParamKey', 'cirq.TParamVal']]
|
|
32
|
+
ProductOrZipSweepLike = dict['cirq.TParamKey', Union['cirq.TParamVal', Sequence['cirq.TParamVal']]]
|
|
43
33
|
|
|
44
34
|
|
|
45
35
|
def _check_duplicate_keys(sweeps):
|
|
@@ -71,8 +61,8 @@ class Sweep(metaclass=abc.ABCMeta):
|
|
|
71
61
|
see the Product and Zip documentation.
|
|
72
62
|
"""
|
|
73
63
|
|
|
74
|
-
def __mul__(self, other:
|
|
75
|
-
factors:
|
|
64
|
+
def __mul__(self, other: Sweep) -> Sweep:
|
|
65
|
+
factors: list[Sweep] = []
|
|
76
66
|
if isinstance(self, Product):
|
|
77
67
|
factors.extend(self.factors)
|
|
78
68
|
else:
|
|
@@ -85,8 +75,8 @@ class Sweep(metaclass=abc.ABCMeta):
|
|
|
85
75
|
raise TypeError(f'cannot multiply sweep and {type(other)}')
|
|
86
76
|
return Product(*factors)
|
|
87
77
|
|
|
88
|
-
def __add__(self, other:
|
|
89
|
-
sweeps:
|
|
78
|
+
def __add__(self, other: Sweep) -> Sweep:
|
|
79
|
+
sweeps: list[Sweep] = []
|
|
90
80
|
if isinstance(self, Zip):
|
|
91
81
|
sweeps.extend(self.sweeps)
|
|
92
82
|
else:
|
|
@@ -108,7 +98,7 @@ class Sweep(metaclass=abc.ABCMeta):
|
|
|
108
98
|
|
|
109
99
|
@property
|
|
110
100
|
@abc.abstractmethod
|
|
111
|
-
def keys(self) ->
|
|
101
|
+
def keys(self) -> list[cirq.TParamKey]:
|
|
112
102
|
"""The keys for the all of the sympy.Symbols that are resolved."""
|
|
113
103
|
|
|
114
104
|
@abc.abstractmethod
|
|
@@ -119,16 +109,15 @@ class Sweep(metaclass=abc.ABCMeta):
|
|
|
119
109
|
for params in self.param_tuples():
|
|
120
110
|
yield resolver.ParamResolver(collections.OrderedDict(params))
|
|
121
111
|
|
|
122
|
-
# pylint: disable=function-redefined
|
|
123
112
|
@overload
|
|
124
113
|
def __getitem__(self, val: int) -> resolver.ParamResolver:
|
|
125
114
|
pass
|
|
126
115
|
|
|
127
116
|
@overload
|
|
128
|
-
def __getitem__(self, val: slice) ->
|
|
117
|
+
def __getitem__(self, val: slice) -> Sweep:
|
|
129
118
|
pass
|
|
130
119
|
|
|
131
|
-
def __getitem__(self, val:
|
|
120
|
+
def __getitem__(self, val: int | slice) -> resolver.ParamResolver | Sweep:
|
|
132
121
|
n = len(self)
|
|
133
122
|
if isinstance(val, int):
|
|
134
123
|
if val < -n or val >= n:
|
|
@@ -139,7 +128,7 @@ class Sweep(metaclass=abc.ABCMeta):
|
|
|
139
128
|
if not isinstance(val, slice):
|
|
140
129
|
raise TypeError(f'Sweep indices must be either int or slices, not {type(val)}')
|
|
141
130
|
|
|
142
|
-
inds_map:
|
|
131
|
+
inds_map: dict[int, int] = {
|
|
143
132
|
sweep_i: slice_i for slice_i, sweep_i in enumerate(range(n)[val])
|
|
144
133
|
}
|
|
145
134
|
results = [resolver.ParamResolver()] * len(inds_map)
|
|
@@ -149,8 +138,6 @@ class Sweep(metaclass=abc.ABCMeta):
|
|
|
149
138
|
|
|
150
139
|
return ListSweep(results)
|
|
151
140
|
|
|
152
|
-
# pylint: enable=function-redefined
|
|
153
|
-
|
|
154
141
|
@abc.abstractmethod
|
|
155
142
|
def param_tuples(self) -> Iterator[Params]:
|
|
156
143
|
"""An iterator over (key, value) pairs assigning Symbol key to value."""
|
|
@@ -186,7 +173,7 @@ class _Unit(Sweep):
|
|
|
186
173
|
return True
|
|
187
174
|
|
|
188
175
|
@property
|
|
189
|
-
def keys(self) ->
|
|
176
|
+
def keys(self) -> list[cirq.TParamKey]:
|
|
190
177
|
return []
|
|
191
178
|
|
|
192
179
|
def __len__(self) -> int:
|
|
@@ -198,7 +185,7 @@ class _Unit(Sweep):
|
|
|
198
185
|
def __repr__(self) -> str:
|
|
199
186
|
return 'cirq.UnitSweep'
|
|
200
187
|
|
|
201
|
-
def _json_dict_(self) ->
|
|
188
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
202
189
|
return {}
|
|
203
190
|
|
|
204
191
|
|
|
@@ -233,8 +220,8 @@ class Product(Sweep):
|
|
|
233
220
|
return hash(tuple(self.factors))
|
|
234
221
|
|
|
235
222
|
@property
|
|
236
|
-
def keys(self) ->
|
|
237
|
-
return
|
|
223
|
+
def keys(self) -> list[cirq.TParamKey]:
|
|
224
|
+
return list(itertools.chain.from_iterable(factor.keys for factor in self.factors))
|
|
238
225
|
|
|
239
226
|
def __len__(self) -> int:
|
|
240
227
|
length = 1
|
|
@@ -243,16 +230,10 @@ class Product(Sweep):
|
|
|
243
230
|
return length
|
|
244
231
|
|
|
245
232
|
def param_tuples(self) -> Iterator[Params]:
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
first, rest = factors[0], factors[1:]
|
|
251
|
-
for first_values in first.param_tuples():
|
|
252
|
-
for rest_values in _gen(rest):
|
|
253
|
-
yield first_values + rest_values
|
|
254
|
-
|
|
255
|
-
return _gen(self.factors)
|
|
233
|
+
yield from map(
|
|
234
|
+
lambda values: tuple(itertools.chain.from_iterable(values)),
|
|
235
|
+
itertools.product(*(factor.param_tuples() for factor in self.factors)),
|
|
236
|
+
)
|
|
256
237
|
|
|
257
238
|
def __repr__(self) -> str:
|
|
258
239
|
factors_repr = ', '.join(repr(f) for f in self.factors)
|
|
@@ -269,7 +250,7 @@ class Product(Sweep):
|
|
|
269
250
|
factor_strs.append(factor_str)
|
|
270
251
|
return ' * '.join(factor_strs)
|
|
271
252
|
|
|
272
|
-
def _json_dict_(self) ->
|
|
253
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
273
254
|
return protocols.obj_to_dict_helper(self, ['factors'])
|
|
274
255
|
|
|
275
256
|
@classmethod
|
|
@@ -308,7 +289,7 @@ class Concat(Sweep):
|
|
|
308
289
|
return hash(tuple(self.sweeps))
|
|
309
290
|
|
|
310
291
|
@property
|
|
311
|
-
def keys(self) ->
|
|
292
|
+
def keys(self) -> list[cirq.TParamKey]:
|
|
312
293
|
return self.sweeps[0].keys
|
|
313
294
|
|
|
314
295
|
def __len__(self) -> int:
|
|
@@ -326,7 +307,7 @@ class Concat(Sweep):
|
|
|
326
307
|
sweeps_repr = ', '.join(repr(s) for s in self.sweeps)
|
|
327
308
|
return f'Concat({sweeps_repr})'
|
|
328
309
|
|
|
329
|
-
def _json_dict_(self) ->
|
|
310
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
330
311
|
return protocols.obj_to_dict_helper(self, ['sweeps'])
|
|
331
312
|
|
|
332
313
|
@classmethod
|
|
@@ -361,8 +342,8 @@ class Zip(Sweep):
|
|
|
361
342
|
return hash(tuple(self.sweeps))
|
|
362
343
|
|
|
363
344
|
@property
|
|
364
|
-
def keys(self) ->
|
|
365
|
-
return
|
|
345
|
+
def keys(self) -> list[cirq.TParamKey]:
|
|
346
|
+
return list(itertools.chain.from_iterable(sweep.keys for sweep in self.sweeps))
|
|
366
347
|
|
|
367
348
|
def __len__(self) -> int:
|
|
368
349
|
if not self.sweeps:
|
|
@@ -372,7 +353,7 @@ class Zip(Sweep):
|
|
|
372
353
|
def param_tuples(self) -> Iterator[Params]:
|
|
373
354
|
iters = [sweep.param_tuples() for sweep in self.sweeps]
|
|
374
355
|
for values in zip(*iters):
|
|
375
|
-
yield
|
|
356
|
+
yield tuple(itertools.chain.from_iterable(values))
|
|
376
357
|
|
|
377
358
|
def __repr__(self) -> str:
|
|
378
359
|
sweeps_repr = ', '.join(repr(s) for s in self.sweeps)
|
|
@@ -383,7 +364,7 @@ class Zip(Sweep):
|
|
|
383
364
|
return 'Zip()'
|
|
384
365
|
return ' + '.join(str(s) if isinstance(s, Product) else repr(s) for s in self.sweeps)
|
|
385
366
|
|
|
386
|
-
def _json_dict_(self) ->
|
|
367
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
387
368
|
return protocols.obj_to_dict_helper(self, ['sweeps'])
|
|
388
369
|
|
|
389
370
|
@classmethod
|
|
@@ -449,7 +430,7 @@ class ZipLongest(Zip):
|
|
|
449
430
|
class SingleSweep(Sweep):
|
|
450
431
|
"""A simple sweep over one parameter with values from an iterator."""
|
|
451
432
|
|
|
452
|
-
def __init__(self, key:
|
|
433
|
+
def __init__(self, key: cirq.TParamKey) -> None:
|
|
453
434
|
if isinstance(key, sympy.Symbol):
|
|
454
435
|
key = str(key)
|
|
455
436
|
self.key = key
|
|
@@ -463,11 +444,11 @@ class SingleSweep(Sweep):
|
|
|
463
444
|
return hash((self.__class__, self._tuple()))
|
|
464
445
|
|
|
465
446
|
@abc.abstractmethod
|
|
466
|
-
def _tuple(self) ->
|
|
447
|
+
def _tuple(self) -> tuple[Any, ...]:
|
|
467
448
|
pass
|
|
468
449
|
|
|
469
450
|
@property
|
|
470
|
-
def keys(self) ->
|
|
451
|
+
def keys(self) -> list[cirq.TParamKey]:
|
|
471
452
|
return [self.key]
|
|
472
453
|
|
|
473
454
|
def param_tuples(self) -> Iterator[Params]:
|
|
@@ -483,7 +464,7 @@ class Points(SingleSweep):
|
|
|
483
464
|
"""A simple sweep with explicitly supplied values."""
|
|
484
465
|
|
|
485
466
|
def __init__(
|
|
486
|
-
self, key:
|
|
467
|
+
self, key: cirq.TParamKey, points: Sequence[float], metadata: Any | None = None
|
|
487
468
|
) -> None:
|
|
488
469
|
"""Creates a sweep on a variable with supplied values.
|
|
489
470
|
|
|
@@ -500,7 +481,7 @@ class Points(SingleSweep):
|
|
|
500
481
|
self.points = points
|
|
501
482
|
self.metadata = metadata
|
|
502
483
|
|
|
503
|
-
def _tuple(self) ->
|
|
484
|
+
def _tuple(self) -> tuple[str | sympy.Expr, Sequence[float]]:
|
|
504
485
|
return self.key, tuple(self.points)
|
|
505
486
|
|
|
506
487
|
def __len__(self) -> int:
|
|
@@ -513,7 +494,7 @@ class Points(SingleSweep):
|
|
|
513
494
|
metadata_repr = f', metadata={self.metadata!r}' if self.metadata is not None else ""
|
|
514
495
|
return f'cirq.Points({self.key!r}, {self.points!r}{metadata_repr})'
|
|
515
496
|
|
|
516
|
-
def _json_dict_(self) ->
|
|
497
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
517
498
|
if self.metadata is not None:
|
|
518
499
|
return protocols.obj_to_dict_helper(self, ["key", "points", "metadata"])
|
|
519
500
|
return protocols.obj_to_dict_helper(self, ["key", "points"])
|
|
@@ -524,11 +505,11 @@ class Linspace(SingleSweep):
|
|
|
524
505
|
|
|
525
506
|
def __init__(
|
|
526
507
|
self,
|
|
527
|
-
key:
|
|
508
|
+
key: cirq.TParamKey,
|
|
528
509
|
start: float,
|
|
529
510
|
stop: float,
|
|
530
511
|
length: int,
|
|
531
|
-
metadata:
|
|
512
|
+
metadata: Any | None = None,
|
|
532
513
|
) -> None:
|
|
533
514
|
"""Creates a linear-spaced sweep for a given key.
|
|
534
515
|
|
|
@@ -549,7 +530,7 @@ class Linspace(SingleSweep):
|
|
|
549
530
|
self.length = length
|
|
550
531
|
self.metadata = metadata
|
|
551
532
|
|
|
552
|
-
def _tuple(self) ->
|
|
533
|
+
def _tuple(self) -> tuple[str | sympy.Expr, float, float, int]:
|
|
553
534
|
return (self.key, self.start, self.stop, self.length)
|
|
554
535
|
|
|
555
536
|
def __len__(self) -> int:
|
|
@@ -570,7 +551,7 @@ class Linspace(SingleSweep):
|
|
|
570
551
|
f'stop={self.stop!r}, length={self.length!r}{metadata_repr})'
|
|
571
552
|
)
|
|
572
553
|
|
|
573
|
-
def _json_dict_(self) ->
|
|
554
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
574
555
|
if self.metadata is not None:
|
|
575
556
|
return protocols.obj_to_dict_helper(
|
|
576
557
|
self, ["key", "start", "stop", "length", "metadata"]
|
|
@@ -592,7 +573,7 @@ class ListSweep(Sweep):
|
|
|
592
573
|
TypeError: If `resolver_list` is not a `cirq.ParamResolver` or a
|
|
593
574
|
dict.
|
|
594
575
|
"""
|
|
595
|
-
self.resolver_list:
|
|
576
|
+
self.resolver_list: list[resolver.ParamResolver] = []
|
|
596
577
|
for r in resolver_list:
|
|
597
578
|
if not isinstance(r, (dict, resolver.ParamResolver)):
|
|
598
579
|
raise TypeError(f'Not a ParamResolver or dict: <{r!r}>')
|
|
@@ -607,7 +588,7 @@ class ListSweep(Sweep):
|
|
|
607
588
|
return not self == other
|
|
608
589
|
|
|
609
590
|
@property
|
|
610
|
-
def keys(self) ->
|
|
591
|
+
def keys(self) -> list[cirq.TParamKey]:
|
|
611
592
|
if not self.resolver_list:
|
|
612
593
|
return []
|
|
613
594
|
return list(map(str, self.resolver_list[0].param_dict))
|
|
@@ -622,7 +603,7 @@ class ListSweep(Sweep):
|
|
|
622
603
|
def __repr__(self) -> str:
|
|
623
604
|
return f'cirq.ListSweep({self.resolver_list!r})'
|
|
624
605
|
|
|
625
|
-
def _json_dict_(self) ->
|
|
606
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
626
607
|
return protocols.obj_to_dict_helper(self, ["resolver_list"])
|
|
627
608
|
|
|
628
609
|
|
cirq/study/sweeps_test.py
CHANGED
|
@@ -11,6 +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
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
14
17
|
import pytest
|
|
15
18
|
import sympy
|
|
16
19
|
|
|
@@ -76,6 +79,11 @@ def test_zip():
|
|
|
76
79
|
assert len(sweep) == 3
|
|
77
80
|
assert _values(sweep, 'a') == [1, 2, 3]
|
|
78
81
|
assert _values(sweep, 'b') == [4, 5, 6]
|
|
82
|
+
assert list(sweep.param_tuples()) == [
|
|
83
|
+
(('a', 1), ('b', 4)),
|
|
84
|
+
(('a', 2), ('b', 5)),
|
|
85
|
+
(('a', 3), ('b', 6)),
|
|
86
|
+
]
|
|
79
87
|
|
|
80
88
|
|
|
81
89
|
def test_zip_longest():
|
|
@@ -150,6 +158,30 @@ def test_product():
|
|
|
150
158
|
assert _values(sweep, 'b') == [3, 3, 4, 4, 3, 3, 4, 4]
|
|
151
159
|
assert _values(sweep, 'c') == [5, 6, 5, 6, 5, 6, 5, 6]
|
|
152
160
|
|
|
161
|
+
sweep = cirq.Points('a', [1, 2]) * (cirq.Points('b', [3, 4, 5]))
|
|
162
|
+
assert list(map(list, sweep.param_tuples())) == [
|
|
163
|
+
[('a', 1), ('b', 3)],
|
|
164
|
+
[('a', 1), ('b', 4)],
|
|
165
|
+
[('a', 1), ('b', 5)],
|
|
166
|
+
[('a', 2), ('b', 3)],
|
|
167
|
+
[('a', 2), ('b', 4)],
|
|
168
|
+
[('a', 2), ('b', 5)],
|
|
169
|
+
]
|
|
170
|
+
|
|
171
|
+
sweep = cirq.Product(*[cirq.Points(str(i), [0]) for i in range(1025)])
|
|
172
|
+
assert list(map(list, sweep.param_tuples())) == [[(str(i), 0) for i in range(1025)]]
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def test_nested_product_zip():
|
|
176
|
+
sweep = cirq.Product(
|
|
177
|
+
cirq.Product(cirq.Points('a', [0]), cirq.Points('b', [0])),
|
|
178
|
+
cirq.Zip(cirq.Points('c', [0, 1]), cirq.Points('d', [0, 1])),
|
|
179
|
+
)
|
|
180
|
+
assert list(map(list, sweep.param_tuples())) == [
|
|
181
|
+
[('a', 0), ('b', 0), ('c', 0), ('d', 0)],
|
|
182
|
+
[('a', 0), ('b', 0), ('c', 1), ('d', 1)],
|
|
183
|
+
]
|
|
184
|
+
|
|
153
185
|
|
|
154
186
|
def test_zip_addition():
|
|
155
187
|
zip_sweep = cirq.Zip(cirq.Points('a', [1, 2]), cirq.Points('b', [3, 4]))
|
|
@@ -164,6 +196,7 @@ def test_empty_product():
|
|
|
164
196
|
sweep = cirq.Product()
|
|
165
197
|
assert len(sweep) == len(list(sweep)) == 1
|
|
166
198
|
assert str(sweep) == 'Product()'
|
|
199
|
+
assert list(map(list, sweep.param_tuples())) == [[]]
|
|
167
200
|
|
|
168
201
|
|
|
169
202
|
def test_slice_access_error():
|
cirq/testing/__init__.py
CHANGED
|
@@ -15,12 +15,11 @@
|
|
|
15
15
|
"""Utilities for testing code."""
|
|
16
16
|
|
|
17
17
|
from cirq.testing.circuit_compare import (
|
|
18
|
-
#
|
|
19
|
-
|
|
20
|
-
assert_circuits_have_same_unitary_given_final_permutation as assert_circuits_have_same_unitary_given_final_permutation,
|
|
18
|
+
assert_circuits_with_terminal_measurements_are_equivalent as assert_circuits_with_terminal_measurements_are_equivalent, # noqa: E501
|
|
19
|
+
assert_circuits_have_same_unitary_given_final_permutation as assert_circuits_have_same_unitary_given_final_permutation, # noqa: E501
|
|
21
20
|
assert_has_consistent_apply_channel as assert_has_consistent_apply_channel,
|
|
22
21
|
assert_has_consistent_apply_unitary as assert_has_consistent_apply_unitary,
|
|
23
|
-
assert_has_consistent_apply_unitary_for_various_exponents as assert_has_consistent_apply_unitary_for_various_exponents,
|
|
22
|
+
assert_has_consistent_apply_unitary_for_various_exponents as assert_has_consistent_apply_unitary_for_various_exponents, # noqa: E501
|
|
24
23
|
assert_has_diagram as assert_has_diagram,
|
|
25
24
|
assert_same_circuits as assert_same_circuits,
|
|
26
25
|
highlight_text_differences as highlight_text_differences,
|
|
@@ -28,8 +27,7 @@ from cirq.testing.circuit_compare import (
|
|
|
28
27
|
)
|
|
29
28
|
|
|
30
29
|
from cirq.testing.consistent_act_on import (
|
|
31
|
-
#
|
|
32
|
-
assert_all_implemented_act_on_effects_match_unitary as assert_all_implemented_act_on_effects_match_unitary,
|
|
30
|
+
assert_all_implemented_act_on_effects_match_unitary as assert_all_implemented_act_on_effects_match_unitary, # noqa: E501
|
|
33
31
|
)
|
|
34
32
|
|
|
35
33
|
from cirq.testing.consistent_channels import (
|
|
@@ -48,8 +46,7 @@ from cirq.testing.consistent_decomposition import (
|
|
|
48
46
|
)
|
|
49
47
|
|
|
50
48
|
from cirq.testing.consistent_pauli_expansion import (
|
|
51
|
-
#
|
|
52
|
-
assert_pauli_expansion_is_consistent_with_unitary as assert_pauli_expansion_is_consistent_with_unitary,
|
|
49
|
+
assert_pauli_expansion_is_consistent_with_unitary as assert_pauli_expansion_is_consistent_with_unitary, # noqa: E501
|
|
53
50
|
)
|
|
54
51
|
|
|
55
52
|
from cirq.testing.consistent_phase_by import (
|
|
@@ -57,11 +54,10 @@ from cirq.testing.consistent_phase_by import (
|
|
|
57
54
|
)
|
|
58
55
|
|
|
59
56
|
from cirq.testing.consistent_protocols import (
|
|
60
|
-
#
|
|
61
|
-
assert_eigengate_implements_consistent_protocols as assert_eigengate_implements_consistent_protocols,
|
|
57
|
+
assert_eigengate_implements_consistent_protocols as assert_eigengate_implements_consistent_protocols, # noqa: E501
|
|
62
58
|
assert_has_consistent_trace_distance_bound as assert_has_consistent_trace_distance_bound,
|
|
63
59
|
assert_implements_consistent_protocols as assert_implements_consistent_protocols,
|
|
64
|
-
assert_commutes_magic_method_consistent_with_unitaries as assert_commutes_magic_method_consistent_with_unitaries,
|
|
60
|
+
assert_commutes_magic_method_consistent_with_unitaries as assert_commutes_magic_method_consistent_with_unitaries, # noqa: E501
|
|
65
61
|
)
|
|
66
62
|
|
|
67
63
|
from cirq.testing.consistent_qasm import (
|
cirq/testing/circuit_compare.py
CHANGED
|
@@ -12,10 +12,12 @@
|
|
|
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 itertools
|
|
16
18
|
import random
|
|
17
19
|
from collections import defaultdict
|
|
18
|
-
from typing import Any,
|
|
20
|
+
from typing import Any, Iterable, Sequence
|
|
19
21
|
|
|
20
22
|
import numpy as np
|
|
21
23
|
import sympy
|
|
@@ -78,7 +80,7 @@ def _measurement_subspaces(
|
|
|
78
80
|
measurement_mask |= 1 << i
|
|
79
81
|
|
|
80
82
|
# Keyed by computational basis state with lowest index.
|
|
81
|
-
measurement_subspaces:
|
|
83
|
+
measurement_subspaces: dict[int, list[int]] = defaultdict(list)
|
|
82
84
|
computational_basis = range(1 << n_qubits)
|
|
83
85
|
|
|
84
86
|
for basis_state in computational_basis:
|
|
@@ -115,9 +117,7 @@ def assert_circuits_with_terminal_measurements_are_equivalent(
|
|
|
115
117
|
reference: A circuit with the correct function.
|
|
116
118
|
atol: Absolute error tolerance.
|
|
117
119
|
"""
|
|
118
|
-
# pylint: disable=unused-variable
|
|
119
120
|
__tracebackhide__ = True
|
|
120
|
-
# pylint: enable=unused-variable
|
|
121
121
|
|
|
122
122
|
measured_qubits_actual = {
|
|
123
123
|
qubit
|
|
@@ -213,7 +213,7 @@ def assert_same_circuits(
|
|
|
213
213
|
|
|
214
214
|
def _first_differing_moment_index(
|
|
215
215
|
circuit1: circuits.AbstractCircuit, circuit2: circuits.AbstractCircuit
|
|
216
|
-
) ->
|
|
216
|
+
) -> int | None:
|
|
217
217
|
for i, (m1, m2) in enumerate(itertools.zip_longest(circuit1, circuit2)):
|
|
218
218
|
if m1 != m2:
|
|
219
219
|
return i
|
|
@@ -223,7 +223,7 @@ def _first_differing_moment_index(
|
|
|
223
223
|
def assert_circuits_have_same_unitary_given_final_permutation(
|
|
224
224
|
actual: circuits.AbstractCircuit,
|
|
225
225
|
expected: circuits.AbstractCircuit,
|
|
226
|
-
qubit_map:
|
|
226
|
+
qubit_map: dict[ops.Qid, ops.Qid],
|
|
227
227
|
) -> None:
|
|
228
228
|
"""Asserts two circuits have the same unitary up to a final permutation of qubits.
|
|
229
229
|
|
|
@@ -255,7 +255,7 @@ def assert_circuits_have_same_unitary_given_final_permutation(
|
|
|
255
255
|
|
|
256
256
|
|
|
257
257
|
def assert_has_diagram(
|
|
258
|
-
actual:
|
|
258
|
+
actual: circuits.AbstractCircuit | circuits.Moment, desired: str, **kwargs
|
|
259
259
|
) -> None:
|
|
260
260
|
"""Determines if a given circuit has the desired text diagram.
|
|
261
261
|
|
|
@@ -265,9 +265,7 @@ def assert_has_diagram(
|
|
|
265
265
|
beginning and whitespace at the end are ignored.
|
|
266
266
|
**kwargs: Keyword arguments to be passed to actual.to_text_diagram().
|
|
267
267
|
"""
|
|
268
|
-
# pylint: disable=unused-variable
|
|
269
268
|
__tracebackhide__ = True
|
|
270
|
-
# pylint: enable=unused-variable
|
|
271
269
|
actual_diagram = actual.to_text_diagram(**kwargs).lstrip("\n").rstrip()
|
|
272
270
|
desired_diagram = desired.lstrip("\n").rstrip()
|
|
273
271
|
|
|
@@ -295,9 +293,7 @@ def assert_has_consistent_apply_unitary(val: Any, *, atol: float = 1e-8) -> None
|
|
|
295
293
|
val: The value under test. Should have a `__pow__` method.
|
|
296
294
|
atol: Absolute error tolerance.
|
|
297
295
|
"""
|
|
298
|
-
# pylint: disable=unused-variable
|
|
299
296
|
__tracebackhide__ = True
|
|
300
|
-
# pylint: enable=unused-variable
|
|
301
297
|
|
|
302
298
|
_assert_apply_unitary_works_when_axes_transposed(val, atol=atol)
|
|
303
299
|
|
|
@@ -339,9 +335,8 @@ def assert_has_consistent_apply_channel(val: Any, *, atol: float = 1e-8) -> None
|
|
|
339
335
|
val: The value under test. Should have a `__pow__` method.
|
|
340
336
|
atol: Absolute error tolerance.
|
|
341
337
|
"""
|
|
342
|
-
# pylint: disable=unused-variable
|
|
343
338
|
__tracebackhide__ = True
|
|
344
|
-
|
|
339
|
+
assert hasattr(val, '_apply_channel_')
|
|
345
340
|
|
|
346
341
|
kraus = protocols.kraus(val, default=None)
|
|
347
342
|
expected = qis.kraus_to_superoperator(kraus) if kraus is not None else None
|
|
@@ -461,9 +456,7 @@ def assert_has_consistent_apply_unitary_for_various_exponents(
|
|
|
461
456
|
the value's `__pow__` returns `NotImplemented` for any of these,
|
|
462
457
|
they are skipped.
|
|
463
458
|
"""
|
|
464
|
-
# pylint: disable=unused-variable
|
|
465
459
|
__tracebackhide__ = True
|
|
466
|
-
# pylint: enable=unused-variable
|
|
467
460
|
|
|
468
461
|
for exponent in exponents:
|
|
469
462
|
gate = protocols.pow(val, exponent, default=None)
|
|
@@ -483,9 +476,7 @@ def assert_has_consistent_qid_shape(val: Any) -> None:
|
|
|
483
476
|
val: The value under test. Should have `_qid_shape_` and/or
|
|
484
477
|
`num_qubits_` methods. Can optionally have a `qubits` property.
|
|
485
478
|
"""
|
|
486
|
-
# pylint: disable=unused-variable
|
|
487
479
|
__tracebackhide__ = True
|
|
488
|
-
# pylint: enable=unused-variable
|
|
489
480
|
default = (-1,)
|
|
490
481
|
qid_shape = protocols.qid_shape(val, default)
|
|
491
482
|
num_qubits = protocols.num_qubits(val, default)
|
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
-
from
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from typing import Any, cast, TYPE_CHECKING
|
|
16
18
|
|
|
17
19
|
import numpy as np
|
|
18
20
|
|
|
@@ -20,7 +22,6 @@ from cirq import protocols
|
|
|
20
22
|
from cirq.circuits.circuit import Circuit
|
|
21
23
|
from cirq.devices import LineQubit
|
|
22
24
|
from cirq.ops import common_gates
|
|
23
|
-
from cirq.ops.dense_pauli_string import DensePauliString
|
|
24
25
|
from cirq.qis import clifford_tableau
|
|
25
26
|
from cirq.sim import final_state_vector, state_vector_simulation_state
|
|
26
27
|
from cirq.sim.clifford import (
|
|
@@ -29,8 +30,13 @@ from cirq.sim.clifford import (
|
|
|
29
30
|
stabilizer_state_ch_form,
|
|
30
31
|
)
|
|
31
32
|
|
|
33
|
+
if TYPE_CHECKING:
|
|
34
|
+
import cirq
|
|
35
|
+
|
|
32
36
|
|
|
33
|
-
def state_vector_has_stabilizer(
|
|
37
|
+
def state_vector_has_stabilizer(
|
|
38
|
+
state_vector: np.ndarray, stabilizer: cirq.DensePauliString
|
|
39
|
+
) -> bool:
|
|
34
40
|
"""Checks that the state_vector is stabilized by the given stabilizer.
|
|
35
41
|
|
|
36
42
|
The stabilizer should not modify the value of the state_vector, up to the
|
|
@@ -46,9 +52,9 @@ def state_vector_has_stabilizer(state_vector: np.ndarray, stabilizer: DensePauli
|
|
|
46
52
|
"""
|
|
47
53
|
|
|
48
54
|
qubits = LineQubit.range(protocols.num_qubits(stabilizer))
|
|
49
|
-
complex_dtype:
|
|
55
|
+
complex_dtype: type[np.complexfloating] = np.complex64
|
|
50
56
|
if np.issubdtype(state_vector.dtype, np.complexfloating):
|
|
51
|
-
complex_dtype = cast(
|
|
57
|
+
complex_dtype = cast(type[np.complexfloating], state_vector.dtype)
|
|
52
58
|
args = state_vector_simulation_state.StateVectorSimulationState(
|
|
53
59
|
available_buffer=np.empty_like(state_vector),
|
|
54
60
|
qubits=qubits,
|
|
@@ -79,9 +85,7 @@ def assert_all_implemented_act_on_effects_match_unitary(
|
|
|
79
85
|
val and StabilizerChFormSimulationState inputs.
|
|
80
86
|
"""
|
|
81
87
|
|
|
82
|
-
# pylint: disable=unused-variable
|
|
83
88
|
__tracebackhide__ = True
|
|
84
|
-
# pylint: enable=unused-variable
|
|
85
89
|
|
|
86
90
|
num_qubits_val = protocols.num_qubits(val)
|
|
87
91
|
|
|
@@ -145,9 +149,7 @@ def assert_all_implemented_act_on_effects_match_unitary(
|
|
|
145
149
|
)
|
|
146
150
|
|
|
147
151
|
|
|
148
|
-
def _final_clifford_tableau(
|
|
149
|
-
circuit: Circuit, qubit_map
|
|
150
|
-
) -> Optional[clifford_tableau.CliffordTableau]:
|
|
152
|
+
def _final_clifford_tableau(circuit: Circuit, qubit_map) -> clifford_tableau.CliffordTableau | None:
|
|
151
153
|
"""Evolves a default CliffordTableau through the input circuit.
|
|
152
154
|
|
|
153
155
|
Initializes a CliffordTableau with default args for the given qubits and
|
|
@@ -175,7 +177,7 @@ def _final_clifford_tableau(
|
|
|
175
177
|
|
|
176
178
|
def _final_stabilizer_state_ch_form(
|
|
177
179
|
circuit: Circuit, qubit_map
|
|
178
|
-
) ->
|
|
180
|
+
) -> stabilizer_state_ch_form.StabilizerStateChForm | None:
|
|
179
181
|
"""Evolves a default StabilizerStateChForm through the input circuit.
|
|
180
182
|
|
|
181
183
|
Initializes a StabilizerStateChForm with default args for the given qubits
|
|
@@ -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 Sequence
|
|
16
18
|
|
|
17
19
|
import numpy as np
|
|
@@ -24,7 +26,7 @@ class GoodGate(cirq.testing.SingleQubitGate):
|
|
|
24
26
|
def _unitary_(self):
|
|
25
27
|
return np.array([[0, 1], [1, 0]])
|
|
26
28
|
|
|
27
|
-
def _act_on_(self, sim_state:
|
|
29
|
+
def _act_on_(self, sim_state: cirq.SimulationStateBase, qubits: Sequence[cirq.Qid]):
|
|
28
30
|
if isinstance(sim_state, cirq.CliffordTableauSimulationState):
|
|
29
31
|
tableau = sim_state.tableau
|
|
30
32
|
q = sim_state.qubit_map[qubits[0]]
|
|
@@ -37,7 +39,7 @@ class BadGate(cirq.testing.SingleQubitGate):
|
|
|
37
39
|
def _unitary_(self):
|
|
38
40
|
return np.array([[0, 1j], [1, 0]])
|
|
39
41
|
|
|
40
|
-
def _act_on_(self, sim_state:
|
|
42
|
+
def _act_on_(self, sim_state: cirq.SimulationStateBase, qubits: Sequence[cirq.Qid]):
|
|
41
43
|
if isinstance(sim_state, cirq.CliffordTableauSimulationState):
|
|
42
44
|
tableau = sim_state.tableau
|
|
43
45
|
q = sim_state.qubit_map[qubits[0]]
|
|
@@ -55,7 +57,7 @@ class UnimplementedUnitaryGate(cirq.testing.TwoQubitGate):
|
|
|
55
57
|
return np.array([[0, 0, 0, 1], [0, 0, 1, 0], [0, 1, 0, 0], [1, 0, 0, 0]])
|
|
56
58
|
|
|
57
59
|
|
|
58
|
-
def test_assert_act_on_clifford_tableau_effect_matches_unitary():
|
|
60
|
+
def test_assert_act_on_clifford_tableau_effect_matches_unitary() -> None:
|
|
59
61
|
cirq.testing.assert_all_implemented_act_on_effects_match_unitary(GoodGate())
|
|
60
62
|
cirq.testing.assert_all_implemented_act_on_effects_match_unitary(
|
|
61
63
|
GoodGate().on(cirq.LineQubit(1))
|