cirq-core 1.4.0.dev20240529225110__py3-none-any.whl → 1.5.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 +587 -569
- cirq/_compat.py +9 -0
- cirq/_compat_test.py +11 -9
- cirq/_import.py +7 -8
- cirq/_version.py +31 -1
- cirq/_version_test.py +1 -1
- cirq/circuits/__init__.py +15 -9
- cirq/circuits/_block_diagram_drawer.py +1 -2
- cirq/circuits/_block_diagram_drawer_test.py +3 -3
- cirq/circuits/_box_drawing_character_data.py +0 -1
- cirq/circuits/_box_drawing_character_data_test.py +2 -2
- cirq/circuits/_bucket_priority_queue.py +0 -1
- cirq/circuits/_bucket_priority_queue_test.py +1 -1
- cirq/circuits/circuit.py +336 -234
- cirq/circuits/circuit_operation.py +102 -52
- cirq/circuits/circuit_operation_test.py +85 -4
- cirq/circuits/circuit_test.py +101 -32
- cirq/circuits/frozen_circuit.py +36 -32
- cirq/circuits/insert_strategy.py +10 -0
- cirq/circuits/insert_strategy_test.py +20 -0
- cirq/circuits/moment.py +79 -80
- cirq/circuits/moment_test.py +105 -2
- cirq/circuits/optimization_pass.py +15 -15
- cirq/circuits/optimization_pass_test.py +8 -9
- cirq/circuits/qasm_output.py +64 -33
- cirq/circuits/qasm_output_test.py +63 -2
- cirq/circuits/text_diagram_drawer.py +26 -56
- cirq/circuits/text_diagram_drawer_test.py +5 -4
- cirq/contrib/__init__.py +2 -2
- cirq/contrib/acquaintance/__init__.py +44 -29
- cirq/contrib/acquaintance/bipartite.py +8 -7
- cirq/contrib/acquaintance/bipartite_test.py +11 -1
- cirq/contrib/acquaintance/devices.py +5 -4
- cirq/contrib/acquaintance/devices_test.py +5 -1
- cirq/contrib/acquaintance/executor.py +18 -21
- cirq/contrib/acquaintance/executor_test.py +3 -2
- cirq/contrib/acquaintance/gates.py +36 -27
- cirq/contrib/acquaintance/gates_test.py +1 -1
- cirq/contrib/acquaintance/inspection_utils.py +10 -9
- cirq/contrib/acquaintance/inspection_utils_test.py +6 -1
- cirq/contrib/acquaintance/mutation_utils.py +10 -10
- cirq/contrib/acquaintance/optimizers.py +7 -6
- cirq/contrib/acquaintance/optimizers_test.py +1 -1
- cirq/contrib/acquaintance/permutation.py +22 -21
- cirq/contrib/acquaintance/permutation_test.py +1 -1
- cirq/contrib/acquaintance/shift.py +8 -6
- cirq/contrib/acquaintance/shift_swap_network.py +6 -4
- cirq/contrib/acquaintance/strategies/__init__.py +9 -3
- cirq/contrib/acquaintance/strategies/complete.py +4 -3
- cirq/contrib/acquaintance/strategies/cubic.py +5 -3
- cirq/contrib/acquaintance/strategies/quartic_paired.py +8 -6
- cirq/contrib/acquaintance/topological_sort.py +4 -2
- cirq/contrib/bayesian_network/__init__.py +3 -1
- cirq/contrib/bayesian_network/bayesian_network_gate.py +5 -3
- cirq/contrib/circuitdag/__init__.py +1 -1
- cirq/contrib/circuitdag/circuit_dag.py +24 -24
- cirq/contrib/circuitdag/circuit_dag_test.py +1 -1
- cirq/contrib/custom_simulators/custom_state_simulator.py +10 -8
- cirq/contrib/custom_simulators/custom_state_simulator_test.py +15 -11
- cirq/contrib/graph_device/__init__.py +8 -8
- cirq/contrib/graph_device/graph_device.py +8 -8
- cirq/contrib/graph_device/graph_device_test.py +0 -1
- cirq/contrib/graph_device/hypergraph_test.py +1 -0
- cirq/contrib/json.py +1 -2
- cirq/contrib/json_test.py +2 -2
- cirq/contrib/noise_models/__init__.py +5 -6
- cirq/contrib/noise_models/noise_models.py +8 -6
- cirq/contrib/paulistring/__init__.py +22 -10
- cirq/contrib/paulistring/clifford_optimize.py +1 -1
- cirq/contrib/paulistring/clifford_optimize_test.py +0 -1
- cirq/contrib/paulistring/clifford_target_gateset.py +15 -12
- cirq/contrib/paulistring/optimize.py +2 -2
- cirq/contrib/paulistring/optimize_test.py +0 -1
- cirq/contrib/paulistring/pauli_string_dag_test.py +0 -1
- cirq/contrib/paulistring/pauli_string_measurement_with_readout_mitigation.py +379 -0
- cirq/contrib/paulistring/pauli_string_measurement_with_readout_mitigation_test.py +523 -0
- cirq/contrib/paulistring/pauli_string_optimize.py +3 -1
- cirq/contrib/paulistring/pauli_string_optimize_test.py +1 -3
- cirq/contrib/paulistring/recombine.py +2 -2
- cirq/contrib/paulistring/recombine_test.py +2 -2
- cirq/contrib/paulistring/separate.py +3 -4
- cirq/contrib/qasm_import/__init__.py +2 -2
- cirq/contrib/qasm_import/_lexer.py +21 -26
- cirq/contrib/qasm_import/_lexer_test.py +90 -6
- cirq/contrib/qasm_import/_parser.py +238 -47
- cirq/contrib/qasm_import/_parser_test.py +514 -59
- cirq/contrib/qasm_import/qasm_test.py +1 -1
- cirq/contrib/qcircuit/__init__.py +6 -4
- cirq/contrib/qcircuit/qcircuit_diagram.py +5 -2
- cirq/contrib/qcircuit/qcircuit_pdf.py +1 -2
- cirq/{experiments/grid_parallel_two_qubit_xeb_test.py → contrib/qcircuit/qcircuit_pdf_test.py} +13 -12
- cirq/contrib/qcircuit/qcircuit_test.py +1 -1
- cirq/contrib/quantum_volume/__init__.py +7 -7
- cirq/contrib/quantum_volume/quantum_volume.py +6 -11
- cirq/contrib/quantum_volume/quantum_volume_test.py +3 -1
- cirq/contrib/quimb/__init__.py +16 -13
- cirq/contrib/quimb/density_matrix.py +1 -1
- cirq/contrib/quimb/mps_simulator.py +27 -28
- cirq/contrib/quimb/mps_simulator_test.py +5 -0
- cirq/contrib/quimb/state_vector.py +3 -10
- cirq/contrib/quirk/__init__.py +1 -1
- cirq/contrib/quirk/export_to_quirk.py +3 -3
- cirq/contrib/routing/__init__.py +12 -9
- cirq/contrib/routing/device.py +1 -1
- cirq/contrib/routing/device_test.py +1 -2
- cirq/contrib/routing/greedy.py +7 -5
- cirq/contrib/routing/greedy_test.py +5 -3
- cirq/contrib/routing/initialization.py +3 -1
- cirq/contrib/routing/initialization_test.py +1 -1
- cirq/contrib/routing/swap_network.py +6 -6
- cirq/contrib/routing/utils.py +6 -4
- cirq/contrib/routing/utils_test.py +1 -2
- cirq/{type_workarounds.py → contrib/shuffle_circuits/__init__.py} +5 -10
- cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking.py +250 -0
- cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking_test.py +363 -0
- cirq/contrib/svg/__init__.py +1 -1
- cirq/contrib/svg/svg.py +12 -10
- cirq/contrib/svg/svg_test.py +3 -2
- cirq/devices/__init__.py +34 -25
- cirq/devices/device.py +16 -12
- cirq/devices/device_test.py +1 -0
- cirq/devices/grid_device_metadata.py +16 -12
- cirq/devices/grid_device_metadata_test.py +2 -1
- cirq/devices/grid_qubit.py +31 -26
- cirq/devices/grid_qubit_test.py +30 -1
- cirq/devices/insertion_noise_model.py +6 -6
- cirq/devices/insertion_noise_model_test.py +1 -1
- cirq/devices/line_qubit.py +28 -20
- cirq/devices/line_qubit_test.py +26 -0
- cirq/devices/named_topologies.py +12 -10
- cirq/devices/named_topologies_test.py +5 -4
- cirq/devices/noise_model.py +29 -33
- cirq/devices/noise_properties.py +2 -2
- cirq/devices/noise_properties_test.py +2 -2
- cirq/devices/noise_utils.py +3 -3
- cirq/devices/superconducting_qubits_noise_properties.py +2 -2
- cirq/devices/superconducting_qubits_noise_properties_test.py +3 -3
- cirq/devices/thermal_noise_model.py +2 -1
- cirq/devices/unconstrained_device.py +1 -1
- cirq/devices/unconstrained_device_test.py +6 -0
- cirq/experiments/__init__.py +51 -34
- cirq/experiments/qubit_characterizations.py +17 -15
- cirq/experiments/qubit_characterizations_test.py +4 -6
- cirq/experiments/random_quantum_circuit_generation.py +10 -9
- cirq/experiments/random_quantum_circuit_generation_test.py +21 -4
- cirq/experiments/readout_confusion_matrix.py +73 -8
- cirq/experiments/readout_confusion_matrix_test.py +104 -1
- cirq/experiments/single_qubit_readout_calibration.py +8 -6
- cirq/experiments/single_qubit_readout_calibration_test.py +1 -1
- cirq/experiments/t1_decay_experiment.py +4 -5
- cirq/experiments/t1_decay_experiment_test.py +1 -2
- cirq/experiments/t2_decay_experiment.py +0 -1
- cirq/experiments/t2_decay_experiment_test.py +1 -2
- cirq/experiments/two_qubit_xeb.py +157 -33
- cirq/experiments/two_qubit_xeb_test.py +38 -22
- cirq/experiments/xeb_fitting.py +99 -19
- cirq/experiments/xeb_fitting_test.py +64 -25
- cirq/experiments/xeb_sampling.py +14 -18
- cirq/experiments/xeb_simulation.py +4 -3
- cirq/experiments/xeb_simulation_test.py +20 -14
- cirq/experiments/z_phase_calibration.py +368 -0
- cirq/experiments/z_phase_calibration_test.py +241 -0
- cirq/interop/__init__.py +4 -1
- cirq/interop/quirk/__init__.py +7 -4
- cirq/interop/quirk/cells/__init__.py +17 -6
- cirq/interop/quirk/cells/arithmetic_cells.py +8 -8
- cirq/interop/quirk/cells/arithmetic_cells_test.py +1 -1
- cirq/interop/quirk/cells/cell.py +6 -6
- cirq/interop/quirk/cells/composite_cell.py +5 -5
- cirq/interop/quirk/cells/composite_cell_test.py +1 -1
- cirq/interop/quirk/cells/control_cells.py +1 -1
- cirq/interop/quirk/cells/frequency_space_cells.py +2 -2
- cirq/interop/quirk/cells/ignored_cells.py +1 -1
- cirq/interop/quirk/cells/input_cells.py +1 -1
- cirq/interop/quirk/cells/input_cells_test.py +1 -1
- cirq/interop/quirk/cells/input_rotation_cells.py +1 -1
- cirq/interop/quirk/cells/input_rotation_cells_test.py +1 -1
- cirq/interop/quirk/cells/measurement_cells.py +1 -1
- cirq/interop/quirk/cells/parse.py +8 -7
- cirq/interop/quirk/cells/parse_test.py +2 -2
- cirq/interop/quirk/cells/single_qubit_rotation_cells.py +1 -1
- cirq/interop/quirk/cells/swap_cell_test.py +1 -1
- cirq/interop/quirk/cells/unsupported_cells.py +1 -1
- cirq/interop/quirk/url_to_circuit.py +7 -7
- cirq/interop/quirk/url_to_circuit_test.py +1 -1
- cirq/ion/__init__.py +4 -2
- cirq/json_resolver_cache.py +15 -7
- cirq/linalg/__init__.py +62 -51
- cirq/linalg/combinators.py +4 -4
- cirq/linalg/combinators_test.py +4 -1
- cirq/linalg/decompositions.py +15 -40
- cirq/linalg/decompositions_test.py +16 -22
- cirq/linalg/diagonalize.py +1 -1
- cirq/linalg/diagonalize_test.py +1 -1
- cirq/linalg/operator_spaces.py +20 -4
- cirq/linalg/operator_spaces_test.py +15 -2
- cirq/linalg/predicates.py +3 -3
- cirq/linalg/predicates_test.py +1 -0
- cirq/linalg/tolerance.py +2 -2
- cirq/linalg/transformations.py +30 -12
- cirq/linalg/transformations_test.py +13 -0
- cirq/neutral_atoms/__init__.py +2 -2
- cirq/neutral_atoms/convert_to_neutral_atom_gates_test.py +0 -1
- cirq/ops/__init__.py +172 -132
- cirq/ops/arithmetic_operation.py +2 -2
- cirq/ops/arithmetic_operation_test.py +2 -2
- cirq/ops/boolean_hamiltonian.py +3 -2
- cirq/ops/classically_controlled_operation.py +39 -12
- cirq/ops/classically_controlled_operation_test.py +147 -1
- cirq/ops/clifford_gate.py +38 -36
- cirq/ops/clifford_gate_test.py +75 -1
- cirq/ops/common_channels.py +16 -45
- cirq/ops/common_channels_test.py +10 -0
- cirq/ops/common_gate_families.py +1 -1
- cirq/ops/common_gate_families_test.py +1 -0
- cirq/ops/common_gates.py +48 -49
- cirq/ops/common_gates_test.py +18 -2
- cirq/ops/control_values.py +3 -3
- cirq/ops/control_values_test.py +2 -1
- cirq/ops/controlled_gate.py +36 -23
- cirq/ops/controlled_gate_test.py +70 -3
- cirq/ops/controlled_operation.py +6 -5
- cirq/ops/controlled_operation_test.py +7 -3
- cirq/ops/dense_pauli_string.py +11 -11
- cirq/ops/diagonal_gate.py +2 -2
- cirq/ops/diagonal_gate_test.py +1 -0
- cirq/ops/eigen_gate.py +16 -36
- cirq/ops/eigen_gate_test.py +60 -10
- cirq/ops/fourier_transform.py +1 -3
- cirq/ops/fourier_transform_test.py +2 -1
- cirq/ops/fsim_gate.py +42 -3
- cirq/ops/fsim_gate_test.py +21 -0
- cirq/ops/gate_operation.py +8 -8
- cirq/ops/gate_operation_test.py +4 -2
- cirq/ops/gateset_test.py +11 -2
- cirq/ops/global_phase_op.py +8 -7
- cirq/ops/global_phase_op_test.py +1 -1
- cirq/ops/greedy_qubit_manager_test.py +5 -0
- cirq/ops/identity.py +14 -4
- cirq/ops/identity_test.py +24 -0
- cirq/ops/kraus_channel.py +1 -0
- cirq/ops/kraus_channel_test.py +3 -1
- cirq/ops/linear_combinations.py +27 -21
- cirq/ops/linear_combinations_test.py +23 -4
- cirq/ops/matrix_gates.py +24 -8
- cirq/ops/measure_util.py +2 -2
- cirq/ops/measurement_gate.py +7 -4
- cirq/ops/measurement_gate_test.py +2 -1
- cirq/ops/mixed_unitary_channel.py +1 -0
- cirq/ops/mixed_unitary_channel_test.py +3 -1
- cirq/ops/named_qubit.py +8 -1
- cirq/ops/op_tree.py +3 -30
- cirq/ops/op_tree_test.py +4 -0
- cirq/ops/parallel_gate.py +2 -3
- cirq/ops/parallel_gate_test.py +2 -1
- cirq/ops/parity_gates.py +7 -8
- cirq/ops/parity_gates_test.py +1 -0
- cirq/ops/pauli_gates.py +5 -11
- cirq/ops/pauli_gates_test.py +1 -0
- cirq/ops/pauli_interaction_gate.py +11 -5
- cirq/ops/pauli_interaction_gate_test.py +2 -3
- cirq/ops/pauli_measurement_gate.py +6 -5
- cirq/ops/pauli_measurement_gate_test.py +1 -0
- cirq/ops/pauli_string.py +115 -130
- cirq/ops/pauli_string_phasor.py +21 -20
- cirq/ops/pauli_string_phasor_test.py +13 -3
- cirq/ops/pauli_string_raw_types.py +1 -0
- cirq/ops/pauli_string_test.py +192 -55
- cirq/ops/pauli_sum_exponential.py +3 -4
- cirq/ops/pauli_sum_exponential_test.py +0 -1
- cirq/ops/permutation_gate.py +2 -2
- cirq/ops/permutation_gate_test.py +1 -1
- cirq/ops/phased_iswap_gate.py +6 -7
- cirq/ops/phased_iswap_gate_test.py +21 -5
- cirq/ops/phased_x_gate.py +11 -25
- cirq/ops/phased_x_gate_test.py +19 -3
- cirq/ops/phased_x_z_gate.py +12 -11
- cirq/ops/projector.py +4 -5
- cirq/ops/qubit_manager.py +2 -1
- cirq/ops/qubit_manager_test.py +2 -1
- cirq/ops/qubit_order.py +1 -1
- cirq/ops/random_gate_channel.py +1 -1
- cirq/ops/random_gate_channel_test.py +0 -6
- cirq/ops/raw_types.py +146 -50
- cirq/ops/raw_types_test.py +37 -3
- cirq/ops/state_preparation_channel.py +2 -2
- cirq/ops/state_preparation_channel_test.py +2 -1
- cirq/ops/swap_gates.py +9 -4
- cirq/ops/three_qubit_gates.py +8 -8
- cirq/ops/three_qubit_gates_test.py +1 -0
- cirq/ops/two_qubit_diagonal_gate.py +4 -3
- cirq/ops/uniform_superposition_gate.py +4 -4
- cirq/ops/uniform_superposition_gate_test.py +1 -0
- cirq/ops/wait_gate.py +6 -8
- cirq/protocols/__init__.py +135 -83
- cirq/protocols/act_on_protocol.py +1 -1
- cirq/protocols/act_on_protocol_test.py +1 -1
- cirq/protocols/apply_channel_protocol.py +3 -3
- cirq/protocols/apply_mixture_protocol.py +15 -9
- cirq/protocols/apply_mixture_protocol_test.py +11 -0
- cirq/protocols/apply_unitary_protocol.py +2 -2
- cirq/protocols/apply_unitary_protocol_test.py +2 -1
- cirq/protocols/approximate_equality_protocol.py +7 -8
- cirq/protocols/approximate_equality_protocol_test.py +3 -1
- cirq/protocols/circuit_diagram_info_protocol.py +8 -6
- cirq/protocols/circuit_diagram_info_protocol_test.py +5 -0
- cirq/protocols/commutes_protocol.py +6 -6
- cirq/protocols/control_key_protocol.py +1 -1
- cirq/protocols/decompose_protocol.py +4 -5
- cirq/protocols/decompose_protocol_test.py +2 -1
- cirq/protocols/equal_up_to_global_phase_protocol.py +3 -3
- cirq/protocols/equal_up_to_global_phase_protocol_test.py +7 -0
- cirq/protocols/has_stabilizer_effect_protocol.py +5 -5
- cirq/protocols/has_unitary_protocol.py +1 -1
- cirq/protocols/has_unitary_protocol_test.py +8 -7
- cirq/protocols/hash_from_pickle_test.py +120 -0
- cirq/protocols/inverse_protocol.py +1 -1
- cirq/protocols/json_serialization.py +14 -1
- cirq/protocols/json_serialization_test.py +28 -7
- cirq/protocols/json_test_data/BitMaskKeyCondition.json +86 -0
- cirq/protocols/json_test_data/BitMaskKeyCondition.repr +7 -0
- cirq/protocols/json_test_data/Concat.json +19 -0
- cirq/protocols/json_test_data/Concat.repr +1 -0
- cirq/protocols/json_test_data/README.md +4 -2
- cirq/protocols/json_test_data/SympyCondition.json +60 -15
- cirq/protocols/json_test_data/SympyCondition.repr +4 -1
- cirq/protocols/json_test_data/_InverseCompositeGate.json +10 -0
- cirq/protocols/json_test_data/_InverseCompositeGate.repr +1 -0
- cirq/protocols/json_test_data/__init__.py +1 -1
- cirq/protocols/json_test_data/sympy.And.json +13 -0
- cirq/protocols/json_test_data/sympy.And.repr +1 -0
- cirq/protocols/json_test_data/sympy.Indexed.json +18 -0
- cirq/protocols/json_test_data/sympy.Indexed.repr +1 -0
- cirq/protocols/json_test_data/sympy.IndexedBase.json +9 -0
- cirq/protocols/json_test_data/sympy.IndexedBase.repr +1 -0
- cirq/protocols/json_test_data/sympy.Not.json +9 -0
- cirq/protocols/json_test_data/sympy.Not.repr +1 -0
- cirq/protocols/json_test_data/sympy.Or.json +13 -0
- cirq/protocols/json_test_data/sympy.Or.repr +1 -0
- cirq/protocols/json_test_data/sympy.Xor.json +13 -0
- cirq/protocols/json_test_data/sympy.Xor.repr +1 -0
- cirq/protocols/kraus_protocol.py +8 -8
- cirq/protocols/kraus_protocol_test.py +0 -1
- cirq/protocols/measurement_key_protocol.py +1 -1
- cirq/protocols/measurement_key_protocol_test.py +7 -7
- cirq/protocols/mixture_protocol.py +6 -4
- cirq/protocols/mixture_protocol_test.py +21 -13
- cirq/protocols/pauli_expansion_protocol.py +1 -0
- cirq/protocols/pow_protocol.py +1 -1
- cirq/protocols/qasm.py +25 -6
- cirq/protocols/qasm_test.py +17 -0
- cirq/protocols/qid_shape_protocol.py +2 -2
- cirq/protocols/resolve_parameters.py +2 -3
- cirq/protocols/resolve_parameters_test.py +2 -1
- cirq/protocols/trace_distance_bound.py +1 -1
- cirq/protocols/trace_distance_bound_test.py +1 -0
- cirq/protocols/unitary_protocol.py +3 -3
- cirq/protocols/unitary_protocol_test.py +1 -1
- cirq/qis/__init__.py +48 -35
- cirq/qis/channels_test.py +0 -9
- cirq/qis/clifford_tableau.py +46 -26
- cirq/qis/clifford_tableau_test.py +2 -1
- cirq/qis/entropy.py +115 -0
- cirq/qis/entropy_test.py +43 -0
- cirq/qis/measures.py +5 -4
- cirq/qis/measures_test.py +7 -0
- cirq/qis/noise_utils_test.py +4 -4
- cirq/qis/quantum_state_representation.py +1 -1
- cirq/qis/states.py +7 -7
- cirq/sim/__init__.py +55 -37
- cirq/sim/classical_simulator.py +7 -6
- cirq/sim/classical_simulator_test.py +3 -1
- cirq/sim/clifford/__init__.py +17 -9
- cirq/sim/clifford/clifford_simulator.py +5 -4
- cirq/sim/clifford/clifford_simulator_test.py +32 -9
- cirq/sim/clifford/clifford_tableau_simulation_state.py +1 -1
- cirq/sim/clifford/stabilizer_simulation_state.py +1 -1
- cirq/sim/clifford/stabilizer_state_ch_form.py +4 -3
- cirq/sim/density_matrix_simulator.py +3 -2
- cirq/sim/density_matrix_simulator_test.py +12 -4
- cirq/sim/density_matrix_utils.py +1 -1
- cirq/sim/mux.py +2 -2
- cirq/sim/simulation_state.py +4 -5
- cirq/sim/simulation_state_base.py +2 -2
- cirq/sim/simulation_state_test.py +1 -1
- cirq/sim/simulation_utils.py +3 -1
- cirq/sim/simulation_utils_test.py +2 -3
- cirq/sim/simulator.py +7 -6
- cirq/sim/simulator_base.py +5 -5
- cirq/sim/simulator_test.py +14 -3
- cirq/sim/sparse_simulator.py +4 -3
- cirq/sim/sparse_simulator_test.py +17 -9
- cirq/sim/state_vector.py +2 -2
- cirq/sim/state_vector_simulation_state_test.py +1 -1
- cirq/sim/state_vector_simulator.py +4 -4
- cirq/sim/state_vector_test.py +27 -32
- cirq/study/__init__.py +27 -21
- cirq/study/flatten_expressions.py +5 -6
- cirq/study/flatten_expressions_test.py +1 -1
- cirq/study/resolver.py +14 -11
- cirq/study/resolver_test.py +10 -1
- cirq/study/result.py +3 -3
- cirq/study/sweepable.py +15 -9
- cirq/study/sweepable_test.py +27 -0
- cirq/study/sweeps.py +65 -10
- cirq/study/sweeps_test.py +123 -0
- cirq/testing/__init__.py +86 -57
- cirq/testing/_compat_test_data/module_a/__init__.py +2 -2
- cirq/testing/_compat_test_data/module_a/sub/subsub/__init__.py +1 -1
- cirq/testing/circuit_compare.py +3 -4
- cirq/testing/circuit_compare_test.py +7 -8
- cirq/testing/consistent_act_on.py +3 -3
- cirq/testing/consistent_channels_test.py +2 -1
- cirq/testing/consistent_controlled_gate_op.py +3 -2
- cirq/testing/consistent_controlled_gate_op_test.py +2 -3
- cirq/testing/consistent_decomposition.py +1 -1
- cirq/testing/consistent_decomposition_test.py +1 -2
- cirq/testing/consistent_pauli_expansion_test.py +1 -1
- cirq/testing/consistent_phase_by.py +1 -1
- cirq/testing/consistent_phase_by_test.py +1 -2
- cirq/testing/consistent_protocols.py +11 -11
- cirq/testing/consistent_protocols_test.py +4 -5
- cirq/testing/consistent_qasm.py +8 -12
- cirq/testing/consistent_qasm_test.py +1 -1
- cirq/testing/consistent_resolve_parameters.py +2 -1
- cirq/testing/consistent_specified_has_unitary_test.py +1 -1
- cirq/testing/consistent_unitary.py +3 -1
- cirq/testing/consistent_unitary_test.py +3 -3
- cirq/testing/devices.py +1 -1
- cirq/testing/devices_test.py +1 -0
- cirq/testing/equals_tester.py +2 -4
- cirq/testing/equals_tester_test.py +6 -5
- cirq/testing/equivalent_basis_map.py +1 -0
- cirq/testing/equivalent_basis_map_test.py +0 -1
- cirq/testing/gate_features_test.py +5 -0
- cirq/testing/json.py +4 -4
- cirq/testing/lin_alg_utils_test.py +1 -1
- cirq/testing/order_tester.py +1 -1
- cirq/testing/order_tester_test.py +1 -1
- cirq/testing/pytest_utils.py +57 -0
- cirq/testing/pytest_utils_test.py +35 -0
- cirq/testing/random_circuit.py +2 -2
- cirq/testing/random_circuit_test.py +2 -2
- cirq/testing/routing_devices_test.py +2 -1
- cirq/testing/sample_circuits.py +1 -1
- cirq/testing/sample_gates.py +5 -4
- cirq/testing/sample_gates_test.py +2 -2
- cirq/transformers/__init__.py +101 -82
- cirq/transformers/align.py +12 -1
- cirq/transformers/align_test.py +13 -0
- cirq/transformers/analytical_decompositions/__init__.py +27 -24
- cirq/transformers/analytical_decompositions/clifford_decomposition.py +2 -1
- cirq/transformers/analytical_decompositions/clifford_decomposition_test.py +1 -1
- cirq/transformers/analytical_decompositions/controlled_gate_decomposition.py +1 -1
- cirq/transformers/analytical_decompositions/controlled_gate_decomposition_test.py +2 -0
- cirq/transformers/analytical_decompositions/cphase_to_fsim.py +1 -1
- cirq/transformers/analytical_decompositions/cphase_to_fsim_test.py +1 -1
- cirq/transformers/analytical_decompositions/pauli_string_decomposition.py +2 -2
- cirq/transformers/analytical_decompositions/pauli_string_decomposition_test.py +4 -4
- cirq/transformers/analytical_decompositions/quantum_shannon_decomposition.py +99 -24
- cirq/transformers/analytical_decompositions/quantum_shannon_decomposition_test.py +105 -14
- cirq/transformers/analytical_decompositions/single_qubit_decompositions.py +1 -1
- cirq/transformers/analytical_decompositions/single_to_two_qubit_isometry.py +1 -1
- cirq/transformers/analytical_decompositions/single_to_two_qubit_isometry_test.py +1 -0
- cirq/transformers/analytical_decompositions/three_qubit_decomposition.py +3 -4
- cirq/transformers/analytical_decompositions/three_qubit_decomposition_test.py +1 -1
- cirq/transformers/analytical_decompositions/two_qubit_state_preparation.py +2 -1
- cirq/transformers/analytical_decompositions/two_qubit_state_preparation_test.py +2 -1
- cirq/transformers/analytical_decompositions/two_qubit_to_cz.py +5 -6
- cirq/transformers/analytical_decompositions/two_qubit_to_cz_test.py +2 -2
- cirq/transformers/analytical_decompositions/two_qubit_to_fsim.py +1 -1
- cirq/transformers/analytical_decompositions/two_qubit_to_fsim_test.py +1 -2
- cirq/transformers/analytical_decompositions/two_qubit_to_ms.py +2 -2
- cirq/transformers/analytical_decompositions/two_qubit_to_sqrt_iswap.py +2 -2
- cirq/transformers/analytical_decompositions/two_qubit_to_sqrt_iswap_test.py +2 -1
- cirq/transformers/drop_empty_moments.py +1 -0
- cirq/transformers/drop_negligible_operations.py +1 -0
- cirq/transformers/dynamical_decoupling.py +255 -43
- cirq/transformers/dynamical_decoupling_test.py +730 -17
- cirq/transformers/eject_phased_paulis.py +29 -15
- cirq/transformers/eject_phased_paulis_test.py +3 -8
- cirq/transformers/eject_z.py +3 -2
- cirq/transformers/eject_z_test.py +3 -3
- cirq/transformers/gauge_compiling/__init__.py +25 -9
- cirq/transformers/gauge_compiling/cphase_gauge.py +146 -0
- cirq/transformers/gauge_compiling/cphase_gauge_test.py +42 -0
- cirq/transformers/gauge_compiling/cz_gauge.py +4 -4
- cirq/transformers/gauge_compiling/gauge_compiling.py +245 -6
- cirq/transformers/gauge_compiling/gauge_compiling_test.py +107 -2
- cirq/transformers/gauge_compiling/gauge_compiling_test_utils.py +39 -2
- cirq/transformers/gauge_compiling/gauge_compiling_test_utils_test.py +10 -1
- cirq/transformers/gauge_compiling/iswap_gauge.py +2 -2
- cirq/transformers/gauge_compiling/spin_inversion_gauge.py +2 -2
- cirq/transformers/gauge_compiling/sqrt_cz_gauge.py +23 -5
- cirq/transformers/gauge_compiling/sqrt_iswap_gauge.py +3 -2
- cirq/transformers/heuristic_decompositions/__init__.py +3 -3
- cirq/transformers/heuristic_decompositions/gate_tabulation_math_utils.py +2 -1
- cirq/transformers/heuristic_decompositions/gate_tabulation_math_utils_test.py +1 -1
- cirq/transformers/heuristic_decompositions/two_qubit_gate_tabulation.py +4 -4
- cirq/transformers/heuristic_decompositions/two_qubit_gate_tabulation_test.py +4 -4
- cirq/transformers/insertion_sort.py +64 -0
- cirq/transformers/insertion_sort_test.py +34 -0
- cirq/transformers/measurement_transformers.py +14 -1
- cirq/transformers/measurement_transformers_test.py +35 -0
- cirq/transformers/merge_k_qubit_gates.py +2 -2
- cirq/transformers/merge_single_qubit_gates.py +1 -1
- cirq/transformers/merge_single_qubit_gates_test.py +1 -1
- cirq/transformers/noise_adding.py +115 -0
- cirq/transformers/noise_adding_test.py +54 -0
- cirq/transformers/optimize_for_target_gateset.py +1 -1
- cirq/transformers/optimize_for_target_gateset_test.py +3 -2
- cirq/transformers/qubit_management_transformers.py +1 -1
- cirq/transformers/randomized_measurements.py +171 -0
- cirq/transformers/randomized_measurements_test.py +68 -0
- cirq/transformers/routing/__init__.py +14 -5
- cirq/transformers/routing/initial_mapper.py +1 -1
- cirq/transformers/routing/initial_mapper_test.py +1 -0
- cirq/transformers/routing/line_initial_mapper.py +3 -2
- cirq/transformers/routing/mapping_manager.py +2 -2
- cirq/transformers/routing/mapping_manager_test.py +2 -2
- cirq/transformers/routing/route_circuit_cqc.py +3 -2
- cirq/transformers/routing/route_circuit_cqc_test.py +2 -1
- cirq/transformers/routing/visualize_routed_circuit.py +1 -0
- cirq/transformers/routing/visualize_routed_circuit_test.py +1 -0
- cirq/transformers/stratify.py +2 -2
- cirq/transformers/synchronize_terminal_measurements.py +2 -1
- cirq/transformers/target_gatesets/__init__.py +7 -5
- cirq/transformers/target_gatesets/compilation_target_gateset.py +16 -3
- cirq/transformers/target_gatesets/compilation_target_gateset_test.py +2 -0
- cirq/transformers/target_gatesets/cz_gateset.py +5 -1
- cirq/transformers/target_gatesets/cz_gateset_test.py +23 -2
- cirq/transformers/target_gatesets/sqrt_iswap_gateset.py +1 -1
- cirq/transformers/target_gatesets/sqrt_iswap_gateset_test.py +3 -2
- cirq/transformers/transformer_api.py +5 -4
- cirq/transformers/transformer_api_test.py +11 -3
- cirq/transformers/transformer_primitives.py +9 -31
- cirq/transformers/transformer_primitives_test.py +6 -5
- cirq/value/__init__.py +51 -30
- cirq/value/abc_alt.py +1 -2
- cirq/value/angle.py +2 -0
- cirq/value/classical_data.py +1 -0
- cirq/value/condition.py +149 -3
- cirq/value/condition_test.py +254 -0
- cirq/value/digits.py +1 -1
- cirq/value/duration.py +4 -4
- cirq/value/duration_test.py +2 -1
- cirq/value/linear_dict.py +85 -24
- cirq/value/linear_dict_test.py +94 -3
- cirq/value/measurement_key.py +9 -2
- cirq/value/periodic_value.py +2 -3
- cirq/value/periodic_value_test.py +5 -0
- cirq/value/probability.py +1 -0
- cirq/value/random_state.py +1 -1
- cirq/value/timestamp.py +2 -4
- cirq/value/timestamp_test.py +2 -1
- cirq/value/type_alias.py +2 -2
- cirq/value/value_equality_attr.py +14 -2
- cirq/value/value_equality_attr_test.py +1 -1
- cirq/vis/__init__.py +9 -6
- cirq/vis/density_matrix.py +1 -1
- cirq/vis/density_matrix_test.py +2 -5
- cirq/vis/heatmap.py +49 -12
- cirq/vis/heatmap_test.py +168 -4
- cirq/vis/histogram.py +1 -1
- cirq/vis/histogram_test.py +1 -2
- cirq/vis/state_histogram.py +7 -5
- cirq/vis/state_histogram_test.py +2 -2
- cirq/work/__init__.py +19 -13
- cirq/work/collector.py +2 -2
- cirq/work/observable_grouping.py +2 -2
- cirq/work/observable_measurement.py +3 -3
- cirq/work/observable_measurement_data.py +5 -2
- cirq/work/observable_measurement_test.py +8 -8
- cirq/work/observable_readout_calibration.py +2 -2
- cirq/work/observable_readout_calibration_test.py +2 -1
- cirq/work/observable_settings.py +8 -7
- cirq/work/observable_settings_test.py +3 -2
- cirq/work/pauli_sum_collector.py +1 -1
- cirq/work/sampler.py +8 -20
- cirq/work/sampler_test.py +4 -3
- cirq/work/zeros_sampler.py +1 -1
- cirq_core-1.5.0.dist-info/METADATA +125 -0
- {cirq_core-1.4.0.dev20240529225110.dist-info → cirq_core-1.5.0.dist-info}/RECORD +586 -552
- {cirq_core-1.4.0.dev20240529225110.dist-info → cirq_core-1.5.0.dist-info}/WHEEL +1 -1
- cirq/experiments/grid_parallel_two_qubit_xeb.py +0 -62
- cirq/protocols/json_test_data/GridParallelXEBMetadata.json +0 -119
- cirq/protocols/json_test_data/GridParallelXEBMetadata.repr +0 -1
- cirq_core-1.4.0.dev20240529225110.dist-info/METADATA +0 -50
- {cirq_core-1.4.0.dev20240529225110.dist-info → cirq_core-1.5.0.dist-info}/LICENSE +0 -0
- {cirq_core-1.4.0.dev20240529225110.dist-info → cirq_core-1.5.0.dist-info}/top_level.txt +0 -0
cirq/protocols/__init__.py
CHANGED
|
@@ -14,114 +14,166 @@
|
|
|
14
14
|
|
|
15
15
|
"""Protocols (structural subtyping) supported in Cirq."""
|
|
16
16
|
|
|
17
|
-
from cirq.protocols.act_on_protocol import
|
|
17
|
+
from cirq.protocols.act_on_protocol import (
|
|
18
|
+
act_on as act_on,
|
|
19
|
+
SupportsActOn as SupportsActOn,
|
|
20
|
+
SupportsActOnQubits as SupportsActOnQubits,
|
|
21
|
+
)
|
|
22
|
+
|
|
18
23
|
from cirq.protocols.apply_unitary_protocol import (
|
|
19
|
-
apply_unitaries,
|
|
20
|
-
apply_unitary,
|
|
21
|
-
ApplyUnitaryArgs,
|
|
22
|
-
SupportsConsistentApplyUnitary,
|
|
24
|
+
apply_unitaries as apply_unitaries,
|
|
25
|
+
apply_unitary as apply_unitary,
|
|
26
|
+
ApplyUnitaryArgs as ApplyUnitaryArgs,
|
|
27
|
+
SupportsConsistentApplyUnitary as SupportsConsistentApplyUnitary,
|
|
23
28
|
)
|
|
29
|
+
|
|
24
30
|
from cirq.protocols.apply_channel_protocol import (
|
|
25
|
-
apply_channel,
|
|
26
|
-
ApplyChannelArgs,
|
|
27
|
-
SupportsApplyChannel,
|
|
31
|
+
apply_channel as apply_channel,
|
|
32
|
+
ApplyChannelArgs as ApplyChannelArgs,
|
|
33
|
+
SupportsApplyChannel as SupportsApplyChannel,
|
|
28
34
|
)
|
|
35
|
+
|
|
29
36
|
from cirq.protocols.apply_mixture_protocol import (
|
|
30
|
-
apply_mixture,
|
|
31
|
-
ApplyMixtureArgs,
|
|
32
|
-
SupportsApplyMixture,
|
|
37
|
+
apply_mixture as apply_mixture,
|
|
38
|
+
ApplyMixtureArgs as ApplyMixtureArgs,
|
|
39
|
+
SupportsApplyMixture as SupportsApplyMixture,
|
|
33
40
|
)
|
|
34
|
-
|
|
35
|
-
from cirq.protocols.
|
|
36
|
-
|
|
41
|
+
|
|
42
|
+
from cirq.protocols.approximate_equality_protocol import (
|
|
43
|
+
approx_eq as approx_eq,
|
|
44
|
+
SupportsApproximateEquality as SupportsApproximateEquality,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
from cirq.protocols.kraus_protocol import (
|
|
48
|
+
kraus as kraus,
|
|
49
|
+
has_kraus as has_kraus,
|
|
50
|
+
SupportsKraus as SupportsKraus,
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
from cirq.protocols.commutes_protocol import (
|
|
54
|
+
commutes as commutes,
|
|
55
|
+
definitely_commutes as definitely_commutes,
|
|
56
|
+
SupportsCommutes as SupportsCommutes,
|
|
57
|
+
)
|
|
58
|
+
|
|
37
59
|
from cirq.protocols.control_key_protocol import (
|
|
38
|
-
control_keys,
|
|
39
|
-
measurement_keys_touched,
|
|
40
|
-
SupportsControlKey,
|
|
60
|
+
control_keys as control_keys,
|
|
61
|
+
measurement_keys_touched as measurement_keys_touched,
|
|
62
|
+
SupportsControlKey as SupportsControlKey,
|
|
41
63
|
)
|
|
64
|
+
|
|
42
65
|
from cirq.protocols.circuit_diagram_info_protocol import (
|
|
43
|
-
circuit_diagram_info,
|
|
44
|
-
CircuitDiagramInfo,
|
|
45
|
-
CircuitDiagramInfoArgs,
|
|
46
|
-
LabelEntity,
|
|
47
|
-
SupportsCircuitDiagramInfo,
|
|
66
|
+
circuit_diagram_info as circuit_diagram_info,
|
|
67
|
+
CircuitDiagramInfo as CircuitDiagramInfo,
|
|
68
|
+
CircuitDiagramInfoArgs as CircuitDiagramInfoArgs,
|
|
69
|
+
LabelEntity as LabelEntity,
|
|
70
|
+
SupportsCircuitDiagramInfo as SupportsCircuitDiagramInfo,
|
|
48
71
|
)
|
|
72
|
+
|
|
49
73
|
from cirq.protocols.decompose_protocol import (
|
|
50
|
-
decompose,
|
|
51
|
-
decompose_once,
|
|
52
|
-
decompose_once_with_qubits,
|
|
53
|
-
DecompositionContext,
|
|
54
|
-
SupportsDecompose,
|
|
55
|
-
SupportsDecomposeWithQubits,
|
|
74
|
+
decompose as decompose,
|
|
75
|
+
decompose_once as decompose_once,
|
|
76
|
+
decompose_once_with_qubits as decompose_once_with_qubits,
|
|
77
|
+
DecompositionContext as DecompositionContext,
|
|
78
|
+
SupportsDecompose as SupportsDecompose,
|
|
79
|
+
SupportsDecomposeWithQubits as SupportsDecomposeWithQubits,
|
|
56
80
|
)
|
|
81
|
+
|
|
57
82
|
from cirq.protocols.equal_up_to_global_phase_protocol import (
|
|
58
|
-
equal_up_to_global_phase,
|
|
59
|
-
SupportsEqualUpToGlobalPhase,
|
|
83
|
+
equal_up_to_global_phase as equal_up_to_global_phase,
|
|
84
|
+
SupportsEqualUpToGlobalPhase as SupportsEqualUpToGlobalPhase,
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
from cirq.protocols.has_stabilizer_effect_protocol import (
|
|
88
|
+
has_stabilizer_effect as has_stabilizer_effect,
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
from cirq.protocols.has_unitary_protocol import (
|
|
92
|
+
has_unitary as has_unitary,
|
|
93
|
+
SupportsExplicitHasUnitary as SupportsExplicitHasUnitary,
|
|
60
94
|
)
|
|
61
|
-
|
|
62
|
-
from cirq.protocols.
|
|
63
|
-
|
|
95
|
+
|
|
96
|
+
from cirq.protocols.inverse_protocol import inverse as inverse
|
|
97
|
+
|
|
64
98
|
from cirq.protocols.json_serialization import (
|
|
65
|
-
cirq_type_from_json,
|
|
66
|
-
DEFAULT_RESOLVERS,
|
|
67
|
-
HasJSONNamespace,
|
|
68
|
-
JsonResolver,
|
|
69
|
-
json_cirq_type,
|
|
70
|
-
json_namespace,
|
|
71
|
-
to_json_gzip,
|
|
72
|
-
read_json_gzip,
|
|
73
|
-
to_json,
|
|
74
|
-
read_json,
|
|
75
|
-
obj_to_dict_helper,
|
|
76
|
-
dataclass_json_dict,
|
|
77
|
-
SerializableByKey,
|
|
78
|
-
SupportsJSON,
|
|
99
|
+
cirq_type_from_json as cirq_type_from_json,
|
|
100
|
+
DEFAULT_RESOLVERS as DEFAULT_RESOLVERS,
|
|
101
|
+
HasJSONNamespace as HasJSONNamespace,
|
|
102
|
+
JsonResolver as JsonResolver,
|
|
103
|
+
json_cirq_type as json_cirq_type,
|
|
104
|
+
json_namespace as json_namespace,
|
|
105
|
+
to_json_gzip as to_json_gzip,
|
|
106
|
+
read_json_gzip as read_json_gzip,
|
|
107
|
+
to_json as to_json,
|
|
108
|
+
read_json as read_json,
|
|
109
|
+
obj_to_dict_helper as obj_to_dict_helper,
|
|
110
|
+
dataclass_json_dict as dataclass_json_dict,
|
|
111
|
+
SerializableByKey as SerializableByKey,
|
|
112
|
+
SupportsJSON as SupportsJSON,
|
|
79
113
|
)
|
|
114
|
+
|
|
80
115
|
from cirq.protocols.measurement_key_protocol import (
|
|
81
|
-
is_measurement,
|
|
82
|
-
measurement_key_name,
|
|
83
|
-
measurement_key_obj,
|
|
84
|
-
measurement_key_names,
|
|
85
|
-
measurement_key_objs,
|
|
86
|
-
with_key_path,
|
|
87
|
-
with_key_path_prefix,
|
|
88
|
-
with_measurement_key_mapping,
|
|
89
|
-
with_rescoped_keys,
|
|
90
|
-
SupportsMeasurementKey,
|
|
91
|
-
)
|
|
92
|
-
|
|
93
|
-
from cirq.protocols.
|
|
94
|
-
|
|
116
|
+
is_measurement as is_measurement,
|
|
117
|
+
measurement_key_name as measurement_key_name,
|
|
118
|
+
measurement_key_obj as measurement_key_obj,
|
|
119
|
+
measurement_key_names as measurement_key_names,
|
|
120
|
+
measurement_key_objs as measurement_key_objs,
|
|
121
|
+
with_key_path as with_key_path,
|
|
122
|
+
with_key_path_prefix as with_key_path_prefix,
|
|
123
|
+
with_measurement_key_mapping as with_measurement_key_mapping,
|
|
124
|
+
with_rescoped_keys as with_rescoped_keys,
|
|
125
|
+
SupportsMeasurementKey as SupportsMeasurementKey,
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
from cirq.protocols.mixture_protocol import (
|
|
129
|
+
has_mixture as has_mixture,
|
|
130
|
+
mixture as mixture,
|
|
131
|
+
SupportsMixture as SupportsMixture,
|
|
132
|
+
validate_mixture as validate_mixture,
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
from cirq.protocols.mul_protocol import mul as mul
|
|
136
|
+
|
|
137
|
+
from cirq.protocols.pauli_expansion_protocol import (
|
|
138
|
+
pauli_expansion as pauli_expansion,
|
|
139
|
+
SupportsPauliExpansion as SupportsPauliExpansion,
|
|
140
|
+
)
|
|
95
141
|
|
|
96
142
|
# pylint: disable=redefined-builtin
|
|
97
|
-
from cirq.protocols.pow_protocol import pow
|
|
143
|
+
from cirq.protocols.pow_protocol import pow as pow
|
|
98
144
|
|
|
99
145
|
# pylint: enable=redefined-builtin
|
|
146
|
+
|
|
100
147
|
from cirq.protocols.qasm import (
|
|
101
|
-
qasm,
|
|
102
|
-
QasmArgs,
|
|
103
|
-
SupportsQasm,
|
|
104
|
-
SupportsQasmWithArgs,
|
|
105
|
-
SupportsQasmWithArgsAndQubits,
|
|
148
|
+
qasm as qasm,
|
|
149
|
+
QasmArgs as QasmArgs,
|
|
150
|
+
SupportsQasm as SupportsQasm,
|
|
151
|
+
SupportsQasmWithArgs as SupportsQasmWithArgs,
|
|
152
|
+
SupportsQasmWithArgsAndQubits as SupportsQasmWithArgsAndQubits,
|
|
106
153
|
)
|
|
154
|
+
|
|
107
155
|
from cirq.protocols.trace_distance_bound import (
|
|
108
|
-
SupportsTraceDistanceBound,
|
|
109
|
-
trace_distance_bound,
|
|
110
|
-
trace_distance_from_angle_list,
|
|
156
|
+
SupportsTraceDistanceBound as SupportsTraceDistanceBound,
|
|
157
|
+
trace_distance_bound as trace_distance_bound,
|
|
158
|
+
trace_distance_from_angle_list as trace_distance_from_angle_list,
|
|
111
159
|
)
|
|
160
|
+
|
|
112
161
|
from cirq.protocols.resolve_parameters import (
|
|
113
|
-
is_parameterized,
|
|
114
|
-
parameter_names,
|
|
115
|
-
parameter_symbols,
|
|
116
|
-
resolve_parameters,
|
|
117
|
-
resolve_parameters_once,
|
|
118
|
-
SupportsParameterization,
|
|
119
|
-
)
|
|
120
|
-
|
|
162
|
+
is_parameterized as is_parameterized,
|
|
163
|
+
parameter_names as parameter_names,
|
|
164
|
+
parameter_symbols as parameter_symbols,
|
|
165
|
+
resolve_parameters as resolve_parameters,
|
|
166
|
+
resolve_parameters_once as resolve_parameters_once,
|
|
167
|
+
SupportsParameterization as SupportsParameterization,
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
from cirq.protocols.phase_protocol import phase_by as phase_by, SupportsPhase as SupportsPhase
|
|
171
|
+
|
|
121
172
|
from cirq.protocols.qid_shape_protocol import (
|
|
122
|
-
num_qubits,
|
|
123
|
-
qid_shape,
|
|
124
|
-
SupportsExplicitQidShape,
|
|
125
|
-
SupportsExplicitNumQubits,
|
|
173
|
+
num_qubits as num_qubits,
|
|
174
|
+
qid_shape as qid_shape,
|
|
175
|
+
SupportsExplicitQidShape as SupportsExplicitQidShape,
|
|
176
|
+
SupportsExplicitNumQubits as SupportsExplicitNumQubits,
|
|
126
177
|
)
|
|
127
|
-
|
|
178
|
+
|
|
179
|
+
from cirq.protocols.unitary_protocol import SupportsUnitary as SupportsUnitary, unitary as unitary
|
|
@@ -12,13 +12,13 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
+
from types import NotImplementedType
|
|
15
16
|
from typing import Any, Optional, Sequence, TYPE_CHECKING, Union
|
|
16
17
|
|
|
17
18
|
from typing_extensions import Protocol
|
|
18
19
|
|
|
19
20
|
from cirq import ops
|
|
20
21
|
from cirq._doc import doc_private
|
|
21
|
-
from cirq.type_workarounds import NotImplementedType
|
|
22
22
|
|
|
23
23
|
if TYPE_CHECKING:
|
|
24
24
|
import cirq
|
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
from typing import Any, Sequence, Tuple
|
|
15
|
-
from typing_extensions import Self
|
|
16
15
|
|
|
17
16
|
import numpy as np
|
|
18
17
|
import pytest
|
|
18
|
+
from typing_extensions import Self
|
|
19
19
|
|
|
20
20
|
import cirq
|
|
21
21
|
|
|
@@ -14,17 +14,17 @@
|
|
|
14
14
|
|
|
15
15
|
"""A protocol for implementing high performance channel evolutions."""
|
|
16
16
|
|
|
17
|
-
from
|
|
17
|
+
from types import NotImplementedType
|
|
18
|
+
from typing import Any, Iterable, Optional, Sequence, Tuple, TypeVar, Union
|
|
18
19
|
|
|
19
20
|
import numpy as np
|
|
20
21
|
from typing_extensions import Protocol
|
|
21
22
|
|
|
22
23
|
from cirq import linalg
|
|
23
24
|
from cirq._doc import doc_private
|
|
25
|
+
from cirq.protocols import qid_shape_protocol
|
|
24
26
|
from cirq.protocols.apply_unitary_protocol import apply_unitary, ApplyUnitaryArgs
|
|
25
27
|
from cirq.protocols.kraus_protocol import kraus
|
|
26
|
-
from cirq.protocols import qid_shape_protocol
|
|
27
|
-
from cirq.type_workarounds import NotImplementedType
|
|
28
28
|
|
|
29
29
|
# This is a special indicator value used by the apply_channel method
|
|
30
30
|
# to determine whether or not the caller provided a 'default' argument. It must
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
"""A protocol for implementing high performance mixture evolutions."""
|
|
16
16
|
|
|
17
|
+
from types import NotImplementedType
|
|
17
18
|
from typing import Any, cast, Iterable, Optional, Tuple, TypeVar, Union
|
|
18
19
|
|
|
19
20
|
import numpy as np
|
|
@@ -21,11 +22,8 @@ from typing_extensions import Protocol
|
|
|
21
22
|
|
|
22
23
|
from cirq import linalg
|
|
23
24
|
from cirq._doc import doc_private
|
|
24
|
-
from cirq.protocols.apply_unitary_protocol import apply_unitary, ApplyUnitaryArgs
|
|
25
|
-
|
|
26
|
-
from cirq.protocols.mixture_protocol import mixture
|
|
27
25
|
from cirq.protocols import qid_shape_protocol
|
|
28
|
-
from cirq.
|
|
26
|
+
from cirq.protocols.apply_unitary_protocol import apply_unitary, ApplyUnitaryArgs
|
|
29
27
|
|
|
30
28
|
# This is a special indicator value used by the apply_mixture method
|
|
31
29
|
# to determine whether or not the caller provided a 'default' argument. It must
|
|
@@ -261,9 +259,9 @@ def apply_mixture(
|
|
|
261
259
|
return result
|
|
262
260
|
|
|
263
261
|
# Fallback to using the object's `_mixture_` matrices. (STEP C)
|
|
264
|
-
|
|
265
|
-
if
|
|
266
|
-
return
|
|
262
|
+
result = _apply_mixture_from_mixture_strat(val, args, is_density_matrix)
|
|
263
|
+
if result is not None:
|
|
264
|
+
return result
|
|
267
265
|
|
|
268
266
|
# Don't know how to apply mixture. Fallback to specified default behavior.
|
|
269
267
|
# (STEP D)
|
|
@@ -360,11 +358,19 @@ def _apply_unitary_from_matrix_strat(
|
|
|
360
358
|
return args.target_tensor
|
|
361
359
|
|
|
362
360
|
|
|
363
|
-
def
|
|
361
|
+
def _apply_mixture_from_mixture_strat(
|
|
362
|
+
val: Any, args: 'ApplyMixtureArgs', is_density_matrix: bool
|
|
363
|
+
) -> Optional[np.ndarray]:
|
|
364
364
|
"""Attempt to use unitary matrices in _mixture_ and return the result."""
|
|
365
|
+
method = getattr(val, '_mixture_', None)
|
|
366
|
+
if method is None:
|
|
367
|
+
return None
|
|
368
|
+
prob_mix = method()
|
|
369
|
+
if prob_mix is NotImplemented or prob_mix is None:
|
|
370
|
+
return None
|
|
365
371
|
args.out_buffer[:] = 0
|
|
366
372
|
np.copyto(dst=args.auxiliary_buffer1, src=args.target_tensor)
|
|
367
|
-
for prob, op in
|
|
373
|
+
for prob, op in prob_mix:
|
|
368
374
|
np.copyto(dst=args.target_tensor, src=args.auxiliary_buffer1)
|
|
369
375
|
right_result = _apply_unitary_strat(op, args, is_density_matrix)
|
|
370
376
|
if right_result is None:
|
|
@@ -237,6 +237,17 @@ def test_apply_mixture_no_protocols_implemented():
|
|
|
237
237
|
assert_apply_mixture_returns(NoProtocols(), rho, left_axes=[1], right_axes=[1])
|
|
238
238
|
|
|
239
239
|
|
|
240
|
+
def test_apply_mixture_mixture_returns_not_implemented():
|
|
241
|
+
class NoMixture:
|
|
242
|
+
def _mixture_(self):
|
|
243
|
+
return NotImplemented
|
|
244
|
+
|
|
245
|
+
rho = np.ones((2, 2, 2, 2), dtype=np.complex128)
|
|
246
|
+
|
|
247
|
+
with pytest.raises(TypeError, match='has no'):
|
|
248
|
+
assert_apply_mixture_returns(NoMixture(), rho, left_axes=[1], right_axes=[1])
|
|
249
|
+
|
|
250
|
+
|
|
240
251
|
def test_apply_mixture_no_protocols_implemented_default():
|
|
241
252
|
class NoProtocols:
|
|
242
253
|
pass
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"""A protocol for implementing high performance unitary left-multiplies."""
|
|
16
16
|
|
|
17
17
|
import warnings
|
|
18
|
+
from types import NotImplementedType
|
|
18
19
|
from typing import Any, cast, Iterable, Optional, Sequence, Tuple, TYPE_CHECKING, TypeVar, Union
|
|
19
20
|
|
|
20
21
|
import numpy as np
|
|
@@ -24,7 +25,6 @@ from cirq import linalg, qis
|
|
|
24
25
|
from cirq._doc import doc_private
|
|
25
26
|
from cirq.protocols import qid_shape_protocol
|
|
26
27
|
from cirq.protocols.decompose_protocol import _try_decompose_into_operations_and_qubits
|
|
27
|
-
from cirq.type_workarounds import NotImplementedType
|
|
28
28
|
|
|
29
29
|
if TYPE_CHECKING:
|
|
30
30
|
import cirq
|
|
@@ -390,7 +390,7 @@ def apply_unitary(
|
|
|
390
390
|
# Try each strategy, stopping if one works.
|
|
391
391
|
# Also catch downcasting warnings and throw an error: #2041
|
|
392
392
|
with warnings.catch_warnings():
|
|
393
|
-
warnings.filterwarnings(action="error", category=np.ComplexWarning)
|
|
393
|
+
warnings.filterwarnings(action="error", category=np.exceptions.ComplexWarning)
|
|
394
394
|
for strat in strats:
|
|
395
395
|
result = strat(unitary_value, args)
|
|
396
396
|
if result is None:
|
|
@@ -714,7 +714,8 @@ def test_cast_to_complex():
|
|
|
714
714
|
)
|
|
715
715
|
|
|
716
716
|
with pytest.raises(
|
|
717
|
-
np.ComplexWarning,
|
|
717
|
+
np.exceptions.ComplexWarning,
|
|
718
|
+
match='Casting complex values to real discards the imaginary part',
|
|
718
719
|
):
|
|
719
720
|
cirq.apply_unitary(y0, args)
|
|
720
721
|
|
|
@@ -12,14 +12,13 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
from fractions import Fraction
|
|
15
|
+
import numbers
|
|
17
16
|
from decimal import Decimal
|
|
17
|
+
from fractions import Fraction
|
|
18
|
+
from typing import Any, Iterable
|
|
18
19
|
|
|
19
|
-
import numbers
|
|
20
20
|
import numpy as np
|
|
21
21
|
import sympy
|
|
22
|
-
|
|
23
22
|
from typing_extensions import Protocol
|
|
24
23
|
|
|
25
24
|
from cirq._doc import doc_private
|
|
@@ -29,7 +28,7 @@ class SupportsApproximateEquality(Protocol):
|
|
|
29
28
|
"""Object which can be compared approximately."""
|
|
30
29
|
|
|
31
30
|
@doc_private
|
|
32
|
-
def _approx_eq_(self, other: Any, *, atol:
|
|
31
|
+
def _approx_eq_(self, other: Any, *, atol: float) -> bool:
|
|
33
32
|
"""Approximate comparator.
|
|
34
33
|
|
|
35
34
|
Types implementing this protocol define their own logic for approximate
|
|
@@ -47,7 +46,7 @@ class SupportsApproximateEquality(Protocol):
|
|
|
47
46
|
"""
|
|
48
47
|
|
|
49
48
|
|
|
50
|
-
def approx_eq(val: Any, other: Any, *, atol:
|
|
49
|
+
def approx_eq(val: Any, other: Any, *, atol: float = 1e-8) -> bool:
|
|
51
50
|
"""Approximately compares two objects.
|
|
52
51
|
|
|
53
52
|
If `val` implements SupportsApproxEquality protocol then it is invoked and
|
|
@@ -120,7 +119,7 @@ def approx_eq(val: Any, other: Any, *, atol: Union[int, float] = 1e-8) -> bool:
|
|
|
120
119
|
return val == other
|
|
121
120
|
|
|
122
121
|
|
|
123
|
-
def _approx_eq_iterables(val: Iterable, other: Iterable, *, atol:
|
|
122
|
+
def _approx_eq_iterables(val: Iterable, other: Iterable, *, atol: float) -> bool:
|
|
124
123
|
"""Iterates over arguments and calls approx_eq recursively.
|
|
125
124
|
|
|
126
125
|
Types of `val` and `other` does not necessarily needs to match each other.
|
|
@@ -161,7 +160,7 @@ def _approx_eq_iterables(val: Iterable, other: Iterable, *, atol: Union[int, flo
|
|
|
161
160
|
return True
|
|
162
161
|
|
|
163
162
|
|
|
164
|
-
def _isclose(a: Any, b: Any, *, atol:
|
|
163
|
+
def _isclose(a: Any, b: Any, *, atol: float) -> bool:
|
|
165
164
|
"""Convenience wrapper around np.isclose."""
|
|
166
165
|
|
|
167
166
|
# support casting some standard numeric types
|
|
@@ -12,12 +12,14 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
-
from fractions import Fraction
|
|
16
15
|
from decimal import Decimal
|
|
16
|
+
from fractions import Fraction
|
|
17
17
|
from numbers import Number
|
|
18
|
+
|
|
18
19
|
import numpy as np
|
|
19
20
|
import pytest
|
|
20
21
|
import sympy
|
|
22
|
+
|
|
21
23
|
import cirq
|
|
22
24
|
|
|
23
25
|
|
|
@@ -16,15 +16,15 @@ import re
|
|
|
16
16
|
from fractions import Fraction
|
|
17
17
|
from typing import (
|
|
18
18
|
Any,
|
|
19
|
-
TYPE_CHECKING,
|
|
20
|
-
Optional,
|
|
21
|
-
Union,
|
|
22
|
-
TypeVar,
|
|
23
19
|
Dict,
|
|
24
|
-
overload,
|
|
25
20
|
Iterable,
|
|
26
21
|
List,
|
|
22
|
+
Optional,
|
|
23
|
+
overload,
|
|
27
24
|
Sequence,
|
|
25
|
+
TYPE_CHECKING,
|
|
26
|
+
TypeVar,
|
|
27
|
+
Union,
|
|
28
28
|
)
|
|
29
29
|
|
|
30
30
|
import numpy as np
|
|
@@ -277,6 +277,8 @@ class CircuitDiagramInfoArgs:
|
|
|
277
277
|
if self.precision is not None and not isinstance(radians, sympy.Basic):
|
|
278
278
|
quantity = self.format_real(radians / np.pi)
|
|
279
279
|
return quantity + unit
|
|
280
|
+
if isinstance(radians, np.number):
|
|
281
|
+
return str(radians)
|
|
280
282
|
return repr(radians)
|
|
281
283
|
|
|
282
284
|
def copy(self):
|
|
@@ -340,7 +342,7 @@ def _op_info_with_fallback(
|
|
|
340
342
|
rows: List[LabelEntity] = list(op.qubits)
|
|
341
343
|
if args.label_map is not None:
|
|
342
344
|
rows += protocols.measurement_keys_touched(op) & args.label_map.keys()
|
|
343
|
-
if info is not None:
|
|
345
|
+
if info is not None and info.wire_symbols:
|
|
344
346
|
if max(1, len(rows)) != len(info.wire_symbols):
|
|
345
347
|
raise ValueError(f'Wanted diagram info from {op!r} for {rows!r}) but got {info!r}')
|
|
346
348
|
return info
|
|
@@ -208,6 +208,9 @@ def test_format_real():
|
|
|
208
208
|
assert args.format_real(sympy.Symbol('t')) == 't'
|
|
209
209
|
assert args.format_real(sympy.Symbol('t') * 2 + 1) == '2*t + 1'
|
|
210
210
|
|
|
211
|
+
assert args.format_real(np.float64(1.1)) == '1.1'
|
|
212
|
+
assert args.format_real(np.int32(1)) == '1'
|
|
213
|
+
|
|
211
214
|
args.precision = None
|
|
212
215
|
assert args.format_real(1) == '1'
|
|
213
216
|
assert args.format_real(1.1) == '1.1'
|
|
@@ -252,6 +255,7 @@ def test_format_radians_without_precision():
|
|
|
252
255
|
assert args.format_radians(-np.pi) == '-pi'
|
|
253
256
|
assert args.format_radians(1.1) == '1.1'
|
|
254
257
|
assert args.format_radians(1.234567) == '1.234567'
|
|
258
|
+
assert args.format_radians(np.float32(1.234567)) == '1.234567'
|
|
255
259
|
assert args.format_radians(1 / 7) == repr(1 / 7)
|
|
256
260
|
assert args.format_radians(sympy.Symbol('t')) == 't'
|
|
257
261
|
assert args.format_radians(sympy.Symbol('t') * 2 + 1) == '2*t + 1'
|
|
@@ -261,6 +265,7 @@ def test_format_radians_without_precision():
|
|
|
261
265
|
assert args.format_radians(-np.pi) == '-π'
|
|
262
266
|
assert args.format_radians(1.1) == '1.1'
|
|
263
267
|
assert args.format_radians(1.234567) == '1.234567'
|
|
268
|
+
assert args.format_radians(np.float32(1.234567)) == '1.234567'
|
|
264
269
|
assert args.format_radians(1 / 7) == repr(1 / 7)
|
|
265
270
|
assert args.format_radians(sympy.Symbol('t')) == 't'
|
|
266
271
|
assert args.format_radians(sympy.Symbol('t') * 2 + 1) == '2*t + 1'
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
"""Protocol for determining commutativity."""
|
|
15
15
|
|
|
16
|
+
from types import NotImplementedType
|
|
16
17
|
from typing import Any, overload, TypeVar, Union
|
|
17
18
|
|
|
18
19
|
import numpy as np
|
|
@@ -20,7 +21,6 @@ from typing_extensions import Protocol
|
|
|
20
21
|
|
|
21
22
|
from cirq import linalg
|
|
22
23
|
from cirq._doc import doc_private
|
|
23
|
-
from cirq.type_workarounds import NotImplementedType
|
|
24
24
|
|
|
25
25
|
# This is a special indicator value used by the unitary method to determine
|
|
26
26
|
# whether or not the caller provided a 'default' argument.
|
|
@@ -74,17 +74,17 @@ class SupportsCommutes(Protocol):
|
|
|
74
74
|
|
|
75
75
|
|
|
76
76
|
@overload
|
|
77
|
-
def commutes(v1: Any, v2: Any, *, atol:
|
|
77
|
+
def commutes(v1: Any, v2: Any, *, atol: float = 1e-8) -> bool: ...
|
|
78
78
|
|
|
79
79
|
|
|
80
80
|
@overload
|
|
81
81
|
def commutes(
|
|
82
|
-
v1: Any, v2: Any, *, atol:
|
|
82
|
+
v1: Any, v2: Any, *, atol: float = 1e-8, default: TDefault
|
|
83
83
|
) -> Union[bool, TDefault]: ...
|
|
84
84
|
|
|
85
85
|
|
|
86
86
|
def commutes(
|
|
87
|
-
v1: Any, v2: Any, *, atol:
|
|
87
|
+
v1: Any, v2: Any, *, atol: float = 1e-8, default: Any = RaiseTypeErrorIfNotProvided
|
|
88
88
|
) -> Any:
|
|
89
89
|
"""Determines whether two values commute.
|
|
90
90
|
|
|
@@ -147,7 +147,7 @@ def commutes(
|
|
|
147
147
|
)
|
|
148
148
|
|
|
149
149
|
|
|
150
|
-
def definitely_commutes(v1: Any, v2: Any, *, atol:
|
|
150
|
+
def definitely_commutes(v1: Any, v2: Any, *, atol: float = 1e-8) -> bool:
|
|
151
151
|
"""Determines whether two values definitely commute.
|
|
152
152
|
|
|
153
153
|
Returns:
|
|
@@ -158,7 +158,7 @@ def definitely_commutes(v1: Any, v2: Any, *, atol: Union[int, float] = 1e-8) ->
|
|
|
158
158
|
|
|
159
159
|
|
|
160
160
|
def _strat_commutes_from_commutes(
|
|
161
|
-
v1: Any, v2: Any, *, atol:
|
|
161
|
+
v1: Any, v2: Any, *, atol: float = 1e-8
|
|
162
162
|
) -> Union[bool, NotImplementedType, None]:
|
|
163
163
|
"""Attempts to determine commutativity via the objects' _commutes_
|
|
164
164
|
method."""
|
|
@@ -13,13 +13,13 @@
|
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
"""Protocol for object that have control keys."""
|
|
15
15
|
|
|
16
|
+
from types import NotImplementedType
|
|
16
17
|
from typing import Any, FrozenSet, TYPE_CHECKING, Union
|
|
17
18
|
|
|
18
19
|
from typing_extensions import Protocol
|
|
19
20
|
|
|
20
21
|
from cirq._doc import doc_private
|
|
21
22
|
from cirq.protocols import measurement_key_protocol
|
|
22
|
-
from cirq.type_workarounds import NotImplementedType
|
|
23
23
|
|
|
24
24
|
if TYPE_CHECKING:
|
|
25
25
|
import cirq
|
|
@@ -11,12 +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
|
-
import itertools
|
|
15
14
|
import dataclasses
|
|
16
15
|
import inspect
|
|
16
|
+
import itertools
|
|
17
17
|
from collections import defaultdict
|
|
18
|
+
from types import NotImplementedType
|
|
18
19
|
from typing import (
|
|
19
|
-
TYPE_CHECKING,
|
|
20
20
|
Any,
|
|
21
21
|
Callable,
|
|
22
22
|
Dict,
|
|
@@ -27,17 +27,16 @@ from typing import (
|
|
|
27
27
|
overload,
|
|
28
28
|
Sequence,
|
|
29
29
|
Tuple,
|
|
30
|
+
TYPE_CHECKING,
|
|
30
31
|
TypeVar,
|
|
31
32
|
Union,
|
|
32
33
|
)
|
|
33
|
-
from typing_extensions import runtime_checkable
|
|
34
34
|
|
|
35
|
-
from typing_extensions import Protocol
|
|
35
|
+
from typing_extensions import Protocol, runtime_checkable
|
|
36
36
|
|
|
37
37
|
from cirq import devices, ops
|
|
38
38
|
from cirq._doc import doc_private
|
|
39
39
|
from cirq.protocols import qid_shape_protocol
|
|
40
|
-
from cirq.type_workarounds import NotImplementedType
|
|
41
40
|
|
|
42
41
|
if TYPE_CHECKING:
|
|
43
42
|
import cirq
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
import itertools
|
|
15
15
|
from typing import Optional
|
|
16
16
|
from unittest import mock
|
|
17
|
+
|
|
17
18
|
import pytest
|
|
18
19
|
|
|
19
20
|
import cirq
|
|
@@ -357,7 +358,7 @@ class RecursiveDecompose(cirq.Gate):
|
|
|
357
358
|
|
|
358
359
|
def _decompose_(self, qubits):
|
|
359
360
|
if self.with_context:
|
|
360
|
-
assert False
|
|
361
|
+
assert False # pragma: no cover
|
|
361
362
|
else:
|
|
362
363
|
return self._decompose_impl(qubits, self.mock_qm)
|
|
363
364
|
|