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
|
@@ -12,13 +12,15 @@
|
|
|
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 numpy as np
|
|
16
18
|
import pytest
|
|
17
19
|
|
|
18
20
|
import cirq
|
|
19
21
|
|
|
20
22
|
|
|
21
|
-
def test_default_parameter():
|
|
23
|
+
def test_default_parameter() -> None:
|
|
22
24
|
qid_shape = (2,)
|
|
23
25
|
tensor = cirq.to_valid_density_matrix(
|
|
24
26
|
0, len(qid_shape), qid_shape=qid_shape, dtype=np.complex64
|
|
@@ -32,13 +34,13 @@ def test_default_parameter():
|
|
|
32
34
|
assert args.qid_shape == qid_shape
|
|
33
35
|
|
|
34
36
|
|
|
35
|
-
def test_shallow_copy_buffers():
|
|
37
|
+
def test_shallow_copy_buffers() -> None:
|
|
36
38
|
args = cirq.DensityMatrixSimulationState(qubits=cirq.LineQubit.range(1), initial_state=0)
|
|
37
39
|
copy = args.copy(deep_copy_buffers=False)
|
|
38
40
|
assert copy.available_buffer is args.available_buffer
|
|
39
41
|
|
|
40
42
|
|
|
41
|
-
def test_decomposed_fallback():
|
|
43
|
+
def test_decomposed_fallback() -> None:
|
|
42
44
|
class Composite(cirq.Gate):
|
|
43
45
|
def num_qubits(self) -> int:
|
|
44
46
|
return 1
|
|
@@ -59,7 +61,7 @@ def test_decomposed_fallback():
|
|
|
59
61
|
)
|
|
60
62
|
|
|
61
63
|
|
|
62
|
-
def test_cannot_act():
|
|
64
|
+
def test_cannot_act() -> None:
|
|
63
65
|
class NoDetails:
|
|
64
66
|
pass
|
|
65
67
|
|
|
@@ -73,12 +75,12 @@ def test_cannot_act():
|
|
|
73
75
|
cirq.act_on(NoDetails(), args, qubits=())
|
|
74
76
|
|
|
75
77
|
|
|
76
|
-
def test_qid_shape_error():
|
|
78
|
+
def test_qid_shape_error() -> None:
|
|
77
79
|
with pytest.raises(ValueError, match="qid_shape must be provided"):
|
|
78
80
|
cirq.sim.density_matrix_simulation_state._BufferedDensityMatrix.create(initial_state=0)
|
|
79
81
|
|
|
80
82
|
|
|
81
|
-
def test_initial_state_vector():
|
|
83
|
+
def test_initial_state_vector() -> None:
|
|
82
84
|
qubits = cirq.LineQubit.range(3)
|
|
83
85
|
args = cirq.DensityMatrixSimulationState(
|
|
84
86
|
qubits=qubits, initial_state=np.full((8,), 1 / np.sqrt(8)), dtype=np.complex64
|
|
@@ -91,7 +93,7 @@ def test_initial_state_vector():
|
|
|
91
93
|
assert args2.target_tensor.shape == (2, 2, 2, 2, 2, 2)
|
|
92
94
|
|
|
93
95
|
|
|
94
|
-
def test_initial_state_matrix():
|
|
96
|
+
def test_initial_state_matrix() -> None:
|
|
95
97
|
qubits = cirq.LineQubit.range(3)
|
|
96
98
|
args = cirq.DensityMatrixSimulationState(
|
|
97
99
|
qubits=qubits, initial_state=np.full((8, 8), 1 / 8), dtype=np.complex64
|
|
@@ -104,7 +106,7 @@ def test_initial_state_matrix():
|
|
|
104
106
|
assert args2.target_tensor.shape == (2, 2, 2, 2, 2, 2)
|
|
105
107
|
|
|
106
108
|
|
|
107
|
-
def test_initial_state_bad_shape():
|
|
109
|
+
def test_initial_state_bad_shape() -> None:
|
|
108
110
|
qubits = cirq.LineQubit.range(3)
|
|
109
111
|
with pytest.raises(ValueError, match="Invalid quantum state"):
|
|
110
112
|
cirq.DensityMatrixSimulationState(
|
|
@@ -11,8 +11,12 @@
|
|
|
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
|
"""Simulator for density matrices that simulates noisy quantum circuits."""
|
|
15
|
-
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
from typing import Any, Sequence, TYPE_CHECKING
|
|
16
20
|
|
|
17
21
|
import numpy as np
|
|
18
22
|
|
|
@@ -115,9 +119,9 @@ class DensityMatrixSimulator(
|
|
|
115
119
|
def __init__(
|
|
116
120
|
self,
|
|
117
121
|
*,
|
|
118
|
-
dtype:
|
|
119
|
-
noise:
|
|
120
|
-
seed:
|
|
122
|
+
dtype: type[np.complexfloating] = np.complex64,
|
|
123
|
+
noise: cirq.NOISE_MODEL_LIKE = None,
|
|
124
|
+
seed: cirq.RANDOM_STATE_OR_SEED_LIKE = None,
|
|
121
125
|
split_untangled_states: bool = True,
|
|
122
126
|
):
|
|
123
127
|
"""Density matrix simulator.
|
|
@@ -147,12 +151,10 @@ class DensityMatrixSimulator(
|
|
|
147
151
|
|
|
148
152
|
def _create_partial_simulation_state(
|
|
149
153
|
self,
|
|
150
|
-
initial_state:
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
classical_data: 'cirq.ClassicalDataStore',
|
|
155
|
-
) -> 'cirq.DensityMatrixSimulationState':
|
|
154
|
+
initial_state: np.ndarray | cirq.STATE_VECTOR_LIKE | cirq.DensityMatrixSimulationState,
|
|
155
|
+
qubits: Sequence[cirq.Qid],
|
|
156
|
+
classical_data: cirq.ClassicalDataStore,
|
|
157
|
+
) -> cirq.DensityMatrixSimulationState:
|
|
156
158
|
"""Creates the DensityMatrixSimulationState for a circuit.
|
|
157
159
|
|
|
158
160
|
Args:
|
|
@@ -183,16 +185,16 @@ class DensityMatrixSimulator(
|
|
|
183
185
|
return not protocols.measurement_keys_touched(val)
|
|
184
186
|
|
|
185
187
|
def _create_step_result(
|
|
186
|
-
self, sim_state:
|
|
188
|
+
self, sim_state: cirq.SimulationStateBase[cirq.DensityMatrixSimulationState]
|
|
187
189
|
):
|
|
188
190
|
return DensityMatrixStepResult(sim_state=sim_state, dtype=self._dtype)
|
|
189
191
|
|
|
190
192
|
def _create_simulator_trial_result(
|
|
191
193
|
self,
|
|
192
|
-
params:
|
|
193
|
-
measurements:
|
|
194
|
-
final_simulator_state:
|
|
195
|
-
) ->
|
|
194
|
+
params: cirq.ParamResolver,
|
|
195
|
+
measurements: dict[str, np.ndarray],
|
|
196
|
+
final_simulator_state: cirq.SimulationStateBase[cirq.DensityMatrixSimulationState],
|
|
197
|
+
) -> cirq.DensityMatrixTrialResult:
|
|
196
198
|
return DensityMatrixTrialResult(
|
|
197
199
|
params=params, measurements=measurements, final_simulator_state=final_simulator_state
|
|
198
200
|
)
|
|
@@ -200,13 +202,13 @@ class DensityMatrixSimulator(
|
|
|
200
202
|
# TODO(#4209): Deduplicate with identical code in sparse_simulator.
|
|
201
203
|
def simulate_expectation_values_sweep(
|
|
202
204
|
self,
|
|
203
|
-
program:
|
|
204
|
-
observables:
|
|
205
|
-
params:
|
|
206
|
-
qubit_order:
|
|
205
|
+
program: cirq.AbstractCircuit,
|
|
206
|
+
observables: cirq.PauliSumLike | list[cirq.PauliSumLike],
|
|
207
|
+
params: cirq.Sweepable,
|
|
208
|
+
qubit_order: cirq.QubitOrderOrList = ops.QubitOrder.DEFAULT,
|
|
207
209
|
initial_state: Any = None,
|
|
208
210
|
permit_terminal_measurements: bool = False,
|
|
209
|
-
) ->
|
|
211
|
+
) -> list[list[float]]:
|
|
210
212
|
if not permit_terminal_measurements and program.are_any_measurements_terminal():
|
|
211
213
|
raise ValueError(
|
|
212
214
|
'Provided circuit has terminal measurements, which may '
|
|
@@ -216,7 +218,7 @@ class DensityMatrixSimulator(
|
|
|
216
218
|
swept_evs = []
|
|
217
219
|
qubit_order = ops.QubitOrder.as_qubit_order(qubit_order)
|
|
218
220
|
qmap = {q: i for i, q in enumerate(qubit_order.order_for(program.all_qubits()))}
|
|
219
|
-
if not isinstance(observables,
|
|
221
|
+
if not isinstance(observables, list):
|
|
220
222
|
observables = [observables]
|
|
221
223
|
pslist = [ops.PauliSum.wrap(pslike) for pslike in observables]
|
|
222
224
|
for param_resolver in study.to_resolvers(params):
|
|
@@ -242,8 +244,8 @@ class DensityMatrixStepResult(simulator_base.StepResultBase['cirq.DensityMatrixS
|
|
|
242
244
|
|
|
243
245
|
def __init__(
|
|
244
246
|
self,
|
|
245
|
-
sim_state:
|
|
246
|
-
dtype:
|
|
247
|
+
sim_state: cirq.SimulationStateBase[cirq.DensityMatrixSimulationState],
|
|
248
|
+
dtype: type[np.complexfloating] = np.complex64,
|
|
247
249
|
):
|
|
248
250
|
"""DensityMatrixStepResult.
|
|
249
251
|
|
|
@@ -254,7 +256,7 @@ class DensityMatrixStepResult(simulator_base.StepResultBase['cirq.DensityMatrixS
|
|
|
254
256
|
"""
|
|
255
257
|
super().__init__(sim_state)
|
|
256
258
|
self._dtype = dtype
|
|
257
|
-
self._density_matrix:
|
|
259
|
+
self._density_matrix: np.ndarray | None = None
|
|
258
260
|
|
|
259
261
|
def density_matrix(self, copy=True):
|
|
260
262
|
"""Returns the density matrix at this step in the simulation.
|
|
@@ -353,14 +355,14 @@ class DensityMatrixTrialResult(
|
|
|
353
355
|
|
|
354
356
|
def __init__(
|
|
355
357
|
self,
|
|
356
|
-
params:
|
|
357
|
-
measurements:
|
|
358
|
-
final_simulator_state:
|
|
358
|
+
params: cirq.ParamResolver,
|
|
359
|
+
measurements: dict[str, np.ndarray],
|
|
360
|
+
final_simulator_state: cirq.SimulationStateBase[cirq.DensityMatrixSimulationState],
|
|
359
361
|
) -> None:
|
|
360
362
|
super().__init__(
|
|
361
363
|
params=params, measurements=measurements, final_simulator_state=final_simulator_state
|
|
362
364
|
)
|
|
363
|
-
self._final_density_matrix:
|
|
365
|
+
self._final_density_matrix: np.ndarray | None = None
|
|
364
366
|
|
|
365
367
|
@property
|
|
366
368
|
def final_density_matrix(self) -> np.ndarray:
|
|
@@ -11,9 +11,11 @@
|
|
|
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 itertools
|
|
15
18
|
import random
|
|
16
|
-
from typing import Type, Union
|
|
17
19
|
from unittest import mock
|
|
18
20
|
|
|
19
21
|
import numpy as np
|
|
@@ -53,7 +55,7 @@ def test_invalid_dtype():
|
|
|
53
55
|
|
|
54
56
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
55
57
|
@pytest.mark.parametrize('split', [True, False])
|
|
56
|
-
def test_run_no_measurements(dtype:
|
|
58
|
+
def test_run_no_measurements(dtype: type[np.complexfloating], split: bool):
|
|
57
59
|
q0, q1 = cirq.LineQubit.range(2)
|
|
58
60
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
59
61
|
|
|
@@ -64,7 +66,7 @@ def test_run_no_measurements(dtype: Type[np.complexfloating], split: bool):
|
|
|
64
66
|
|
|
65
67
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
66
68
|
@pytest.mark.parametrize('split', [True, False])
|
|
67
|
-
def test_run_no_results(dtype:
|
|
69
|
+
def test_run_no_results(dtype: type[np.complexfloating], split: bool):
|
|
68
70
|
q0, q1 = cirq.LineQubit.range(2)
|
|
69
71
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
70
72
|
|
|
@@ -75,7 +77,7 @@ def test_run_no_results(dtype: Type[np.complexfloating], split: bool):
|
|
|
75
77
|
|
|
76
78
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
77
79
|
@pytest.mark.parametrize('split', [True, False])
|
|
78
|
-
def test_run_empty_circuit(dtype:
|
|
80
|
+
def test_run_empty_circuit(dtype: type[np.complexfloating], split: bool):
|
|
79
81
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
80
82
|
with pytest.raises(ValueError, match="no measurements"):
|
|
81
83
|
simulator.run(cirq.Circuit())
|
|
@@ -83,7 +85,7 @@ def test_run_empty_circuit(dtype: Type[np.complexfloating], split: bool):
|
|
|
83
85
|
|
|
84
86
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
85
87
|
@pytest.mark.parametrize('split', [True, False])
|
|
86
|
-
def test_run_bit_flips(dtype:
|
|
88
|
+
def test_run_bit_flips(dtype: type[np.complexfloating], split: bool):
|
|
87
89
|
q0, q1 = cirq.LineQubit.range(2)
|
|
88
90
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
89
91
|
for b0 in [0, 1]:
|
|
@@ -97,7 +99,7 @@ def test_run_bit_flips(dtype: Type[np.complexfloating], split: bool):
|
|
|
97
99
|
|
|
98
100
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
99
101
|
@pytest.mark.parametrize('split', [True, False])
|
|
100
|
-
def test_run_bit_flips_with_dephasing(dtype:
|
|
102
|
+
def test_run_bit_flips_with_dephasing(dtype: type[np.complexfloating], split: bool):
|
|
101
103
|
q0, q1 = cirq.LineQubit.range(2)
|
|
102
104
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
103
105
|
for b0 in [0, 1]:
|
|
@@ -111,7 +113,7 @@ def test_run_bit_flips_with_dephasing(dtype: Type[np.complexfloating], split: bo
|
|
|
111
113
|
|
|
112
114
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
113
115
|
@pytest.mark.parametrize('split', [True, False])
|
|
114
|
-
def test_run_qudit_increments(dtype:
|
|
116
|
+
def test_run_qudit_increments(dtype: type[np.complexfloating], split: bool):
|
|
115
117
|
q0, q1 = cirq.LineQid.for_qid_shape((3, 4))
|
|
116
118
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
117
119
|
for b0 in [0, 1, 2]:
|
|
@@ -130,7 +132,7 @@ def test_run_qudit_increments(dtype: Type[np.complexfloating], split: bool):
|
|
|
130
132
|
|
|
131
133
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
132
134
|
@pytest.mark.parametrize('split', [True, False])
|
|
133
|
-
def test_run_not_channel_op(dtype:
|
|
135
|
+
def test_run_not_channel_op(dtype: type[np.complexfloating], split: bool):
|
|
134
136
|
class BadOp(cirq.Operation):
|
|
135
137
|
def __init__(self, qubits):
|
|
136
138
|
self._qubits = qubits
|
|
@@ -151,7 +153,7 @@ def test_run_not_channel_op(dtype: Type[np.complexfloating], split: bool):
|
|
|
151
153
|
|
|
152
154
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
153
155
|
@pytest.mark.parametrize('split', [True, False])
|
|
154
|
-
def test_run_mixture(dtype:
|
|
156
|
+
def test_run_mixture(dtype: type[np.complexfloating], split: bool):
|
|
155
157
|
q0, q1 = cirq.LineQubit.range(2)
|
|
156
158
|
circuit = cirq.Circuit(cirq.bit_flip(0.5)(q0), cirq.measure(q0), cirq.measure(q1))
|
|
157
159
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
@@ -165,7 +167,7 @@ def test_run_mixture(dtype: Type[np.complexfloating], split: bool):
|
|
|
165
167
|
|
|
166
168
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
167
169
|
@pytest.mark.parametrize('split', [True, False])
|
|
168
|
-
def test_run_qudit_mixture(dtype:
|
|
170
|
+
def test_run_qudit_mixture(dtype: type[np.complexfloating], split: bool):
|
|
169
171
|
q0, q1 = cirq.LineQid.for_qid_shape((3, 2))
|
|
170
172
|
mixture = _TestMixture(
|
|
171
173
|
[
|
|
@@ -186,7 +188,7 @@ def test_run_qudit_mixture(dtype: Type[np.complexfloating], split: bool):
|
|
|
186
188
|
|
|
187
189
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
188
190
|
@pytest.mark.parametrize('split', [True, False])
|
|
189
|
-
def test_run_channel(dtype:
|
|
191
|
+
def test_run_channel(dtype: type[np.complexfloating], split: bool):
|
|
190
192
|
q0, q1 = cirq.LineQubit.range(2)
|
|
191
193
|
circuit = cirq.Circuit(
|
|
192
194
|
cirq.X(q0), cirq.amplitude_damp(0.5)(q0), cirq.measure(q0), cirq.measure(q1)
|
|
@@ -203,7 +205,7 @@ def test_run_channel(dtype: Type[np.complexfloating], split: bool):
|
|
|
203
205
|
|
|
204
206
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
205
207
|
@pytest.mark.parametrize('split', [True, False])
|
|
206
|
-
def test_run_decomposable_channel(dtype:
|
|
208
|
+
def test_run_decomposable_channel(dtype: type[np.complexfloating], split: bool):
|
|
207
209
|
q0, q1 = cirq.LineQubit.range(2)
|
|
208
210
|
|
|
209
211
|
circuit = cirq.Circuit(
|
|
@@ -224,7 +226,7 @@ def test_run_decomposable_channel(dtype: Type[np.complexfloating], split: bool):
|
|
|
224
226
|
|
|
225
227
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
226
228
|
@pytest.mark.parametrize('split', [True, False])
|
|
227
|
-
def test_run_qudit_channel(dtype:
|
|
229
|
+
def test_run_qudit_channel(dtype: type[np.complexfloating], split: bool):
|
|
228
230
|
class TestChannel(cirq.Gate):
|
|
229
231
|
def _qid_shape_(self):
|
|
230
232
|
return (3,)
|
|
@@ -256,7 +258,7 @@ def test_run_qudit_channel(dtype: Type[np.complexfloating], split: bool):
|
|
|
256
258
|
|
|
257
259
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
258
260
|
@pytest.mark.parametrize('split', [True, False])
|
|
259
|
-
def test_run_measure_at_end_no_repetitions(dtype:
|
|
261
|
+
def test_run_measure_at_end_no_repetitions(dtype: type[np.complexfloating], split: bool):
|
|
260
262
|
q0, q1 = cirq.LineQubit.range(2)
|
|
261
263
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
262
264
|
with mock.patch.object(simulator, '_core_iterator', wraps=simulator._core_iterator) as mock_sim:
|
|
@@ -275,7 +277,7 @@ def test_run_measure_at_end_no_repetitions(dtype: Type[np.complexfloating], spli
|
|
|
275
277
|
|
|
276
278
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
277
279
|
@pytest.mark.parametrize('split', [True, False])
|
|
278
|
-
def test_run_repetitions_measure_at_end(dtype:
|
|
280
|
+
def test_run_repetitions_measure_at_end(dtype: type[np.complexfloating], split: bool):
|
|
279
281
|
q0, q1 = cirq.LineQubit.range(2)
|
|
280
282
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
281
283
|
with mock.patch.object(simulator, '_core_iterator', wraps=simulator._core_iterator) as mock_sim:
|
|
@@ -294,7 +296,7 @@ def test_run_repetitions_measure_at_end(dtype: Type[np.complexfloating], split:
|
|
|
294
296
|
|
|
295
297
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
296
298
|
@pytest.mark.parametrize('split', [True, False])
|
|
297
|
-
def test_run_qudits_repetitions_measure_at_end(dtype:
|
|
299
|
+
def test_run_qudits_repetitions_measure_at_end(dtype: type[np.complexfloating], split: bool):
|
|
298
300
|
q0, q1 = cirq.LineQid.for_qid_shape((2, 3))
|
|
299
301
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
300
302
|
with mock.patch.object(simulator, '_core_iterator', wraps=simulator._core_iterator) as mock_sim:
|
|
@@ -316,7 +318,7 @@ def test_run_qudits_repetitions_measure_at_end(dtype: Type[np.complexfloating],
|
|
|
316
318
|
|
|
317
319
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
318
320
|
@pytest.mark.parametrize('split', [True, False])
|
|
319
|
-
def test_run_measurement_not_terminal_no_repetitions(dtype:
|
|
321
|
+
def test_run_measurement_not_terminal_no_repetitions(dtype: type[np.complexfloating], split: bool):
|
|
320
322
|
q0, q1 = cirq.LineQubit.range(2)
|
|
321
323
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
322
324
|
with mock.patch.object(simulator, '_core_iterator', wraps=simulator._core_iterator) as mock_sim:
|
|
@@ -340,7 +342,7 @@ def test_run_measurement_not_terminal_no_repetitions(dtype: Type[np.complexfloat
|
|
|
340
342
|
|
|
341
343
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
342
344
|
@pytest.mark.parametrize('split', [True, False])
|
|
343
|
-
def test_run_repetitions_measurement_not_terminal(dtype:
|
|
345
|
+
def test_run_repetitions_measurement_not_terminal(dtype: type[np.complexfloating], split: bool):
|
|
344
346
|
q0, q1 = cirq.LineQubit.range(2)
|
|
345
347
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
346
348
|
with mock.patch.object(simulator, '_core_iterator', wraps=simulator._core_iterator) as mock_sim:
|
|
@@ -365,7 +367,7 @@ def test_run_repetitions_measurement_not_terminal(dtype: Type[np.complexfloating
|
|
|
365
367
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
366
368
|
@pytest.mark.parametrize('split', [True, False])
|
|
367
369
|
def test_run_qudits_repetitions_measurement_not_terminal(
|
|
368
|
-
dtype:
|
|
370
|
+
dtype: type[np.complexfloating], split: bool
|
|
369
371
|
):
|
|
370
372
|
q0, q1 = cirq.LineQid.for_qid_shape((2, 3))
|
|
371
373
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
@@ -390,7 +392,7 @@ def test_run_qudits_repetitions_measurement_not_terminal(
|
|
|
390
392
|
|
|
391
393
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
392
394
|
@pytest.mark.parametrize('split', [True, False])
|
|
393
|
-
def test_run_param_resolver(dtype:
|
|
395
|
+
def test_run_param_resolver(dtype: type[np.complexfloating], split: bool):
|
|
394
396
|
q0, q1 = cirq.LineQubit.range(2)
|
|
395
397
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
396
398
|
for b0 in [0, 1]:
|
|
@@ -404,13 +406,12 @@ def test_run_param_resolver(dtype: Type[np.complexfloating], split: bool):
|
|
|
404
406
|
param_resolver = {'b0': b0, 'b1': b1}
|
|
405
407
|
result = simulator.run(circuit, param_resolver=param_resolver)
|
|
406
408
|
np.testing.assert_equal(result.measurements, {'q(0)': [[b0]], 'q(1)': [[b1]]})
|
|
407
|
-
# pylint: disable=line-too-long
|
|
408
409
|
np.testing.assert_equal(result.params, cirq.ParamResolver(param_resolver))
|
|
409
410
|
|
|
410
411
|
|
|
411
412
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
412
413
|
@pytest.mark.parametrize('split', [True, False])
|
|
413
|
-
def test_run_correlations(dtype:
|
|
414
|
+
def test_run_correlations(dtype: type[np.complexfloating], split: bool):
|
|
414
415
|
q0, q1 = cirq.LineQubit.range(2)
|
|
415
416
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
416
417
|
circuit = cirq.Circuit(cirq.H(q0), cirq.CNOT(q0, q1), cirq.measure(q0, q1))
|
|
@@ -422,7 +423,7 @@ def test_run_correlations(dtype: Type[np.complexfloating], split: bool):
|
|
|
422
423
|
|
|
423
424
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
424
425
|
@pytest.mark.parametrize('split', [True, False])
|
|
425
|
-
def test_run_measure_multiple_qubits(dtype:
|
|
426
|
+
def test_run_measure_multiple_qubits(dtype: type[np.complexfloating], split: bool):
|
|
426
427
|
q0, q1 = cirq.LineQubit.range(2)
|
|
427
428
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
428
429
|
for b0 in [0, 1]:
|
|
@@ -434,7 +435,7 @@ def test_run_measure_multiple_qubits(dtype: Type[np.complexfloating], split: boo
|
|
|
434
435
|
|
|
435
436
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
436
437
|
@pytest.mark.parametrize('split', [True, False])
|
|
437
|
-
def test_run_measure_multiple_qudits(dtype:
|
|
438
|
+
def test_run_measure_multiple_qudits(dtype: type[np.complexfloating], split: bool):
|
|
438
439
|
q0, q1 = cirq.LineQid.for_qid_shape((2, 3))
|
|
439
440
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
440
441
|
for b0 in [0, 1]:
|
|
@@ -448,7 +449,7 @@ def test_run_measure_multiple_qudits(dtype: Type[np.complexfloating], split: boo
|
|
|
448
449
|
|
|
449
450
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
450
451
|
@pytest.mark.parametrize('split', [True, False])
|
|
451
|
-
def test_run_sweeps_param_resolvers(dtype:
|
|
452
|
+
def test_run_sweeps_param_resolvers(dtype: type[np.complexfloating], split: bool):
|
|
452
453
|
q0, q1 = cirq.LineQubit.range(2)
|
|
453
454
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
454
455
|
for b0 in [0, 1]:
|
|
@@ -474,7 +475,7 @@ def test_run_sweeps_param_resolvers(dtype: Type[np.complexfloating], split: bool
|
|
|
474
475
|
|
|
475
476
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
476
477
|
@pytest.mark.parametrize('split', [True, False])
|
|
477
|
-
def test_simulate_no_circuit(dtype:
|
|
478
|
+
def test_simulate_no_circuit(dtype: type[np.complexfloating], split: bool):
|
|
478
479
|
q0, q1 = cirq.LineQubit.range(2)
|
|
479
480
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
480
481
|
circuit = cirq.Circuit()
|
|
@@ -487,7 +488,7 @@ def test_simulate_no_circuit(dtype: Type[np.complexfloating], split: bool):
|
|
|
487
488
|
|
|
488
489
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
489
490
|
@pytest.mark.parametrize('split', [True, False])
|
|
490
|
-
def test_simulate(dtype:
|
|
491
|
+
def test_simulate(dtype: type[np.complexfloating], split: bool):
|
|
491
492
|
q0, q1 = cirq.LineQubit.range(2)
|
|
492
493
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
493
494
|
circuit = cirq.Circuit(cirq.H(q0), cirq.H(q1))
|
|
@@ -498,7 +499,7 @@ def test_simulate(dtype: Type[np.complexfloating], split: bool):
|
|
|
498
499
|
|
|
499
500
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
500
501
|
@pytest.mark.parametrize('split', [True, False])
|
|
501
|
-
def test_simulate_qudits(dtype:
|
|
502
|
+
def test_simulate_qudits(dtype: type[np.complexfloating], split: bool):
|
|
502
503
|
q0, q1 = cirq.LineQid.for_qid_shape((2, 3))
|
|
503
504
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
504
505
|
circuit = cirq.Circuit(cirq.H(q0), cirq.XPowGate(dimension=3)(q1) ** 2)
|
|
@@ -512,7 +513,7 @@ def test_simulate_qudits(dtype: Type[np.complexfloating], split: bool):
|
|
|
512
513
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
513
514
|
@pytest.mark.parametrize('split', [True, False])
|
|
514
515
|
def test_reset_one_qubit_does_not_affect_partial_trace_of_other_qubits(
|
|
515
|
-
dtype:
|
|
516
|
+
dtype: type[np.complexfloating], split: bool
|
|
516
517
|
):
|
|
517
518
|
q0, q1 = cirq.LineQubit.range(2)
|
|
518
519
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
@@ -531,7 +532,7 @@ def test_reset_one_qubit_does_not_affect_partial_trace_of_other_qubits(
|
|
|
531
532
|
[cirq.testing.random_circuit(cirq.LineQubit.range(4), 5, 0.9) for _ in range(20)],
|
|
532
533
|
),
|
|
533
534
|
)
|
|
534
|
-
def test_simulate_compare_to_state_vector_simulator(dtype:
|
|
535
|
+
def test_simulate_compare_to_state_vector_simulator(dtype: type[np.complexfloating], circuit):
|
|
535
536
|
qubits = cirq.LineQubit.range(4)
|
|
536
537
|
pure_result = (
|
|
537
538
|
cirq.Simulator(dtype=dtype).simulate(circuit, qubit_order=qubits).density_matrix_of()
|
|
@@ -547,7 +548,7 @@ def test_simulate_compare_to_state_vector_simulator(dtype: Type[np.complexfloati
|
|
|
547
548
|
|
|
548
549
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
549
550
|
@pytest.mark.parametrize('split', [True, False])
|
|
550
|
-
def test_simulate_bit_flips(dtype:
|
|
551
|
+
def test_simulate_bit_flips(dtype: type[np.complexfloating], split: bool):
|
|
551
552
|
q0, q1 = cirq.LineQubit.range(2)
|
|
552
553
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
553
554
|
for b0 in [0, 1]:
|
|
@@ -564,7 +565,7 @@ def test_simulate_bit_flips(dtype: Type[np.complexfloating], split: bool):
|
|
|
564
565
|
|
|
565
566
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
566
567
|
@pytest.mark.parametrize('split', [True, False])
|
|
567
|
-
def test_simulate_qudit_increments(dtype:
|
|
568
|
+
def test_simulate_qudit_increments(dtype: type[np.complexfloating], split: bool):
|
|
568
569
|
q0, q1 = cirq.LineQid.for_qid_shape((2, 3))
|
|
569
570
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
570
571
|
for b0 in [0, 1]:
|
|
@@ -589,9 +590,9 @@ def test_simulate_qudit_increments(dtype: Type[np.complexfloating], split: bool)
|
|
|
589
590
|
[1, cirq.DensityMatrixSimulationState(initial_state=1, qubits=cirq.LineQubit.range(2))],
|
|
590
591
|
)
|
|
591
592
|
def test_simulate_initial_state(
|
|
592
|
-
dtype:
|
|
593
|
+
dtype: type[np.complexfloating],
|
|
593
594
|
split: bool,
|
|
594
|
-
initial_state:
|
|
595
|
+
initial_state: int | cirq.DensityMatrixSimulationState,
|
|
595
596
|
):
|
|
596
597
|
q0, q1 = cirq.LineQubit.range(2)
|
|
597
598
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
@@ -606,7 +607,7 @@ def test_simulate_initial_state(
|
|
|
606
607
|
|
|
607
608
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
608
609
|
@pytest.mark.parametrize('split', [True, False])
|
|
609
|
-
def test_simulation_state(dtype:
|
|
610
|
+
def test_simulation_state(dtype: type[np.complexfloating], split: bool):
|
|
610
611
|
q0, q1 = cirq.LineQubit.range(2)
|
|
611
612
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
612
613
|
for b0 in [0, 1]:
|
|
@@ -633,7 +634,7 @@ def test_simulate_tps_initial_state():
|
|
|
633
634
|
|
|
634
635
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
635
636
|
@pytest.mark.parametrize('split', [True, False])
|
|
636
|
-
def test_simulate_initial_qudit_state(dtype:
|
|
637
|
+
def test_simulate_initial_qudit_state(dtype: type[np.complexfloating], split: bool):
|
|
637
638
|
q0, q1 = cirq.LineQid.for_qid_shape((3, 4))
|
|
638
639
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
639
640
|
for b0 in [0, 1, 2]:
|
|
@@ -653,7 +654,7 @@ def test_simulate_initial_qudit_state(dtype: Type[np.complexfloating], split: bo
|
|
|
653
654
|
|
|
654
655
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
655
656
|
@pytest.mark.parametrize('split', [True, False])
|
|
656
|
-
def test_simulate_qubit_order(dtype:
|
|
657
|
+
def test_simulate_qubit_order(dtype: type[np.complexfloating], split: bool):
|
|
657
658
|
q0, q1 = cirq.LineQubit.range(2)
|
|
658
659
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
659
660
|
for b0 in [0, 1]:
|
|
@@ -667,7 +668,7 @@ def test_simulate_qubit_order(dtype: Type[np.complexfloating], split: bool):
|
|
|
667
668
|
|
|
668
669
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
669
670
|
@pytest.mark.parametrize('split', [True, False])
|
|
670
|
-
def test_simulate_param_resolver(dtype:
|
|
671
|
+
def test_simulate_param_resolver(dtype: type[np.complexfloating], split: bool):
|
|
671
672
|
q0, q1 = cirq.LineQubit.range(2)
|
|
672
673
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
673
674
|
for b0 in [0, 1]:
|
|
@@ -686,7 +687,7 @@ def test_simulate_param_resolver(dtype: Type[np.complexfloating], split: bool):
|
|
|
686
687
|
|
|
687
688
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
688
689
|
@pytest.mark.parametrize('split', [True, False])
|
|
689
|
-
def test_simulate_measure_multiple_qubits(dtype:
|
|
690
|
+
def test_simulate_measure_multiple_qubits(dtype: type[np.complexfloating], split: bool):
|
|
690
691
|
q0, q1 = cirq.LineQubit.range(2)
|
|
691
692
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
692
693
|
for b0 in [0, 1]:
|
|
@@ -698,7 +699,7 @@ def test_simulate_measure_multiple_qubits(dtype: Type[np.complexfloating], split
|
|
|
698
699
|
|
|
699
700
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
700
701
|
@pytest.mark.parametrize('split', [True, False])
|
|
701
|
-
def test_simulate_measure_multiple_qudits(dtype:
|
|
702
|
+
def test_simulate_measure_multiple_qudits(dtype: type[np.complexfloating], split: bool):
|
|
702
703
|
q0, q1 = cirq.LineQid.for_qid_shape((2, 3))
|
|
703
704
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
704
705
|
for b0 in [0, 1]:
|
|
@@ -712,7 +713,7 @@ def test_simulate_measure_multiple_qudits(dtype: Type[np.complexfloating], split
|
|
|
712
713
|
|
|
713
714
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
714
715
|
@pytest.mark.parametrize('split', [True, False])
|
|
715
|
-
def test_simulate_sweeps_param_resolver(dtype:
|
|
716
|
+
def test_simulate_sweeps_param_resolver(dtype: type[np.complexfloating], split: bool):
|
|
716
717
|
q0, q1 = cirq.LineQubit.range(2)
|
|
717
718
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
718
719
|
for b0 in [0, 1]:
|
|
@@ -739,7 +740,7 @@ def test_simulate_sweeps_param_resolver(dtype: Type[np.complexfloating], split:
|
|
|
739
740
|
|
|
740
741
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
741
742
|
@pytest.mark.parametrize('split', [True, False])
|
|
742
|
-
def test_simulate_moment_steps(dtype:
|
|
743
|
+
def test_simulate_moment_steps(dtype: type[np.complexfloating], split: bool):
|
|
743
744
|
q0, q1 = cirq.LineQubit.range(2)
|
|
744
745
|
circuit = cirq.Circuit(cirq.H(q0), cirq.H(q1), cirq.H(q0), cirq.H(q1))
|
|
745
746
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
@@ -753,7 +754,7 @@ def test_simulate_moment_steps(dtype: Type[np.complexfloating], split: bool):
|
|
|
753
754
|
|
|
754
755
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
755
756
|
@pytest.mark.parametrize('split', [True, False])
|
|
756
|
-
def test_simulate_moment_steps_qudits(dtype:
|
|
757
|
+
def test_simulate_moment_steps_qudits(dtype: type[np.complexfloating], split: bool):
|
|
757
758
|
q0, q1 = cirq.LineQid.for_qid_shape((2, 3))
|
|
758
759
|
circuit = cirq.Circuit(
|
|
759
760
|
cirq.XPowGate(dimension=2)(q0),
|
|
@@ -774,10 +775,9 @@ def test_simulate_moment_steps_qudits(dtype: Type[np.complexfloating], split: bo
|
|
|
774
775
|
|
|
775
776
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
776
777
|
@pytest.mark.parametrize('split', [True, False])
|
|
777
|
-
def test_simulate_moment_steps_empty_circuit(dtype:
|
|
778
|
+
def test_simulate_moment_steps_empty_circuit(dtype: type[np.complexfloating], split: bool):
|
|
778
779
|
circuit = cirq.Circuit()
|
|
779
780
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
780
|
-
step = None
|
|
781
781
|
for step in simulator.simulate_moment_steps(circuit):
|
|
782
782
|
pass
|
|
783
783
|
assert np.allclose(step.density_matrix(), np.array([[1]]))
|
|
@@ -786,7 +786,7 @@ def test_simulate_moment_steps_empty_circuit(dtype: Type[np.complexfloating], sp
|
|
|
786
786
|
|
|
787
787
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
788
788
|
@pytest.mark.parametrize('split', [True, False])
|
|
789
|
-
def test_simulate_moment_steps_sample(dtype:
|
|
789
|
+
def test_simulate_moment_steps_sample(dtype: type[np.complexfloating], split: bool):
|
|
790
790
|
q0, q1 = cirq.LineQubit.range(2)
|
|
791
791
|
circuit = cirq.Circuit(cirq.H(q0), cirq.CNOT(q0, q1))
|
|
792
792
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
@@ -807,7 +807,7 @@ def test_simulate_moment_steps_sample(dtype: Type[np.complexfloating], split: bo
|
|
|
807
807
|
|
|
808
808
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
809
809
|
@pytest.mark.parametrize('split', [True, False])
|
|
810
|
-
def test_simulate_moment_steps_sample_qudits(dtype:
|
|
810
|
+
def test_simulate_moment_steps_sample_qudits(dtype: type[np.complexfloating], split: bool):
|
|
811
811
|
class TestGate(cirq.Gate):
|
|
812
812
|
"""Swaps the 2nd qid |0> and |2> states when the 1st is |1>."""
|
|
813
813
|
|
|
@@ -837,7 +837,7 @@ def test_simulate_moment_steps_sample_qudits(dtype: Type[np.complexfloating], sp
|
|
|
837
837
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
838
838
|
@pytest.mark.parametrize('split', [True, False])
|
|
839
839
|
def test_simulate_moment_steps_intermediate_measurement(
|
|
840
|
-
dtype:
|
|
840
|
+
dtype: type[np.complexfloating], split: bool
|
|
841
841
|
):
|
|
842
842
|
q0 = cirq.LineQubit(0)
|
|
843
843
|
circuit = cirq.Circuit(cirq.H(q0), cirq.measure(q0), cirq.H(q0))
|