cirq-core 1.5.0.dev20250409225226__py3-none-any.whl → 1.6.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of cirq-core might be problematic. Click here for more details.
- cirq/__init__.py +16 -17
- cirq/_compat.py +21 -20
- cirq/_compat_test.py +14 -34
- cirq/_doc.py +4 -2
- cirq/_import.py +8 -6
- cirq/_import_test.py +4 -2
- cirq/_version.py +6 -6
- cirq/_version_test.py +2 -2
- cirq/circuits/_block_diagram_drawer.py +11 -10
- cirq/circuits/_block_diagram_drawer_test.py +8 -6
- cirq/circuits/_box_drawing_character_data.py +8 -8
- cirq/circuits/_box_drawing_character_data_test.py +3 -1
- cirq/circuits/_bucket_priority_queue.py +9 -7
- cirq/circuits/_bucket_priority_queue_test.py +22 -20
- cirq/circuits/circuit.py +248 -172
- cirq/circuits/circuit_operation.py +73 -83
- cirq/circuits/circuit_operation_test.py +128 -90
- cirq/circuits/circuit_test.py +211 -151
- cirq/circuits/frozen_circuit.py +23 -60
- cirq/circuits/frozen_circuit_test.py +31 -8
- cirq/circuits/insert_strategy.py +7 -5
- cirq/circuits/insert_strategy_test.py +4 -2
- cirq/circuits/moment.py +88 -40
- cirq/circuits/moment_test.py +128 -51
- cirq/circuits/optimization_pass.py +5 -5
- cirq/circuits/optimization_pass_test.py +10 -10
- cirq/circuits/qasm_output.py +11 -11
- cirq/circuits/qasm_output_test.py +25 -22
- cirq/circuits/text_diagram_drawer.py +23 -38
- cirq/circuits/text_diagram_drawer_test.py +19 -17
- cirq/conftest.py +4 -3
- cirq/contrib/__init__.py +4 -4
- cirq/contrib/acquaintance/__init__.py +1 -1
- cirq/contrib/acquaintance/bipartite.py +5 -8
- cirq/contrib/acquaintance/bipartite_test.py +18 -13
- cirq/contrib/acquaintance/devices.py +2 -2
- cirq/contrib/acquaintance/devices_test.py +5 -3
- cirq/contrib/acquaintance/executor.py +5 -5
- cirq/contrib/acquaintance/executor_test.py +13 -9
- cirq/contrib/acquaintance/gates.py +18 -28
- cirq/contrib/acquaintance/gates_test.py +24 -20
- cirq/contrib/acquaintance/inspection_utils.py +8 -4
- cirq/contrib/acquaintance/inspection_utils_test.py +4 -2
- cirq/contrib/acquaintance/mutation_utils.py +4 -4
- cirq/contrib/acquaintance/mutation_utils_test.py +4 -2
- cirq/contrib/acquaintance/optimizers.py +4 -4
- cirq/contrib/acquaintance/optimizers_test.py +4 -1
- cirq/contrib/acquaintance/permutation.py +15 -27
- cirq/contrib/acquaintance/permutation_test.py +26 -17
- cirq/contrib/acquaintance/shift.py +4 -4
- cirq/contrib/acquaintance/shift_swap_network.py +4 -4
- cirq/contrib/acquaintance/shift_swap_network_test.py +9 -6
- cirq/contrib/acquaintance/shift_test.py +8 -6
- cirq/contrib/acquaintance/strategies/cubic.py +2 -2
- cirq/contrib/acquaintance/strategies/cubic_test.py +4 -2
- cirq/contrib/acquaintance/strategies/quartic_paired.py +6 -6
- cirq/contrib/acquaintance/strategies/quartic_paired_test.py +10 -6
- cirq/contrib/acquaintance/testing.py +2 -0
- cirq/contrib/acquaintance/topological_sort.py +2 -2
- cirq/contrib/acquaintance/topological_sort_test.py +3 -1
- cirq/contrib/bayesian_network/bayesian_network_gate.py +9 -10
- cirq/contrib/bayesian_network/bayesian_network_gate_test.py +14 -9
- cirq/contrib/circuitdag/circuit_dag.py +4 -4
- cirq/contrib/circuitdag/circuit_dag_test.py +17 -15
- cirq/contrib/custom_simulators/custom_state_simulator.py +5 -5
- cirq/contrib/custom_simulators/custom_state_simulator_test.py +22 -17
- cirq/contrib/graph_device/graph_device.py +12 -11
- cirq/contrib/graph_device/graph_device_test.py +18 -14
- cirq/contrib/graph_device/hypergraph.py +16 -14
- cirq/contrib/graph_device/hypergraph_test.py +13 -11
- cirq/contrib/graph_device/uniform_graph_device.py +6 -4
- cirq/contrib/graph_device/uniform_graph_device_test.py +11 -3
- cirq/contrib/hacks/disable_validation.py +6 -1
- cirq/contrib/hacks/disable_validation_test.py +3 -1
- cirq/contrib/json.py +31 -5
- cirq/contrib/json_test.py +6 -3
- cirq/contrib/json_test_data/DampedReadoutNoiseModel.json +12 -0
- cirq/contrib/json_test_data/DampedReadoutNoiseModel.repr +4 -0
- cirq/contrib/json_test_data/DepolarizingNoiseModel.json +12 -0
- cirq/contrib/json_test_data/DepolarizingNoiseModel.repr +4 -0
- cirq/contrib/json_test_data/DepolarizingWithDampedReadoutNoiseModel.json +6 -0
- cirq/contrib/json_test_data/DepolarizingWithDampedReadoutNoiseModel.repr +1 -0
- cirq/contrib/json_test_data/DepolarizingWithReadoutNoiseModel.json +5 -0
- cirq/contrib/json_test_data/DepolarizingWithReadoutNoiseModel.repr +1 -0
- cirq/contrib/json_test_data/ReadoutNoiseModel.json +12 -0
- cirq/contrib/json_test_data/ReadoutNoiseModel.repr +4 -0
- cirq/contrib/json_test_data/__init__.py +17 -0
- cirq/contrib/json_test_data/spec.py +32 -0
- cirq/contrib/noise_models/noise_models.py +119 -5
- cirq/contrib/noise_models/noise_models_test.py +37 -9
- cirq/contrib/paulistring/clifford_optimize.py +6 -4
- cirq/contrib/paulistring/clifford_optimize_test.py +6 -5
- cirq/contrib/paulistring/clifford_target_gateset.py +10 -10
- cirq/contrib/paulistring/clifford_target_gateset_test.py +13 -11
- cirq/contrib/paulistring/optimize.py +2 -0
- cirq/contrib/paulistring/optimize_test.py +4 -3
- cirq/contrib/paulistring/pauli_string_dag.py +2 -0
- cirq/contrib/paulistring/pauli_string_dag_test.py +3 -1
- cirq/contrib/paulistring/pauli_string_measurement_with_readout_mitigation.py +255 -120
- cirq/contrib/paulistring/pauli_string_measurement_with_readout_mitigation_test.py +398 -19
- cirq/contrib/paulistring/pauli_string_optimize.py +7 -1
- cirq/contrib/paulistring/pauli_string_optimize_test.py +5 -3
- cirq/contrib/paulistring/recombine.py +6 -4
- cirq/contrib/paulistring/recombine_test.py +3 -1
- cirq/contrib/paulistring/separate.py +9 -6
- cirq/contrib/paulistring/separate_test.py +3 -1
- cirq/contrib/qasm_import/_lexer.py +3 -2
- cirq/contrib/qasm_import/_lexer_test.py +49 -13
- cirq/contrib/qasm_import/_parser.py +547 -83
- cirq/contrib/qasm_import/_parser_test.py +988 -97
- cirq/contrib/qasm_import/exception.py +2 -0
- cirq/contrib/qasm_import/qasm.py +8 -2
- cirq/contrib/qasm_import/qasm_test.py +7 -4
- cirq/contrib/qcircuit/qcircuit_diagram_info.py +5 -5
- cirq/contrib/qcircuit/qcircuit_diagram_info_test.py +4 -1
- cirq/contrib/qcircuit/qcircuit_pdf.py +7 -3
- cirq/contrib/qcircuit/qcircuit_pdf_test.py +3 -1
- cirq/contrib/qcircuit/qcircuit_test.py +10 -8
- cirq/contrib/quantum_volume/quantum_volume.py +31 -27
- cirq/contrib/quantum_volume/quantum_volume_test.py +19 -16
- cirq/contrib/quimb/density_matrix.py +15 -14
- cirq/contrib/quimb/density_matrix_test.py +10 -7
- cirq/contrib/quimb/grid_circuits.py +5 -2
- cirq/contrib/quimb/grid_circuits_test.py +3 -0
- cirq/contrib/quimb/mps_simulator.py +20 -20
- cirq/contrib/quimb/mps_simulator_test.py +3 -0
- cirq/contrib/quimb/state_vector.py +12 -11
- cirq/contrib/quimb/state_vector_test.py +3 -0
- cirq/contrib/quirk/export_to_quirk.py +5 -3
- cirq/contrib/quirk/export_to_quirk_test.py +18 -16
- cirq/contrib/quirk/linearize_circuit.py +2 -0
- cirq/contrib/quirk/quirk_gate.py +18 -17
- cirq/contrib/routing/device.py +5 -3
- cirq/contrib/routing/device_test.py +2 -0
- cirq/contrib/routing/greedy.py +10 -21
- cirq/contrib/routing/greedy_test.py +4 -2
- cirq/contrib/routing/initialization.py +2 -2
- cirq/contrib/routing/initialization_test.py +5 -3
- cirq/contrib/routing/router.py +9 -5
- cirq/contrib/routing/router_test.py +2 -0
- cirq/contrib/routing/swap_network.py +3 -3
- cirq/contrib/routing/swap_network_test.py +3 -1
- cirq/contrib/routing/utils.py +2 -2
- cirq/contrib/routing/utils_test.py +3 -0
- cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking.py +15 -9
- cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking_test.py +3 -0
- cirq/contrib/svg/svg.py +3 -3
- cirq/contrib/svg/svg_test.py +8 -5
- cirq/devices/device.py +4 -4
- cirq/devices/device_test.py +7 -4
- cirq/devices/grid_device_metadata.py +10 -10
- cirq/devices/grid_device_metadata_test.py +3 -0
- cirq/devices/grid_qubit.py +29 -21
- cirq/devices/grid_qubit_test.py +3 -0
- cirq/devices/insertion_noise_model.py +7 -7
- cirq/devices/insertion_noise_model_test.py +7 -5
- cirq/devices/line_qubit.py +13 -13
- cirq/devices/line_qubit_test.py +2 -0
- cirq/devices/named_topologies.py +18 -29
- cirq/devices/named_topologies_test.py +13 -10
- cirq/devices/noise_model.py +3 -3
- cirq/devices/noise_model_test.py +19 -15
- cirq/devices/noise_properties.py +15 -6
- cirq/devices/noise_properties_test.py +34 -3
- cirq/devices/noise_utils.py +11 -9
- cirq/devices/noise_utils_test.py +2 -0
- cirq/devices/superconducting_qubits_noise_properties.py +23 -22
- cirq/devices/superconducting_qubits_noise_properties_test.py +6 -6
- cirq/devices/thermal_noise_model.py +107 -37
- cirq/devices/thermal_noise_model_test.py +21 -0
- cirq/devices/unconstrained_device.py +5 -3
- cirq/devices/unconstrained_device_test.py +2 -0
- cirq/experiments/__init__.py +4 -2
- cirq/experiments/benchmarking/__init__.py +17 -0
- cirq/experiments/benchmarking/parallel_xeb.py +677 -0
- cirq/experiments/benchmarking/parallel_xeb_test.py +447 -0
- cirq/experiments/fidelity_estimation.py +14 -8
- cirq/experiments/fidelity_estimation_test.py +3 -0
- cirq/experiments/n_qubit_tomography.py +17 -16
- cirq/experiments/n_qubit_tomography_test.py +8 -5
- cirq/experiments/purity_estimation.py +2 -0
- cirq/experiments/purity_estimation_test.py +2 -0
- cirq/experiments/qubit_characterizations.py +207 -103
- cirq/experiments/qubit_characterizations_test.py +40 -12
- cirq/experiments/random_quantum_circuit_generation.py +56 -70
- cirq/experiments/random_quantum_circuit_generation_test.py +11 -8
- cirq/experiments/readout_confusion_matrix.py +24 -22
- cirq/experiments/readout_confusion_matrix_test.py +2 -0
- cirq/experiments/single_qubit_readout_calibration.py +30 -15
- cirq/experiments/single_qubit_readout_calibration_test.py +5 -2
- cirq/experiments/t1_decay_experiment.py +9 -7
- cirq/experiments/t1_decay_experiment_test.py +13 -11
- cirq/experiments/t2_decay_experiment.py +16 -13
- cirq/experiments/t2_decay_experiment_test.py +2 -0
- cirq/experiments/two_qubit_xeb.py +64 -57
- cirq/experiments/two_qubit_xeb_test.py +10 -6
- cirq/experiments/xeb_fitting.py +39 -35
- cirq/experiments/xeb_sampling.py +37 -44
- cirq/experiments/xeb_sampling_test.py +3 -0
- cirq/experiments/xeb_simulation.py +14 -10
- cirq/experiments/xeb_simulation_test.py +5 -5
- cirq/experiments/z_phase_calibration.py +32 -29
- cirq/experiments/z_phase_calibration_test.py +3 -4
- cirq/interop/quirk/cells/__init__.py +1 -1
- cirq/interop/quirk/cells/all_cells.py +7 -2
- cirq/interop/quirk/cells/arithmetic_cells.py +29 -41
- cirq/interop/quirk/cells/arithmetic_cells_test.py +17 -14
- cirq/interop/quirk/cells/cell.py +19 -28
- cirq/interop/quirk/cells/cell_test.py +3 -0
- cirq/interop/quirk/cells/composite_cell.py +13 -28
- cirq/interop/quirk/cells/composite_cell_test.py +2 -0
- cirq/interop/quirk/cells/control_cells.py +15 -15
- cirq/interop/quirk/cells/control_cells_test.py +7 -5
- cirq/interop/quirk/cells/frequency_space_cells.py +4 -3
- cirq/interop/quirk/cells/frequency_space_cells_test.py +3 -1
- cirq/interop/quirk/cells/ignored_cells.py +3 -0
- cirq/interop/quirk/cells/ignored_cells_test.py +3 -1
- cirq/interop/quirk/cells/input_cells.py +7 -5
- cirq/interop/quirk/cells/input_cells_test.py +7 -5
- cirq/interop/quirk/cells/input_rotation_cells.py +15 -13
- cirq/interop/quirk/cells/input_rotation_cells_test.py +9 -7
- cirq/interop/quirk/cells/measurement_cells.py +5 -2
- cirq/interop/quirk/cells/measurement_cells_test.py +3 -1
- cirq/interop/quirk/cells/parse.py +22 -23
- cirq/interop/quirk/cells/parse_test.py +12 -10
- cirq/interop/quirk/cells/qubit_permutation_cells.py +5 -3
- cirq/interop/quirk/cells/qubit_permutation_cells_test.py +9 -7
- cirq/interop/quirk/cells/scalar_cells.py +4 -1
- cirq/interop/quirk/cells/scalar_cells_test.py +3 -1
- cirq/interop/quirk/cells/single_qubit_rotation_cells.py +5 -2
- cirq/interop/quirk/cells/single_qubit_rotation_cells_test.py +5 -3
- cirq/interop/quirk/cells/swap_cell.py +8 -6
- cirq/interop/quirk/cells/swap_cell_test.py +6 -4
- cirq/interop/quirk/cells/testing.py +6 -6
- cirq/interop/quirk/cells/testing_test.py +8 -6
- cirq/interop/quirk/cells/unsupported_cells.py +3 -0
- cirq/interop/quirk/cells/unsupported_cells_test.py +4 -2
- cirq/interop/quirk/url_to_circuit.py +23 -36
- cirq/interop/quirk/url_to_circuit_test.py +4 -1
- cirq/json_resolver_cache.py +14 -12
- cirq/linalg/__init__.py +4 -6
- cirq/linalg/combinators.py +7 -5
- cirq/linalg/combinators_test.py +10 -7
- cirq/linalg/decompositions.py +24 -35
- cirq/linalg/decompositions_test.py +3 -1
- cirq/linalg/diagonalize.py +6 -4
- cirq/linalg/diagonalize_test.py +15 -14
- cirq/linalg/operator_spaces.py +14 -14
- cirq/linalg/operator_spaces_test.py +13 -11
- cirq/linalg/predicates.py +18 -9
- cirq/linalg/predicates_test.py +5 -0
- cirq/linalg/tolerance.py +6 -3
- cirq/linalg/tolerance_test.py +6 -4
- cirq/linalg/transformations.py +23 -20
- cirq/linalg/transformations_test.py +73 -43
- cirq/neutral_atoms/convert_to_neutral_atom_gates.py +9 -3
- cirq/neutral_atoms/convert_to_neutral_atom_gates_test.py +3 -1
- cirq/neutral_atoms/neutral_atom_devices.py +2 -0
- cirq/ops/__init__.py +2 -0
- cirq/ops/arithmetic_operation.py +21 -21
- cirq/ops/arithmetic_operation_test.py +7 -8
- cirq/ops/boolean_hamiltonian.py +23 -22
- cirq/ops/boolean_hamiltonian_test.py +12 -9
- cirq/ops/classically_controlled_operation.py +31 -36
- cirq/ops/classically_controlled_operation_test.py +121 -117
- cirq/ops/clifford_gate.py +98 -81
- cirq/ops/clifford_gate_test.py +72 -57
- cirq/ops/common_channels.py +44 -44
- cirq/ops/common_channels_test.py +83 -81
- cirq/ops/common_gate_families.py +9 -7
- cirq/ops/common_gate_families_test.py +11 -7
- cirq/ops/common_gates.py +164 -183
- cirq/ops/common_gates_test.py +135 -95
- cirq/ops/control_values.py +23 -26
- cirq/ops/control_values_test.py +22 -20
- cirq/ops/controlled_gate.py +64 -112
- cirq/ops/controlled_gate_test.py +130 -35
- cirq/ops/controlled_operation.py +24 -35
- cirq/ops/controlled_operation_test.py +8 -6
- cirq/ops/dense_pauli_string.py +38 -49
- cirq/ops/dense_pauli_string_test.py +4 -2
- cirq/ops/diagonal_gate.py +18 -31
- cirq/ops/diagonal_gate_test.py +13 -13
- cirq/ops/eigen_gate.py +29 -29
- cirq/ops/eigen_gate_test.py +45 -28
- cirq/ops/fourier_transform.py +14 -20
- cirq/ops/fourier_transform_test.py +15 -12
- cirq/ops/fsim_gate.py +43 -42
- cirq/ops/fsim_gate_test.py +29 -29
- cirq/ops/gate_features.py +2 -0
- cirq/ops/gate_features_test.py +5 -3
- cirq/ops/gate_operation.py +43 -65
- cirq/ops/gate_operation_test.py +46 -42
- cirq/ops/gateset.py +28 -40
- cirq/ops/gateset_test.py +4 -2
- cirq/ops/global_phase_op.py +45 -20
- cirq/ops/global_phase_op_test.py +44 -20
- cirq/ops/greedy_qubit_manager.py +10 -8
- cirq/ops/greedy_qubit_manager_test.py +5 -3
- cirq/ops/identity.py +14 -12
- cirq/ops/identity_test.py +24 -20
- cirq/ops/kraus_channel.py +11 -8
- cirq/ops/kraus_channel_test.py +14 -11
- cirq/ops/linear_combinations.py +65 -77
- cirq/ops/linear_combinations_test.py +14 -9
- cirq/ops/matrix_gates.py +21 -18
- cirq/ops/matrix_gates_test.py +16 -0
- cirq/ops/measure_util.py +15 -20
- cirq/ops/measure_util_test.py +2 -0
- cirq/ops/measurement_gate.py +26 -37
- cirq/ops/measurement_gate_test.py +2 -0
- cirq/ops/mixed_unitary_channel.py +12 -9
- cirq/ops/mixed_unitary_channel_test.py +14 -11
- cirq/ops/named_qubit.py +16 -13
- cirq/ops/named_qubit_test.py +15 -13
- cirq/ops/op_tree.py +9 -7
- cirq/ops/op_tree_test.py +22 -19
- cirq/ops/parallel_gate.py +15 -17
- cirq/ops/parallel_gate_test.py +18 -16
- cirq/ops/parity_gates.py +23 -25
- cirq/ops/parity_gates_test.py +36 -32
- cirq/ops/pauli_gates.py +22 -21
- cirq/ops/pauli_gates_test.py +29 -20
- cirq/ops/pauli_interaction_gate.py +15 -19
- cirq/ops/pauli_interaction_gate_test.py +10 -8
- cirq/ops/pauli_measurement_gate.py +23 -35
- cirq/ops/pauli_measurement_gate_test.py +2 -0
- cirq/ops/pauli_string.py +92 -120
- cirq/ops/pauli_string_phasor.py +52 -45
- cirq/ops/pauli_string_phasor_test.py +4 -5
- cirq/ops/pauli_string_raw_types.py +9 -7
- cirq/ops/pauli_string_raw_types_test.py +2 -0
- cirq/ops/pauli_string_test.py +31 -154
- cirq/ops/pauli_sum_exponential.py +12 -12
- cirq/ops/pauli_sum_exponential_test.py +12 -10
- cirq/ops/permutation_gate.py +8 -6
- cirq/ops/permutation_gate_test.py +10 -8
- cirq/ops/phased_iswap_gate.py +16 -16
- cirq/ops/phased_iswap_gate_test.py +17 -15
- cirq/ops/phased_x_gate.py +16 -17
- cirq/ops/phased_x_gate_test.py +18 -16
- cirq/ops/phased_x_z_gate.py +24 -22
- cirq/ops/phased_x_z_gate_test.py +17 -11
- cirq/ops/projector.py +16 -11
- cirq/ops/projector_test.py +19 -16
- cirq/ops/qid_util.py +7 -5
- cirq/ops/qid_util_test.py +2 -0
- cirq/ops/qubit_manager.py +11 -9
- cirq/ops/qubit_manager_test.py +6 -4
- cirq/ops/qubit_order.py +11 -14
- cirq/ops/qubit_order_or_list.py +4 -2
- cirq/ops/qubit_order_test.py +12 -10
- cirq/ops/random_gate_channel.py +12 -10
- cirq/ops/random_gate_channel_test.py +14 -11
- cirq/ops/raw_types.py +109 -129
- cirq/ops/raw_types_test.py +63 -57
- cirq/ops/state_preparation_channel.py +7 -7
- cirq/ops/state_preparation_channel_test.py +11 -9
- cirq/ops/swap_gates.py +13 -15
- cirq/ops/swap_gates_test.py +19 -17
- cirq/ops/tags.py +5 -3
- cirq/ops/tags_test.py +4 -2
- cirq/ops/three_qubit_gates.py +43 -76
- cirq/ops/three_qubit_gates_test.py +19 -17
- cirq/ops/two_qubit_diagonal_gate.py +13 -13
- cirq/ops/two_qubit_diagonal_gate_test.py +10 -8
- cirq/ops/uniform_superposition_gate.py +5 -3
- cirq/ops/uniform_superposition_gate_test.py +5 -3
- cirq/ops/wait_gate.py +17 -14
- cirq/ops/wait_gate_test.py +9 -6
- cirq/protocols/__init__.py +0 -3
- cirq/protocols/act_on_protocol.py +8 -6
- cirq/protocols/act_on_protocol_test.py +15 -12
- cirq/protocols/apply_channel_protocol.py +10 -14
- cirq/protocols/apply_channel_protocol_test.py +2 -0
- cirq/protocols/apply_mixture_protocol.py +13 -42
- cirq/protocols/apply_mixture_protocol_test.py +7 -5
- cirq/protocols/apply_unitary_protocol.py +39 -34
- cirq/protocols/apply_unitary_protocol_test.py +4 -1
- cirq/protocols/approximate_equality_protocol.py +2 -0
- cirq/protocols/approximate_equality_protocol_test.py +2 -0
- cirq/protocols/circuit_diagram_info_protocol.py +58 -42
- cirq/protocols/circuit_diagram_info_protocol_test.py +70 -12
- cirq/protocols/commutes_protocol.py +8 -7
- cirq/protocols/commutes_protocol_test.py +2 -0
- cirq/protocols/control_key_protocol.py +6 -4
- cirq/protocols/control_key_protocol_test.py +3 -1
- cirq/protocols/decompose_protocol.py +49 -48
- cirq/protocols/decompose_protocol_test.py +27 -16
- cirq/protocols/equal_up_to_global_phase_protocol.py +2 -0
- cirq/protocols/equal_up_to_global_phase_protocol_test.py +9 -6
- cirq/protocols/has_stabilizer_effect_protocol.py +7 -5
- cirq/protocols/has_stabilizer_effect_protocol_test.py +7 -5
- cirq/protocols/has_unitary_protocol.py +10 -6
- cirq/protocols/has_unitary_protocol_test.py +13 -8
- cirq/protocols/hash_from_pickle_test.py +2 -11
- cirq/protocols/inverse_protocol.py +13 -16
- cirq/protocols/inverse_protocol_test.py +5 -3
- cirq/protocols/json_serialization.py +35 -54
- cirq/protocols/json_serialization_test.py +14 -21
- cirq/protocols/json_test_data/CXSWAP.json +46 -0
- cirq/protocols/json_test_data/CXSWAP.repr +13 -0
- cirq/protocols/json_test_data/CZSWAP.json +46 -0
- cirq/protocols/json_test_data/CZSWAP.repr +13 -0
- cirq/protocols/json_test_data/CircuitOperation.json +6 -3
- cirq/protocols/json_test_data/CircuitOperation.repr_inward +4 -2
- cirq/protocols/json_test_data/Moment.json +24 -1
- cirq/protocols/json_test_data/Moment.repr +6 -1
- cirq/protocols/json_test_data/ThermalNoiseModel.json +32 -0
- cirq/protocols/json_test_data/ThermalNoiseModel.repr +1 -0
- cirq/protocols/json_test_data/spec.py +6 -2
- cirq/protocols/kraus_protocol.py +47 -7
- cirq/protocols/kraus_protocol_test.py +86 -12
- cirq/protocols/measurement_key_protocol.py +15 -16
- cirq/protocols/measurement_key_protocol_test.py +13 -11
- cirq/protocols/mixture_protocol.py +7 -5
- cirq/protocols/mixture_protocol_test.py +4 -2
- cirq/protocols/mul_protocol.py +2 -3
- cirq/protocols/mul_protocol_test.py +2 -0
- cirq/protocols/pauli_expansion_protocol.py +6 -3
- cirq/protocols/pauli_expansion_protocol_test.py +5 -3
- cirq/protocols/phase_protocol.py +2 -0
- cirq/protocols/phase_protocol_test.py +3 -1
- cirq/protocols/pow_protocol.py +11 -16
- cirq/protocols/pow_protocol_test.py +2 -0
- cirq/protocols/qasm.py +14 -20
- cirq/protocols/qasm_test.py +6 -3
- cirq/protocols/qid_shape_protocol.py +8 -8
- cirq/protocols/qid_shape_protocol_test.py +3 -1
- cirq/protocols/resolve_parameters.py +5 -3
- cirq/protocols/resolve_parameters_test.py +8 -7
- cirq/protocols/trace_distance_bound.py +6 -4
- cirq/protocols/trace_distance_bound_test.py +3 -1
- cirq/protocols/unitary_protocol.py +17 -7
- cirq/protocols/unitary_protocol_test.py +12 -2
- cirq/qis/channels.py +6 -2
- cirq/qis/channels_test.py +20 -16
- cirq/qis/clifford_tableau.py +21 -19
- cirq/qis/clifford_tableau_test.py +2 -2
- cirq/qis/entropy.py +14 -3
- cirq/qis/entropy_test.py +3 -1
- cirq/qis/measures.py +13 -13
- cirq/qis/measures_test.py +20 -14
- cirq/qis/noise_utils.py +2 -0
- cirq/qis/noise_utils_test.py +9 -7
- cirq/qis/quantum_state_representation.py +7 -8
- cirq/qis/states.py +58 -56
- cirq/qis/states_test.py +2 -0
- cirq/sim/classical_simulator.py +23 -22
- cirq/sim/classical_simulator_test.py +2 -0
- cirq/sim/clifford/clifford_simulator.py +23 -21
- cirq/sim/clifford/clifford_simulator_test.py +7 -4
- cirq/sim/clifford/clifford_tableau_simulation_state.py +10 -7
- cirq/sim/clifford/clifford_tableau_simulation_state_test.py +5 -5
- cirq/sim/clifford/stabilizer_ch_form_simulation_state.py +8 -6
- cirq/sim/clifford/stabilizer_ch_form_simulation_state_test.py +8 -6
- cirq/sim/clifford/stabilizer_sampler.py +9 -7
- cirq/sim/clifford/stabilizer_sampler_test.py +4 -2
- cirq/sim/clifford/stabilizer_simulation_state.py +14 -13
- cirq/sim/clifford/stabilizer_simulation_state_test.py +6 -4
- cirq/sim/clifford/stabilizer_state_ch_form.py +13 -11
- cirq/sim/clifford/stabilizer_state_ch_form_test.py +4 -2
- cirq/sim/density_matrix_simulation_state.py +26 -27
- cirq/sim/density_matrix_simulation_state_test.py +10 -8
- cirq/sim/density_matrix_simulator.py +30 -28
- cirq/sim/density_matrix_simulator_test.py +48 -48
- cirq/sim/density_matrix_utils.py +13 -11
- cirq/sim/density_matrix_utils_test.py +38 -36
- cirq/sim/mux.py +33 -31
- cirq/sim/mux_test.py +3 -0
- cirq/sim/simulation_product_state.py +15 -15
- cirq/sim/simulation_product_state_test.py +29 -26
- cirq/sim/simulation_state.py +29 -38
- cirq/sim/simulation_state_base.py +21 -32
- cirq/sim/simulation_state_test.py +15 -13
- cirq/sim/simulation_utils.py +5 -2
- cirq/sim/simulation_utils_test.py +5 -2
- cirq/sim/simulator.py +90 -106
- cirq/sim/simulator_base.py +33 -45
- cirq/sim/simulator_base_test.py +20 -15
- cirq/sim/simulator_test.py +23 -14
- cirq/sim/sparse_simulator.py +19 -17
- cirq/sim/sparse_simulator_test.py +41 -40
- cirq/sim/state_vector.py +15 -12
- cirq/sim/state_vector_simulation_state.py +31 -31
- cirq/sim/state_vector_simulation_state_test.py +16 -14
- cirq/sim/state_vector_simulator.py +17 -14
- cirq/sim/state_vector_simulator_test.py +2 -0
- cirq/sim/state_vector_test.py +6 -3
- cirq/study/flatten_expressions.py +16 -15
- cirq/study/flatten_expressions_test.py +13 -11
- cirq/study/resolver.py +18 -17
- cirq/study/resolver_test.py +22 -20
- cirq/study/result.py +17 -27
- cirq/study/result_test.py +2 -0
- cirq/study/sweepable.py +12 -10
- cirq/study/sweepable_test.py +3 -0
- cirq/study/sweeps.py +42 -61
- cirq/study/sweeps_test.py +33 -0
- cirq/testing/__init__.py +7 -11
- cirq/testing/_compat_test_data/module_a/__init__.py +1 -0
- cirq/testing/_compat_test_data/module_a/module_b/__init__.py +1 -0
- cirq/testing/_compat_test_data/module_a/sub/__init__.py +1 -0
- cirq/testing/circuit_compare.py +8 -17
- cirq/testing/circuit_compare_test.py +2 -0
- cirq/testing/consistent_act_on.py +13 -11
- cirq/testing/consistent_act_on_test.py +5 -3
- cirq/testing/consistent_channels.py +2 -0
- cirq/testing/consistent_channels_test.py +10 -8
- cirq/testing/consistent_controlled_gate_op.py +5 -5
- cirq/testing/consistent_controlled_gate_op_test.py +18 -18
- cirq/testing/consistent_decomposition.py +2 -2
- cirq/testing/consistent_decomposition_test.py +4 -2
- cirq/testing/consistent_pauli_expansion.py +2 -0
- cirq/testing/consistent_pauli_expansion_test.py +3 -1
- cirq/testing/consistent_phase_by.py +2 -0
- cirq/testing/consistent_phase_by_test.py +3 -1
- cirq/testing/consistent_protocols.py +14 -20
- cirq/testing/consistent_protocols_test.py +13 -11
- cirq/testing/consistent_qasm.py +6 -4
- cirq/testing/consistent_qasm_test.py +7 -7
- cirq/testing/consistent_resolve_parameters.py +2 -0
- cirq/testing/consistent_specified_has_unitary.py +2 -2
- cirq/testing/consistent_specified_has_unitary_test.py +6 -4
- cirq/testing/consistent_unitary.py +1 -0
- cirq/testing/consistent_unitary_test.py +4 -2
- cirq/testing/deprecation.py +5 -2
- cirq/testing/deprecation_test.py +5 -2
- cirq/testing/devices.py +7 -4
- cirq/testing/devices_test.py +7 -4
- cirq/testing/equals_tester.py +4 -2
- cirq/testing/equals_tester_test.py +21 -17
- cirq/testing/equivalent_basis_map.py +6 -4
- cirq/testing/equivalent_basis_map_test.py +6 -4
- cirq/testing/equivalent_repr_eval.py +6 -4
- cirq/testing/equivalent_repr_eval_test.py +5 -3
- cirq/testing/gate_features.py +2 -0
- cirq/testing/gate_features_test.py +7 -5
- cirq/testing/json.py +19 -15
- cirq/testing/json_test.py +5 -3
- cirq/testing/lin_alg_utils.py +10 -11
- cirq/testing/lin_alg_utils_test.py +14 -12
- cirq/testing/logs.py +7 -6
- cirq/testing/logs_test.py +9 -7
- cirq/testing/no_identifier_qubit.py +4 -2
- cirq/testing/no_identifier_qubit_test.py +5 -3
- cirq/testing/op_tree.py +2 -0
- cirq/testing/op_tree_test.py +4 -1
- cirq/testing/order_tester.py +2 -0
- cirq/testing/order_tester_test.py +8 -6
- cirq/testing/pytest_utils.py +2 -0
- cirq/testing/pytest_utils_test.py +4 -2
- cirq/testing/random_circuit.py +21 -20
- cirq/testing/random_circuit_test.py +12 -9
- cirq/testing/repr_pretty_tester.py +1 -0
- cirq/testing/repr_pretty_tester_test.py +5 -3
- cirq/testing/routing_devices.py +4 -1
- cirq/testing/routing_devices_test.py +9 -6
- cirq/testing/sample_circuits.py +4 -1
- cirq/testing/sample_circuits_test.py +3 -1
- cirq/testing/sample_gates.py +3 -0
- cirq/testing/sample_gates_test.py +5 -2
- cirq/transformers/__init__.py +11 -4
- cirq/transformers/align.py +9 -7
- cirq/transformers/align_test.py +2 -0
- cirq/transformers/analytical_decompositions/__init__.py +3 -6
- cirq/transformers/analytical_decompositions/clifford_decomposition.py +18 -16
- cirq/transformers/analytical_decompositions/clifford_decomposition_test.py +2 -0
- cirq/transformers/analytical_decompositions/controlled_gate_decomposition.py +19 -16
- cirq/transformers/analytical_decompositions/controlled_gate_decomposition_test.py +2 -0
- cirq/transformers/analytical_decompositions/cphase_to_fsim.py +11 -9
- cirq/transformers/analytical_decompositions/cphase_to_fsim_test.py +5 -3
- cirq/transformers/analytical_decompositions/pauli_string_decomposition.py +5 -3
- cirq/transformers/analytical_decompositions/pauli_string_decomposition_test.py +5 -3
- cirq/transformers/analytical_decompositions/quantum_shannon_decomposition.py +141 -44
- cirq/transformers/analytical_decompositions/quantum_shannon_decomposition_test.py +35 -1
- cirq/transformers/analytical_decompositions/single_qubit_decompositions.py +8 -7
- cirq/transformers/analytical_decompositions/single_qubit_decompositions_test.py +2 -0
- cirq/transformers/analytical_decompositions/single_to_two_qubit_isometry.py +7 -4
- cirq/transformers/analytical_decompositions/single_to_two_qubit_isometry_test.py +3 -0
- cirq/transformers/analytical_decompositions/three_qubit_decomposition.py +11 -19
- cirq/transformers/analytical_decompositions/three_qubit_decomposition_test.py +8 -33
- cirq/transformers/analytical_decompositions/two_qubit_state_preparation.py +9 -11
- cirq/transformers/analytical_decompositions/two_qubit_state_preparation_test.py +2 -0
- cirq/transformers/analytical_decompositions/two_qubit_to_cz.py +91 -27
- cirq/transformers/analytical_decompositions/two_qubit_to_cz_test.py +36 -7
- cirq/transformers/analytical_decompositions/two_qubit_to_fsim.py +20 -21
- cirq/transformers/analytical_decompositions/two_qubit_to_fsim_test.py +8 -6
- cirq/transformers/analytical_decompositions/two_qubit_to_ms.py +13 -15
- cirq/transformers/analytical_decompositions/two_qubit_to_ms_test.py +3 -1
- cirq/transformers/analytical_decompositions/two_qubit_to_sqrt_iswap.py +39 -41
- cirq/transformers/analytical_decompositions/two_qubit_to_sqrt_iswap_test.py +2 -0
- cirq/transformers/drop_empty_moments.py +5 -3
- cirq/transformers/drop_empty_moments_test.py +4 -2
- cirq/transformers/drop_negligible_operations.py +7 -5
- cirq/transformers/drop_negligible_operations_test.py +2 -0
- cirq/transformers/dynamical_decoupling.py +49 -42
- cirq/transformers/dynamical_decoupling_test.py +223 -205
- cirq/transformers/eject_phased_paulis.py +28 -26
- cirq/transformers/eject_phased_paulis_test.py +12 -9
- cirq/transformers/eject_z.py +12 -12
- cirq/transformers/eject_z_test.py +2 -2
- cirq/transformers/expand_composite.py +6 -4
- cirq/transformers/expand_composite_test.py +3 -1
- cirq/transformers/gauge_compiling/__init__.py +3 -1
- cirq/transformers/gauge_compiling/cphase_gauge.py +2 -0
- cirq/transformers/gauge_compiling/cphase_gauge_test.py +2 -0
- cirq/transformers/gauge_compiling/cz_gauge.py +2 -0
- cirq/transformers/gauge_compiling/cz_gauge_test.py +1 -0
- cirq/transformers/gauge_compiling/gauge_compiling.py +45 -41
- cirq/transformers/gauge_compiling/gauge_compiling_test.py +2 -0
- cirq/transformers/gauge_compiling/gauge_compiling_test_utils.py +1 -0
- cirq/transformers/gauge_compiling/gauge_compiling_test_utils_test.py +5 -1
- cirq/transformers/gauge_compiling/iswap_gauge.py +2 -0
- cirq/transformers/gauge_compiling/iswap_gauge_test.py +1 -0
- cirq/transformers/gauge_compiling/spin_inversion_gauge.py +2 -0
- cirq/transformers/gauge_compiling/spin_inversion_gauge_test.py +2 -0
- cirq/transformers/gauge_compiling/sqrt_cz_gauge.py +7 -6
- cirq/transformers/gauge_compiling/sqrt_cz_gauge_test.py +2 -0
- cirq/transformers/gauge_compiling/sqrt_iswap_gauge.py +2 -0
- cirq/transformers/gauge_compiling/sqrt_iswap_gauge_test.py +2 -0
- cirq/transformers/heuristic_decompositions/gate_tabulation_math_utils.py +6 -3
- cirq/transformers/heuristic_decompositions/gate_tabulation_math_utils_test.py +3 -0
- cirq/transformers/heuristic_decompositions/two_qubit_gate_tabulation.py +12 -9
- cirq/transformers/heuristic_decompositions/two_qubit_gate_tabulation_test.py +9 -7
- cirq/transformers/insertion_sort.py +8 -6
- cirq/transformers/insertion_sort_test.py +3 -1
- cirq/transformers/measurement_transformers.py +29 -29
- cirq/transformers/measurement_transformers_test.py +2 -0
- cirq/transformers/merge_k_qubit_gates.py +12 -10
- cirq/transformers/merge_k_qubit_gates_test.py +18 -18
- cirq/transformers/merge_single_qubit_gates.py +197 -20
- cirq/transformers/merge_single_qubit_gates_test.py +177 -5
- cirq/transformers/noise_adding.py +5 -3
- cirq/transformers/noise_adding_test.py +2 -0
- cirq/transformers/optimize_for_target_gateset.py +19 -17
- cirq/transformers/optimize_for_target_gateset_test.py +11 -8
- cirq/transformers/qubit_management_transformers.py +13 -11
- cirq/transformers/qubit_management_transformers_test.py +5 -3
- cirq/transformers/randomized_measurements.py +16 -14
- cirq/transformers/randomized_measurements_test.py +10 -4
- cirq/transformers/routing/initial_mapper.py +6 -4
- cirq/transformers/routing/initial_mapper_test.py +2 -0
- cirq/transformers/routing/line_initial_mapper.py +16 -14
- cirq/transformers/routing/line_initial_mapper_test.py +9 -7
- cirq/transformers/routing/mapping_manager.py +10 -10
- cirq/transformers/routing/mapping_manager_test.py +2 -0
- cirq/transformers/routing/route_circuit_cqc.py +33 -31
- cirq/transformers/routing/route_circuit_cqc_test.py +15 -13
- cirq/transformers/routing/visualize_routed_circuit.py +8 -7
- cirq/transformers/routing/visualize_routed_circuit_test.py +4 -2
- cirq/transformers/stratify.py +17 -15
- cirq/transformers/stratify_test.py +3 -0
- cirq/transformers/symbolize.py +103 -0
- cirq/transformers/symbolize_test.py +62 -0
- cirq/transformers/synchronize_terminal_measurements.py +10 -10
- cirq/transformers/synchronize_terminal_measurements_test.py +12 -10
- cirq/transformers/tag_transformers.py +97 -0
- cirq/transformers/tag_transformers_test.py +103 -0
- cirq/transformers/target_gatesets/compilation_target_gateset.py +21 -19
- cirq/transformers/target_gatesets/compilation_target_gateset_test.py +20 -16
- cirq/transformers/target_gatesets/cz_gateset.py +7 -5
- cirq/transformers/target_gatesets/cz_gateset_test.py +21 -19
- cirq/transformers/target_gatesets/sqrt_iswap_gateset.py +9 -7
- cirq/transformers/target_gatesets/sqrt_iswap_gateset_test.py +25 -25
- cirq/transformers/transformer_api.py +34 -47
- cirq/transformers/transformer_api_test.py +9 -8
- cirq/transformers/transformer_primitives.py +39 -49
- cirq/transformers/transformer_primitives_test.py +10 -17
- cirq/value/abc_alt.py +6 -4
- cirq/value/abc_alt_test.py +5 -3
- cirq/value/angle.py +11 -12
- cirq/value/angle_test.py +5 -3
- cirq/value/classical_data.py +27 -27
- cirq/value/classical_data_test.py +11 -8
- cirq/value/condition.py +26 -24
- cirq/value/condition_test.py +2 -0
- cirq/value/digits.py +14 -11
- cirq/value/digits_test.py +2 -0
- cirq/value/duration.py +23 -20
- cirq/value/duration_test.py +2 -0
- cirq/value/linear_dict.py +25 -30
- cirq/value/linear_dict_test.py +10 -8
- cirq/value/measurement_key.py +12 -12
- cirq/value/measurement_key_test.py +2 -0
- cirq/value/periodic_value.py +4 -4
- cirq/value/periodic_value_test.py +11 -7
- cirq/value/probability.py +3 -1
- cirq/value/probability_test.py +4 -2
- cirq/value/product_state.py +15 -13
- cirq/value/product_state_test.py +4 -1
- cirq/value/random_state.py +2 -0
- cirq/value/random_state_test.py +5 -3
- cirq/value/timestamp.py +11 -7
- cirq/value/timestamp_test.py +14 -12
- cirq/value/type_alias.py +4 -4
- cirq/value/value_equality_attr.py +8 -9
- cirq/value/value_equality_attr_test.py +14 -11
- cirq/vis/density_matrix.py +3 -3
- cirq/vis/density_matrix_test.py +20 -17
- cirq/vis/heatmap.py +24 -37
- cirq/vis/heatmap_test.py +3 -0
- cirq/vis/histogram.py +9 -6
- cirq/vis/histogram_test.py +5 -2
- cirq/vis/state_histogram.py +10 -8
- cirq/vis/state_histogram_test.py +7 -5
- cirq/vis/vis_utils.py +4 -1
- cirq/vis/vis_utils_test.py +4 -1
- cirq/work/collector.py +12 -18
- cirq/work/collector_test.py +15 -10
- cirq/work/observable_grouping.py +6 -7
- cirq/work/observable_grouping_test.py +10 -9
- cirq/work/observable_measurement.py +47 -45
- cirq/work/observable_measurement_data.py +22 -17
- cirq/work/observable_measurement_data_test.py +4 -1
- cirq/work/observable_measurement_test.py +48 -29
- cirq/work/observable_readout_calibration.py +5 -2
- cirq/work/observable_readout_calibration_test.py +5 -2
- cirq/work/observable_settings.py +13 -22
- cirq/work/observable_settings_test.py +9 -7
- cirq/work/pauli_sum_collector.py +12 -10
- cirq/work/pauli_sum_collector_test.py +9 -9
- cirq/work/sampler.py +42 -43
- cirq/work/sampler_test.py +31 -24
- cirq/work/zeros_sampler.py +6 -4
- cirq/work/zeros_sampler_test.py +7 -5
- {cirq_core-1.5.0.dev20250409225226.dist-info → cirq_core-1.6.0.dist-info}/METADATA +7 -8
- cirq_core-1.6.0.dist-info/RECORD +1241 -0
- {cirq_core-1.5.0.dev20250409225226.dist-info → cirq_core-1.6.0.dist-info}/WHEEL +1 -1
- cirq_core-1.5.0.dev20250409225226.dist-info/RECORD +0 -1216
- {cirq_core-1.5.0.dev20250409225226.dist-info → cirq_core-1.6.0.dist-info}/licenses/LICENSE +0 -0
- {cirq_core-1.5.0.dev20250409225226.dist-info → cirq_core-1.6.0.dist-info}/top_level.txt +0 -0
cirq/testing/lin_alg_utils.py
CHANGED
|
@@ -11,9 +11,12 @@
|
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
|
+
|
|
14
15
|
"""A testing class with utilities for checking linear algebra."""
|
|
15
16
|
|
|
16
|
-
from
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
from typing import TYPE_CHECKING
|
|
17
20
|
|
|
18
21
|
import numpy as np
|
|
19
22
|
|
|
@@ -24,7 +27,7 @@ if TYPE_CHECKING:
|
|
|
24
27
|
|
|
25
28
|
|
|
26
29
|
def random_superposition(
|
|
27
|
-
dim: int, *, random_state:
|
|
30
|
+
dim: int, *, random_state: cirq.RANDOM_STATE_OR_SEED_LIKE = None
|
|
28
31
|
) -> np.ndarray:
|
|
29
32
|
"""Returns a random unit-length vector from the uniform distribution.
|
|
30
33
|
|
|
@@ -46,7 +49,7 @@ def random_superposition(
|
|
|
46
49
|
|
|
47
50
|
|
|
48
51
|
def random_density_matrix(
|
|
49
|
-
dim: int, *, random_state:
|
|
52
|
+
dim: int, *, random_state: cirq.RANDOM_STATE_OR_SEED_LIKE = None
|
|
50
53
|
) -> np.ndarray:
|
|
51
54
|
"""Returns a random density matrix distributed with Hilbert-Schmidt measure.
|
|
52
55
|
|
|
@@ -68,9 +71,7 @@ def random_density_matrix(
|
|
|
68
71
|
return mat / np.trace(mat)
|
|
69
72
|
|
|
70
73
|
|
|
71
|
-
def random_unitary(
|
|
72
|
-
dim: int, *, random_state: 'cirq.RANDOM_STATE_OR_SEED_LIKE' = None
|
|
73
|
-
) -> np.ndarray:
|
|
74
|
+
def random_unitary(dim: int, *, random_state: cirq.RANDOM_STATE_OR_SEED_LIKE = None) -> np.ndarray:
|
|
74
75
|
"""Returns a random unitary matrix distributed with Haar measure.
|
|
75
76
|
|
|
76
77
|
Args:
|
|
@@ -93,7 +94,7 @@ def random_unitary(
|
|
|
93
94
|
|
|
94
95
|
|
|
95
96
|
def random_orthogonal(
|
|
96
|
-
dim: int, *, random_state:
|
|
97
|
+
dim: int, *, random_state: cirq.RANDOM_STATE_OR_SEED_LIKE = None
|
|
97
98
|
) -> np.ndarray:
|
|
98
99
|
"""Returns a random orthogonal matrix distributed with Haar measure.
|
|
99
100
|
|
|
@@ -119,7 +120,7 @@ def random_orthogonal(
|
|
|
119
120
|
|
|
120
121
|
|
|
121
122
|
def random_special_unitary(
|
|
122
|
-
dim: int, *, random_state:
|
|
123
|
+
dim: int, *, random_state: np.random.RandomState | None = None
|
|
123
124
|
) -> np.ndarray:
|
|
124
125
|
"""Returns a random special unitary distributed with Haar measure.
|
|
125
126
|
|
|
@@ -139,7 +140,7 @@ def random_special_unitary(
|
|
|
139
140
|
|
|
140
141
|
|
|
141
142
|
def random_special_orthogonal(
|
|
142
|
-
dim: int, *, random_state:
|
|
143
|
+
dim: int, *, random_state: cirq.RANDOM_STATE_OR_SEED_LIKE = None
|
|
143
144
|
) -> np.ndarray:
|
|
144
145
|
"""Returns a random special orthogonal matrix distributed with Haar measure.
|
|
145
146
|
|
|
@@ -185,9 +186,7 @@ def assert_allclose_up_to_global_phase(
|
|
|
185
186
|
Raises:
|
|
186
187
|
AssertionError: The matrices aren't nearly equal up to global phase.
|
|
187
188
|
"""
|
|
188
|
-
# pylint: disable=unused-variable
|
|
189
189
|
__tracebackhide__ = True
|
|
190
|
-
# pylint: enable=unused-variable
|
|
191
190
|
|
|
192
191
|
actual, desired = linalg.match_global_phase(actual, desired)
|
|
193
192
|
np.testing.assert_allclose(
|
|
@@ -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
|
|
|
@@ -28,14 +30,14 @@ from cirq.testing import (
|
|
|
28
30
|
|
|
29
31
|
|
|
30
32
|
@pytest.mark.parametrize('dim', range(1, 10))
|
|
31
|
-
def test_random_superposition(dim):
|
|
33
|
+
def test_random_superposition(dim) -> None:
|
|
32
34
|
state = random_superposition(dim)
|
|
33
35
|
|
|
34
36
|
assert dim == len(state)
|
|
35
37
|
assert np.isclose(np.linalg.norm(state), 1.0)
|
|
36
38
|
|
|
37
39
|
|
|
38
|
-
def test_random_superposition_deterministic_given_seed():
|
|
40
|
+
def test_random_superposition_deterministic_given_seed() -> None:
|
|
39
41
|
state1 = random_superposition(10, random_state=1234)
|
|
40
42
|
state2 = random_superposition(10, random_state=1234)
|
|
41
43
|
|
|
@@ -43,7 +45,7 @@ def test_random_superposition_deterministic_given_seed():
|
|
|
43
45
|
|
|
44
46
|
|
|
45
47
|
@pytest.mark.parametrize('dim', range(1, 10))
|
|
46
|
-
def test_random_density_matrix(dim):
|
|
48
|
+
def test_random_density_matrix(dim) -> None:
|
|
47
49
|
state = random_density_matrix(dim)
|
|
48
50
|
|
|
49
51
|
assert state.shape == (dim, dim)
|
|
@@ -53,14 +55,14 @@ def test_random_density_matrix(dim):
|
|
|
53
55
|
assert np.all(eigs >= 0)
|
|
54
56
|
|
|
55
57
|
|
|
56
|
-
def test_random_density_matrix_deterministic_given_seed():
|
|
58
|
+
def test_random_density_matrix_deterministic_given_seed() -> None:
|
|
57
59
|
state1 = random_density_matrix(10, random_state=1234)
|
|
58
60
|
state2 = random_density_matrix(10, random_state=1234)
|
|
59
61
|
|
|
60
62
|
np.testing.assert_equal(state1, state2)
|
|
61
63
|
|
|
62
64
|
|
|
63
|
-
def test_random_unitary():
|
|
65
|
+
def test_random_unitary() -> None:
|
|
64
66
|
u1 = random_unitary(2)
|
|
65
67
|
u2 = random_unitary(2)
|
|
66
68
|
assert is_unitary(u1)
|
|
@@ -68,7 +70,7 @@ def test_random_unitary():
|
|
|
68
70
|
assert not np.allclose(u1, u2)
|
|
69
71
|
|
|
70
72
|
|
|
71
|
-
def test_random_orthogonal():
|
|
73
|
+
def test_random_orthogonal() -> None:
|
|
72
74
|
o1 = random_orthogonal(2)
|
|
73
75
|
o2 = random_orthogonal(2)
|
|
74
76
|
assert is_orthogonal(o1)
|
|
@@ -76,14 +78,14 @@ def test_random_orthogonal():
|
|
|
76
78
|
assert not np.allclose(o1, o2)
|
|
77
79
|
|
|
78
80
|
|
|
79
|
-
def test_random_orthogonal_deterministic_given_seed():
|
|
81
|
+
def test_random_orthogonal_deterministic_given_seed() -> None:
|
|
80
82
|
o1 = random_orthogonal(2, random_state=1234)
|
|
81
83
|
o2 = random_orthogonal(2, random_state=1234)
|
|
82
84
|
|
|
83
85
|
np.testing.assert_equal(o1, o2)
|
|
84
86
|
|
|
85
87
|
|
|
86
|
-
def test_random_special_unitary():
|
|
88
|
+
def test_random_special_unitary() -> None:
|
|
87
89
|
u1 = random_special_unitary(2)
|
|
88
90
|
u2 = random_special_unitary(2)
|
|
89
91
|
assert is_special_unitary(u1)
|
|
@@ -91,7 +93,7 @@ def test_random_special_unitary():
|
|
|
91
93
|
assert not np.allclose(u1, u2)
|
|
92
94
|
|
|
93
95
|
|
|
94
|
-
def test_seeded_special_unitary():
|
|
96
|
+
def test_seeded_special_unitary() -> None:
|
|
95
97
|
u1 = random_special_unitary(2, random_state=np.random.RandomState(1))
|
|
96
98
|
u2 = random_special_unitary(2, random_state=np.random.RandomState(1))
|
|
97
99
|
u3 = random_special_unitary(2, random_state=np.random.RandomState(2))
|
|
@@ -99,7 +101,7 @@ def test_seeded_special_unitary():
|
|
|
99
101
|
assert not np.allclose(u1, u3)
|
|
100
102
|
|
|
101
103
|
|
|
102
|
-
def test_random_special_orthogonal():
|
|
104
|
+
def test_random_special_orthogonal() -> None:
|
|
103
105
|
o1 = random_special_orthogonal(2)
|
|
104
106
|
o2 = random_special_orthogonal(2)
|
|
105
107
|
assert is_special_orthogonal(o1)
|
|
@@ -107,14 +109,14 @@ def test_random_special_orthogonal():
|
|
|
107
109
|
assert not np.allclose(o1, o2)
|
|
108
110
|
|
|
109
111
|
|
|
110
|
-
def test_random_special_orthogonal_deterministic_given_seed():
|
|
112
|
+
def test_random_special_orthogonal_deterministic_given_seed() -> None:
|
|
111
113
|
o1 = random_special_orthogonal(2, random_state=1234)
|
|
112
114
|
o2 = random_special_orthogonal(2, random_state=1234)
|
|
113
115
|
|
|
114
116
|
np.testing.assert_equal(o1, o2)
|
|
115
117
|
|
|
116
118
|
|
|
117
|
-
def test_assert_allclose_up_to_global_phase():
|
|
119
|
+
def test_assert_allclose_up_to_global_phase() -> None:
|
|
118
120
|
assert_allclose_up_to_global_phase(np.array([[1]]), np.array([[1j]]), atol=0)
|
|
119
121
|
|
|
120
122
|
with pytest.raises(AssertionError):
|
cirq/testing/logs.py
CHANGED
|
@@ -11,20 +11,24 @@
|
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
|
+
|
|
14
15
|
"""Helper for testing python logging statements."""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
15
19
|
import contextlib
|
|
16
20
|
import logging
|
|
17
|
-
from typing import Iterator
|
|
21
|
+
from typing import Iterator
|
|
18
22
|
|
|
19
23
|
|
|
20
24
|
@contextlib.contextmanager
|
|
21
25
|
def assert_logs(
|
|
22
26
|
*matches: str,
|
|
23
|
-
count:
|
|
27
|
+
count: int | None = 1,
|
|
24
28
|
min_level: int = logging.WARNING,
|
|
25
29
|
max_level: int = logging.CRITICAL,
|
|
26
30
|
capture_warnings: bool = True,
|
|
27
|
-
) -> Iterator[
|
|
31
|
+
) -> Iterator[list[logging.LogRecord]]:
|
|
28
32
|
"""A context manager for testing logging and warning events.
|
|
29
33
|
|
|
30
34
|
To use this one wraps the code that is to be tested for log events within
|
|
@@ -92,6 +96,3 @@ def assert_logs(
|
|
|
92
96
|
f'{match} expected to appear in log messages but it was '
|
|
93
97
|
f'not found. Log messages: {msgs}.'
|
|
94
98
|
)
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
# pylint: enable=missing-raises-doc
|
cirq/testing/logs_test.py
CHANGED
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
15
17
|
import logging
|
|
16
18
|
import warnings
|
|
17
19
|
|
|
@@ -20,7 +22,7 @@ import pytest
|
|
|
20
22
|
import cirq.testing
|
|
21
23
|
|
|
22
24
|
|
|
23
|
-
def test_assert_logs_valid_single_logs():
|
|
25
|
+
def test_assert_logs_valid_single_logs() -> None:
|
|
24
26
|
with cirq.testing.assert_logs('apple'):
|
|
25
27
|
logging.error('orange apple fruit')
|
|
26
28
|
|
|
@@ -43,7 +45,7 @@ def test_assert_logs_valid_single_logs():
|
|
|
43
45
|
warnings.warn('orange apple fruit')
|
|
44
46
|
|
|
45
47
|
|
|
46
|
-
def test_assert_logs_invalid_single_logs():
|
|
48
|
+
def test_assert_logs_invalid_single_logs() -> None:
|
|
47
49
|
match = (
|
|
48
50
|
'^dog expected to appear in log messages but it was not found. '
|
|
49
51
|
'Log messages: \\[\'orange apple fruit\'\\].$'
|
|
@@ -57,7 +59,7 @@ def test_assert_logs_invalid_single_logs():
|
|
|
57
59
|
logging.error('orange apple fruit')
|
|
58
60
|
|
|
59
61
|
|
|
60
|
-
def test_assert_logs_valid_multiple_logs():
|
|
62
|
+
def test_assert_logs_valid_multiple_logs() -> None:
|
|
61
63
|
with cirq.testing.assert_logs('apple', count=2):
|
|
62
64
|
logging.error('orange apple fruit')
|
|
63
65
|
logging.error('other')
|
|
@@ -84,7 +86,7 @@ def test_assert_logs_valid_multiple_logs():
|
|
|
84
86
|
logging.warning('other two')
|
|
85
87
|
|
|
86
88
|
|
|
87
|
-
def test_assert_logs_invalid_multiple_logs():
|
|
89
|
+
def test_assert_logs_invalid_multiple_logs() -> None:
|
|
88
90
|
with pytest.raises(AssertionError, match='^Expected 1 log message but got 2. Log messages.*$'):
|
|
89
91
|
with cirq.testing.assert_logs('dog'):
|
|
90
92
|
logging.error('orange apple fruit')
|
|
@@ -107,7 +109,7 @@ def test_assert_logs_invalid_multiple_logs():
|
|
|
107
109
|
logging.error('whatever')
|
|
108
110
|
|
|
109
111
|
|
|
110
|
-
def test_assert_logs_log_level():
|
|
112
|
+
def test_assert_logs_log_level() -> None:
|
|
111
113
|
# Default minlevel is WARNING, max level CRITICAL
|
|
112
114
|
with cirq.testing.assert_logs('apple'):
|
|
113
115
|
logging.error('orange apple fruit')
|
|
@@ -131,7 +133,7 @@ def test_assert_logs_log_level():
|
|
|
131
133
|
logging.warning("info warning 1")
|
|
132
134
|
|
|
133
135
|
|
|
134
|
-
def test_invalid_levels():
|
|
136
|
+
def test_invalid_levels() -> None:
|
|
135
137
|
with pytest.raises(ValueError, match="min_level.*max_level"):
|
|
136
138
|
with cirq.testing.assert_logs(
|
|
137
139
|
"test", min_level=logging.CRITICAL, max_level=logging.WARNING
|
|
@@ -139,7 +141,7 @@ def test_invalid_levels():
|
|
|
139
141
|
pass
|
|
140
142
|
|
|
141
143
|
|
|
142
|
-
def test_assert_logs_warnings():
|
|
144
|
+
def test_assert_logs_warnings() -> None:
|
|
143
145
|
# Capture all warnings in one context, so that test cases that will
|
|
144
146
|
# display a warning do not do so when the test is run.
|
|
145
147
|
with warnings.catch_warnings(record=True):
|
|
@@ -11,7 +11,9 @@
|
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
|
-
from
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
from typing import Any
|
|
15
17
|
|
|
16
18
|
from cirq import protocols
|
|
17
19
|
from cirq.ops import raw_types
|
|
@@ -35,5 +37,5 @@ class NoIdentifierQubit(raw_types.Qid):
|
|
|
35
37
|
def __repr__(self) -> str:
|
|
36
38
|
return 'cirq.testing.NoIdentifierQubit()'
|
|
37
39
|
|
|
38
|
-
def _json_dict_(self) ->
|
|
40
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
39
41
|
return protocols.obj_to_dict_helper(self, [])
|
|
@@ -12,19 +12,21 @@
|
|
|
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 cirq
|
|
16
18
|
|
|
17
19
|
|
|
18
|
-
def test_named_qubit_repr():
|
|
20
|
+
def test_named_qubit_repr() -> None:
|
|
19
21
|
q = cirq.testing.NoIdentifierQubit()
|
|
20
22
|
assert repr(q) == "cirq.testing.NoIdentifierQubit()"
|
|
21
23
|
|
|
22
24
|
|
|
23
|
-
def test_comparsion_key():
|
|
25
|
+
def test_comparsion_key() -> None:
|
|
24
26
|
q = cirq.testing.NoIdentifierQubit()
|
|
25
27
|
p = cirq.testing.NoIdentifierQubit()
|
|
26
28
|
assert p == q
|
|
27
29
|
|
|
28
30
|
|
|
29
|
-
def test_to_json():
|
|
31
|
+
def test_to_json() -> None:
|
|
30
32
|
assert cirq.testing.NoIdentifierQubit()._json_dict_() == {}
|
cirq/testing/op_tree.py
CHANGED
cirq/testing/op_tree_test.py
CHANGED
|
@@ -11,13 +11,16 @@
|
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
14
17
|
import pytest
|
|
15
18
|
|
|
16
19
|
import cirq
|
|
17
20
|
from cirq.testing import assert_equivalent_op_tree
|
|
18
21
|
|
|
19
22
|
|
|
20
|
-
def test_assert_equivalent_op_tree():
|
|
23
|
+
def test_assert_equivalent_op_tree() -> None:
|
|
21
24
|
assert_equivalent_op_tree([], [])
|
|
22
25
|
a = cirq.NamedQubit("a")
|
|
23
26
|
assert_equivalent_op_tree([cirq.X(a)], [cirq.X(a)])
|
cirq/testing/order_tester.py
CHANGED
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
15
17
|
import fractions
|
|
16
18
|
|
|
17
19
|
import pytest
|
|
@@ -62,7 +64,7 @@ class MockValue:
|
|
|
62
64
|
return f'MockValue(val={self.val!r}, ...)'
|
|
63
65
|
|
|
64
66
|
|
|
65
|
-
def test_add_ordering_group_correct():
|
|
67
|
+
def test_add_ordering_group_correct() -> None:
|
|
66
68
|
ot = cirq.testing.OrderTester()
|
|
67
69
|
ot.add_ascending(-4, 0)
|
|
68
70
|
ot.add_ascending(1, 2)
|
|
@@ -70,7 +72,7 @@ def test_add_ordering_group_correct():
|
|
|
70
72
|
ot.add_ascending_equivalence_group(float('inf'), float('inf'))
|
|
71
73
|
|
|
72
74
|
|
|
73
|
-
def test_add_ordering_group_incorrect():
|
|
75
|
+
def test_add_ordering_group_incorrect() -> None:
|
|
74
76
|
ot = cirq.testing.OrderTester()
|
|
75
77
|
ot.add_ascending(0)
|
|
76
78
|
with pytest.raises(AssertionError):
|
|
@@ -88,7 +90,7 @@ def test_add_ordering_group_incorrect():
|
|
|
88
90
|
ot.add_ascending(0)
|
|
89
91
|
|
|
90
92
|
|
|
91
|
-
def test_propagates_internal_errors():
|
|
93
|
+
def test_propagates_internal_errors() -> None:
|
|
92
94
|
class UnorderableClass: # pragma: no cover
|
|
93
95
|
def __eq__(self, other):
|
|
94
96
|
return NotImplemented
|
|
@@ -113,7 +115,7 @@ def test_propagates_internal_errors():
|
|
|
113
115
|
ot.add_ascending(UnorderableClass())
|
|
114
116
|
|
|
115
117
|
|
|
116
|
-
def test_add_ascending_equivalence_group():
|
|
118
|
+
def test_add_ascending_equivalence_group() -> None:
|
|
117
119
|
ot = cirq.testing.OrderTester()
|
|
118
120
|
with pytest.raises(AssertionError, match='Expected X=1 to equal Y=3'):
|
|
119
121
|
ot.add_ascending_equivalence_group(1, 3)
|
|
@@ -127,7 +129,7 @@ def test_add_ascending_equivalence_group():
|
|
|
127
129
|
ot.add_ascending_equivalence_group(5)
|
|
128
130
|
|
|
129
131
|
|
|
130
|
-
def test_fails_to_return_not_implemented_vs_unknown():
|
|
132
|
+
def test_fails_to_return_not_implemented_vs_unknown() -> None:
|
|
131
133
|
def make_impls(bad_index: int, bad_result: bool):
|
|
132
134
|
def make_impl(i, op):
|
|
133
135
|
def impl(x, y):
|
|
@@ -153,7 +155,7 @@ def test_fails_to_return_not_implemented_vs_unknown():
|
|
|
153
155
|
ot.add_ascending(MockValue(1, *good_impls))
|
|
154
156
|
|
|
155
157
|
|
|
156
|
-
def test_fails_on_inconsistent_hashes():
|
|
158
|
+
def test_fails_on_inconsistent_hashes() -> None:
|
|
157
159
|
class ModifiedHash(tuple):
|
|
158
160
|
def __hash__(self):
|
|
159
161
|
return super().__hash__() ^ 1
|
cirq/testing/pytest_utils.py
CHANGED
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
15
17
|
from unittest.mock import Mock
|
|
16
18
|
|
|
17
19
|
import pytest
|
|
@@ -19,7 +21,7 @@ import pytest
|
|
|
19
21
|
import cirq
|
|
20
22
|
|
|
21
23
|
|
|
22
|
-
def test_retry_once_after_timeout():
|
|
24
|
+
def test_retry_once_after_timeout() -> None:
|
|
23
25
|
testfunc = Mock(side_effect=[TimeoutError("first call fails"), None])
|
|
24
26
|
decoratedfunc = cirq.testing.retry_once_after_timeout(testfunc)
|
|
25
27
|
with pytest.warns(UserWarning, match="Retrying.*transitive TimeoutError"):
|
|
@@ -27,7 +29,7 @@ def test_retry_once_after_timeout():
|
|
|
27
29
|
assert testfunc.call_count == 2
|
|
28
30
|
|
|
29
31
|
|
|
30
|
-
def test_retry_once_with_later_random_values():
|
|
32
|
+
def test_retry_once_with_later_random_values() -> None:
|
|
31
33
|
testfunc = Mock(side_effect=[AssertionError("first call fails"), None])
|
|
32
34
|
decoratedfunc = cirq.testing.retry_once_with_later_random_values(testfunc)
|
|
33
35
|
with pytest.warns(UserWarning, match="Retrying.*failing seed.*pytest-randomly"):
|
cirq/testing/random_circuit.py
CHANGED
|
@@ -12,27 +12,28 @@
|
|
|
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 Sequence, TYPE_CHECKING
|
|
16
18
|
|
|
17
19
|
from cirq import circuits, ops, value
|
|
18
20
|
from cirq._doc import document
|
|
19
|
-
from cirq.ops import Qid
|
|
20
21
|
|
|
21
22
|
if TYPE_CHECKING:
|
|
22
23
|
import cirq
|
|
23
24
|
|
|
24
|
-
DEFAULT_GATE_DOMAIN:
|
|
25
|
-
ops.CNOT: 2,
|
|
26
|
-
ops.CZ: 2,
|
|
27
|
-
ops.H: 1,
|
|
28
|
-
ops.ISWAP: 2,
|
|
25
|
+
DEFAULT_GATE_DOMAIN: dict[ops.Gate, int] = {
|
|
26
|
+
ops.CNOT: 2, # type: ignore[has-type]
|
|
27
|
+
ops.CZ: 2, # type: ignore[has-type]
|
|
28
|
+
ops.H: 1, # type: ignore[has-type]
|
|
29
|
+
ops.ISWAP: 2, # type: ignore[has-type]
|
|
29
30
|
ops.CZPowGate(): 2,
|
|
30
|
-
ops.S: 1,
|
|
31
|
-
ops.SWAP: 2,
|
|
32
|
-
ops.T: 1,
|
|
33
|
-
ops.X: 1,
|
|
34
|
-
ops.Y: 1,
|
|
35
|
-
ops.Z: 1,
|
|
31
|
+
ops.S: 1, # type: ignore[has-type]
|
|
32
|
+
ops.SWAP: 2, # type: ignore[has-type]
|
|
33
|
+
ops.T: 1, # type: ignore[has-type]
|
|
34
|
+
ops.X: 1, # type: ignore[has-type]
|
|
35
|
+
ops.Y: 1, # type: ignore[has-type]
|
|
36
|
+
ops.Z: 1, # type: ignore[has-type]
|
|
36
37
|
}
|
|
37
38
|
document(
|
|
38
39
|
DEFAULT_GATE_DOMAIN,
|
|
@@ -45,11 +46,11 @@ and Z gates.
|
|
|
45
46
|
|
|
46
47
|
|
|
47
48
|
def random_circuit(
|
|
48
|
-
qubits:
|
|
49
|
+
qubits: Sequence[cirq.Qid] | int,
|
|
49
50
|
n_moments: int,
|
|
50
51
|
op_density: float,
|
|
51
|
-
gate_domain:
|
|
52
|
-
random_state:
|
|
52
|
+
gate_domain: dict[ops.Gate, int] | None = None,
|
|
53
|
+
random_state: cirq.RANDOM_STATE_OR_SEED_LIKE = None,
|
|
53
54
|
) -> circuits.Circuit:
|
|
54
55
|
"""Generates a random circuit.
|
|
55
56
|
|
|
@@ -106,7 +107,7 @@ def random_circuit(
|
|
|
106
107
|
|
|
107
108
|
prng = value.parse_random_state(random_state)
|
|
108
109
|
|
|
109
|
-
moments:
|
|
110
|
+
moments: list[circuits.Moment] = []
|
|
110
111
|
gate_arity_pairs = sorted(gate_domain.items(), key=repr)
|
|
111
112
|
num_gates = len(gate_domain)
|
|
112
113
|
for _ in range(n_moments):
|
|
@@ -125,9 +126,9 @@ def random_circuit(
|
|
|
125
126
|
|
|
126
127
|
def random_two_qubit_circuit_with_czs(
|
|
127
128
|
num_czs: int = 3,
|
|
128
|
-
q0:
|
|
129
|
-
q1:
|
|
130
|
-
random_state:
|
|
129
|
+
q0: cirq.Qid | None = None,
|
|
130
|
+
q1: cirq.Qid | None = None,
|
|
131
|
+
random_state: cirq.RANDOM_STATE_OR_SEED_LIKE = None,
|
|
131
132
|
) -> circuits.Circuit:
|
|
132
133
|
"""Creates a random two qubit circuit with the given number of CNOTs.
|
|
133
134
|
|
|
@@ -11,8 +11,11 @@
|
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
14
17
|
import random
|
|
15
|
-
from typing import cast,
|
|
18
|
+
from typing import cast, Sequence
|
|
16
19
|
|
|
17
20
|
import numpy as np
|
|
18
21
|
import pytest
|
|
@@ -21,7 +24,7 @@ import cirq
|
|
|
21
24
|
import cirq.testing
|
|
22
25
|
|
|
23
26
|
|
|
24
|
-
def test_random_circuit_errors():
|
|
27
|
+
def test_random_circuit_errors() -> None:
|
|
25
28
|
with pytest.raises(ValueError, match='but was -1'):
|
|
26
29
|
_ = cirq.testing.random_circuit(qubits=5, n_moments=5, op_density=-1)
|
|
27
30
|
|
|
@@ -72,12 +75,12 @@ def _cases_for_random_circuit():
|
|
|
72
75
|
'n_qubits,n_moments,op_density,gate_domain,pass_qubits', _cases_for_random_circuit()
|
|
73
76
|
)
|
|
74
77
|
def test_random_circuit(
|
|
75
|
-
n_qubits:
|
|
78
|
+
n_qubits: int | Sequence[cirq.Qid],
|
|
76
79
|
n_moments: int,
|
|
77
80
|
op_density: float,
|
|
78
|
-
gate_domain:
|
|
81
|
+
gate_domain: dict[cirq.Gate, int] | None,
|
|
79
82
|
pass_qubits: bool,
|
|
80
|
-
):
|
|
83
|
+
) -> None:
|
|
81
84
|
qubit_set = cirq.LineQubit.range(n_qubits)
|
|
82
85
|
qubit_arg = qubit_set if pass_qubits else n_qubits
|
|
83
86
|
circuit = cirq.testing.random_circuit(qubit_arg, n_moments, op_density, gate_domain)
|
|
@@ -92,7 +95,7 @@ def test_random_circuit(
|
|
|
92
95
|
|
|
93
96
|
|
|
94
97
|
@pytest.mark.parametrize('seed', [random.randint(0, 2**32) for _ in range(10)])
|
|
95
|
-
def test_random_circuit_reproducible_with_seed(seed):
|
|
98
|
+
def test_random_circuit_reproducible_with_seed(seed) -> None:
|
|
96
99
|
wrappers = (lambda s: s, np.random.RandomState)
|
|
97
100
|
circuits = [
|
|
98
101
|
cirq.testing.random_circuit(
|
|
@@ -105,7 +108,7 @@ def test_random_circuit_reproducible_with_seed(seed):
|
|
|
105
108
|
eq.add_equality_group(*circuits)
|
|
106
109
|
|
|
107
110
|
|
|
108
|
-
def test_random_circuit_not_expected_number_of_qubits():
|
|
111
|
+
def test_random_circuit_not_expected_number_of_qubits() -> None:
|
|
109
112
|
circuit = cirq.testing.random_circuit(
|
|
110
113
|
qubits=3, n_moments=1, op_density=1.0, gate_domain={cirq.CNOT: 2}
|
|
111
114
|
)
|
|
@@ -114,7 +117,7 @@ def test_random_circuit_not_expected_number_of_qubits():
|
|
|
114
117
|
assert len(circuit.all_qubits()) == 2
|
|
115
118
|
|
|
116
119
|
|
|
117
|
-
def test_random_circuit_reproducible_between_runs():
|
|
120
|
+
def test_random_circuit_reproducible_between_runs() -> None:
|
|
118
121
|
circuit = cirq.testing.random_circuit(5, 8, 0.5, random_state=77)
|
|
119
122
|
expected_diagram = """
|
|
120
123
|
┌──┐
|
|
@@ -132,7 +135,7 @@ def test_random_circuit_reproducible_between_runs():
|
|
|
132
135
|
cirq.testing.assert_has_diagram(circuit, expected_diagram)
|
|
133
136
|
|
|
134
137
|
|
|
135
|
-
def test_random_two_qubit_circuit_with_czs():
|
|
138
|
+
def test_random_two_qubit_circuit_with_czs() -> None:
|
|
136
139
|
num_czs = lambda circuit: len(
|
|
137
140
|
[o for o in circuit.all_operations() if isinstance(o.gate, cirq.CZPowGate)]
|
|
138
141
|
)
|
|
@@ -12,10 +12,12 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
15
17
|
import cirq.testing
|
|
16
18
|
|
|
17
19
|
|
|
18
|
-
def test_fake_printer():
|
|
20
|
+
def test_fake_printer() -> None:
|
|
19
21
|
p = cirq.testing.FakePrinter()
|
|
20
22
|
assert p.text_pretty == ""
|
|
21
23
|
p.text("stuff")
|
|
@@ -24,7 +26,7 @@ def test_fake_printer():
|
|
|
24
26
|
assert p.text_pretty == "stuff more"
|
|
25
27
|
|
|
26
28
|
|
|
27
|
-
def test_assert_repr_pretty():
|
|
29
|
+
def test_assert_repr_pretty() -> None:
|
|
28
30
|
class TestClass:
|
|
29
31
|
def _repr_pretty_(self, p, cycle):
|
|
30
32
|
p.text("TestClass" if cycle else "I'm so pretty")
|
|
@@ -44,7 +46,7 @@ def test_assert_repr_pretty():
|
|
|
44
46
|
cirq.testing.assert_repr_pretty(TestClassMultipleTexts(), "TestClass", cycle=True)
|
|
45
47
|
|
|
46
48
|
|
|
47
|
-
def test_assert_repr_pretty_contains():
|
|
49
|
+
def test_assert_repr_pretty_contains() -> None:
|
|
48
50
|
class TestClass:
|
|
49
51
|
def _repr_pretty_(self, p, cycle):
|
|
50
52
|
p.text("TestClass" if cycle else "I'm so pretty")
|