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/ops/common_channels_test.py
CHANGED
|
@@ -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
|
import re
|
|
16
18
|
|
|
17
19
|
import numpy as np
|
|
@@ -56,7 +58,7 @@ def assert_mixtures_equal(actual, expected):
|
|
|
56
58
|
np.testing.assert_almost_equal(a[1], e[1])
|
|
57
59
|
|
|
58
60
|
|
|
59
|
-
def test_asymmetric_depolarizing_channel():
|
|
61
|
+
def test_asymmetric_depolarizing_channel() -> None:
|
|
60
62
|
d = cirq.asymmetric_depolarize(0.1, 0.2, 0.3)
|
|
61
63
|
np.testing.assert_almost_equal(
|
|
62
64
|
cirq.kraus(d),
|
|
@@ -68,25 +70,25 @@ def test_asymmetric_depolarizing_channel():
|
|
|
68
70
|
assert cirq.AsymmetricDepolarizingChannel(p_x=0, p_y=0.1, p_z=0).num_qubits() == 1
|
|
69
71
|
|
|
70
72
|
|
|
71
|
-
def test_asymmetric_depolarizing_mixture():
|
|
73
|
+
def test_asymmetric_depolarizing_mixture() -> None:
|
|
72
74
|
d = cirq.asymmetric_depolarize(0.1, 0.2, 0.3)
|
|
73
75
|
assert_mixtures_equal(cirq.mixture(d), ((0.4, np.eye(2)), (0.1, X), (0.2, Y), (0.3, Z)))
|
|
74
76
|
assert cirq.has_mixture(d)
|
|
75
77
|
|
|
76
78
|
|
|
77
|
-
def test_asymmetric_depolarizing_channel_repr():
|
|
79
|
+
def test_asymmetric_depolarizing_channel_repr() -> None:
|
|
78
80
|
cirq.testing.assert_equivalent_repr(cirq.AsymmetricDepolarizingChannel(0.1, 0.2, 0.3))
|
|
79
81
|
|
|
80
82
|
|
|
81
|
-
def test_asymmetric_depolarizing_channel_str():
|
|
83
|
+
def test_asymmetric_depolarizing_channel_str() -> None:
|
|
82
84
|
assert (
|
|
83
85
|
str(cirq.asymmetric_depolarize(0.1, 0.2, 0.3))
|
|
84
86
|
== "asymmetric_depolarize(error_probabilities={'I': 0.3999999999999999, "
|
|
85
|
-
|
|
87
|
+
"'X': 0.1, 'Y': 0.2, 'Z': 0.3})"
|
|
86
88
|
)
|
|
87
89
|
|
|
88
90
|
|
|
89
|
-
def test_asymmetric_depolarizing_channel_eq():
|
|
91
|
+
def test_asymmetric_depolarizing_channel_eq() -> None:
|
|
90
92
|
a = cirq.asymmetric_depolarize(0.0099999, 0.01)
|
|
91
93
|
b = cirq.asymmetric_depolarize(0.01, 0.0099999)
|
|
92
94
|
c = cirq.asymmetric_depolarize(0.0, 0.0, 0.0)
|
|
@@ -109,7 +111,7 @@ def test_asymmetric_depolarizing_channel_eq():
|
|
|
109
111
|
@pytest.mark.parametrize(
|
|
110
112
|
'p_x,p_y,p_z', ((-0.1, 0.0, 0.0), (0.0, -0.1, 0.0), (0.0, 0.0, -0.1), (0.1, -0.1, 0.1))
|
|
111
113
|
)
|
|
112
|
-
def test_asymmetric_depolarizing_channel_negative_probability(p_x, p_y, p_z):
|
|
114
|
+
def test_asymmetric_depolarizing_channel_negative_probability(p_x, p_y, p_z) -> None:
|
|
113
115
|
with pytest.raises(ValueError, match='was less than 0'):
|
|
114
116
|
cirq.asymmetric_depolarize(p_x, p_y, p_z)
|
|
115
117
|
|
|
@@ -117,12 +119,12 @@ def test_asymmetric_depolarizing_channel_negative_probability(p_x, p_y, p_z):
|
|
|
117
119
|
@pytest.mark.parametrize(
|
|
118
120
|
'p_x,p_y,p_z', ((1.1, 0.0, 0.0), (0.0, 1.1, 0.0), (0.0, 0.0, 1.1), (0.1, 0.9, 0.1))
|
|
119
121
|
)
|
|
120
|
-
def test_asymmetric_depolarizing_channel_bigly_probability(p_x, p_y, p_z):
|
|
122
|
+
def test_asymmetric_depolarizing_channel_bigly_probability(p_x, p_y, p_z) -> None:
|
|
121
123
|
with pytest.raises(ValueError, match='was greater than 1'):
|
|
122
124
|
cirq.asymmetric_depolarize(p_x, p_y, p_z)
|
|
123
125
|
|
|
124
126
|
|
|
125
|
-
def test_asymmetric_depolarizing_channel_text_diagram():
|
|
127
|
+
def test_asymmetric_depolarizing_channel_text_diagram() -> None:
|
|
126
128
|
a = cirq.asymmetric_depolarize(1 / 9, 2 / 9, 3 / 9)
|
|
127
129
|
assert cirq.circuit_diagram_info(a, args=no_precision) == cirq.CircuitDiagramInfo(
|
|
128
130
|
wire_symbols=('A(0.1111111111111111,0.2222222222222222,' + '0.3333333333333333)',)
|
|
@@ -135,7 +137,7 @@ def test_asymmetric_depolarizing_channel_text_diagram():
|
|
|
135
137
|
)
|
|
136
138
|
|
|
137
139
|
|
|
138
|
-
def test_depolarizing_channel():
|
|
140
|
+
def test_depolarizing_channel() -> None:
|
|
139
141
|
d = cirq.depolarize(0.3)
|
|
140
142
|
np.testing.assert_almost_equal(
|
|
141
143
|
cirq.kraus(d),
|
|
@@ -145,7 +147,7 @@ def test_depolarizing_channel():
|
|
|
145
147
|
cirq.testing.assert_consistent_mixture(d)
|
|
146
148
|
|
|
147
149
|
|
|
148
|
-
def test_depolarizing_channel_two_qubits():
|
|
150
|
+
def test_depolarizing_channel_two_qubits() -> None:
|
|
149
151
|
d = cirq.depolarize(0.15, n_qubits=2)
|
|
150
152
|
np.testing.assert_almost_equal(
|
|
151
153
|
cirq.kraus(d),
|
|
@@ -182,13 +184,13 @@ def test_depolarizing_channel_two_qubits():
|
|
|
182
184
|
)
|
|
183
185
|
|
|
184
186
|
|
|
185
|
-
def test_depolarizing_mixture():
|
|
187
|
+
def test_depolarizing_mixture() -> None:
|
|
186
188
|
d = cirq.depolarize(0.3)
|
|
187
189
|
assert_mixtures_equal(cirq.mixture(d), ((0.7, np.eye(2)), (0.1, X), (0.1, Y), (0.1, Z)))
|
|
188
190
|
assert cirq.has_mixture(d)
|
|
189
191
|
|
|
190
192
|
|
|
191
|
-
def test_depolarizing_mixture_two_qubits():
|
|
193
|
+
def test_depolarizing_mixture_two_qubits() -> None:
|
|
192
194
|
d = cirq.depolarize(0.15, n_qubits=2)
|
|
193
195
|
assert_mixtures_equal(
|
|
194
196
|
cirq.mixture(d),
|
|
@@ -214,23 +216,23 @@ def test_depolarizing_mixture_two_qubits():
|
|
|
214
216
|
assert cirq.has_mixture(d)
|
|
215
217
|
|
|
216
218
|
|
|
217
|
-
def test_depolarizing_channel_repr():
|
|
219
|
+
def test_depolarizing_channel_repr() -> None:
|
|
218
220
|
cirq.testing.assert_equivalent_repr(cirq.DepolarizingChannel(0.3))
|
|
219
221
|
|
|
220
222
|
|
|
221
|
-
def test_depolarizing_channel_repr_two_qubits():
|
|
223
|
+
def test_depolarizing_channel_repr_two_qubits() -> None:
|
|
222
224
|
cirq.testing.assert_equivalent_repr(cirq.DepolarizingChannel(0.3, n_qubits=2))
|
|
223
225
|
|
|
224
226
|
|
|
225
|
-
def test_depolarizing_channel_str():
|
|
227
|
+
def test_depolarizing_channel_str() -> None:
|
|
226
228
|
assert str(cirq.depolarize(0.3)) == 'depolarize(p=0.3)'
|
|
227
229
|
|
|
228
230
|
|
|
229
|
-
def test_depolarizing_channel_str_two_qubits():
|
|
231
|
+
def test_depolarizing_channel_str_two_qubits() -> None:
|
|
230
232
|
assert str(cirq.depolarize(0.3, n_qubits=2)) == 'depolarize(p=0.3,n_qubits=2)'
|
|
231
233
|
|
|
232
234
|
|
|
233
|
-
def test_deprecated_on_each_for_depolarizing_channel_one_qubit():
|
|
235
|
+
def test_deprecated_on_each_for_depolarizing_channel_one_qubit() -> None:
|
|
234
236
|
q0 = cirq.LineQubit.range(1)
|
|
235
237
|
op = cirq.DepolarizingChannel(p=0.1, n_qubits=1)
|
|
236
238
|
|
|
@@ -240,7 +242,7 @@ def test_deprecated_on_each_for_depolarizing_channel_one_qubit():
|
|
|
240
242
|
op.on_each('bogus object')
|
|
241
243
|
|
|
242
244
|
|
|
243
|
-
def test_deprecated_on_each_for_depolarizing_channel_two_qubits():
|
|
245
|
+
def test_deprecated_on_each_for_depolarizing_channel_two_qubits() -> None:
|
|
244
246
|
q0, q1, q2, q3, q4, q5 = cirq.LineQubit.range(6)
|
|
245
247
|
op = cirq.DepolarizingChannel(p=0.1, n_qubits=2)
|
|
246
248
|
|
|
@@ -259,19 +261,19 @@ def test_deprecated_on_each_for_depolarizing_channel_two_qubits():
|
|
|
259
261
|
op.on_each([(False, None)])
|
|
260
262
|
|
|
261
263
|
|
|
262
|
-
def test_depolarizing_channel_apply_two_qubits():
|
|
264
|
+
def test_depolarizing_channel_apply_two_qubits() -> None:
|
|
263
265
|
q0, q1 = cirq.LineQubit.range(2)
|
|
264
266
|
op = cirq.DepolarizingChannel(p=0.1, n_qubits=2)
|
|
265
267
|
op(q0, q1)
|
|
266
268
|
|
|
267
269
|
|
|
268
|
-
def test_asymmetric_depolarizing_channel_apply_two_qubits():
|
|
270
|
+
def test_asymmetric_depolarizing_channel_apply_two_qubits() -> None:
|
|
269
271
|
q0, q1 = cirq.LineQubit.range(2)
|
|
270
272
|
op = cirq.AsymmetricDepolarizingChannel(error_probabilities={'XX': 0.1})
|
|
271
273
|
op(q0, q1)
|
|
272
274
|
|
|
273
275
|
|
|
274
|
-
def test_depolarizing_channel_eq():
|
|
276
|
+
def test_depolarizing_channel_eq() -> None:
|
|
275
277
|
a = cirq.depolarize(p=0.0099999)
|
|
276
278
|
b = cirq.depolarize(p=0.01)
|
|
277
279
|
c = cirq.depolarize(0.0)
|
|
@@ -288,14 +290,14 @@ def test_depolarizing_channel_eq():
|
|
|
288
290
|
et.add_equality_group(cirq.depolarize(1.0, n_qubits=2))
|
|
289
291
|
|
|
290
292
|
|
|
291
|
-
def test_depolarizing_channel_invalid_probability():
|
|
293
|
+
def test_depolarizing_channel_invalid_probability() -> None:
|
|
292
294
|
with pytest.raises(ValueError, match=re.escape('p(I) was greater than 1.')):
|
|
293
295
|
cirq.depolarize(-0.1)
|
|
294
296
|
with pytest.raises(ValueError, match=re.escape('p(I) was less than 0.')):
|
|
295
297
|
cirq.depolarize(1.1)
|
|
296
298
|
|
|
297
299
|
|
|
298
|
-
def test_depolarizing_channel_text_diagram():
|
|
300
|
+
def test_depolarizing_channel_text_diagram() -> None:
|
|
299
301
|
d = cirq.depolarize(0.1234567)
|
|
300
302
|
assert cirq.circuit_diagram_info(d, args=round_to_6_prec) == cirq.CircuitDiagramInfo(
|
|
301
303
|
wire_symbols=('D(0.123457)',)
|
|
@@ -308,7 +310,7 @@ def test_depolarizing_channel_text_diagram():
|
|
|
308
310
|
)
|
|
309
311
|
|
|
310
312
|
|
|
311
|
-
def test_depolarizing_channel_text_diagram_two_qubits():
|
|
313
|
+
def test_depolarizing_channel_text_diagram_two_qubits() -> None:
|
|
312
314
|
d = cirq.depolarize(0.1234567, n_qubits=2)
|
|
313
315
|
assert cirq.circuit_diagram_info(d, args=round_to_6_prec) == cirq.CircuitDiagramInfo(
|
|
314
316
|
wire_symbols=('D(0.123457)', '#2')
|
|
@@ -321,7 +323,7 @@ def test_depolarizing_channel_text_diagram_two_qubits():
|
|
|
321
323
|
)
|
|
322
324
|
|
|
323
325
|
|
|
324
|
-
def test_generalized_amplitude_damping_channel():
|
|
326
|
+
def test_generalized_amplitude_damping_channel() -> None:
|
|
325
327
|
d = cirq.generalized_amplitude_damp(0.1, 0.3)
|
|
326
328
|
np.testing.assert_almost_equal(
|
|
327
329
|
cirq.kraus(d),
|
|
@@ -336,18 +338,18 @@ def test_generalized_amplitude_damping_channel():
|
|
|
336
338
|
assert not cirq.has_mixture(d)
|
|
337
339
|
|
|
338
340
|
|
|
339
|
-
def test_generalized_amplitude_damping_repr():
|
|
341
|
+
def test_generalized_amplitude_damping_repr() -> None:
|
|
340
342
|
cirq.testing.assert_equivalent_repr(cirq.GeneralizedAmplitudeDampingChannel(0.1, 0.3))
|
|
341
343
|
|
|
342
344
|
|
|
343
|
-
def test_generalized_amplitude_damping_str():
|
|
345
|
+
def test_generalized_amplitude_damping_str() -> None:
|
|
344
346
|
assert (
|
|
345
347
|
str(cirq.generalized_amplitude_damp(0.1, 0.3))
|
|
346
348
|
== 'generalized_amplitude_damp(p=0.1,gamma=0.3)'
|
|
347
349
|
)
|
|
348
350
|
|
|
349
351
|
|
|
350
|
-
def test_generalized_amplitude_damping_channel_eq():
|
|
352
|
+
def test_generalized_amplitude_damping_channel_eq() -> None:
|
|
351
353
|
a = cirq.generalized_amplitude_damp(0.0099999, 0.01)
|
|
352
354
|
b = cirq.generalized_amplitude_damp(0.01, 0.0099999)
|
|
353
355
|
|
|
@@ -364,18 +366,18 @@ def test_generalized_amplitude_damping_channel_eq():
|
|
|
364
366
|
|
|
365
367
|
|
|
366
368
|
@pytest.mark.parametrize('p, gamma', ((-0.1, 0.0), (0.0, -0.1), (0.1, -0.1), (-0.1, 0.1)))
|
|
367
|
-
def test_generalized_amplitude_damping_channel_negative_probability(p, gamma):
|
|
369
|
+
def test_generalized_amplitude_damping_channel_negative_probability(p, gamma) -> None:
|
|
368
370
|
with pytest.raises(ValueError, match='was less than 0'):
|
|
369
371
|
cirq.generalized_amplitude_damp(p, gamma)
|
|
370
372
|
|
|
371
373
|
|
|
372
374
|
@pytest.mark.parametrize('p,gamma', ((1.1, 0.0), (0.0, 1.1), (1.1, 1.1)))
|
|
373
|
-
def test_generalized_amplitude_damping_channel_bigly_probability(p, gamma):
|
|
375
|
+
def test_generalized_amplitude_damping_channel_bigly_probability(p, gamma) -> None:
|
|
374
376
|
with pytest.raises(ValueError, match='was greater than 1'):
|
|
375
377
|
cirq.generalized_amplitude_damp(p, gamma)
|
|
376
378
|
|
|
377
379
|
|
|
378
|
-
def test_generalized_amplitude_damping_channel_text_diagram():
|
|
380
|
+
def test_generalized_amplitude_damping_channel_text_diagram() -> None:
|
|
379
381
|
a = cirq.generalized_amplitude_damp(0.1, 0.39558391)
|
|
380
382
|
assert cirq.circuit_diagram_info(a, args=round_to_6_prec) == cirq.CircuitDiagramInfo(
|
|
381
383
|
wire_symbols=('GAD(0.1,0.395584)',)
|
|
@@ -388,7 +390,7 @@ def test_generalized_amplitude_damping_channel_text_diagram():
|
|
|
388
390
|
)
|
|
389
391
|
|
|
390
392
|
|
|
391
|
-
def test_amplitude_damping_channel():
|
|
393
|
+
def test_amplitude_damping_channel() -> None:
|
|
392
394
|
d = cirq.amplitude_damp(0.3)
|
|
393
395
|
np.testing.assert_almost_equal(
|
|
394
396
|
cirq.kraus(d),
|
|
@@ -401,15 +403,15 @@ def test_amplitude_damping_channel():
|
|
|
401
403
|
assert not cirq.has_mixture(d)
|
|
402
404
|
|
|
403
405
|
|
|
404
|
-
def test_amplitude_damping_channel_repr():
|
|
406
|
+
def test_amplitude_damping_channel_repr() -> None:
|
|
405
407
|
cirq.testing.assert_equivalent_repr(cirq.AmplitudeDampingChannel(0.3))
|
|
406
408
|
|
|
407
409
|
|
|
408
|
-
def test_amplitude_damping_channel_str():
|
|
410
|
+
def test_amplitude_damping_channel_str() -> None:
|
|
409
411
|
assert str(cirq.amplitude_damp(0.3)) == 'amplitude_damp(gamma=0.3)'
|
|
410
412
|
|
|
411
413
|
|
|
412
|
-
def test_amplitude_damping_channel_eq():
|
|
414
|
+
def test_amplitude_damping_channel_eq() -> None:
|
|
413
415
|
a = cirq.amplitude_damp(0.0099999)
|
|
414
416
|
b = cirq.amplitude_damp(0.01)
|
|
415
417
|
c = cirq.amplitude_damp(0.0)
|
|
@@ -425,14 +427,14 @@ def test_amplitude_damping_channel_eq():
|
|
|
425
427
|
et.add_equality_group(cirq.amplitude_damp(0.8))
|
|
426
428
|
|
|
427
429
|
|
|
428
|
-
def test_amplitude_damping_channel_invalid_probability():
|
|
430
|
+
def test_amplitude_damping_channel_invalid_probability() -> None:
|
|
429
431
|
with pytest.raises(ValueError, match='was less than 0'):
|
|
430
432
|
cirq.amplitude_damp(-0.1)
|
|
431
433
|
with pytest.raises(ValueError, match='was greater than 1'):
|
|
432
434
|
cirq.amplitude_damp(1.1)
|
|
433
435
|
|
|
434
436
|
|
|
435
|
-
def test_amplitude_damping_channel_text_diagram():
|
|
437
|
+
def test_amplitude_damping_channel_text_diagram() -> None:
|
|
436
438
|
ad = cirq.amplitude_damp(0.38059322)
|
|
437
439
|
assert cirq.circuit_diagram_info(ad, args=round_to_6_prec) == cirq.CircuitDiagramInfo(
|
|
438
440
|
wire_symbols=('AD(0.380593)',)
|
|
@@ -445,7 +447,7 @@ def test_amplitude_damping_channel_text_diagram():
|
|
|
445
447
|
)
|
|
446
448
|
|
|
447
449
|
|
|
448
|
-
def test_reset_channel():
|
|
450
|
+
def test_reset_channel() -> None:
|
|
449
451
|
r = cirq.reset(cirq.LineQubit(0))
|
|
450
452
|
np.testing.assert_almost_equal(
|
|
451
453
|
cirq.kraus(r), (np.array([[1.0, 0.0], [0.0, 0]]), np.array([[0.0, 1.0], [0.0, 0.0]]))
|
|
@@ -470,22 +472,22 @@ def test_reset_channel():
|
|
|
470
472
|
assert cirq.qid_shape(r) == (3,)
|
|
471
473
|
|
|
472
474
|
|
|
473
|
-
def test_reset_channel_equality():
|
|
475
|
+
def test_reset_channel_equality() -> None:
|
|
474
476
|
assert cirq.reset(cirq.LineQubit(0)).gate == cirq.ResetChannel()
|
|
475
477
|
assert cirq.reset(cirq.LineQid(0, 3)).gate == cirq.ResetChannel(3)
|
|
476
478
|
|
|
477
479
|
|
|
478
|
-
def test_reset_channel_repr():
|
|
480
|
+
def test_reset_channel_repr() -> None:
|
|
479
481
|
cirq.testing.assert_equivalent_repr(cirq.ResetChannel())
|
|
480
482
|
cirq.testing.assert_equivalent_repr(cirq.ResetChannel(3))
|
|
481
483
|
|
|
482
484
|
|
|
483
|
-
def test_reset_channel_str():
|
|
485
|
+
def test_reset_channel_str() -> None:
|
|
484
486
|
assert str(cirq.ResetChannel()) == 'reset'
|
|
485
487
|
assert str(cirq.ResetChannel(3)) == 'reset'
|
|
486
488
|
|
|
487
489
|
|
|
488
|
-
def test_reset_channel_text_diagram():
|
|
490
|
+
def test_reset_channel_text_diagram() -> None:
|
|
489
491
|
assert cirq.circuit_diagram_info(cirq.ResetChannel()) == cirq.CircuitDiagramInfo(
|
|
490
492
|
wire_symbols=('R',)
|
|
491
493
|
)
|
|
@@ -494,7 +496,7 @@ def test_reset_channel_text_diagram():
|
|
|
494
496
|
)
|
|
495
497
|
|
|
496
498
|
|
|
497
|
-
def test_reset_act_on():
|
|
499
|
+
def test_reset_act_on() -> None:
|
|
498
500
|
with pytest.raises(TypeError, match="Failed to act"):
|
|
499
501
|
cirq.act_on(cirq.ResetChannel(), ExampleSimulationState(), qubits=())
|
|
500
502
|
|
|
@@ -523,7 +525,7 @@ def test_reset_act_on():
|
|
|
523
525
|
)
|
|
524
526
|
|
|
525
527
|
|
|
526
|
-
def test_reset_each():
|
|
528
|
+
def test_reset_each() -> None:
|
|
527
529
|
qubits = cirq.LineQubit.range(8)
|
|
528
530
|
for n in range(len(qubits) + 1):
|
|
529
531
|
ops = cirq.reset_each(*qubits[:n])
|
|
@@ -533,14 +535,14 @@ def test_reset_each():
|
|
|
533
535
|
assert op.qubits == (qubits[i],)
|
|
534
536
|
|
|
535
537
|
|
|
536
|
-
def test_reset_consistency():
|
|
538
|
+
def test_reset_consistency() -> None:
|
|
537
539
|
two_d_chan = cirq.ResetChannel()
|
|
538
540
|
cirq.testing.assert_has_consistent_apply_channel(two_d_chan)
|
|
539
541
|
three_d_chan = cirq.ResetChannel(dimension=3)
|
|
540
542
|
cirq.testing.assert_has_consistent_apply_channel(three_d_chan)
|
|
541
543
|
|
|
542
544
|
|
|
543
|
-
def test_phase_damping_channel():
|
|
545
|
+
def test_phase_damping_channel() -> None:
|
|
544
546
|
d = cirq.phase_damp(0.3)
|
|
545
547
|
np.testing.assert_almost_equal(
|
|
546
548
|
cirq.kraus(d),
|
|
@@ -553,15 +555,15 @@ def test_phase_damping_channel():
|
|
|
553
555
|
assert not cirq.has_mixture(d)
|
|
554
556
|
|
|
555
557
|
|
|
556
|
-
def test_phase_damping_channel_repr():
|
|
558
|
+
def test_phase_damping_channel_repr() -> None:
|
|
557
559
|
cirq.testing.assert_equivalent_repr(cirq.PhaseDampingChannel(0.3))
|
|
558
560
|
|
|
559
561
|
|
|
560
|
-
def test_phase_damping_channel_str():
|
|
562
|
+
def test_phase_damping_channel_str() -> None:
|
|
561
563
|
assert str(cirq.phase_damp(0.3)) == 'phase_damp(gamma=0.3)'
|
|
562
564
|
|
|
563
565
|
|
|
564
|
-
def test_phase_damping_channel_eq():
|
|
566
|
+
def test_phase_damping_channel_eq() -> None:
|
|
565
567
|
a = cirq.phase_damp(0.0099999)
|
|
566
568
|
b = cirq.phase_damp(0.01)
|
|
567
569
|
c = cirq.phase_damp(0.0)
|
|
@@ -577,14 +579,14 @@ def test_phase_damping_channel_eq():
|
|
|
577
579
|
et.add_equality_group(cirq.phase_damp(0.8))
|
|
578
580
|
|
|
579
581
|
|
|
580
|
-
def test_phase_damping_channel_invalid_probability():
|
|
582
|
+
def test_phase_damping_channel_invalid_probability() -> None:
|
|
581
583
|
with pytest.raises(ValueError, match='was less than 0'):
|
|
582
584
|
cirq.phase_damp(-0.1)
|
|
583
585
|
with pytest.raises(ValueError, match='was greater than 1'):
|
|
584
586
|
cirq.phase_damp(1.1)
|
|
585
587
|
|
|
586
588
|
|
|
587
|
-
def test_phase_damping_channel_text_diagram():
|
|
589
|
+
def test_phase_damping_channel_text_diagram() -> None:
|
|
588
590
|
pd = cirq.phase_damp(0.1000009)
|
|
589
591
|
assert cirq.circuit_diagram_info(pd, args=round_to_6_prec) == cirq.CircuitDiagramInfo(
|
|
590
592
|
wire_symbols=('PD(0.100001)',)
|
|
@@ -597,7 +599,7 @@ def test_phase_damping_channel_text_diagram():
|
|
|
597
599
|
)
|
|
598
600
|
|
|
599
601
|
|
|
600
|
-
def test_phase_damp_consistency():
|
|
602
|
+
def test_phase_damp_consistency() -> None:
|
|
601
603
|
full_damp = cirq.PhaseDampingChannel(gamma=1)
|
|
602
604
|
cirq.testing.assert_has_consistent_apply_channel(full_damp)
|
|
603
605
|
partial_damp = cirq.PhaseDampingChannel(gamma=0.5)
|
|
@@ -606,7 +608,7 @@ def test_phase_damp_consistency():
|
|
|
606
608
|
cirq.testing.assert_has_consistent_apply_channel(no_damp)
|
|
607
609
|
|
|
608
610
|
|
|
609
|
-
def test_phase_flip_channel():
|
|
611
|
+
def test_phase_flip_channel() -> None:
|
|
610
612
|
d = cirq.phase_flip(0.3)
|
|
611
613
|
np.testing.assert_almost_equal(
|
|
612
614
|
cirq.kraus(d), (np.sqrt(1.0 - 0.3) * np.eye(2), np.sqrt(0.3) * Z)
|
|
@@ -615,28 +617,28 @@ def test_phase_flip_channel():
|
|
|
615
617
|
cirq.testing.assert_consistent_mixture(d)
|
|
616
618
|
|
|
617
619
|
|
|
618
|
-
def test_phase_flip_mixture():
|
|
620
|
+
def test_phase_flip_mixture() -> None:
|
|
619
621
|
d = cirq.phase_flip(0.3)
|
|
620
622
|
assert_mixtures_equal(cirq.mixture(d), ((0.7, np.eye(2)), (0.3, Z)))
|
|
621
623
|
assert cirq.has_mixture(d)
|
|
622
624
|
|
|
623
625
|
|
|
624
|
-
def test_phase_flip_overload():
|
|
626
|
+
def test_phase_flip_overload() -> None:
|
|
625
627
|
d = cirq.phase_flip()
|
|
626
628
|
d2 = cirq.phase_flip(0.3)
|
|
627
629
|
assert str(d) == 'Z'
|
|
628
630
|
assert str(d2) == 'phase_flip(p=0.3)'
|
|
629
631
|
|
|
630
632
|
|
|
631
|
-
def test_phase_flip_channel_repr():
|
|
633
|
+
def test_phase_flip_channel_repr() -> None:
|
|
632
634
|
cirq.testing.assert_equivalent_repr(cirq.PhaseFlipChannel(0.3))
|
|
633
635
|
|
|
634
636
|
|
|
635
|
-
def test_phase_flip_channel_str():
|
|
637
|
+
def test_phase_flip_channel_str() -> None:
|
|
636
638
|
assert str(cirq.phase_flip(0.3)) == 'phase_flip(p=0.3)'
|
|
637
639
|
|
|
638
640
|
|
|
639
|
-
def test_phase_flip_channel_eq():
|
|
641
|
+
def test_phase_flip_channel_eq() -> None:
|
|
640
642
|
a = cirq.phase_flip(0.0099999)
|
|
641
643
|
b = cirq.phase_flip(0.01)
|
|
642
644
|
c = cirq.phase_flip(0.0)
|
|
@@ -652,14 +654,14 @@ def test_phase_flip_channel_eq():
|
|
|
652
654
|
et.add_equality_group(cirq.phase_flip(0.8))
|
|
653
655
|
|
|
654
656
|
|
|
655
|
-
def test_phase_flip_channel_invalid_probability():
|
|
657
|
+
def test_phase_flip_channel_invalid_probability() -> None:
|
|
656
658
|
with pytest.raises(ValueError, match='was less than 0'):
|
|
657
659
|
cirq.phase_flip(-0.1)
|
|
658
660
|
with pytest.raises(ValueError, match='was greater than 1'):
|
|
659
661
|
cirq.phase_flip(1.1)
|
|
660
662
|
|
|
661
663
|
|
|
662
|
-
def test_phase_flip_channel_text_diagram():
|
|
664
|
+
def test_phase_flip_channel_text_diagram() -> None:
|
|
663
665
|
pf = cirq.phase_flip(0.987654)
|
|
664
666
|
assert cirq.circuit_diagram_info(pf, args=round_to_6_prec) == cirq.CircuitDiagramInfo(
|
|
665
667
|
wire_symbols=('PF(0.987654)',)
|
|
@@ -672,7 +674,7 @@ def test_phase_flip_channel_text_diagram():
|
|
|
672
674
|
)
|
|
673
675
|
|
|
674
676
|
|
|
675
|
-
def test_bit_flip_channel():
|
|
677
|
+
def test_bit_flip_channel() -> None:
|
|
676
678
|
d = cirq.bit_flip(0.3)
|
|
677
679
|
np.testing.assert_almost_equal(
|
|
678
680
|
cirq.kraus(d), (np.sqrt(1.0 - 0.3) * np.eye(2), np.sqrt(0.3) * X)
|
|
@@ -681,28 +683,28 @@ def test_bit_flip_channel():
|
|
|
681
683
|
cirq.testing.assert_consistent_mixture(d)
|
|
682
684
|
|
|
683
685
|
|
|
684
|
-
def test_bit_flip_mixture():
|
|
686
|
+
def test_bit_flip_mixture() -> None:
|
|
685
687
|
d = cirq.bit_flip(0.3)
|
|
686
688
|
assert_mixtures_equal(cirq.mixture(d), ((0.7, np.eye(2)), (0.3, X)))
|
|
687
689
|
assert cirq.has_mixture(d)
|
|
688
690
|
|
|
689
691
|
|
|
690
|
-
def test_bit_flip_overload():
|
|
692
|
+
def test_bit_flip_overload() -> None:
|
|
691
693
|
d = cirq.bit_flip()
|
|
692
694
|
d2 = cirq.bit_flip(0.3)
|
|
693
695
|
assert str(d) == 'X'
|
|
694
696
|
assert str(d2) == 'bit_flip(p=0.3)'
|
|
695
697
|
|
|
696
698
|
|
|
697
|
-
def test_bit_flip_channel_repr():
|
|
699
|
+
def test_bit_flip_channel_repr() -> None:
|
|
698
700
|
cirq.testing.assert_equivalent_repr(cirq.BitFlipChannel(0.3))
|
|
699
701
|
|
|
700
702
|
|
|
701
|
-
def test_bit_flip_channel_str():
|
|
703
|
+
def test_bit_flip_channel_str() -> None:
|
|
702
704
|
assert str(cirq.bit_flip(0.3)) == 'bit_flip(p=0.3)'
|
|
703
705
|
|
|
704
706
|
|
|
705
|
-
def test_bit_flip_channel_eq():
|
|
707
|
+
def test_bit_flip_channel_eq() -> None:
|
|
706
708
|
a = cirq.bit_flip(0.0099999)
|
|
707
709
|
b = cirq.bit_flip(0.01)
|
|
708
710
|
c = cirq.bit_flip(0.0)
|
|
@@ -718,14 +720,14 @@ def test_bit_flip_channel_eq():
|
|
|
718
720
|
et.add_equality_group(cirq.bit_flip(0.8))
|
|
719
721
|
|
|
720
722
|
|
|
721
|
-
def test_bit_flip_channel_invalid_probability():
|
|
723
|
+
def test_bit_flip_channel_invalid_probability() -> None:
|
|
722
724
|
with pytest.raises(ValueError, match='was less than 0'):
|
|
723
725
|
cirq.bit_flip(-0.1)
|
|
724
726
|
with pytest.raises(ValueError, match='was greater than 1'):
|
|
725
727
|
cirq.bit_flip(1.1)
|
|
726
728
|
|
|
727
729
|
|
|
728
|
-
def test_bit_flip_channel_text_diagram():
|
|
730
|
+
def test_bit_flip_channel_text_diagram() -> None:
|
|
729
731
|
bf = cirq.bit_flip(0.1234567)
|
|
730
732
|
assert cirq.circuit_diagram_info(bf, args=round_to_6_prec) == cirq.CircuitDiagramInfo(
|
|
731
733
|
wire_symbols=('BF(0.123457)',)
|
|
@@ -738,7 +740,7 @@ def test_bit_flip_channel_text_diagram():
|
|
|
738
740
|
)
|
|
739
741
|
|
|
740
742
|
|
|
741
|
-
def test_stabilizer_supports_depolarize():
|
|
743
|
+
def test_stabilizer_supports_depolarize() -> None:
|
|
742
744
|
with pytest.raises(TypeError, match="act_on"):
|
|
743
745
|
for _ in range(100):
|
|
744
746
|
cirq.act_on(cirq.depolarize(3 / 4), ExampleSimulationState(), qubits=())
|
|
@@ -749,7 +751,7 @@ def test_stabilizer_supports_depolarize():
|
|
|
749
751
|
assert 5 < m < 95
|
|
750
752
|
|
|
751
753
|
|
|
752
|
-
def test_default_asymmetric_depolarizing_channel():
|
|
754
|
+
def test_default_asymmetric_depolarizing_channel() -> None:
|
|
753
755
|
d = cirq.asymmetric_depolarize()
|
|
754
756
|
assert d.p_i == 1.0
|
|
755
757
|
assert d.p_x == 0.0
|
|
@@ -758,28 +760,28 @@ def test_default_asymmetric_depolarizing_channel():
|
|
|
758
760
|
assert d.num_qubits() == 1
|
|
759
761
|
|
|
760
762
|
|
|
761
|
-
def test_bad_error_probabilities_gate():
|
|
763
|
+
def test_bad_error_probabilities_gate() -> None:
|
|
762
764
|
with pytest.raises(ValueError, match='AB is not made solely of I, X, Y, Z.'):
|
|
763
765
|
cirq.asymmetric_depolarize(error_probabilities={'AB': 1.0})
|
|
764
766
|
with pytest.raises(ValueError, match='Y must have 2 Pauli gates.'):
|
|
765
767
|
cirq.asymmetric_depolarize(error_probabilities={'IX': 0.8, 'Y': 0.2})
|
|
766
768
|
|
|
767
769
|
|
|
768
|
-
def test_bad_probs():
|
|
770
|
+
def test_bad_probs() -> None:
|
|
769
771
|
with pytest.raises(ValueError, match=re.escape('p(X) was greater than 1.')):
|
|
770
772
|
cirq.asymmetric_depolarize(error_probabilities={'X': 1.1, 'Y': -0.1})
|
|
771
773
|
with pytest.raises(ValueError, match=re.escape('Probabilities do not add up to 1')):
|
|
772
774
|
cirq.asymmetric_depolarize(error_probabilities={'X': 0.7, 'Y': 0.6})
|
|
773
775
|
|
|
774
776
|
|
|
775
|
-
def test_missing_prob_mass():
|
|
777
|
+
def test_missing_prob_mass() -> None:
|
|
776
778
|
with pytest.raises(ValueError, match='Probabilities do not add up to 1'):
|
|
777
779
|
cirq.asymmetric_depolarize(error_probabilities={'X': 0.1, 'I': 0.2})
|
|
778
780
|
d = cirq.asymmetric_depolarize(error_probabilities={'X': 0.1})
|
|
779
781
|
np.testing.assert_almost_equal(d.error_probabilities['I'], 0.9)
|
|
780
782
|
|
|
781
783
|
|
|
782
|
-
def test_multi_asymmetric_depolarizing_channel():
|
|
784
|
+
def test_multi_asymmetric_depolarizing_channel() -> None:
|
|
783
785
|
d = cirq.asymmetric_depolarize(error_probabilities={'II': 0.8, 'XX': 0.2})
|
|
784
786
|
np.testing.assert_almost_equal(
|
|
785
787
|
cirq.kraus(d), (np.sqrt(0.8) * np.eye(4), np.sqrt(0.2) * np.kron(X, X))
|
|
@@ -798,20 +800,20 @@ def test_multi_asymmetric_depolarizing_channel():
|
|
|
798
800
|
assert d.p_z == 0.0
|
|
799
801
|
|
|
800
802
|
|
|
801
|
-
def test_multi_asymmetric_depolarizing_mixture():
|
|
803
|
+
def test_multi_asymmetric_depolarizing_mixture() -> None:
|
|
802
804
|
d = cirq.asymmetric_depolarize(error_probabilities={'II': 0.8, 'XX': 0.2})
|
|
803
805
|
assert_mixtures_equal(cirq.mixture(d), ((0.8, np.eye(4)), (0.2, np.kron(X, X))))
|
|
804
806
|
assert cirq.has_mixture(d)
|
|
805
807
|
np.testing.assert_equal(d._num_qubits_(), 2)
|
|
806
808
|
|
|
807
809
|
|
|
808
|
-
def test_multi_asymmetric_depolarizing_channel_repr():
|
|
810
|
+
def test_multi_asymmetric_depolarizing_channel_repr() -> None:
|
|
809
811
|
cirq.testing.assert_equivalent_repr(
|
|
810
812
|
cirq.AsymmetricDepolarizingChannel(error_probabilities={'II': 0.8, 'XX': 0.2})
|
|
811
813
|
)
|
|
812
814
|
|
|
813
815
|
|
|
814
|
-
def test_multi_asymmetric_depolarizing_eq():
|
|
816
|
+
def test_multi_asymmetric_depolarizing_eq() -> None:
|
|
815
817
|
a = cirq.asymmetric_depolarize(error_probabilities={'I': 0.8, 'X': 0.2})
|
|
816
818
|
b = cirq.asymmetric_depolarize(error_probabilities={'II': 0.8, 'XX': 0.2})
|
|
817
819
|
|
|
@@ -845,13 +847,13 @@ def test_multi_asymmetric_depolarizing_eq():
|
|
|
845
847
|
assert not cirq.approx_eq(a, cirq.X)
|
|
846
848
|
|
|
847
849
|
|
|
848
|
-
def test_multi_asymmetric_depolarizing_channel_str():
|
|
850
|
+
def test_multi_asymmetric_depolarizing_channel_str() -> None:
|
|
849
851
|
assert str(cirq.asymmetric_depolarize(error_probabilities={'II': 0.8, 'XX': 0.2})) == (
|
|
850
852
|
"asymmetric_depolarize(error_probabilities={'II': 0.8, 'XX': 0.2})"
|
|
851
853
|
)
|
|
852
854
|
|
|
853
855
|
|
|
854
|
-
def test_multi_asymmetric_depolarizing_channel_text_diagram():
|
|
856
|
+
def test_multi_asymmetric_depolarizing_channel_text_diagram() -> None:
|
|
855
857
|
a = cirq.asymmetric_depolarize(error_probabilities={'II': 2 / 3, 'XX': 1 / 3})
|
|
856
858
|
assert cirq.circuit_diagram_info(a, args=no_precision) == cirq.CircuitDiagramInfo(
|
|
857
859
|
wire_symbols=('A(II:0.6666666666666666, XX:0.3333333333333333)', '(1)')
|
|
@@ -867,5 +869,5 @@ def test_multi_asymmetric_depolarizing_channel_text_diagram():
|
|
|
867
869
|
)
|
|
868
870
|
|
|
869
871
|
|
|
870
|
-
def test_reset_stabilizer():
|
|
872
|
+
def test_reset_stabilizer() -> None:
|
|
871
873
|
assert cirq.has_stabilizer_effect(cirq.reset(cirq.LineQubit(0)))
|
cirq/ops/common_gate_families.py
CHANGED
|
@@ -14,7 +14,9 @@
|
|
|
14
14
|
|
|
15
15
|
"""Common Gate Families used in cirq-core"""
|
|
16
16
|
|
|
17
|
-
from
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
from typing import Any, cast
|
|
18
20
|
|
|
19
21
|
from cirq import protocols
|
|
20
22
|
from cirq.ops import eigen_gate, gateset, parallel_gate, raw_types
|
|
@@ -23,7 +25,7 @@ from cirq.ops import eigen_gate, gateset, parallel_gate, raw_types
|
|
|
23
25
|
class AnyUnitaryGateFamily(gateset.GateFamily):
|
|
24
26
|
"""GateFamily which accepts any N-Qubit unitary gate."""
|
|
25
27
|
|
|
26
|
-
def __init__(self, num_qubits:
|
|
28
|
+
def __init__(self, num_qubits: int | None = None) -> None:
|
|
27
29
|
"""Init AnyUnitaryGateFamily
|
|
28
30
|
|
|
29
31
|
Args:
|
|
@@ -63,7 +65,7 @@ class AnyUnitaryGateFamily(gateset.GateFamily):
|
|
|
63
65
|
class AnyIntegerPowerGateFamily(gateset.GateFamily):
|
|
64
66
|
"""GateFamily which accepts instances of a given `cirq.EigenGate`, raised to integer power."""
|
|
65
67
|
|
|
66
|
-
def __init__(self, gate:
|
|
68
|
+
def __init__(self, gate: type[eigen_gate.EigenGate]) -> None:
|
|
67
69
|
"""Init AnyIntegerPowerGateFamily
|
|
68
70
|
|
|
69
71
|
Args:
|
|
@@ -127,11 +129,11 @@ class ParallelGateFamily(gateset.GateFamily):
|
|
|
127
129
|
|
|
128
130
|
def __init__(
|
|
129
131
|
self,
|
|
130
|
-
gate:
|
|
132
|
+
gate: type[raw_types.Gate] | raw_types.Gate,
|
|
131
133
|
*,
|
|
132
|
-
name:
|
|
133
|
-
description:
|
|
134
|
-
max_parallel_allowed:
|
|
134
|
+
name: str | None = None,
|
|
135
|
+
description: str | None = None,
|
|
136
|
+
max_parallel_allowed: int | None = None,
|
|
135
137
|
) -> None:
|
|
136
138
|
"""Inits ParallelGateFamily
|
|
137
139
|
|