cirq-core 1.5.0.dev20250409225226__py3-none-any.whl → 1.6.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of cirq-core might be problematic. Click here for more details.
- cirq/__init__.py +16 -17
- cirq/_compat.py +21 -20
- cirq/_compat_test.py +14 -34
- cirq/_doc.py +4 -2
- cirq/_import.py +8 -6
- cirq/_import_test.py +4 -2
- cirq/_version.py +6 -6
- cirq/_version_test.py +2 -2
- cirq/circuits/_block_diagram_drawer.py +11 -10
- cirq/circuits/_block_diagram_drawer_test.py +8 -6
- cirq/circuits/_box_drawing_character_data.py +8 -8
- cirq/circuits/_box_drawing_character_data_test.py +3 -1
- cirq/circuits/_bucket_priority_queue.py +9 -7
- cirq/circuits/_bucket_priority_queue_test.py +22 -20
- cirq/circuits/circuit.py +248 -172
- cirq/circuits/circuit_operation.py +73 -83
- cirq/circuits/circuit_operation_test.py +128 -90
- cirq/circuits/circuit_test.py +211 -151
- cirq/circuits/frozen_circuit.py +23 -60
- cirq/circuits/frozen_circuit_test.py +31 -8
- cirq/circuits/insert_strategy.py +7 -5
- cirq/circuits/insert_strategy_test.py +4 -2
- cirq/circuits/moment.py +88 -40
- cirq/circuits/moment_test.py +128 -51
- cirq/circuits/optimization_pass.py +5 -5
- cirq/circuits/optimization_pass_test.py +10 -10
- cirq/circuits/qasm_output.py +11 -11
- cirq/circuits/qasm_output_test.py +25 -22
- cirq/circuits/text_diagram_drawer.py +23 -38
- cirq/circuits/text_diagram_drawer_test.py +19 -17
- cirq/conftest.py +4 -3
- cirq/contrib/__init__.py +4 -4
- cirq/contrib/acquaintance/__init__.py +1 -1
- cirq/contrib/acquaintance/bipartite.py +5 -8
- cirq/contrib/acquaintance/bipartite_test.py +18 -13
- cirq/contrib/acquaintance/devices.py +2 -2
- cirq/contrib/acquaintance/devices_test.py +5 -3
- cirq/contrib/acquaintance/executor.py +5 -5
- cirq/contrib/acquaintance/executor_test.py +13 -9
- cirq/contrib/acquaintance/gates.py +18 -28
- cirq/contrib/acquaintance/gates_test.py +24 -20
- cirq/contrib/acquaintance/inspection_utils.py +8 -4
- cirq/contrib/acquaintance/inspection_utils_test.py +4 -2
- cirq/contrib/acquaintance/mutation_utils.py +4 -4
- cirq/contrib/acquaintance/mutation_utils_test.py +4 -2
- cirq/contrib/acquaintance/optimizers.py +4 -4
- cirq/contrib/acquaintance/optimizers_test.py +4 -1
- cirq/contrib/acquaintance/permutation.py +15 -27
- cirq/contrib/acquaintance/permutation_test.py +26 -17
- cirq/contrib/acquaintance/shift.py +4 -4
- cirq/contrib/acquaintance/shift_swap_network.py +4 -4
- cirq/contrib/acquaintance/shift_swap_network_test.py +9 -6
- cirq/contrib/acquaintance/shift_test.py +8 -6
- cirq/contrib/acquaintance/strategies/cubic.py +2 -2
- cirq/contrib/acquaintance/strategies/cubic_test.py +4 -2
- cirq/contrib/acquaintance/strategies/quartic_paired.py +6 -6
- cirq/contrib/acquaintance/strategies/quartic_paired_test.py +10 -6
- cirq/contrib/acquaintance/testing.py +2 -0
- cirq/contrib/acquaintance/topological_sort.py +2 -2
- cirq/contrib/acquaintance/topological_sort_test.py +3 -1
- cirq/contrib/bayesian_network/bayesian_network_gate.py +9 -10
- cirq/contrib/bayesian_network/bayesian_network_gate_test.py +14 -9
- cirq/contrib/circuitdag/circuit_dag.py +4 -4
- cirq/contrib/circuitdag/circuit_dag_test.py +17 -15
- cirq/contrib/custom_simulators/custom_state_simulator.py +5 -5
- cirq/contrib/custom_simulators/custom_state_simulator_test.py +22 -17
- cirq/contrib/graph_device/graph_device.py +12 -11
- cirq/contrib/graph_device/graph_device_test.py +18 -14
- cirq/contrib/graph_device/hypergraph.py +16 -14
- cirq/contrib/graph_device/hypergraph_test.py +13 -11
- cirq/contrib/graph_device/uniform_graph_device.py +6 -4
- cirq/contrib/graph_device/uniform_graph_device_test.py +11 -3
- cirq/contrib/hacks/disable_validation.py +6 -1
- cirq/contrib/hacks/disable_validation_test.py +3 -1
- cirq/contrib/json.py +31 -5
- cirq/contrib/json_test.py +6 -3
- cirq/contrib/json_test_data/DampedReadoutNoiseModel.json +12 -0
- cirq/contrib/json_test_data/DampedReadoutNoiseModel.repr +4 -0
- cirq/contrib/json_test_data/DepolarizingNoiseModel.json +12 -0
- cirq/contrib/json_test_data/DepolarizingNoiseModel.repr +4 -0
- cirq/contrib/json_test_data/DepolarizingWithDampedReadoutNoiseModel.json +6 -0
- cirq/contrib/json_test_data/DepolarizingWithDampedReadoutNoiseModel.repr +1 -0
- cirq/contrib/json_test_data/DepolarizingWithReadoutNoiseModel.json +5 -0
- cirq/contrib/json_test_data/DepolarizingWithReadoutNoiseModel.repr +1 -0
- cirq/contrib/json_test_data/ReadoutNoiseModel.json +12 -0
- cirq/contrib/json_test_data/ReadoutNoiseModel.repr +4 -0
- cirq/contrib/json_test_data/__init__.py +17 -0
- cirq/contrib/json_test_data/spec.py +32 -0
- cirq/contrib/noise_models/noise_models.py +119 -5
- cirq/contrib/noise_models/noise_models_test.py +37 -9
- cirq/contrib/paulistring/clifford_optimize.py +6 -4
- cirq/contrib/paulistring/clifford_optimize_test.py +6 -5
- cirq/contrib/paulistring/clifford_target_gateset.py +10 -10
- cirq/contrib/paulistring/clifford_target_gateset_test.py +13 -11
- cirq/contrib/paulistring/optimize.py +2 -0
- cirq/contrib/paulistring/optimize_test.py +4 -3
- cirq/contrib/paulistring/pauli_string_dag.py +2 -0
- cirq/contrib/paulistring/pauli_string_dag_test.py +3 -1
- cirq/contrib/paulistring/pauli_string_measurement_with_readout_mitigation.py +255 -120
- cirq/contrib/paulistring/pauli_string_measurement_with_readout_mitigation_test.py +398 -19
- cirq/contrib/paulistring/pauli_string_optimize.py +7 -1
- cirq/contrib/paulistring/pauli_string_optimize_test.py +5 -3
- cirq/contrib/paulistring/recombine.py +6 -4
- cirq/contrib/paulistring/recombine_test.py +3 -1
- cirq/contrib/paulistring/separate.py +9 -6
- cirq/contrib/paulistring/separate_test.py +3 -1
- cirq/contrib/qasm_import/_lexer.py +3 -2
- cirq/contrib/qasm_import/_lexer_test.py +49 -13
- cirq/contrib/qasm_import/_parser.py +547 -83
- cirq/contrib/qasm_import/_parser_test.py +988 -97
- cirq/contrib/qasm_import/exception.py +2 -0
- cirq/contrib/qasm_import/qasm.py +8 -2
- cirq/contrib/qasm_import/qasm_test.py +7 -4
- cirq/contrib/qcircuit/qcircuit_diagram_info.py +5 -5
- cirq/contrib/qcircuit/qcircuit_diagram_info_test.py +4 -1
- cirq/contrib/qcircuit/qcircuit_pdf.py +7 -3
- cirq/contrib/qcircuit/qcircuit_pdf_test.py +3 -1
- cirq/contrib/qcircuit/qcircuit_test.py +10 -8
- cirq/contrib/quantum_volume/quantum_volume.py +31 -27
- cirq/contrib/quantum_volume/quantum_volume_test.py +19 -16
- cirq/contrib/quimb/density_matrix.py +15 -14
- cirq/contrib/quimb/density_matrix_test.py +10 -7
- cirq/contrib/quimb/grid_circuits.py +5 -2
- cirq/contrib/quimb/grid_circuits_test.py +3 -0
- cirq/contrib/quimb/mps_simulator.py +20 -20
- cirq/contrib/quimb/mps_simulator_test.py +3 -0
- cirq/contrib/quimb/state_vector.py +12 -11
- cirq/contrib/quimb/state_vector_test.py +3 -0
- cirq/contrib/quirk/export_to_quirk.py +5 -3
- cirq/contrib/quirk/export_to_quirk_test.py +18 -16
- cirq/contrib/quirk/linearize_circuit.py +2 -0
- cirq/contrib/quirk/quirk_gate.py +18 -17
- cirq/contrib/routing/device.py +5 -3
- cirq/contrib/routing/device_test.py +2 -0
- cirq/contrib/routing/greedy.py +10 -21
- cirq/contrib/routing/greedy_test.py +4 -2
- cirq/contrib/routing/initialization.py +2 -2
- cirq/contrib/routing/initialization_test.py +5 -3
- cirq/contrib/routing/router.py +9 -5
- cirq/contrib/routing/router_test.py +2 -0
- cirq/contrib/routing/swap_network.py +3 -3
- cirq/contrib/routing/swap_network_test.py +3 -1
- cirq/contrib/routing/utils.py +2 -2
- cirq/contrib/routing/utils_test.py +3 -0
- cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking.py +15 -9
- cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking_test.py +3 -0
- cirq/contrib/svg/svg.py +3 -3
- cirq/contrib/svg/svg_test.py +8 -5
- cirq/devices/device.py +4 -4
- cirq/devices/device_test.py +7 -4
- cirq/devices/grid_device_metadata.py +10 -10
- cirq/devices/grid_device_metadata_test.py +3 -0
- cirq/devices/grid_qubit.py +29 -21
- cirq/devices/grid_qubit_test.py +3 -0
- cirq/devices/insertion_noise_model.py +7 -7
- cirq/devices/insertion_noise_model_test.py +7 -5
- cirq/devices/line_qubit.py +13 -13
- cirq/devices/line_qubit_test.py +2 -0
- cirq/devices/named_topologies.py +18 -29
- cirq/devices/named_topologies_test.py +13 -10
- cirq/devices/noise_model.py +3 -3
- cirq/devices/noise_model_test.py +19 -15
- cirq/devices/noise_properties.py +15 -6
- cirq/devices/noise_properties_test.py +34 -3
- cirq/devices/noise_utils.py +11 -9
- cirq/devices/noise_utils_test.py +2 -0
- cirq/devices/superconducting_qubits_noise_properties.py +23 -22
- cirq/devices/superconducting_qubits_noise_properties_test.py +6 -6
- cirq/devices/thermal_noise_model.py +107 -37
- cirq/devices/thermal_noise_model_test.py +21 -0
- cirq/devices/unconstrained_device.py +5 -3
- cirq/devices/unconstrained_device_test.py +2 -0
- cirq/experiments/__init__.py +4 -2
- cirq/experiments/benchmarking/__init__.py +17 -0
- cirq/experiments/benchmarking/parallel_xeb.py +677 -0
- cirq/experiments/benchmarking/parallel_xeb_test.py +447 -0
- cirq/experiments/fidelity_estimation.py +14 -8
- cirq/experiments/fidelity_estimation_test.py +3 -0
- cirq/experiments/n_qubit_tomography.py +17 -16
- cirq/experiments/n_qubit_tomography_test.py +8 -5
- cirq/experiments/purity_estimation.py +2 -0
- cirq/experiments/purity_estimation_test.py +2 -0
- cirq/experiments/qubit_characterizations.py +207 -103
- cirq/experiments/qubit_characterizations_test.py +40 -12
- cirq/experiments/random_quantum_circuit_generation.py +56 -70
- cirq/experiments/random_quantum_circuit_generation_test.py +11 -8
- cirq/experiments/readout_confusion_matrix.py +24 -22
- cirq/experiments/readout_confusion_matrix_test.py +2 -0
- cirq/experiments/single_qubit_readout_calibration.py +30 -15
- cirq/experiments/single_qubit_readout_calibration_test.py +5 -2
- cirq/experiments/t1_decay_experiment.py +9 -7
- cirq/experiments/t1_decay_experiment_test.py +13 -11
- cirq/experiments/t2_decay_experiment.py +16 -13
- cirq/experiments/t2_decay_experiment_test.py +2 -0
- cirq/experiments/two_qubit_xeb.py +64 -57
- cirq/experiments/two_qubit_xeb_test.py +10 -6
- cirq/experiments/xeb_fitting.py +39 -35
- cirq/experiments/xeb_sampling.py +37 -44
- cirq/experiments/xeb_sampling_test.py +3 -0
- cirq/experiments/xeb_simulation.py +14 -10
- cirq/experiments/xeb_simulation_test.py +5 -5
- cirq/experiments/z_phase_calibration.py +32 -29
- cirq/experiments/z_phase_calibration_test.py +3 -4
- cirq/interop/quirk/cells/__init__.py +1 -1
- cirq/interop/quirk/cells/all_cells.py +7 -2
- cirq/interop/quirk/cells/arithmetic_cells.py +29 -41
- cirq/interop/quirk/cells/arithmetic_cells_test.py +17 -14
- cirq/interop/quirk/cells/cell.py +19 -28
- cirq/interop/quirk/cells/cell_test.py +3 -0
- cirq/interop/quirk/cells/composite_cell.py +13 -28
- cirq/interop/quirk/cells/composite_cell_test.py +2 -0
- cirq/interop/quirk/cells/control_cells.py +15 -15
- cirq/interop/quirk/cells/control_cells_test.py +7 -5
- cirq/interop/quirk/cells/frequency_space_cells.py +4 -3
- cirq/interop/quirk/cells/frequency_space_cells_test.py +3 -1
- cirq/interop/quirk/cells/ignored_cells.py +3 -0
- cirq/interop/quirk/cells/ignored_cells_test.py +3 -1
- cirq/interop/quirk/cells/input_cells.py +7 -5
- cirq/interop/quirk/cells/input_cells_test.py +7 -5
- cirq/interop/quirk/cells/input_rotation_cells.py +15 -13
- cirq/interop/quirk/cells/input_rotation_cells_test.py +9 -7
- cirq/interop/quirk/cells/measurement_cells.py +5 -2
- cirq/interop/quirk/cells/measurement_cells_test.py +3 -1
- cirq/interop/quirk/cells/parse.py +22 -23
- cirq/interop/quirk/cells/parse_test.py +12 -10
- cirq/interop/quirk/cells/qubit_permutation_cells.py +5 -3
- cirq/interop/quirk/cells/qubit_permutation_cells_test.py +9 -7
- cirq/interop/quirk/cells/scalar_cells.py +4 -1
- cirq/interop/quirk/cells/scalar_cells_test.py +3 -1
- cirq/interop/quirk/cells/single_qubit_rotation_cells.py +5 -2
- cirq/interop/quirk/cells/single_qubit_rotation_cells_test.py +5 -3
- cirq/interop/quirk/cells/swap_cell.py +8 -6
- cirq/interop/quirk/cells/swap_cell_test.py +6 -4
- cirq/interop/quirk/cells/testing.py +6 -6
- cirq/interop/quirk/cells/testing_test.py +8 -6
- cirq/interop/quirk/cells/unsupported_cells.py +3 -0
- cirq/interop/quirk/cells/unsupported_cells_test.py +4 -2
- cirq/interop/quirk/url_to_circuit.py +23 -36
- cirq/interop/quirk/url_to_circuit_test.py +4 -1
- cirq/json_resolver_cache.py +14 -12
- cirq/linalg/__init__.py +4 -6
- cirq/linalg/combinators.py +7 -5
- cirq/linalg/combinators_test.py +10 -7
- cirq/linalg/decompositions.py +24 -35
- cirq/linalg/decompositions_test.py +3 -1
- cirq/linalg/diagonalize.py +6 -4
- cirq/linalg/diagonalize_test.py +15 -14
- cirq/linalg/operator_spaces.py +14 -14
- cirq/linalg/operator_spaces_test.py +13 -11
- cirq/linalg/predicates.py +18 -9
- cirq/linalg/predicates_test.py +5 -0
- cirq/linalg/tolerance.py +6 -3
- cirq/linalg/tolerance_test.py +6 -4
- cirq/linalg/transformations.py +23 -20
- cirq/linalg/transformations_test.py +73 -43
- cirq/neutral_atoms/convert_to_neutral_atom_gates.py +9 -3
- cirq/neutral_atoms/convert_to_neutral_atom_gates_test.py +3 -1
- cirq/neutral_atoms/neutral_atom_devices.py +2 -0
- cirq/ops/__init__.py +2 -0
- cirq/ops/arithmetic_operation.py +21 -21
- cirq/ops/arithmetic_operation_test.py +7 -8
- cirq/ops/boolean_hamiltonian.py +23 -22
- cirq/ops/boolean_hamiltonian_test.py +12 -9
- cirq/ops/classically_controlled_operation.py +31 -36
- cirq/ops/classically_controlled_operation_test.py +121 -117
- cirq/ops/clifford_gate.py +98 -81
- cirq/ops/clifford_gate_test.py +72 -57
- cirq/ops/common_channels.py +44 -44
- cirq/ops/common_channels_test.py +83 -81
- cirq/ops/common_gate_families.py +9 -7
- cirq/ops/common_gate_families_test.py +11 -7
- cirq/ops/common_gates.py +164 -183
- cirq/ops/common_gates_test.py +135 -95
- cirq/ops/control_values.py +23 -26
- cirq/ops/control_values_test.py +22 -20
- cirq/ops/controlled_gate.py +64 -112
- cirq/ops/controlled_gate_test.py +130 -35
- cirq/ops/controlled_operation.py +24 -35
- cirq/ops/controlled_operation_test.py +8 -6
- cirq/ops/dense_pauli_string.py +38 -49
- cirq/ops/dense_pauli_string_test.py +4 -2
- cirq/ops/diagonal_gate.py +18 -31
- cirq/ops/diagonal_gate_test.py +13 -13
- cirq/ops/eigen_gate.py +29 -29
- cirq/ops/eigen_gate_test.py +45 -28
- cirq/ops/fourier_transform.py +14 -20
- cirq/ops/fourier_transform_test.py +15 -12
- cirq/ops/fsim_gate.py +43 -42
- cirq/ops/fsim_gate_test.py +29 -29
- cirq/ops/gate_features.py +2 -0
- cirq/ops/gate_features_test.py +5 -3
- cirq/ops/gate_operation.py +43 -65
- cirq/ops/gate_operation_test.py +46 -42
- cirq/ops/gateset.py +28 -40
- cirq/ops/gateset_test.py +4 -2
- cirq/ops/global_phase_op.py +45 -20
- cirq/ops/global_phase_op_test.py +44 -20
- cirq/ops/greedy_qubit_manager.py +10 -8
- cirq/ops/greedy_qubit_manager_test.py +5 -3
- cirq/ops/identity.py +14 -12
- cirq/ops/identity_test.py +24 -20
- cirq/ops/kraus_channel.py +11 -8
- cirq/ops/kraus_channel_test.py +14 -11
- cirq/ops/linear_combinations.py +65 -77
- cirq/ops/linear_combinations_test.py +14 -9
- cirq/ops/matrix_gates.py +21 -18
- cirq/ops/matrix_gates_test.py +16 -0
- cirq/ops/measure_util.py +15 -20
- cirq/ops/measure_util_test.py +2 -0
- cirq/ops/measurement_gate.py +26 -37
- cirq/ops/measurement_gate_test.py +2 -0
- cirq/ops/mixed_unitary_channel.py +12 -9
- cirq/ops/mixed_unitary_channel_test.py +14 -11
- cirq/ops/named_qubit.py +16 -13
- cirq/ops/named_qubit_test.py +15 -13
- cirq/ops/op_tree.py +9 -7
- cirq/ops/op_tree_test.py +22 -19
- cirq/ops/parallel_gate.py +15 -17
- cirq/ops/parallel_gate_test.py +18 -16
- cirq/ops/parity_gates.py +23 -25
- cirq/ops/parity_gates_test.py +36 -32
- cirq/ops/pauli_gates.py +22 -21
- cirq/ops/pauli_gates_test.py +29 -20
- cirq/ops/pauli_interaction_gate.py +15 -19
- cirq/ops/pauli_interaction_gate_test.py +10 -8
- cirq/ops/pauli_measurement_gate.py +23 -35
- cirq/ops/pauli_measurement_gate_test.py +2 -0
- cirq/ops/pauli_string.py +92 -120
- cirq/ops/pauli_string_phasor.py +52 -45
- cirq/ops/pauli_string_phasor_test.py +4 -5
- cirq/ops/pauli_string_raw_types.py +9 -7
- cirq/ops/pauli_string_raw_types_test.py +2 -0
- cirq/ops/pauli_string_test.py +31 -154
- cirq/ops/pauli_sum_exponential.py +12 -12
- cirq/ops/pauli_sum_exponential_test.py +12 -10
- cirq/ops/permutation_gate.py +8 -6
- cirq/ops/permutation_gate_test.py +10 -8
- cirq/ops/phased_iswap_gate.py +16 -16
- cirq/ops/phased_iswap_gate_test.py +17 -15
- cirq/ops/phased_x_gate.py +16 -17
- cirq/ops/phased_x_gate_test.py +18 -16
- cirq/ops/phased_x_z_gate.py +24 -22
- cirq/ops/phased_x_z_gate_test.py +17 -11
- cirq/ops/projector.py +16 -11
- cirq/ops/projector_test.py +19 -16
- cirq/ops/qid_util.py +7 -5
- cirq/ops/qid_util_test.py +2 -0
- cirq/ops/qubit_manager.py +11 -9
- cirq/ops/qubit_manager_test.py +6 -4
- cirq/ops/qubit_order.py +11 -14
- cirq/ops/qubit_order_or_list.py +4 -2
- cirq/ops/qubit_order_test.py +12 -10
- cirq/ops/random_gate_channel.py +12 -10
- cirq/ops/random_gate_channel_test.py +14 -11
- cirq/ops/raw_types.py +109 -129
- cirq/ops/raw_types_test.py +63 -57
- cirq/ops/state_preparation_channel.py +7 -7
- cirq/ops/state_preparation_channel_test.py +11 -9
- cirq/ops/swap_gates.py +13 -15
- cirq/ops/swap_gates_test.py +19 -17
- cirq/ops/tags.py +5 -3
- cirq/ops/tags_test.py +4 -2
- cirq/ops/three_qubit_gates.py +43 -76
- cirq/ops/three_qubit_gates_test.py +19 -17
- cirq/ops/two_qubit_diagonal_gate.py +13 -13
- cirq/ops/two_qubit_diagonal_gate_test.py +10 -8
- cirq/ops/uniform_superposition_gate.py +5 -3
- cirq/ops/uniform_superposition_gate_test.py +5 -3
- cirq/ops/wait_gate.py +17 -14
- cirq/ops/wait_gate_test.py +9 -6
- cirq/protocols/__init__.py +0 -3
- cirq/protocols/act_on_protocol.py +8 -6
- cirq/protocols/act_on_protocol_test.py +15 -12
- cirq/protocols/apply_channel_protocol.py +10 -14
- cirq/protocols/apply_channel_protocol_test.py +2 -0
- cirq/protocols/apply_mixture_protocol.py +13 -42
- cirq/protocols/apply_mixture_protocol_test.py +7 -5
- cirq/protocols/apply_unitary_protocol.py +39 -34
- cirq/protocols/apply_unitary_protocol_test.py +4 -1
- cirq/protocols/approximate_equality_protocol.py +2 -0
- cirq/protocols/approximate_equality_protocol_test.py +2 -0
- cirq/protocols/circuit_diagram_info_protocol.py +58 -42
- cirq/protocols/circuit_diagram_info_protocol_test.py +70 -12
- cirq/protocols/commutes_protocol.py +8 -7
- cirq/protocols/commutes_protocol_test.py +2 -0
- cirq/protocols/control_key_protocol.py +6 -4
- cirq/protocols/control_key_protocol_test.py +3 -1
- cirq/protocols/decompose_protocol.py +49 -48
- cirq/protocols/decompose_protocol_test.py +27 -16
- cirq/protocols/equal_up_to_global_phase_protocol.py +2 -0
- cirq/protocols/equal_up_to_global_phase_protocol_test.py +9 -6
- cirq/protocols/has_stabilizer_effect_protocol.py +7 -5
- cirq/protocols/has_stabilizer_effect_protocol_test.py +7 -5
- cirq/protocols/has_unitary_protocol.py +10 -6
- cirq/protocols/has_unitary_protocol_test.py +13 -8
- cirq/protocols/hash_from_pickle_test.py +2 -11
- cirq/protocols/inverse_protocol.py +13 -16
- cirq/protocols/inverse_protocol_test.py +5 -3
- cirq/protocols/json_serialization.py +35 -54
- cirq/protocols/json_serialization_test.py +14 -21
- cirq/protocols/json_test_data/CXSWAP.json +46 -0
- cirq/protocols/json_test_data/CXSWAP.repr +13 -0
- cirq/protocols/json_test_data/CZSWAP.json +46 -0
- cirq/protocols/json_test_data/CZSWAP.repr +13 -0
- cirq/protocols/json_test_data/CircuitOperation.json +6 -3
- cirq/protocols/json_test_data/CircuitOperation.repr_inward +4 -2
- cirq/protocols/json_test_data/Moment.json +24 -1
- cirq/protocols/json_test_data/Moment.repr +6 -1
- cirq/protocols/json_test_data/ThermalNoiseModel.json +32 -0
- cirq/protocols/json_test_data/ThermalNoiseModel.repr +1 -0
- cirq/protocols/json_test_data/spec.py +6 -2
- cirq/protocols/kraus_protocol.py +47 -7
- cirq/protocols/kraus_protocol_test.py +86 -12
- cirq/protocols/measurement_key_protocol.py +15 -16
- cirq/protocols/measurement_key_protocol_test.py +13 -11
- cirq/protocols/mixture_protocol.py +7 -5
- cirq/protocols/mixture_protocol_test.py +4 -2
- cirq/protocols/mul_protocol.py +2 -3
- cirq/protocols/mul_protocol_test.py +2 -0
- cirq/protocols/pauli_expansion_protocol.py +6 -3
- cirq/protocols/pauli_expansion_protocol_test.py +5 -3
- cirq/protocols/phase_protocol.py +2 -0
- cirq/protocols/phase_protocol_test.py +3 -1
- cirq/protocols/pow_protocol.py +11 -16
- cirq/protocols/pow_protocol_test.py +2 -0
- cirq/protocols/qasm.py +14 -20
- cirq/protocols/qasm_test.py +6 -3
- cirq/protocols/qid_shape_protocol.py +8 -8
- cirq/protocols/qid_shape_protocol_test.py +3 -1
- cirq/protocols/resolve_parameters.py +5 -3
- cirq/protocols/resolve_parameters_test.py +8 -7
- cirq/protocols/trace_distance_bound.py +6 -4
- cirq/protocols/trace_distance_bound_test.py +3 -1
- cirq/protocols/unitary_protocol.py +17 -7
- cirq/protocols/unitary_protocol_test.py +12 -2
- cirq/qis/channels.py +6 -2
- cirq/qis/channels_test.py +20 -16
- cirq/qis/clifford_tableau.py +21 -19
- cirq/qis/clifford_tableau_test.py +2 -2
- cirq/qis/entropy.py +14 -3
- cirq/qis/entropy_test.py +3 -1
- cirq/qis/measures.py +13 -13
- cirq/qis/measures_test.py +20 -14
- cirq/qis/noise_utils.py +2 -0
- cirq/qis/noise_utils_test.py +9 -7
- cirq/qis/quantum_state_representation.py +7 -8
- cirq/qis/states.py +58 -56
- cirq/qis/states_test.py +2 -0
- cirq/sim/classical_simulator.py +23 -22
- cirq/sim/classical_simulator_test.py +2 -0
- cirq/sim/clifford/clifford_simulator.py +23 -21
- cirq/sim/clifford/clifford_simulator_test.py +7 -4
- cirq/sim/clifford/clifford_tableau_simulation_state.py +10 -7
- cirq/sim/clifford/clifford_tableau_simulation_state_test.py +5 -5
- cirq/sim/clifford/stabilizer_ch_form_simulation_state.py +8 -6
- cirq/sim/clifford/stabilizer_ch_form_simulation_state_test.py +8 -6
- cirq/sim/clifford/stabilizer_sampler.py +9 -7
- cirq/sim/clifford/stabilizer_sampler_test.py +4 -2
- cirq/sim/clifford/stabilizer_simulation_state.py +14 -13
- cirq/sim/clifford/stabilizer_simulation_state_test.py +6 -4
- cirq/sim/clifford/stabilizer_state_ch_form.py +13 -11
- cirq/sim/clifford/stabilizer_state_ch_form_test.py +4 -2
- cirq/sim/density_matrix_simulation_state.py +26 -27
- cirq/sim/density_matrix_simulation_state_test.py +10 -8
- cirq/sim/density_matrix_simulator.py +30 -28
- cirq/sim/density_matrix_simulator_test.py +48 -48
- cirq/sim/density_matrix_utils.py +13 -11
- cirq/sim/density_matrix_utils_test.py +38 -36
- cirq/sim/mux.py +33 -31
- cirq/sim/mux_test.py +3 -0
- cirq/sim/simulation_product_state.py +15 -15
- cirq/sim/simulation_product_state_test.py +29 -26
- cirq/sim/simulation_state.py +29 -38
- cirq/sim/simulation_state_base.py +21 -32
- cirq/sim/simulation_state_test.py +15 -13
- cirq/sim/simulation_utils.py +5 -2
- cirq/sim/simulation_utils_test.py +5 -2
- cirq/sim/simulator.py +90 -106
- cirq/sim/simulator_base.py +33 -45
- cirq/sim/simulator_base_test.py +20 -15
- cirq/sim/simulator_test.py +23 -14
- cirq/sim/sparse_simulator.py +19 -17
- cirq/sim/sparse_simulator_test.py +41 -40
- cirq/sim/state_vector.py +15 -12
- cirq/sim/state_vector_simulation_state.py +31 -31
- cirq/sim/state_vector_simulation_state_test.py +16 -14
- cirq/sim/state_vector_simulator.py +17 -14
- cirq/sim/state_vector_simulator_test.py +2 -0
- cirq/sim/state_vector_test.py +6 -3
- cirq/study/flatten_expressions.py +16 -15
- cirq/study/flatten_expressions_test.py +13 -11
- cirq/study/resolver.py +18 -17
- cirq/study/resolver_test.py +22 -20
- cirq/study/result.py +17 -27
- cirq/study/result_test.py +2 -0
- cirq/study/sweepable.py +12 -10
- cirq/study/sweepable_test.py +3 -0
- cirq/study/sweeps.py +42 -61
- cirq/study/sweeps_test.py +33 -0
- cirq/testing/__init__.py +7 -11
- cirq/testing/_compat_test_data/module_a/__init__.py +1 -0
- cirq/testing/_compat_test_data/module_a/module_b/__init__.py +1 -0
- cirq/testing/_compat_test_data/module_a/sub/__init__.py +1 -0
- cirq/testing/circuit_compare.py +8 -17
- cirq/testing/circuit_compare_test.py +2 -0
- cirq/testing/consistent_act_on.py +13 -11
- cirq/testing/consistent_act_on_test.py +5 -3
- cirq/testing/consistent_channels.py +2 -0
- cirq/testing/consistent_channels_test.py +10 -8
- cirq/testing/consistent_controlled_gate_op.py +5 -5
- cirq/testing/consistent_controlled_gate_op_test.py +18 -18
- cirq/testing/consistent_decomposition.py +2 -2
- cirq/testing/consistent_decomposition_test.py +4 -2
- cirq/testing/consistent_pauli_expansion.py +2 -0
- cirq/testing/consistent_pauli_expansion_test.py +3 -1
- cirq/testing/consistent_phase_by.py +2 -0
- cirq/testing/consistent_phase_by_test.py +3 -1
- cirq/testing/consistent_protocols.py +14 -20
- cirq/testing/consistent_protocols_test.py +13 -11
- cirq/testing/consistent_qasm.py +6 -4
- cirq/testing/consistent_qasm_test.py +7 -7
- cirq/testing/consistent_resolve_parameters.py +2 -0
- cirq/testing/consistent_specified_has_unitary.py +2 -2
- cirq/testing/consistent_specified_has_unitary_test.py +6 -4
- cirq/testing/consistent_unitary.py +1 -0
- cirq/testing/consistent_unitary_test.py +4 -2
- cirq/testing/deprecation.py +5 -2
- cirq/testing/deprecation_test.py +5 -2
- cirq/testing/devices.py +7 -4
- cirq/testing/devices_test.py +7 -4
- cirq/testing/equals_tester.py +4 -2
- cirq/testing/equals_tester_test.py +21 -17
- cirq/testing/equivalent_basis_map.py +6 -4
- cirq/testing/equivalent_basis_map_test.py +6 -4
- cirq/testing/equivalent_repr_eval.py +6 -4
- cirq/testing/equivalent_repr_eval_test.py +5 -3
- cirq/testing/gate_features.py +2 -0
- cirq/testing/gate_features_test.py +7 -5
- cirq/testing/json.py +19 -15
- cirq/testing/json_test.py +5 -3
- cirq/testing/lin_alg_utils.py +10 -11
- cirq/testing/lin_alg_utils_test.py +14 -12
- cirq/testing/logs.py +7 -6
- cirq/testing/logs_test.py +9 -7
- cirq/testing/no_identifier_qubit.py +4 -2
- cirq/testing/no_identifier_qubit_test.py +5 -3
- cirq/testing/op_tree.py +2 -0
- cirq/testing/op_tree_test.py +4 -1
- cirq/testing/order_tester.py +2 -0
- cirq/testing/order_tester_test.py +8 -6
- cirq/testing/pytest_utils.py +2 -0
- cirq/testing/pytest_utils_test.py +4 -2
- cirq/testing/random_circuit.py +21 -20
- cirq/testing/random_circuit_test.py +12 -9
- cirq/testing/repr_pretty_tester.py +1 -0
- cirq/testing/repr_pretty_tester_test.py +5 -3
- cirq/testing/routing_devices.py +4 -1
- cirq/testing/routing_devices_test.py +9 -6
- cirq/testing/sample_circuits.py +4 -1
- cirq/testing/sample_circuits_test.py +3 -1
- cirq/testing/sample_gates.py +3 -0
- cirq/testing/sample_gates_test.py +5 -2
- cirq/transformers/__init__.py +11 -4
- cirq/transformers/align.py +9 -7
- cirq/transformers/align_test.py +2 -0
- cirq/transformers/analytical_decompositions/__init__.py +3 -6
- cirq/transformers/analytical_decompositions/clifford_decomposition.py +18 -16
- cirq/transformers/analytical_decompositions/clifford_decomposition_test.py +2 -0
- cirq/transformers/analytical_decompositions/controlled_gate_decomposition.py +19 -16
- cirq/transformers/analytical_decompositions/controlled_gate_decomposition_test.py +2 -0
- cirq/transformers/analytical_decompositions/cphase_to_fsim.py +11 -9
- cirq/transformers/analytical_decompositions/cphase_to_fsim_test.py +5 -3
- cirq/transformers/analytical_decompositions/pauli_string_decomposition.py +5 -3
- cirq/transformers/analytical_decompositions/pauli_string_decomposition_test.py +5 -3
- cirq/transformers/analytical_decompositions/quantum_shannon_decomposition.py +141 -44
- cirq/transformers/analytical_decompositions/quantum_shannon_decomposition_test.py +35 -1
- cirq/transformers/analytical_decompositions/single_qubit_decompositions.py +8 -7
- cirq/transformers/analytical_decompositions/single_qubit_decompositions_test.py +2 -0
- cirq/transformers/analytical_decompositions/single_to_two_qubit_isometry.py +7 -4
- cirq/transformers/analytical_decompositions/single_to_two_qubit_isometry_test.py +3 -0
- cirq/transformers/analytical_decompositions/three_qubit_decomposition.py +11 -19
- cirq/transformers/analytical_decompositions/three_qubit_decomposition_test.py +8 -33
- cirq/transformers/analytical_decompositions/two_qubit_state_preparation.py +9 -11
- cirq/transformers/analytical_decompositions/two_qubit_state_preparation_test.py +2 -0
- cirq/transformers/analytical_decompositions/two_qubit_to_cz.py +91 -27
- cirq/transformers/analytical_decompositions/two_qubit_to_cz_test.py +36 -7
- cirq/transformers/analytical_decompositions/two_qubit_to_fsim.py +20 -21
- cirq/transformers/analytical_decompositions/two_qubit_to_fsim_test.py +8 -6
- cirq/transformers/analytical_decompositions/two_qubit_to_ms.py +13 -15
- cirq/transformers/analytical_decompositions/two_qubit_to_ms_test.py +3 -1
- cirq/transformers/analytical_decompositions/two_qubit_to_sqrt_iswap.py +39 -41
- cirq/transformers/analytical_decompositions/two_qubit_to_sqrt_iswap_test.py +2 -0
- cirq/transformers/drop_empty_moments.py +5 -3
- cirq/transformers/drop_empty_moments_test.py +4 -2
- cirq/transformers/drop_negligible_operations.py +7 -5
- cirq/transformers/drop_negligible_operations_test.py +2 -0
- cirq/transformers/dynamical_decoupling.py +49 -42
- cirq/transformers/dynamical_decoupling_test.py +223 -205
- cirq/transformers/eject_phased_paulis.py +28 -26
- cirq/transformers/eject_phased_paulis_test.py +12 -9
- cirq/transformers/eject_z.py +12 -12
- cirq/transformers/eject_z_test.py +2 -2
- cirq/transformers/expand_composite.py +6 -4
- cirq/transformers/expand_composite_test.py +3 -1
- cirq/transformers/gauge_compiling/__init__.py +3 -1
- cirq/transformers/gauge_compiling/cphase_gauge.py +2 -0
- cirq/transformers/gauge_compiling/cphase_gauge_test.py +2 -0
- cirq/transformers/gauge_compiling/cz_gauge.py +2 -0
- cirq/transformers/gauge_compiling/cz_gauge_test.py +1 -0
- cirq/transformers/gauge_compiling/gauge_compiling.py +45 -41
- cirq/transformers/gauge_compiling/gauge_compiling_test.py +2 -0
- cirq/transformers/gauge_compiling/gauge_compiling_test_utils.py +1 -0
- cirq/transformers/gauge_compiling/gauge_compiling_test_utils_test.py +5 -1
- cirq/transformers/gauge_compiling/iswap_gauge.py +2 -0
- cirq/transformers/gauge_compiling/iswap_gauge_test.py +1 -0
- cirq/transformers/gauge_compiling/spin_inversion_gauge.py +2 -0
- cirq/transformers/gauge_compiling/spin_inversion_gauge_test.py +2 -0
- cirq/transformers/gauge_compiling/sqrt_cz_gauge.py +7 -6
- cirq/transformers/gauge_compiling/sqrt_cz_gauge_test.py +2 -0
- cirq/transformers/gauge_compiling/sqrt_iswap_gauge.py +2 -0
- cirq/transformers/gauge_compiling/sqrt_iswap_gauge_test.py +2 -0
- cirq/transformers/heuristic_decompositions/gate_tabulation_math_utils.py +6 -3
- cirq/transformers/heuristic_decompositions/gate_tabulation_math_utils_test.py +3 -0
- cirq/transformers/heuristic_decompositions/two_qubit_gate_tabulation.py +12 -9
- cirq/transformers/heuristic_decompositions/two_qubit_gate_tabulation_test.py +9 -7
- cirq/transformers/insertion_sort.py +8 -6
- cirq/transformers/insertion_sort_test.py +3 -1
- cirq/transformers/measurement_transformers.py +29 -29
- cirq/transformers/measurement_transformers_test.py +2 -0
- cirq/transformers/merge_k_qubit_gates.py +12 -10
- cirq/transformers/merge_k_qubit_gates_test.py +18 -18
- cirq/transformers/merge_single_qubit_gates.py +197 -20
- cirq/transformers/merge_single_qubit_gates_test.py +177 -5
- cirq/transformers/noise_adding.py +5 -3
- cirq/transformers/noise_adding_test.py +2 -0
- cirq/transformers/optimize_for_target_gateset.py +19 -17
- cirq/transformers/optimize_for_target_gateset_test.py +11 -8
- cirq/transformers/qubit_management_transformers.py +13 -11
- cirq/transformers/qubit_management_transformers_test.py +5 -3
- cirq/transformers/randomized_measurements.py +16 -14
- cirq/transformers/randomized_measurements_test.py +10 -4
- cirq/transformers/routing/initial_mapper.py +6 -4
- cirq/transformers/routing/initial_mapper_test.py +2 -0
- cirq/transformers/routing/line_initial_mapper.py +16 -14
- cirq/transformers/routing/line_initial_mapper_test.py +9 -7
- cirq/transformers/routing/mapping_manager.py +10 -10
- cirq/transformers/routing/mapping_manager_test.py +2 -0
- cirq/transformers/routing/route_circuit_cqc.py +33 -31
- cirq/transformers/routing/route_circuit_cqc_test.py +15 -13
- cirq/transformers/routing/visualize_routed_circuit.py +8 -7
- cirq/transformers/routing/visualize_routed_circuit_test.py +4 -2
- cirq/transformers/stratify.py +17 -15
- cirq/transformers/stratify_test.py +3 -0
- cirq/transformers/symbolize.py +103 -0
- cirq/transformers/symbolize_test.py +62 -0
- cirq/transformers/synchronize_terminal_measurements.py +10 -10
- cirq/transformers/synchronize_terminal_measurements_test.py +12 -10
- cirq/transformers/tag_transformers.py +97 -0
- cirq/transformers/tag_transformers_test.py +103 -0
- cirq/transformers/target_gatesets/compilation_target_gateset.py +21 -19
- cirq/transformers/target_gatesets/compilation_target_gateset_test.py +20 -16
- cirq/transformers/target_gatesets/cz_gateset.py +7 -5
- cirq/transformers/target_gatesets/cz_gateset_test.py +21 -19
- cirq/transformers/target_gatesets/sqrt_iswap_gateset.py +9 -7
- cirq/transformers/target_gatesets/sqrt_iswap_gateset_test.py +25 -25
- cirq/transformers/transformer_api.py +34 -47
- cirq/transformers/transformer_api_test.py +9 -8
- cirq/transformers/transformer_primitives.py +39 -49
- cirq/transformers/transformer_primitives_test.py +10 -17
- cirq/value/abc_alt.py +6 -4
- cirq/value/abc_alt_test.py +5 -3
- cirq/value/angle.py +11 -12
- cirq/value/angle_test.py +5 -3
- cirq/value/classical_data.py +27 -27
- cirq/value/classical_data_test.py +11 -8
- cirq/value/condition.py +26 -24
- cirq/value/condition_test.py +2 -0
- cirq/value/digits.py +14 -11
- cirq/value/digits_test.py +2 -0
- cirq/value/duration.py +23 -20
- cirq/value/duration_test.py +2 -0
- cirq/value/linear_dict.py +25 -30
- cirq/value/linear_dict_test.py +10 -8
- cirq/value/measurement_key.py +12 -12
- cirq/value/measurement_key_test.py +2 -0
- cirq/value/periodic_value.py +4 -4
- cirq/value/periodic_value_test.py +11 -7
- cirq/value/probability.py +3 -1
- cirq/value/probability_test.py +4 -2
- cirq/value/product_state.py +15 -13
- cirq/value/product_state_test.py +4 -1
- cirq/value/random_state.py +2 -0
- cirq/value/random_state_test.py +5 -3
- cirq/value/timestamp.py +11 -7
- cirq/value/timestamp_test.py +14 -12
- cirq/value/type_alias.py +4 -4
- cirq/value/value_equality_attr.py +8 -9
- cirq/value/value_equality_attr_test.py +14 -11
- cirq/vis/density_matrix.py +3 -3
- cirq/vis/density_matrix_test.py +20 -17
- cirq/vis/heatmap.py +24 -37
- cirq/vis/heatmap_test.py +3 -0
- cirq/vis/histogram.py +9 -6
- cirq/vis/histogram_test.py +5 -2
- cirq/vis/state_histogram.py +10 -8
- cirq/vis/state_histogram_test.py +7 -5
- cirq/vis/vis_utils.py +4 -1
- cirq/vis/vis_utils_test.py +4 -1
- cirq/work/collector.py +12 -18
- cirq/work/collector_test.py +15 -10
- cirq/work/observable_grouping.py +6 -7
- cirq/work/observable_grouping_test.py +10 -9
- cirq/work/observable_measurement.py +47 -45
- cirq/work/observable_measurement_data.py +22 -17
- cirq/work/observable_measurement_data_test.py +4 -1
- cirq/work/observable_measurement_test.py +48 -29
- cirq/work/observable_readout_calibration.py +5 -2
- cirq/work/observable_readout_calibration_test.py +5 -2
- cirq/work/observable_settings.py +13 -22
- cirq/work/observable_settings_test.py +9 -7
- cirq/work/pauli_sum_collector.py +12 -10
- cirq/work/pauli_sum_collector_test.py +9 -9
- cirq/work/sampler.py +42 -43
- cirq/work/sampler_test.py +31 -24
- cirq/work/zeros_sampler.py +6 -4
- cirq/work/zeros_sampler_test.py +7 -5
- {cirq_core-1.5.0.dev20250409225226.dist-info → cirq_core-1.6.0.dist-info}/METADATA +7 -8
- cirq_core-1.6.0.dist-info/RECORD +1241 -0
- {cirq_core-1.5.0.dev20250409225226.dist-info → cirq_core-1.6.0.dist-info}/WHEEL +1 -1
- cirq_core-1.5.0.dev20250409225226.dist-info/RECORD +0 -1216
- {cirq_core-1.5.0.dev20250409225226.dist-info → cirq_core-1.6.0.dist-info}/licenses/LICENSE +0 -0
- {cirq_core-1.5.0.dev20250409225226.dist-info → cirq_core-1.6.0.dist-info}/top_level.txt +0 -0
|
@@ -12,18 +12,20 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
15
17
|
import numpy as np
|
|
16
18
|
import pytest
|
|
17
19
|
|
|
18
20
|
import cirq
|
|
19
21
|
|
|
20
22
|
|
|
21
|
-
def test_assert_consistent_channel_valid():
|
|
23
|
+
def test_assert_consistent_channel_valid() -> None:
|
|
22
24
|
channel = cirq.KrausChannel(kraus_ops=(np.array([[0, 1], [0, 0]]), np.array([[1, 0], [0, 0]])))
|
|
23
25
|
cirq.testing.assert_consistent_channel(channel)
|
|
24
26
|
|
|
25
27
|
|
|
26
|
-
def test_assert_consistent_channel_tolerances():
|
|
28
|
+
def test_assert_consistent_channel_tolerances() -> None:
|
|
27
29
|
# This channel is off by 1e-5 from the identity matrix in the consistency condition.
|
|
28
30
|
channel = cirq.KrausChannel(
|
|
29
31
|
kraus_ops=(np.array([[0, np.sqrt(1 - 1e-5)], [0, 0]]), np.array([[1, 0], [0, 0]]))
|
|
@@ -37,23 +39,23 @@ def test_assert_consistent_channel_tolerances():
|
|
|
37
39
|
cirq.testing.assert_consistent_channel(channel, rtol=0, atol=1e-6)
|
|
38
40
|
|
|
39
41
|
|
|
40
|
-
def test_assert_consistent_channel_invalid():
|
|
42
|
+
def test_assert_consistent_channel_invalid() -> None:
|
|
41
43
|
channel = cirq.KrausChannel(kraus_ops=(np.array([[1, 1], [0, 0]]), np.array([[1, 0], [0, 0]])))
|
|
42
44
|
with pytest.raises(AssertionError, match=r"cirq.KrausChannel.*2 1"):
|
|
43
45
|
cirq.testing.assert_consistent_channel(channel)
|
|
44
46
|
|
|
45
47
|
|
|
46
|
-
def test_assert_consistent_channel_not_kraus():
|
|
48
|
+
def test_assert_consistent_channel_not_kraus() -> None:
|
|
47
49
|
with pytest.raises(AssertionError, match="12.*has_kraus"):
|
|
48
50
|
cirq.testing.assert_consistent_channel(12)
|
|
49
51
|
|
|
50
52
|
|
|
51
|
-
def test_assert_consistent_mixture_valid():
|
|
53
|
+
def test_assert_consistent_mixture_valid() -> None:
|
|
52
54
|
mixture = cirq.X.with_probability(0.1)
|
|
53
55
|
cirq.testing.assert_consistent_mixture(mixture)
|
|
54
56
|
|
|
55
57
|
|
|
56
|
-
def test_assert_consistent_mixture_not_mixture():
|
|
58
|
+
def test_assert_consistent_mixture_not_mixture() -> None:
|
|
57
59
|
not_mixture = cirq.amplitude_damp(0.1)
|
|
58
60
|
with pytest.raises(AssertionError, match="has_mixture"):
|
|
59
61
|
cirq.testing.assert_consistent_mixture(not_mixture)
|
|
@@ -69,7 +71,7 @@ class _MixtureGate(cirq.testing.SingleQubitGate):
|
|
|
69
71
|
return (self._p, cirq.unitary(cirq.I)), (self._q, cirq.unitary(cirq.X))
|
|
70
72
|
|
|
71
73
|
|
|
72
|
-
def test_assert_consistent_mixture_not_normalized():
|
|
74
|
+
def test_assert_consistent_mixture_not_normalized() -> None:
|
|
73
75
|
mixture = _MixtureGate(0.1, 0.85)
|
|
74
76
|
with pytest.raises(AssertionError, match="sum to 1"):
|
|
75
77
|
cirq.testing.assert_consistent_mixture(mixture)
|
|
@@ -79,7 +81,7 @@ def test_assert_consistent_mixture_not_normalized():
|
|
|
79
81
|
cirq.testing.assert_consistent_mixture(mixture)
|
|
80
82
|
|
|
81
83
|
|
|
82
|
-
def test_assert_consistent_mixture_tolerances():
|
|
84
|
+
def test_assert_consistent_mixture_tolerances() -> None:
|
|
83
85
|
|
|
84
86
|
# This gate is 1e-5 off being properly normalized.
|
|
85
87
|
mixture = _MixtureGate(0.1, 0.9 - 1e-5)
|
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
-
from
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from typing import Collection, Sequence
|
|
16
18
|
|
|
17
19
|
import numpy as np
|
|
18
20
|
|
|
@@ -23,7 +25,7 @@ def assert_controlled_and_controlled_by_identical(
|
|
|
23
25
|
gate: ops.Gate,
|
|
24
26
|
*,
|
|
25
27
|
num_controls: Sequence[int] = (2, 1, 3, 10),
|
|
26
|
-
control_values:
|
|
28
|
+
control_values: Sequence[Sequence[int | Collection[int]] | None] | None = None,
|
|
27
29
|
) -> None:
|
|
28
30
|
"""Checks that gate.on().controlled_by() == gate.controlled().on()"""
|
|
29
31
|
if control_values is not None:
|
|
@@ -50,9 +52,7 @@ def assert_controlled_unitary_consistent(gate: ops.Gate):
|
|
|
50
52
|
|
|
51
53
|
|
|
52
54
|
def _assert_gate_consistent(
|
|
53
|
-
gate: ops.Gate,
|
|
54
|
-
num_controls: int,
|
|
55
|
-
control_values: Optional[Sequence[Union[int, Collection[int]]]],
|
|
55
|
+
gate: ops.Gate, num_controls: int, control_values: Sequence[int | Collection[int]] | None
|
|
56
56
|
) -> None:
|
|
57
57
|
gate_controlled = gate.controlled(num_controls, control_values)
|
|
58
58
|
qubits = devices.LineQid.for_gate(gate_controlled)
|
|
@@ -12,53 +12,53 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
-
from
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from typing import Collection, Sequence, TYPE_CHECKING
|
|
16
18
|
|
|
17
19
|
import numpy as np
|
|
18
20
|
import pytest
|
|
19
21
|
|
|
20
22
|
import cirq
|
|
21
|
-
|
|
23
|
+
|
|
24
|
+
if TYPE_CHECKING:
|
|
25
|
+
from cirq.ops import control_values as cv
|
|
22
26
|
|
|
23
27
|
|
|
24
28
|
class GoodGate(cirq.EigenGate, cirq.testing.SingleQubitGate):
|
|
25
|
-
def _eigen_components(self) ->
|
|
29
|
+
def _eigen_components(self) -> list[tuple[float, np.ndarray]]: # pragma: no cover
|
|
26
30
|
return [(0, np.diag([1, 0])), (1, np.diag([0, 1]))]
|
|
27
31
|
|
|
28
32
|
|
|
29
33
|
class BadGateOperation(cirq.GateOperation):
|
|
30
34
|
def controlled_by(
|
|
31
35
|
self,
|
|
32
|
-
*control_qubits:
|
|
33
|
-
control_values:
|
|
34
|
-
|
|
35
|
-
] = None,
|
|
36
|
-
) -> 'cirq.Operation':
|
|
36
|
+
*control_qubits: cirq.Qid,
|
|
37
|
+
control_values: cv.AbstractControlValues | Sequence[int | Collection[int]] | None = None,
|
|
38
|
+
) -> cirq.Operation:
|
|
37
39
|
return cirq.ControlledOperation(control_qubits, self, control_values)
|
|
38
40
|
|
|
39
41
|
|
|
40
42
|
class BadGate(cirq.EigenGate, cirq.testing.SingleQubitGate):
|
|
41
|
-
def _eigen_components(self) ->
|
|
43
|
+
def _eigen_components(self) -> list[tuple[float, np.ndarray]]:
|
|
42
44
|
return [(0, np.diag([1, 0])), (1, np.diag([0, 1]))]
|
|
43
45
|
|
|
44
|
-
def on(self, *qubits:
|
|
46
|
+
def on(self, *qubits: cirq.Qid) -> cirq.Operation:
|
|
45
47
|
return BadGateOperation(self, list(qubits))
|
|
46
48
|
|
|
47
49
|
def controlled(
|
|
48
50
|
self,
|
|
49
|
-
num_controls:
|
|
50
|
-
control_values:
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
control_qid_shape: Optional[Tuple[int, ...]] = None,
|
|
54
|
-
) -> 'cirq.Gate':
|
|
51
|
+
num_controls: int | None = None,
|
|
52
|
+
control_values: cv.AbstractControlValues | Sequence[int | Collection[int]] | None = None,
|
|
53
|
+
control_qid_shape: tuple[int, ...] | None = None,
|
|
54
|
+
) -> cirq.Gate:
|
|
55
55
|
ret = super().controlled(num_controls, control_values, control_qid_shape)
|
|
56
56
|
if num_controls == 1 and control_values is None:
|
|
57
57
|
return cirq.CZPowGate(exponent=self._exponent, global_shift=self._global_shift)
|
|
58
58
|
return ret
|
|
59
59
|
|
|
60
60
|
|
|
61
|
-
def test_assert_controlled_and_controlled_by_identical():
|
|
61
|
+
def test_assert_controlled_and_controlled_by_identical() -> None:
|
|
62
62
|
cirq.testing.assert_controlled_and_controlled_by_identical(GoodGate())
|
|
63
63
|
|
|
64
64
|
with pytest.raises(AssertionError):
|
|
@@ -75,7 +75,7 @@ def test_assert_controlled_and_controlled_by_identical():
|
|
|
75
75
|
)
|
|
76
76
|
|
|
77
77
|
|
|
78
|
-
def test_assert_controlled_unitary_consistent():
|
|
78
|
+
def test_assert_controlled_unitary_consistent() -> None:
|
|
79
79
|
cirq.testing.assert_controlled_and_controlled_by_identical(
|
|
80
80
|
GoodGate(exponent=0.5, global_shift=1 / 3)
|
|
81
81
|
)
|
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
15
17
|
from typing import Any
|
|
16
18
|
|
|
17
19
|
import numpy as np
|
|
@@ -22,9 +24,7 @@ from cirq.testing import lin_alg_utils
|
|
|
22
24
|
|
|
23
25
|
def assert_decompose_is_consistent_with_unitary(val: Any, ignoring_global_phase: bool = False):
|
|
24
26
|
"""Uses `val._unitary_` to check `val._phase_by_`'s behavior."""
|
|
25
|
-
# pylint: disable=unused-variable
|
|
26
27
|
__tracebackhide__ = True
|
|
27
|
-
# pylint: enable=unused-variable
|
|
28
28
|
|
|
29
29
|
expected = protocols.unitary(val, None)
|
|
30
30
|
if expected is None:
|
|
@@ -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 numpy as np
|
|
16
18
|
import pytest
|
|
17
19
|
import sympy
|
|
@@ -35,7 +37,7 @@ class BadGateDecompose(cirq.testing.SingleQubitGate):
|
|
|
35
37
|
return np.array([[0, 1], [1, 0]])
|
|
36
38
|
|
|
37
39
|
|
|
38
|
-
def test_assert_decompose_is_consistent_with_unitary():
|
|
40
|
+
def test_assert_decompose_is_consistent_with_unitary() -> None:
|
|
39
41
|
cirq.testing.assert_decompose_is_consistent_with_unitary(GoodGateDecompose())
|
|
40
42
|
|
|
41
43
|
cirq.testing.assert_decompose_is_consistent_with_unitary(
|
|
@@ -89,7 +91,7 @@ class ParameterizedGate(cirq.Gate):
|
|
|
89
91
|
yield cirq.Y(qubits[1]) ** sympy.Symbol("y")
|
|
90
92
|
|
|
91
93
|
|
|
92
|
-
def test_assert_decompose_ends_at_default_gateset():
|
|
94
|
+
def test_assert_decompose_ends_at_default_gateset() -> None:
|
|
93
95
|
cirq.testing.assert_decompose_ends_at_default_gateset(GateDecomposesToDefaultGateset())
|
|
94
96
|
cirq.testing.assert_decompose_ends_at_default_gateset(
|
|
95
97
|
GateDecomposesToDefaultGateset().on(*cirq.LineQubit.range(2))
|
|
@@ -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 numpy as np
|
|
16
18
|
import pytest
|
|
17
19
|
|
|
@@ -52,7 +54,7 @@ class BadGateInconsistentPauliExpansion(cirq.testing.SingleQubitGate):
|
|
|
52
54
|
return cirq.LinearDict({'X': np.sqrt(1 / 6), 'Y': np.sqrt(1 / 3), 'Z': np.sqrt(1 / 2)})
|
|
53
55
|
|
|
54
56
|
|
|
55
|
-
def test_assert_pauli_expansion_is_consistent_with_unitary():
|
|
57
|
+
def test_assert_pauli_expansion_is_consistent_with_unitary() -> None:
|
|
56
58
|
cirq.testing.assert_pauli_expansion_is_consistent_with_unitary(GoodGateExplicitPauliExpansion())
|
|
57
59
|
cirq.testing.assert_pauli_expansion_is_consistent_with_unitary(GoodGateNoPauliExpansion())
|
|
58
60
|
cirq.testing.assert_pauli_expansion_is_consistent_with_unitary(GoodGateNoUnitary())
|
|
@@ -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 numpy as np
|
|
16
18
|
import pytest
|
|
17
19
|
|
|
@@ -89,7 +91,7 @@ class SemiBadPhaser:
|
|
|
89
91
|
return SemiBadPhaser([resolver.value_of(val, recursive) for val in self.e])
|
|
90
92
|
|
|
91
93
|
|
|
92
|
-
def test_assert_phase_by_is_consistent_with_unitary():
|
|
94
|
+
def test_assert_phase_by_is_consistent_with_unitary() -> None:
|
|
93
95
|
cirq.testing.assert_phase_by_is_consistent_with_unitary(GoodPhaser(0.5))
|
|
94
96
|
|
|
95
97
|
cirq.testing.assert_phase_by_is_consistent_with_unitary(GoodQuditPhaser(0.5))
|
|
@@ -12,8 +12,10 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
15
17
|
import itertools
|
|
16
|
-
from typing import Any,
|
|
18
|
+
from typing import Any, Sequence
|
|
17
19
|
|
|
18
20
|
import numpy as np
|
|
19
21
|
import sympy
|
|
@@ -47,11 +49,11 @@ def assert_implements_consistent_protocols(
|
|
|
47
49
|
val: Any,
|
|
48
50
|
*,
|
|
49
51
|
exponents: Sequence[Any] = (0, 1, -1, 0.25, sympy.Symbol('s')),
|
|
50
|
-
qubit_count:
|
|
52
|
+
qubit_count: int | None = None,
|
|
51
53
|
ignoring_global_phase: bool = False,
|
|
52
54
|
setup_code: str = 'import cirq\nimport numpy as np\nimport sympy',
|
|
53
|
-
global_vals:
|
|
54
|
-
local_vals:
|
|
55
|
+
global_vals: dict[str, Any] | None = None,
|
|
56
|
+
local_vals: dict[str, Any] | None = None,
|
|
55
57
|
ignore_decompose_to_default_gateset: bool = False,
|
|
56
58
|
) -> None:
|
|
57
59
|
"""Checks that a value is internally consistent and has a good __repr__."""
|
|
@@ -81,22 +83,20 @@ def assert_implements_consistent_protocols(
|
|
|
81
83
|
|
|
82
84
|
|
|
83
85
|
def assert_eigengate_implements_consistent_protocols(
|
|
84
|
-
eigen_gate_type:
|
|
86
|
+
eigen_gate_type: type[ops.EigenGate],
|
|
85
87
|
*,
|
|
86
88
|
exponents: Sequence[value.TParamVal] = (0, 1, -1, 0.25, sympy.Symbol('s')),
|
|
87
89
|
global_shifts: Sequence[float] = (0, -0.5, 0.1),
|
|
88
|
-
qubit_count:
|
|
90
|
+
qubit_count: int | None = None,
|
|
89
91
|
ignoring_global_phase: bool = False,
|
|
90
92
|
setup_code: str = 'import cirq\nimport numpy as np\nimport sympy',
|
|
91
|
-
global_vals:
|
|
92
|
-
local_vals:
|
|
93
|
+
global_vals: dict[str, Any] | None = None,
|
|
94
|
+
local_vals: dict[str, Any] | None = None,
|
|
93
95
|
ignore_decompose_to_default_gateset: bool = False,
|
|
94
96
|
) -> None:
|
|
95
97
|
"""Checks that an EigenGate subclass is internally consistent and has a
|
|
96
98
|
good __repr__."""
|
|
97
|
-
# pylint: disable=unused-variable
|
|
98
99
|
__tracebackhide__ = True
|
|
99
|
-
# pylint: enable=unused-variable
|
|
100
100
|
|
|
101
101
|
for exponent in exponents:
|
|
102
102
|
for shift in global_shifts:
|
|
@@ -111,9 +111,7 @@ def assert_eigengate_implements_consistent_protocols(
|
|
|
111
111
|
|
|
112
112
|
|
|
113
113
|
def assert_eigen_shifts_is_consistent_with_eigen_components(val: ops.EigenGate) -> None:
|
|
114
|
-
# pylint: disable=unused-variable
|
|
115
114
|
__tracebackhide__ = True
|
|
116
|
-
# pylint: enable=unused-variable
|
|
117
115
|
if not protocols.is_parameterized(val):
|
|
118
116
|
assert val._eigen_shifts() == [
|
|
119
117
|
e[0] for e in val._eigen_components()
|
|
@@ -121,9 +119,7 @@ def assert_eigen_shifts_is_consistent_with_eigen_components(val: ops.EigenGate)
|
|
|
121
119
|
|
|
122
120
|
|
|
123
121
|
def assert_has_consistent_trace_distance_bound(val: Any) -> None:
|
|
124
|
-
# pylint: disable=unused-variable
|
|
125
122
|
__tracebackhide__ = True
|
|
126
|
-
# pylint: enable=unused-variable
|
|
127
123
|
u = protocols.unitary(val, default=None)
|
|
128
124
|
val_from_trace = protocols.trace_distance_bound(val)
|
|
129
125
|
assert 0.0 <= val_from_trace <= 1.0
|
|
@@ -143,11 +139,11 @@ def _assert_meets_standards_helper(
|
|
|
143
139
|
*,
|
|
144
140
|
ignoring_global_phase: bool,
|
|
145
141
|
setup_code: str,
|
|
146
|
-
global_vals:
|
|
147
|
-
local_vals:
|
|
142
|
+
global_vals: dict[str, Any] | None,
|
|
143
|
+
local_vals: dict[str, Any] | None,
|
|
148
144
|
ignore_decompose_to_default_gateset: bool,
|
|
149
145
|
) -> None:
|
|
150
|
-
__tracebackhide__ = True
|
|
146
|
+
__tracebackhide__ = True
|
|
151
147
|
|
|
152
148
|
assert_consistent_resolve_parameters(val)
|
|
153
149
|
assert_specifies_has_unitary_if_unitary(val)
|
|
@@ -174,9 +170,7 @@ def _assert_meets_standards_helper(
|
|
|
174
170
|
assert_controlled_unitary_consistent(val)
|
|
175
171
|
|
|
176
172
|
|
|
177
|
-
def assert_commutes_magic_method_consistent_with_unitaries(
|
|
178
|
-
*vals: Sequence[Any], atol: float = 1e-8
|
|
179
|
-
) -> None:
|
|
173
|
+
def assert_commutes_magic_method_consistent_with_unitaries(*vals: Any, atol: float = 1e-8) -> None:
|
|
180
174
|
if any(isinstance(val, ops.Operation) for val in vals):
|
|
181
175
|
raise TypeError('`_commutes_` need not be consistent with unitaries for `Operation`.')
|
|
182
176
|
unitaries = [protocols.unitary(val, None) for val in vals]
|
|
@@ -12,8 +12,10 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
15
17
|
from types import NotImplementedType
|
|
16
|
-
from typing import AbstractSet,
|
|
18
|
+
from typing import AbstractSet, Sequence
|
|
17
19
|
|
|
18
20
|
import numpy as np
|
|
19
21
|
import pytest
|
|
@@ -26,7 +28,7 @@ from cirq._compat import proper_repr
|
|
|
26
28
|
|
|
27
29
|
class GoodGate(cirq.testing.SingleQubitGate):
|
|
28
30
|
def __init__(
|
|
29
|
-
self, *, phase_exponent:
|
|
31
|
+
self, *, phase_exponent: float | sympy.Expr, exponent: float | sympy.Expr = 1.0
|
|
30
32
|
) -> None:
|
|
31
33
|
self.phase_exponent = cirq.canonicalize_half_turns(phase_exponent)
|
|
32
34
|
self.exponent = exponent
|
|
@@ -34,14 +36,14 @@ class GoodGate(cirq.testing.SingleQubitGate):
|
|
|
34
36
|
def _has_unitary_(self):
|
|
35
37
|
return not cirq.is_parameterized(self)
|
|
36
38
|
|
|
37
|
-
def _unitary_(self) ->
|
|
39
|
+
def _unitary_(self) -> np.ndarray | NotImplementedType:
|
|
38
40
|
if cirq.is_parameterized(self):
|
|
39
41
|
return NotImplemented
|
|
40
42
|
z = cirq.unitary(cirq.Z**self.phase_exponent)
|
|
41
43
|
x = cirq.unitary(cirq.X**self.exponent)
|
|
42
44
|
return np.dot(np.dot(z, x), np.conj(z))
|
|
43
45
|
|
|
44
|
-
def _apply_unitary_(self, args: cirq.ApplyUnitaryArgs) ->
|
|
46
|
+
def _apply_unitary_(self, args: cirq.ApplyUnitaryArgs) -> np.ndarray | NotImplementedType:
|
|
45
47
|
if self.exponent != 1 or cirq.is_parameterized(self):
|
|
46
48
|
return NotImplemented
|
|
47
49
|
|
|
@@ -83,7 +85,7 @@ class GoodGate(cirq.testing.SingleQubitGate):
|
|
|
83
85
|
exponent=self.exponent, phase_exponent=self.phase_exponent + phase_turns * 2
|
|
84
86
|
)
|
|
85
87
|
|
|
86
|
-
def __pow__(self, exponent:
|
|
88
|
+
def __pow__(self, exponent: float | sympy.Expr) -> GoodGate:
|
|
87
89
|
new_exponent = cirq.mul(self.exponent, exponent, NotImplemented)
|
|
88
90
|
if new_exponent is NotImplemented:
|
|
89
91
|
return NotImplemented # pragma: no cover
|
|
@@ -101,7 +103,7 @@ class GoodGate(cirq.testing.SingleQubitGate):
|
|
|
101
103
|
def _parameter_names_(self) -> AbstractSet[str]:
|
|
102
104
|
return cirq.parameter_names(self.exponent) | cirq.parameter_names(self.phase_exponent)
|
|
103
105
|
|
|
104
|
-
def _resolve_parameters_(self, resolver, recursive) ->
|
|
106
|
+
def _resolve_parameters_(self, resolver, recursive) -> GoodGate:
|
|
105
107
|
return GoodGate(
|
|
106
108
|
phase_exponent=resolver.value_of(self.phase_exponent, recursive),
|
|
107
109
|
exponent=resolver.value_of(self.exponent, recursive),
|
|
@@ -127,7 +129,7 @@ class BadGateParameterNames(GoodGate):
|
|
|
127
129
|
|
|
128
130
|
|
|
129
131
|
class BadGateApplyUnitaryToTensor(GoodGate):
|
|
130
|
-
def _apply_unitary_(self, args: cirq.ApplyUnitaryArgs) ->
|
|
132
|
+
def _apply_unitary_(self, args: cirq.ApplyUnitaryArgs) -> np.ndarray | NotImplementedType:
|
|
131
133
|
if self.exponent != 1 or cirq.is_parameterized(self):
|
|
132
134
|
return NotImplemented # pragma: no cover
|
|
133
135
|
|
|
@@ -176,7 +178,7 @@ class BadGateRepr(GoodGate):
|
|
|
176
178
|
|
|
177
179
|
|
|
178
180
|
class GoodEigenGate(cirq.EigenGate, cirq.testing.SingleQubitGate):
|
|
179
|
-
def _eigen_components(self) ->
|
|
181
|
+
def _eigen_components(self) -> list[tuple[float, np.ndarray]]:
|
|
180
182
|
return [(0, np.diag([1, 0])), (1, np.diag([0, 1]))]
|
|
181
183
|
|
|
182
184
|
def __repr__(self):
|
|
@@ -199,7 +201,7 @@ class BadEigenGate(GoodEigenGate):
|
|
|
199
201
|
)
|
|
200
202
|
|
|
201
203
|
|
|
202
|
-
def test_assert_implements_consistent_protocols():
|
|
204
|
+
def test_assert_implements_consistent_protocols() -> None:
|
|
203
205
|
cirq.testing.assert_implements_consistent_protocols(
|
|
204
206
|
GoodGate(phase_exponent=0.0), global_vals={'GoodGate': GoodGate}
|
|
205
207
|
)
|
|
@@ -247,7 +249,7 @@ def test_assert_implements_consistent_protocols():
|
|
|
247
249
|
cirq.testing.assert_implements_consistent_protocols(controlled_gate_op_test.BadGate())
|
|
248
250
|
|
|
249
251
|
|
|
250
|
-
def test_assert_eigengate_implements_consistent_protocols():
|
|
252
|
+
def test_assert_eigengate_implements_consistent_protocols() -> None:
|
|
251
253
|
cirq.testing.assert_eigengate_implements_consistent_protocols(
|
|
252
254
|
GoodEigenGate,
|
|
253
255
|
global_vals={'GoodEigenGate': GoodEigenGate},
|
|
@@ -262,7 +264,7 @@ def test_assert_eigengate_implements_consistent_protocols():
|
|
|
262
264
|
)
|
|
263
265
|
|
|
264
266
|
|
|
265
|
-
def test_assert_commutes_magic_method_consistent_with_unitaries():
|
|
267
|
+
def test_assert_commutes_magic_method_consistent_with_unitaries() -> None:
|
|
266
268
|
gate_op = cirq.CNOT(*cirq.LineQubit.range(2))
|
|
267
269
|
with pytest.raises(TypeError):
|
|
268
270
|
cirq.testing.assert_commutes_magic_method_consistent_with_unitaries(gate_op)
|
cirq/testing/consistent_qasm.py
CHANGED
|
@@ -12,8 +12,10 @@
|
|
|
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 warnings
|
|
16
|
-
from typing import Any,
|
|
18
|
+
from typing import Any, Sequence
|
|
17
19
|
|
|
18
20
|
import numpy as np
|
|
19
21
|
|
|
@@ -85,8 +87,8 @@ qreg q[{num_qubits}];
|
|
|
85
87
|
qasm_unitary, unitary, rtol=1e-8, atol=1e-8
|
|
86
88
|
)
|
|
87
89
|
except Exception as ex:
|
|
88
|
-
p_unitary:
|
|
89
|
-
p_qasm_unitary:
|
|
90
|
+
p_unitary: np.ndarray | None
|
|
91
|
+
p_qasm_unitary: np.ndarray | None
|
|
90
92
|
if qasm_unitary is not None:
|
|
91
93
|
p_unitary, p_qasm_unitary = linalg.match_global_phase(unitary, qasm_unitary)
|
|
92
94
|
else:
|
|
@@ -125,7 +127,7 @@ def _indent(*content: str) -> str:
|
|
|
125
127
|
return ' ' + '\n'.join(content).replace('\n', '\n ')
|
|
126
128
|
|
|
127
129
|
|
|
128
|
-
def _reorder_indices_of_matrix(matrix: np.ndarray, new_order:
|
|
130
|
+
def _reorder_indices_of_matrix(matrix: np.ndarray, new_order: list[int]):
|
|
129
131
|
num_qubits = matrix.shape[0].bit_length() - 1
|
|
130
132
|
matrix = np.reshape(matrix, (2,) * 2 * num_qubits)
|
|
131
133
|
all_indices = range(2 * num_qubits)
|
|
@@ -12,8 +12,10 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import importlib.util
|
|
15
18
|
import warnings
|
|
16
|
-
from typing import Tuple
|
|
17
19
|
|
|
18
20
|
import numpy as np
|
|
19
21
|
import pytest
|
|
@@ -41,20 +43,18 @@ class Fixed(cirq.Operation):
|
|
|
41
43
|
|
|
42
44
|
|
|
43
45
|
class QuditGate(cirq.Gate):
|
|
44
|
-
def _qid_shape_(self) ->
|
|
46
|
+
def _qid_shape_(self) -> tuple[int, ...]:
|
|
45
47
|
return (3, 3)
|
|
46
48
|
|
|
47
49
|
def _unitary_(self):
|
|
48
50
|
return np.eye(9)
|
|
49
51
|
|
|
50
|
-
def _qasm_(self, args: cirq.QasmArgs, qubits:
|
|
52
|
+
def _qasm_(self, args: cirq.QasmArgs, qubits: tuple[cirq.Qid, ...]):
|
|
51
53
|
return NotImplemented
|
|
52
54
|
|
|
53
55
|
|
|
54
|
-
def test_assert_qasm_is_consistent_with_unitary():
|
|
55
|
-
|
|
56
|
-
import qiskit as _
|
|
57
|
-
except ImportError: # pragma: no cover
|
|
56
|
+
def test_assert_qasm_is_consistent_with_unitary() -> None:
|
|
57
|
+
if importlib.util.find_spec('qiskit') is None: # pragma: no cover
|
|
58
58
|
warnings.warn(
|
|
59
59
|
"Skipped test_assert_qasm_is_consistent_with_unitary "
|
|
60
60
|
"because qiskit isn't installed to verify against."
|
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
15
17
|
from typing import Any
|
|
16
18
|
|
|
17
19
|
from cirq import protocols
|
|
@@ -20,9 +22,7 @@ from cirq import protocols
|
|
|
20
22
|
def assert_specifies_has_unitary_if_unitary(val: Any) -> None:
|
|
21
23
|
"""Checks that unitary values can be cheaply identifies as unitary."""
|
|
22
24
|
|
|
23
|
-
# pylint: disable=unused-variable
|
|
24
25
|
__tracebackhide__ = True
|
|
25
|
-
# pylint: enable=unused-variable
|
|
26
26
|
|
|
27
27
|
assert not protocols.has_unitary(val) or hasattr(val, '_has_unitary_'), (
|
|
28
28
|
"Value is unitary but doesn't specify a _has_unitary_ method that "
|
|
@@ -12,13 +12,15 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
15
17
|
import numpy as np
|
|
16
18
|
import pytest
|
|
17
19
|
|
|
18
20
|
import cirq
|
|
19
21
|
|
|
20
22
|
|
|
21
|
-
def test_assert_specifies_has_unitary_if_unitary_from_matrix():
|
|
23
|
+
def test_assert_specifies_has_unitary_if_unitary_from_matrix() -> None:
|
|
22
24
|
class Bad:
|
|
23
25
|
def _unitary_(self):
|
|
24
26
|
return np.array([[1]])
|
|
@@ -28,7 +30,7 @@ def test_assert_specifies_has_unitary_if_unitary_from_matrix():
|
|
|
28
30
|
cirq.testing.assert_specifies_has_unitary_if_unitary(Bad())
|
|
29
31
|
|
|
30
32
|
|
|
31
|
-
def test_assert_specifies_has_unitary_if_unitary_from_apply():
|
|
33
|
+
def test_assert_specifies_has_unitary_if_unitary_from_apply() -> None:
|
|
32
34
|
class Bad(cirq.Operation):
|
|
33
35
|
@property
|
|
34
36
|
def qubits(self):
|
|
@@ -45,7 +47,7 @@ def test_assert_specifies_has_unitary_if_unitary_from_apply():
|
|
|
45
47
|
cirq.testing.assert_specifies_has_unitary_if_unitary(Bad())
|
|
46
48
|
|
|
47
49
|
|
|
48
|
-
def test_assert_specifies_has_unitary_if_unitary_from_decompose():
|
|
50
|
+
def test_assert_specifies_has_unitary_if_unitary_from_decompose() -> None:
|
|
49
51
|
class Bad:
|
|
50
52
|
def _decompose_(self):
|
|
51
53
|
return []
|
|
@@ -70,7 +72,7 @@ def test_assert_specifies_has_unitary_if_unitary_from_decompose():
|
|
|
70
72
|
cirq.testing.assert_specifies_has_unitary_if_unitary(Okay())
|
|
71
73
|
|
|
72
74
|
|
|
73
|
-
def test_assert_specifies_has_unitary_if_unitary_pass():
|
|
75
|
+
def test_assert_specifies_has_unitary_if_unitary_pass() -> None:
|
|
74
76
|
class Good:
|
|
75
77
|
def _has_unitary_(self):
|
|
76
78
|
return True
|
|
@@ -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 numpy as np
|
|
16
18
|
import pytest
|
|
17
19
|
|
|
@@ -78,7 +80,7 @@ class CleanCorrectButBorrowableIncorrectGate(cirq.Gate):
|
|
|
78
80
|
(CleanCorrectButBorrowableIncorrectGate(use_clean_ancilla=False), False),
|
|
79
81
|
],
|
|
80
82
|
)
|
|
81
|
-
def test_assert_unitary_is_consistent(g, ignore_phase, is_consistent):
|
|
83
|
+
def test_assert_unitary_is_consistent(g, ignore_phase, is_consistent) -> None:
|
|
82
84
|
if is_consistent:
|
|
83
85
|
cirq.testing.assert_unitary_is_consistent(g, ignore_phase)
|
|
84
86
|
cirq.testing.assert_unitary_is_consistent(g.on(*cirq.LineQid.for_gate(g)), ignore_phase)
|
|
@@ -89,7 +91,7 @@ def test_assert_unitary_is_consistent(g, ignore_phase, is_consistent):
|
|
|
89
91
|
cirq.testing.assert_unitary_is_consistent(g.on(*cirq.LineQid.for_gate(g)), ignore_phase)
|
|
90
92
|
|
|
91
93
|
|
|
92
|
-
def test_failed_decomposition():
|
|
94
|
+
def test_failed_decomposition() -> None:
|
|
93
95
|
with pytest.raises(ValueError):
|
|
94
96
|
cirq.testing.assert_unitary_is_consistent(FailsOnDecompostion())
|
|
95
97
|
|