cirq-core 1.7.0.dev20250825174419__py3-none-any.whl → 1.7.0.dev20251203004401__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.
- cirq/__init__.py +1 -0
- cirq/_compat.py +3 -2
- cirq/_compat_test.py +16 -15
- cirq/_doc.py +4 -3
- cirq/_import.py +2 -1
- cirq/_version.py +1 -1
- cirq/_version_test.py +1 -1
- cirq/circuits/_bucket_priority_queue.py +2 -1
- cirq/circuits/circuit.py +19 -17
- cirq/circuits/circuit_operation.py +2 -1
- cirq/circuits/circuit_operation_test.py +19 -0
- cirq/circuits/circuit_test.py +31 -12
- cirq/circuits/frozen_circuit.py +3 -2
- cirq/circuits/moment.py +3 -15
- cirq/circuits/optimization_pass.py +2 -1
- cirq/circuits/qasm_output.py +39 -10
- cirq/circuits/qasm_output_test.py +51 -2
- cirq/circuits/text_diagram_drawer.py +2 -1
- cirq/contrib/acquaintance/bipartite.py +2 -1
- cirq/contrib/acquaintance/devices.py +1 -1
- cirq/contrib/acquaintance/executor.py +4 -5
- cirq/contrib/acquaintance/executor_test.py +2 -1
- cirq/contrib/acquaintance/gates.py +2 -1
- cirq/contrib/acquaintance/gates_test.py +1 -1
- cirq/contrib/acquaintance/inspection_utils.py +2 -1
- cirq/contrib/acquaintance/mutation_utils.py +2 -1
- cirq/contrib/acquaintance/optimizers.py +2 -1
- cirq/contrib/acquaintance/permutation.py +2 -1
- cirq/contrib/acquaintance/permutation_test.py +1 -1
- cirq/contrib/acquaintance/shift.py +2 -1
- cirq/contrib/acquaintance/shift_swap_network.py +2 -1
- cirq/contrib/acquaintance/strategies/complete.py +3 -2
- cirq/contrib/acquaintance/strategies/cubic.py +2 -1
- cirq/contrib/acquaintance/strategies/quartic_paired.py +2 -1
- cirq/contrib/acquaintance/strategies/quartic_paired_test.py +1 -1
- cirq/contrib/acquaintance/testing.py +2 -1
- cirq/contrib/acquaintance/topological_sort.py +2 -1
- cirq/contrib/bayesian_network/bayesian_network_gate.py +3 -2
- cirq/contrib/circuitdag/circuit_dag.py +4 -2
- cirq/contrib/custom_simulators/custom_state_simulator.py +2 -1
- cirq/contrib/custom_simulators/custom_state_simulator_test.py +1 -1
- cirq/contrib/graph_device/graph_device.py +2 -1
- cirq/contrib/graph_device/graph_device_test.py +2 -1
- cirq/contrib/graph_device/hypergraph.py +2 -1
- cirq/contrib/graph_device/uniform_graph_device.py +2 -1
- cirq/contrib/json.py +14 -2
- cirq/contrib/json_test_data/BayesianNetworkGate.json +10 -0
- cirq/contrib/json_test_data/BayesianNetworkGate.repr +3 -0
- cirq/contrib/json_test_data/QuantumVolumeResult.json +169 -0
- cirq/contrib/json_test_data/QuantumVolumeResult.repr +22 -0
- cirq/contrib/json_test_data/SwapPermutationGate.json +3 -0
- cirq/contrib/json_test_data/SwapPermutationGate.repr +1 -0
- cirq/contrib/json_test_data/spec.py +0 -2
- cirq/contrib/noise_models/noise_models.py +2 -1
- cirq/contrib/paulistring/clifford_optimize.py +20 -2
- cirq/contrib/paulistring/optimize.py +1 -1
- cirq/contrib/paulistring/pauli_string_measurement_with_readout_mitigation.py +146 -35
- cirq/contrib/paulistring/pauli_string_measurement_with_readout_mitigation_test.py +81 -178
- cirq/contrib/paulistring/recombine.py +5 -2
- cirq/contrib/paulistring/separate.py +1 -1
- cirq/contrib/qasm_import/_lexer.py +6 -1
- cirq/contrib/qasm_import/_lexer_test.py +1 -1
- cirq/contrib/qasm_import/_parser.py +24 -8
- cirq/contrib/qasm_import/_parser_test.py +44 -6
- cirq/contrib/qcircuit/qcircuit_pdf_test.py +6 -9
- cirq/contrib/quantikz/__init__.py +21 -0
- cirq/contrib/quantikz/circuit_to_latex_quantikz.py +680 -0
- cirq/contrib/quantikz/circuit_to_latex_quantikz_test.py +253 -0
- cirq/contrib/quantikz/circuit_to_latex_render.py +424 -0
- cirq/contrib/quantikz/circuit_to_latex_render_test.py +44 -0
- cirq/contrib/quantum_volume/quantum_volume.py +2 -1
- cirq/contrib/quimb/density_matrix.py +1 -1
- cirq/contrib/quimb/grid_circuits.py +2 -1
- cirq/contrib/quimb/grid_circuits_test.py +1 -1
- cirq/contrib/quimb/mps_simulator.py +4 -3
- cirq/contrib/quimb/state_vector.py +2 -1
- cirq/contrib/quirk/export_to_quirk.py +2 -1
- cirq/contrib/quirk/linearize_circuit.py +1 -1
- cirq/contrib/quirk/quirk_gate.py +2 -1
- cirq/contrib/routing/device.py +1 -1
- cirq/contrib/routing/greedy.py +2 -1
- cirq/contrib/routing/initialization.py +2 -1
- cirq/contrib/routing/router.py +2 -1
- cirq/contrib/routing/swap_network.py +2 -1
- cirq/contrib/routing/utils.py +2 -1
- cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking.py +7 -5
- cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking_test.py +6 -6
- cirq/devices/device.py +2 -1
- cirq/devices/grid_device_metadata.py +2 -1
- cirq/devices/grid_qubit.py +7 -6
- cirq/devices/insertion_noise_model.py +2 -1
- cirq/devices/line_qubit.py +2 -1
- cirq/devices/named_topologies.py +2 -1
- cirq/devices/noise_model.py +2 -1
- cirq/devices/noise_model_test.py +1 -1
- cirq/devices/noise_properties.py +2 -1
- cirq/devices/superconducting_qubits_noise_properties_test.py +2 -1
- cirq/devices/thermal_noise_model.py +2 -1
- cirq/experiments/__init__.py +2 -0
- cirq/experiments/benchmarking/parallel_xeb.py +2 -1
- cirq/experiments/benchmarking/parallel_xeb_test.py +1 -1
- cirq/experiments/fidelity_estimation.py +2 -1
- cirq/experiments/fidelity_estimation_test.py +1 -1
- cirq/experiments/ghz_2d.py +150 -0
- cirq/experiments/ghz_2d_test.py +155 -0
- cirq/experiments/n_qubit_tomography.py +2 -1
- cirq/experiments/n_qubit_tomography_test.py +1 -1
- cirq/experiments/purity_estimation.py +1 -1
- cirq/experiments/qubit_characterizations.py +33 -4
- cirq/experiments/qubit_characterizations_test.py +16 -0
- cirq/experiments/random_quantum_circuit_generation.py +2 -1
- cirq/experiments/random_quantum_circuit_generation_test.py +2 -1
- cirq/experiments/readout_confusion_matrix.py +2 -1
- cirq/experiments/readout_confusion_matrix_test.py +1 -1
- cirq/experiments/single_qubit_readout_calibration.py +2 -1
- cirq/experiments/single_qubit_readout_calibration_test.py +1 -1
- cirq/experiments/t1_decay_experiment.py +2 -1
- cirq/experiments/two_qubit_xeb.py +2 -1
- cirq/experiments/two_qubit_xeb_test.py +1 -1
- cirq/experiments/xeb_fitting.py +2 -1
- cirq/experiments/xeb_fitting_test.py +1 -1
- cirq/experiments/xeb_sampling.py +5 -3
- cirq/experiments/xeb_sampling_test.py +1 -1
- cirq/experiments/xeb_simulation.py +2 -1
- cirq/experiments/xeb_simulation_test.py +2 -1
- cirq/experiments/z_phase_calibration.py +2 -1
- cirq/experiments/z_phase_calibration_test.py +18 -3
- cirq/interop/quirk/cells/__init__.py +1 -2
- cirq/interop/quirk/cells/all_cells.py +2 -1
- cirq/interop/quirk/cells/arithmetic_cells.py +2 -1
- cirq/interop/quirk/cells/cell.py +2 -1
- cirq/interop/quirk/cells/composite_cell.py +2 -1
- cirq/interop/quirk/cells/composite_cell_test.py +1 -1
- cirq/interop/quirk/cells/control_cells.py +2 -1
- cirq/interop/quirk/cells/frequency_space_cells.py +1 -1
- cirq/interop/quirk/cells/ignored_cells.py +1 -1
- cirq/interop/quirk/cells/input_cells.py +2 -1
- cirq/interop/quirk/cells/input_rotation_cells.py +2 -1
- cirq/interop/quirk/cells/measurement_cells.py +2 -1
- cirq/interop/quirk/cells/parse.py +2 -11
- cirq/interop/quirk/cells/qubit_permutation_cells.py +2 -1
- cirq/interop/quirk/cells/scalar_cells.py +2 -1
- cirq/interop/quirk/cells/single_qubit_rotation_cells.py +2 -1
- cirq/interop/quirk/cells/swap_cell.py +2 -1
- cirq/interop/quirk/cells/unsupported_cells.py +1 -1
- cirq/interop/quirk/url_to_circuit.py +2 -1
- cirq/json_resolver_cache.py +0 -2
- cirq/linalg/decompositions.py +6 -2
- cirq/linalg/decompositions_test.py +1 -0
- cirq/linalg/diagonalize.py +1 -1
- cirq/linalg/predicates.py +2 -1
- cirq/linalg/tolerance.py +2 -1
- cirq/linalg/transformations.py +3 -2
- cirq/ops/arithmetic_operation.py +4 -3
- cirq/ops/arithmetic_operation_test.py +1 -1
- cirq/ops/boolean_hamiltonian.py +4 -3
- cirq/ops/classically_controlled_operation.py +11 -11
- cirq/ops/classically_controlled_operation_test.py +26 -2
- cirq/ops/clifford_gate.py +3 -2
- cirq/ops/clifford_gate_test.py +1 -2
- cirq/ops/common_channels.py +2 -1
- cirq/ops/common_gates.py +3 -2
- cirq/ops/control_values.py +2 -1
- cirq/ops/controlled_gate.py +3 -2
- cirq/ops/controlled_gate_test.py +2 -1
- cirq/ops/controlled_operation.py +3 -2
- cirq/ops/controlled_operation_test.py +2 -1
- cirq/ops/dense_pauli_string.py +44 -81
- cirq/ops/dense_pauli_string_test.py +21 -0
- cirq/ops/diagonal_gate.py +3 -2
- cirq/ops/eigen_gate.py +9 -7
- cirq/ops/fourier_transform.py +3 -2
- cirq/ops/fourier_transform_test.py +2 -4
- cirq/ops/fsim_gate.py +3 -2
- cirq/ops/gate_operation.py +23 -12
- cirq/ops/gateset.py +22 -2
- cirq/ops/global_phase_op.py +3 -2
- cirq/ops/greedy_qubit_manager.py +2 -1
- cirq/ops/identity.py +2 -1
- cirq/ops/kraus_channel.py +2 -1
- cirq/ops/linear_combinations.py +12 -17
- cirq/ops/linear_combinations_test.py +23 -1
- cirq/ops/matrix_gates.py +2 -1
- cirq/ops/measure_util.py +8 -6
- cirq/ops/measurement_gate.py +2 -1
- cirq/ops/mixed_unitary_channel.py +2 -1
- cirq/ops/named_qubit.py +2 -2
- cirq/ops/op_tree.py +2 -1
- cirq/ops/parallel_gate.py +3 -2
- cirq/ops/parity_gates.py +2 -1
- cirq/ops/parity_gates_test.py +35 -0
- cirq/ops/pauli_interaction_gate.py +2 -1
- cirq/ops/pauli_measurement_gate.py +2 -1
- cirq/ops/pauli_string.py +37 -57
- cirq/ops/pauli_string_phasor.py +6 -5
- cirq/ops/pauli_string_raw_types.py +2 -1
- cirq/ops/pauli_string_test.py +49 -6
- cirq/ops/pauli_sum_exponential.py +2 -1
- cirq/ops/permutation_gate.py +2 -1
- cirq/ops/phased_iswap_gate.py +3 -2
- cirq/ops/phased_x_gate.py +5 -4
- cirq/ops/phased_x_z_gate.py +12 -5
- cirq/ops/projector.py +2 -1
- cirq/ops/qubit_manager.py +2 -1
- cirq/ops/qubit_order.py +2 -1
- cirq/ops/qubit_order_or_list.py +1 -1
- cirq/ops/random_gate_channel.py +3 -2
- cirq/ops/raw_types.py +33 -16
- cirq/ops/raw_types_test.py +4 -3
- cirq/ops/state_preparation_channel.py +2 -1
- cirq/ops/three_qubit_gates.py +3 -2
- cirq/ops/two_qubit_diagonal_gate.py +3 -2
- cirq/ops/uniform_superposition_gate.py +2 -1
- cirq/ops/wait_gate.py +10 -4
- cirq/protocols/act_on_protocol.py +2 -1
- cirq/protocols/act_on_protocol_test.py +2 -1
- cirq/protocols/apply_channel_protocol.py +2 -1
- cirq/protocols/apply_mixture_protocol.py +2 -1
- cirq/protocols/apply_mixture_protocol_test.py +2 -1
- cirq/protocols/apply_unitary_protocol.py +2 -1
- cirq/protocols/apply_unitary_protocol_test.py +2 -0
- cirq/protocols/approximate_equality_protocol.py +2 -1
- cirq/protocols/circuit_diagram_info_protocol.py +2 -1
- cirq/protocols/control_key_protocol.py +7 -0
- cirq/protocols/decompose_protocol.py +2 -12
- cirq/protocols/has_stabilizer_effect_protocol.py +1 -1
- cirq/protocols/has_stabilizer_effect_protocol_test.py +11 -9
- cirq/protocols/has_unitary_protocol_test.py +3 -3
- cirq/protocols/hash_from_pickle_test.py +2 -2
- cirq/protocols/inverse_protocol.py +2 -1
- cirq/protocols/json_serialization.py +5 -4
- cirq/protocols/json_serialization_test.py +31 -31
- cirq/protocols/kraus_protocol.py +4 -3
- cirq/protocols/kraus_protocol_test.py +7 -7
- cirq/protocols/measurement_key_protocol.py +32 -8
- cirq/protocols/mixture_protocol.py +3 -2
- cirq/protocols/mixture_protocol_test.py +7 -7
- cirq/protocols/mul_protocol_test.py +4 -4
- cirq/protocols/phase_protocol.py +13 -4
- cirq/protocols/pow_protocol.py +2 -1
- cirq/protocols/pow_protocol_test.py +5 -5
- cirq/protocols/qasm.py +2 -1
- cirq/protocols/qid_shape_protocol.py +2 -1
- cirq/protocols/resolve_parameters.py +17 -15
- cirq/protocols/trace_distance_bound.py +2 -1
- cirq/protocols/unitary_protocol.py +21 -21
- cirq/protocols/unitary_protocol_test.py +31 -19
- cirq/qis/channels.py +1 -1
- cirq/qis/channels_test.py +1 -1
- cirq/qis/clifford_tableau.py +16 -15
- cirq/qis/clifford_tableau_test.py +17 -17
- cirq/qis/entropy.py +3 -3
- cirq/qis/entropy_test.py +1 -1
- cirq/qis/quantum_state_representation.py +2 -1
- cirq/qis/states.py +7 -2
- cirq/qis/states_test.py +54 -54
- cirq/sim/classical_simulator.py +25 -14
- cirq/sim/classical_simulator_test.py +85 -30
- cirq/sim/clifford/clifford_simulator.py +7 -6
- cirq/sim/clifford/clifford_simulator_test.py +51 -50
- cirq/sim/clifford/clifford_tableau_simulation_state.py +2 -1
- cirq/sim/clifford/stabilizer_ch_form_simulation_state.py +2 -1
- cirq/sim/clifford/stabilizer_sampler.py +1 -1
- cirq/sim/clifford/stabilizer_simulation_state.py +2 -1
- cirq/sim/clifford/stabilizer_state_ch_form.py +16 -15
- cirq/sim/clifford/stabilizer_state_ch_form_test.py +0 -1
- cirq/sim/density_matrix_simulation_state.py +7 -6
- cirq/sim/density_matrix_simulator.py +3 -2
- cirq/sim/density_matrix_simulator_test.py +94 -84
- cirq/sim/density_matrix_utils.py +2 -1
- cirq/sim/density_matrix_utils_test.py +1 -1
- cirq/sim/mux.py +35 -8
- cirq/sim/mux_test.py +39 -26
- cirq/sim/simulation_product_state.py +2 -1
- cirq/sim/simulation_product_state_test.py +8 -7
- cirq/sim/simulation_state.py +6 -5
- cirq/sim/simulation_state_base.py +3 -2
- cirq/sim/simulation_state_test.py +7 -6
- cirq/sim/simulation_utils.py +2 -1
- cirq/sim/simulator.py +4 -3
- cirq/sim/simulator_base.py +2 -1
- cirq/sim/simulator_base_test.py +51 -36
- cirq/sim/simulator_test.py +41 -36
- cirq/sim/sparse_simulator.py +3 -2
- cirq/sim/sparse_simulator_test.py +92 -82
- cirq/sim/state_vector.py +5 -6
- cirq/sim/state_vector_simulation_state.py +10 -9
- cirq/sim/state_vector_simulator.py +2 -1
- cirq/sim/state_vector_simulator_test.py +9 -9
- cirq/sim/state_vector_test.py +40 -39
- cirq/study/__init__.py +1 -0
- cirq/study/flatten_expressions.py +2 -1
- cirq/study/resolver.py +31 -18
- cirq/study/resolver_test.py +1 -1
- cirq/study/result.py +2 -1
- cirq/study/result_test.py +20 -20
- cirq/study/sweepable.py +2 -1
- cirq/study/sweepable_test.py +20 -20
- cirq/study/sweeps.py +26 -1
- cirq/study/sweeps_test.py +67 -43
- cirq/testing/_compat_test_data/__init__.py +3 -3
- cirq/testing/circuit_compare.py +2 -1
- cirq/testing/circuit_compare_test.py +16 -14
- cirq/testing/consistent_act_on_test.py +1 -1
- cirq/testing/consistent_channels.py +2 -2
- cirq/testing/consistent_controlled_gate_op.py +2 -2
- cirq/testing/consistent_controlled_gate_op_test.py +2 -1
- cirq/testing/consistent_decomposition.py +4 -2
- cirq/testing/consistent_phase_by.py +1 -1
- cirq/testing/consistent_protocols.py +2 -1
- cirq/testing/consistent_protocols_test.py +3 -3
- cirq/testing/consistent_qasm.py +4 -3
- cirq/testing/consistent_qasm_test.py +3 -3
- cirq/testing/consistent_resolve_parameters.py +1 -1
- cirq/testing/consistent_unitary.py +1 -1
- cirq/testing/consistent_unitary_test.py +1 -1
- cirq/testing/deprecation.py +1 -1
- cirq/testing/devices.py +3 -2
- cirq/testing/equals_tester.py +4 -3
- cirq/testing/equivalent_basis_map.py +4 -2
- cirq/testing/json.py +3 -2
- cirq/testing/lin_alg_utils.py +1 -1
- cirq/testing/logs.py +1 -1
- cirq/testing/op_tree.py +1 -1
- cirq/testing/order_tester.py +2 -2
- cirq/testing/pytest_utils.py +2 -1
- cirq/testing/random_circuit.py +2 -1
- cirq/testing/random_circuit_test.py +2 -1
- cirq/testing/repr_pretty_tester.py +3 -3
- cirq/transformers/__init__.py +1 -0
- cirq/transformers/_connected_component.py +231 -0
- cirq/transformers/_connected_component_test.py +200 -0
- cirq/transformers/align_test.py +13 -13
- cirq/transformers/analytical_decompositions/clifford_decomposition.py +8 -7
- cirq/transformers/analytical_decompositions/clifford_decomposition_test.py +5 -5
- cirq/transformers/analytical_decompositions/controlled_gate_decomposition.py +11 -10
- cirq/transformers/analytical_decompositions/controlled_gate_decomposition_test.py +6 -6
- cirq/transformers/analytical_decompositions/cphase_to_fsim.py +3 -2
- cirq/transformers/analytical_decompositions/cphase_to_fsim_test.py +11 -10
- cirq/transformers/analytical_decompositions/quantum_shannon_decomposition.py +8 -7
- cirq/transformers/analytical_decompositions/quantum_shannon_decomposition_test.py +17 -20
- cirq/transformers/analytical_decompositions/single_qubit_decompositions_test.py +33 -27
- cirq/transformers/analytical_decompositions/single_to_two_qubit_isometry_test.py +1 -1
- cirq/transformers/analytical_decompositions/three_qubit_decomposition.py +1 -1
- cirq/transformers/analytical_decompositions/two_qubit_state_preparation_test.py +12 -11
- cirq/transformers/analytical_decompositions/two_qubit_to_cz.py +5 -2
- cirq/transformers/analytical_decompositions/two_qubit_to_cz_test.py +3 -3
- cirq/transformers/analytical_decompositions/two_qubit_to_fsim.py +2 -1
- cirq/transformers/analytical_decompositions/two_qubit_to_ms.py +2 -1
- cirq/transformers/analytical_decompositions/two_qubit_to_ms_test.py +2 -2
- cirq/transformers/analytical_decompositions/two_qubit_to_sqrt_iswap.py +2 -1
- cirq/transformers/analytical_decompositions/two_qubit_to_sqrt_iswap_test.py +32 -30
- cirq/transformers/drop_negligible_operations_test.py +7 -7
- cirq/transformers/dynamical_decoupling.py +185 -112
- cirq/transformers/dynamical_decoupling_test.py +195 -201
- cirq/transformers/eject_phased_paulis.py +2 -1
- cirq/transformers/eject_phased_paulis_test.py +3 -2
- cirq/transformers/eject_z.py +5 -3
- cirq/transformers/eject_z_test.py +23 -25
- cirq/transformers/expand_composite.py +3 -2
- cirq/transformers/expand_composite_test.py +14 -14
- cirq/transformers/gauge_compiling/__init__.py +13 -0
- cirq/transformers/gauge_compiling/gauge_compiling.py +3 -2
- cirq/transformers/gauge_compiling/gauge_compiling_test.py +14 -12
- cirq/transformers/gauge_compiling/gauge_compiling_test_utils.py +3 -3
- cirq/transformers/gauge_compiling/idle_moments_gauge.py +225 -0
- cirq/transformers/gauge_compiling/idle_moments_gauge_test.py +193 -0
- cirq/transformers/gauge_compiling/multi_moment_cphase_gauge.py +242 -0
- cirq/transformers/gauge_compiling/multi_moment_cphase_gauge_test.py +243 -0
- cirq/transformers/gauge_compiling/multi_moment_gauge_compiling.py +151 -0
- cirq/transformers/gauge_compiling/sqrt_cz_gauge.py +2 -1
- cirq/transformers/heuristic_decompositions/gate_tabulation_math_utils.py +1 -1
- cirq/transformers/heuristic_decompositions/gate_tabulation_math_utils_test.py +6 -6
- cirq/transformers/heuristic_decompositions/two_qubit_gate_tabulation.py +3 -2
- cirq/transformers/measurement_transformers.py +2 -1
- cirq/transformers/measurement_transformers_test.py +45 -39
- cirq/transformers/merge_k_qubit_gates.py +2 -1
- cirq/transformers/merge_k_qubit_gates_test.py +1 -1
- cirq/transformers/merge_single_qubit_gates.py +9 -5
- cirq/transformers/merge_single_qubit_gates_test.py +22 -22
- cirq/transformers/noise_adding_test.py +2 -2
- cirq/transformers/optimize_for_target_gateset.py +2 -1
- cirq/transformers/optimize_for_target_gateset_test.py +11 -9
- cirq/transformers/qubit_management_transformers_test.py +6 -2
- cirq/transformers/routing/mapping_manager.py +2 -1
- cirq/transformers/routing/route_circuit_cqc.py +2 -1
- cirq/transformers/stratify.py +2 -1
- cirq/transformers/symbolize.py +2 -1
- cirq/transformers/tag_transformers.py +2 -1
- cirq/transformers/target_gatesets/compilation_target_gateset.py +2 -1
- cirq/transformers/target_gatesets/cz_gateset.py +2 -1
- cirq/transformers/target_gatesets/cz_gateset_test.py +1 -1
- cirq/transformers/target_gatesets/sqrt_iswap_gateset.py +2 -1
- cirq/transformers/transformer_api.py +2 -1
- cirq/transformers/transformer_primitives.py +271 -145
- cirq/transformers/transformer_primitives_test.py +185 -1
- cirq/value/abc_alt.py +2 -1
- cirq/value/classical_data.py +2 -1
- cirq/value/condition.py +2 -1
- cirq/value/digits.py +9 -2
- cirq/value/duration.py +6 -5
- cirq/value/linear_dict.py +4 -9
- cirq/value/measurement_key.py +2 -1
- cirq/value/periodic_value.py +3 -2
- cirq/value/product_state.py +2 -1
- cirq/value/value_equality_attr.py +2 -1
- cirq/vis/density_matrix.py +1 -1
- cirq/vis/heatmap.py +2 -1
- cirq/vis/histogram.py +2 -1
- cirq/vis/state_histogram.py +2 -1
- cirq/work/collector.py +2 -1
- cirq/work/observable_grouping.py +2 -1
- cirq/work/observable_measurement.py +2 -1
- cirq/work/observable_measurement_data.py +2 -1
- cirq/work/observable_measurement_test.py +1 -1
- cirq/work/observable_readout_calibration.py +2 -1
- cirq/work/observable_readout_calibration_test.py +1 -1
- cirq/work/observable_settings.py +2 -1
- cirq/work/sampler.py +2 -1
- cirq/work/sampler_test.py +1 -1
- {cirq_core-1.7.0.dev20250825174419.dist-info → cirq_core-1.7.0.dev20251203004401.dist-info}/METADATA +5 -6
- {cirq_core-1.7.0.dev20250825174419.dist-info → cirq_core-1.7.0.dev20251203004401.dist-info}/RECORD +425 -406
- cirq/contrib/json_test.py +0 -33
- {cirq_core-1.7.0.dev20250825174419.dist-info → cirq_core-1.7.0.dev20251203004401.dist-info}/WHEEL +0 -0
- {cirq_core-1.7.0.dev20250825174419.dist-info → cirq_core-1.7.0.dev20251203004401.dist-info}/licenses/LICENSE +0 -0
- {cirq_core-1.7.0.dev20250825174419.dist-info → cirq_core-1.7.0.dev20251203004401.dist-info}/top_level.txt +0 -0
cirq/study/sweeps_test.py
CHANGED
|
@@ -20,27 +20,27 @@ import sympy
|
|
|
20
20
|
import cirq
|
|
21
21
|
|
|
22
22
|
|
|
23
|
-
def test_product_duplicate_keys():
|
|
23
|
+
def test_product_duplicate_keys() -> None:
|
|
24
24
|
with pytest.raises(ValueError):
|
|
25
25
|
_ = cirq.Linspace('a', 0, 9, 10) * cirq.Linspace('a', 0, 10, 11)
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
def test_zip_duplicate_keys():
|
|
28
|
+
def test_zip_duplicate_keys() -> None:
|
|
29
29
|
with pytest.raises(ValueError):
|
|
30
30
|
_ = cirq.Linspace('a', 0, 9, 10) + cirq.Linspace('a', 0, 10, 11)
|
|
31
31
|
|
|
32
32
|
|
|
33
|
-
def test_product_wrong_type():
|
|
33
|
+
def test_product_wrong_type() -> None:
|
|
34
34
|
with pytest.raises(TypeError):
|
|
35
|
-
_ = cirq.Linspace('a', 0, 9, 10) * 2
|
|
35
|
+
_ = cirq.Linspace('a', 0, 9, 10) * 2 # type: ignore[operator]
|
|
36
36
|
|
|
37
37
|
|
|
38
|
-
def test_zip_wrong_type():
|
|
38
|
+
def test_zip_wrong_type() -> None:
|
|
39
39
|
with pytest.raises(TypeError):
|
|
40
|
-
_ = cirq.Linspace('a', 0, 9, 10) + 2
|
|
40
|
+
_ = cirq.Linspace('a', 0, 9, 10) + 2 # type: ignore[operator]
|
|
41
41
|
|
|
42
42
|
|
|
43
|
-
def test_linspace():
|
|
43
|
+
def test_linspace() -> None:
|
|
44
44
|
sweep = cirq.Linspace('a', 0.34, 9.16, 7)
|
|
45
45
|
assert len(sweep) == 7
|
|
46
46
|
params = list(sweep.param_tuples())
|
|
@@ -49,7 +49,7 @@ def test_linspace():
|
|
|
49
49
|
assert params[-1] == (('a', 9.16),)
|
|
50
50
|
|
|
51
51
|
|
|
52
|
-
def test_linspace_one_point():
|
|
52
|
+
def test_linspace_one_point() -> None:
|
|
53
53
|
sweep = cirq.Linspace('a', 0.34, 9.16, 1)
|
|
54
54
|
assert len(sweep) == 1
|
|
55
55
|
params = list(sweep.param_tuples())
|
|
@@ -57,7 +57,7 @@ def test_linspace_one_point():
|
|
|
57
57
|
assert params[0] == (('a', 0.34),)
|
|
58
58
|
|
|
59
59
|
|
|
60
|
-
def test_linspace_sympy_symbol():
|
|
60
|
+
def test_linspace_sympy_symbol() -> None:
|
|
61
61
|
a = sympy.Symbol('a')
|
|
62
62
|
sweep = cirq.Linspace(a, 0.34, 9.16, 7)
|
|
63
63
|
assert len(sweep) == 7
|
|
@@ -67,14 +67,14 @@ def test_linspace_sympy_symbol():
|
|
|
67
67
|
assert params[-1] == (('a', 9.16),)
|
|
68
68
|
|
|
69
69
|
|
|
70
|
-
def test_points():
|
|
70
|
+
def test_points() -> None:
|
|
71
71
|
sweep = cirq.Points('a', [1, 2, 3, 4])
|
|
72
72
|
assert len(sweep) == 4
|
|
73
73
|
params = list(sweep)
|
|
74
74
|
assert len(params) == 4
|
|
75
75
|
|
|
76
76
|
|
|
77
|
-
def test_zip():
|
|
77
|
+
def test_zip() -> None:
|
|
78
78
|
sweep = cirq.Points('a', [1, 2, 3]) + cirq.Points('b', [4, 5, 6, 7])
|
|
79
79
|
assert len(sweep) == 3
|
|
80
80
|
assert _values(sweep, 'a') == [1, 2, 3]
|
|
@@ -86,7 +86,7 @@ def test_zip():
|
|
|
86
86
|
]
|
|
87
87
|
|
|
88
88
|
|
|
89
|
-
def test_zip_longest():
|
|
89
|
+
def test_zip_longest() -> None:
|
|
90
90
|
sweep = cirq.ZipLongest(cirq.Points('a', [1, 2, 3]), cirq.Points('b', [4, 5, 6, 7]))
|
|
91
91
|
assert tuple(sweep.param_tuples()) == (
|
|
92
92
|
(('a', 1), ('b', 4)),
|
|
@@ -104,7 +104,7 @@ def test_zip_longest():
|
|
|
104
104
|
)
|
|
105
105
|
|
|
106
106
|
|
|
107
|
-
def test_zip_longest_compatibility():
|
|
107
|
+
def test_zip_longest_compatibility() -> None:
|
|
108
108
|
sweep = cirq.Zip(cirq.Points('a', [1, 2, 3]), cirq.Points('b', [4, 5, 6]))
|
|
109
109
|
sweep_longest = cirq.ZipLongest(cirq.Points('a', [1, 2, 3]), cirq.Points('b', [4, 5, 6]))
|
|
110
110
|
assert tuple(sweep.param_tuples()) == tuple(sweep_longest.param_tuples())
|
|
@@ -118,7 +118,7 @@ def test_zip_longest_compatibility():
|
|
|
118
118
|
assert tuple(sweep.param_tuples()) == tuple(sweep_longest.param_tuples())
|
|
119
119
|
|
|
120
120
|
|
|
121
|
-
def test_empty_zip():
|
|
121
|
+
def test_empty_zip() -> None:
|
|
122
122
|
assert len(cirq.Zip()) == 0
|
|
123
123
|
assert len(cirq.ZipLongest()) == 0
|
|
124
124
|
assert str(cirq.Zip()) == 'Zip()'
|
|
@@ -126,7 +126,7 @@ def test_empty_zip():
|
|
|
126
126
|
_ = cirq.ZipLongest(cirq.Points('e', []), cirq.Points('a', [1, 2, 3]))
|
|
127
127
|
|
|
128
128
|
|
|
129
|
-
def test_zip_eq():
|
|
129
|
+
def test_zip_eq() -> None:
|
|
130
130
|
et = cirq.testing.EqualsTester()
|
|
131
131
|
point_sweep1 = cirq.Points('a', [1, 2, 3])
|
|
132
132
|
point_sweep2 = cirq.Points('b', [4, 5, 6, 7])
|
|
@@ -146,7 +146,7 @@ def test_zip_eq():
|
|
|
146
146
|
et.add_equality_group(cirq.Zip(point_sweep1, point_sweep2))
|
|
147
147
|
|
|
148
148
|
|
|
149
|
-
def test_product():
|
|
149
|
+
def test_product() -> None:
|
|
150
150
|
sweep = cirq.Points('a', [1, 2, 3]) * cirq.Points('b', [4, 5, 6, 7])
|
|
151
151
|
assert len(sweep) == 12
|
|
152
152
|
assert _values(sweep, 'a') == [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]
|
|
@@ -172,7 +172,7 @@ def test_product():
|
|
|
172
172
|
assert list(map(list, sweep.param_tuples())) == [[(str(i), 0) for i in range(1025)]]
|
|
173
173
|
|
|
174
174
|
|
|
175
|
-
def test_nested_product_zip():
|
|
175
|
+
def test_nested_product_zip() -> None:
|
|
176
176
|
sweep = cirq.Product(
|
|
177
177
|
cirq.Product(cirq.Points('a', [0]), cirq.Points('b', [0])),
|
|
178
178
|
cirq.Zip(cirq.Points('c', [0, 1]), cirq.Points('d', [0, 1])),
|
|
@@ -183,7 +183,7 @@ def test_nested_product_zip():
|
|
|
183
183
|
]
|
|
184
184
|
|
|
185
185
|
|
|
186
|
-
def test_zip_addition():
|
|
186
|
+
def test_zip_addition() -> None:
|
|
187
187
|
zip_sweep = cirq.Zip(cirq.Points('a', [1, 2]), cirq.Points('b', [3, 4]))
|
|
188
188
|
zip_sweep2 = cirq.Points('c', [5, 6]) + zip_sweep
|
|
189
189
|
assert len(zip_sweep2) == 2
|
|
@@ -192,17 +192,17 @@ def test_zip_addition():
|
|
|
192
192
|
assert _values(zip_sweep2, 'c') == [5, 6]
|
|
193
193
|
|
|
194
194
|
|
|
195
|
-
def test_empty_product():
|
|
195
|
+
def test_empty_product() -> None:
|
|
196
196
|
sweep = cirq.Product()
|
|
197
197
|
assert len(sweep) == len(list(sweep)) == 1
|
|
198
198
|
assert str(sweep) == 'Product()'
|
|
199
199
|
assert list(map(list, sweep.param_tuples())) == [[]]
|
|
200
200
|
|
|
201
201
|
|
|
202
|
-
def test_slice_access_error():
|
|
202
|
+
def test_slice_access_error() -> None:
|
|
203
203
|
sweep = cirq.Points('a', [1, 2, 3])
|
|
204
204
|
with pytest.raises(TypeError, match='<class \'str\'>'):
|
|
205
|
-
_ = sweep['junk']
|
|
205
|
+
_ = sweep['junk'] # type: ignore[call-overload]
|
|
206
206
|
|
|
207
207
|
with pytest.raises(IndexError):
|
|
208
208
|
_ = sweep[4]
|
|
@@ -211,7 +211,7 @@ def test_slice_access_error():
|
|
|
211
211
|
_ = sweep[-4]
|
|
212
212
|
|
|
213
213
|
|
|
214
|
-
def test_slice_sweep():
|
|
214
|
+
def test_slice_sweep() -> None:
|
|
215
215
|
sweep = cirq.Points('a', [1, 2, 3]) * cirq.Points('b', [4, 5, 6, 7])
|
|
216
216
|
|
|
217
217
|
first_two = sweep[:2]
|
|
@@ -239,7 +239,7 @@ def test_slice_sweep():
|
|
|
239
239
|
assert len(list(single_sweep.param_tuples())) == 1
|
|
240
240
|
|
|
241
241
|
|
|
242
|
-
def test_access_sweep():
|
|
242
|
+
def test_access_sweep() -> None:
|
|
243
243
|
sweep = cirq.Points('a', [1, 2, 3]) * cirq.Points('b', [4, 5, 6, 7])
|
|
244
244
|
|
|
245
245
|
first_elem = sweep[-12]
|
|
@@ -259,7 +259,7 @@ def test_access_sweep():
|
|
|
259
259
|
lambda: ({sympy.Symbol('a'): a, 'b': a + 1} for a in (0, 0.5, 1, -10)),
|
|
260
260
|
],
|
|
261
261
|
)
|
|
262
|
-
def test_list_sweep(r_list_factory):
|
|
262
|
+
def test_list_sweep(r_list_factory) -> None:
|
|
263
263
|
sweep = cirq.ListSweep(r_list_factory())
|
|
264
264
|
assert sweep.keys == ['a', 'b']
|
|
265
265
|
assert len(sweep) == 4
|
|
@@ -270,13 +270,13 @@ def test_list_sweep(r_list_factory):
|
|
|
270
270
|
assert params[3] == (('a', -10), ('b', -9))
|
|
271
271
|
|
|
272
272
|
|
|
273
|
-
def test_list_sweep_empty():
|
|
273
|
+
def test_list_sweep_empty() -> None:
|
|
274
274
|
assert cirq.ListSweep([]).keys == []
|
|
275
275
|
|
|
276
276
|
|
|
277
|
-
def test_list_sweep_type_error():
|
|
277
|
+
def test_list_sweep_type_error() -> None:
|
|
278
278
|
with pytest.raises(TypeError, match='Not a ParamResolver'):
|
|
279
|
-
_ = cirq.ListSweep([cirq.ParamResolver(), 'bad'])
|
|
279
|
+
_ = cirq.ListSweep([cirq.ParamResolver(), 'bad']) # type: ignore[list-item]
|
|
280
280
|
|
|
281
281
|
|
|
282
282
|
def _values(sweep, key):
|
|
@@ -284,7 +284,7 @@ def _values(sweep, key):
|
|
|
284
284
|
return [resolver.value_of(p) for resolver in sweep]
|
|
285
285
|
|
|
286
286
|
|
|
287
|
-
def test_equality():
|
|
287
|
+
def test_equality() -> None:
|
|
288
288
|
et = cirq.testing.EqualsTester()
|
|
289
289
|
|
|
290
290
|
et.add_equality_group(cirq.UnitSweep, cirq.UnitSweep)
|
|
@@ -320,7 +320,7 @@ def test_equality():
|
|
|
320
320
|
et.make_equality_group(lambda: cirq.ListSweep([{'x': 1}, {'x': -1}]))
|
|
321
321
|
|
|
322
322
|
|
|
323
|
-
def test_repr():
|
|
323
|
+
def test_repr() -> None:
|
|
324
324
|
cirq.testing.assert_equivalent_repr(
|
|
325
325
|
cirq.study.sweeps.Product(cirq.UnitSweep),
|
|
326
326
|
setup_code='import cirq\nfrom collections import OrderedDict',
|
|
@@ -343,7 +343,7 @@ def test_repr():
|
|
|
343
343
|
)
|
|
344
344
|
|
|
345
345
|
|
|
346
|
-
def test_zip_product_str():
|
|
346
|
+
def test_zip_product_str() -> None:
|
|
347
347
|
assert (
|
|
348
348
|
str(cirq.UnitSweep + cirq.UnitSweep + cirq.UnitSweep)
|
|
349
349
|
== 'cirq.UnitSweep + cirq.UnitSweep + cirq.UnitSweep'
|
|
@@ -362,7 +362,7 @@ def test_zip_product_str():
|
|
|
362
362
|
)
|
|
363
363
|
|
|
364
364
|
|
|
365
|
-
def test_list_sweep_str():
|
|
365
|
+
def test_list_sweep_str() -> None:
|
|
366
366
|
assert (
|
|
367
367
|
str(cirq.UnitSweep)
|
|
368
368
|
== '''Sweep:
|
|
@@ -411,7 +411,7 @@ def test_list_sweep_str():
|
|
|
411
411
|
)
|
|
412
412
|
|
|
413
413
|
|
|
414
|
-
def test_dict_to_product_sweep():
|
|
414
|
+
def test_dict_to_product_sweep() -> None:
|
|
415
415
|
assert cirq.dict_to_product_sweep({'t': [0, 2, 3]}) == (
|
|
416
416
|
cirq.Product(cirq.Points('t', [0, 2, 3]))
|
|
417
417
|
)
|
|
@@ -421,7 +421,7 @@ def test_dict_to_product_sweep():
|
|
|
421
421
|
)
|
|
422
422
|
|
|
423
423
|
|
|
424
|
-
def test_dict_to_zip_sweep():
|
|
424
|
+
def test_dict_to_zip_sweep() -> None:
|
|
425
425
|
assert cirq.dict_to_zip_sweep({'t': [0, 2, 3]}) == (cirq.Zip(cirq.Points('t', [0, 2, 3])))
|
|
426
426
|
|
|
427
427
|
assert cirq.dict_to_zip_sweep({'t': [0, 1], 's': [2, 3], 'r': 4}) == (
|
|
@@ -429,7 +429,7 @@ def test_dict_to_zip_sweep():
|
|
|
429
429
|
)
|
|
430
430
|
|
|
431
431
|
|
|
432
|
-
def test_concat_linspace():
|
|
432
|
+
def test_concat_linspace() -> None:
|
|
433
433
|
sweep1 = cirq.Linspace('a', 0.34, 9.16, 4)
|
|
434
434
|
sweep2 = cirq.Linspace('a', 10, 20, 4)
|
|
435
435
|
concat_sweep = cirq.Concat(sweep1, sweep2)
|
|
@@ -444,7 +444,7 @@ def test_concat_linspace():
|
|
|
444
444
|
assert params[7] == (('a', 20.0),)
|
|
445
445
|
|
|
446
446
|
|
|
447
|
-
def test_concat_points():
|
|
447
|
+
def test_concat_points() -> None:
|
|
448
448
|
sweep1 = cirq.Points('a', [1, 2])
|
|
449
449
|
sweep2 = cirq.Points('a', [3, 4, 5])
|
|
450
450
|
concat_sweep = cirq.Concat(sweep1, sweep2)
|
|
@@ -456,7 +456,7 @@ def test_concat_points():
|
|
|
456
456
|
assert _values(concat_sweep, 'a') == [1, 2, 3, 4, 5]
|
|
457
457
|
|
|
458
458
|
|
|
459
|
-
def test_concat_many_points():
|
|
459
|
+
def test_concat_many_points() -> None:
|
|
460
460
|
sweep1 = cirq.Points('a', [1, 2])
|
|
461
461
|
sweep2 = cirq.Points('a', [3, 4, 5])
|
|
462
462
|
sweep3 = cirq.Points('a', [6, 7, 8])
|
|
@@ -468,7 +468,7 @@ def test_concat_many_points():
|
|
|
468
468
|
assert _values(concat_sweep, 'a') == [1, 2, 3, 4, 5, 6, 7, 8]
|
|
469
469
|
|
|
470
470
|
|
|
471
|
-
def test_concat_mixed():
|
|
471
|
+
def test_concat_mixed() -> None:
|
|
472
472
|
sweep1 = cirq.Linspace('a', 0, 1, 3)
|
|
473
473
|
sweep2 = cirq.Points('a', [2, 3])
|
|
474
474
|
concat_sweep = cirq.Concat(sweep1, sweep2)
|
|
@@ -477,7 +477,7 @@ def test_concat_mixed():
|
|
|
477
477
|
assert _values(concat_sweep, 'a') == [0.0, 0.5, 1.0, 2, 3]
|
|
478
478
|
|
|
479
479
|
|
|
480
|
-
def test_concat_inconsistent_keys():
|
|
480
|
+
def test_concat_inconsistent_keys() -> None:
|
|
481
481
|
sweep1 = cirq.Linspace('a', 0, 1, 3)
|
|
482
482
|
sweep2 = cirq.Points('b', [2, 3])
|
|
483
483
|
|
|
@@ -485,7 +485,7 @@ def test_concat_inconsistent_keys():
|
|
|
485
485
|
cirq.Concat(sweep1, sweep2)
|
|
486
486
|
|
|
487
487
|
|
|
488
|
-
def test_concat_sympy_symbol():
|
|
488
|
+
def test_concat_sympy_symbol() -> None:
|
|
489
489
|
a = sympy.Symbol('a')
|
|
490
490
|
sweep1 = cirq.Linspace(a, 0, 1, 3)
|
|
491
491
|
sweep2 = cirq.Points(a, [2, 3])
|
|
@@ -495,7 +495,7 @@ def test_concat_sympy_symbol():
|
|
|
495
495
|
assert _values(concat_sweep, 'a') == [0.0, 0.5, 1.0, 2, 3]
|
|
496
496
|
|
|
497
497
|
|
|
498
|
-
def test_concat_repr_and_str():
|
|
498
|
+
def test_concat_repr_and_str() -> None:
|
|
499
499
|
sweep1 = cirq.Linspace('a', 0, 1, 3)
|
|
500
500
|
sweep2 = cirq.Points('a', [2, 3])
|
|
501
501
|
concat_sweep = cirq.Concat(sweep1, sweep2)
|
|
@@ -509,7 +509,7 @@ def test_concat_repr_and_str():
|
|
|
509
509
|
assert str(concat_sweep) == expected_str
|
|
510
510
|
|
|
511
511
|
|
|
512
|
-
def test_concat_large_sweep():
|
|
512
|
+
def test_concat_large_sweep() -> None:
|
|
513
513
|
sweep1 = cirq.Points('a', list(range(101)))
|
|
514
514
|
sweep2 = cirq.Points('a', list(range(101, 202)))
|
|
515
515
|
concat_sweep = cirq.Concat(sweep1, sweep2)
|
|
@@ -518,7 +518,7 @@ def test_concat_large_sweep():
|
|
|
518
518
|
assert _values(concat_sweep, 'a') == list(range(101)) + list(range(101, 202))
|
|
519
519
|
|
|
520
520
|
|
|
521
|
-
def test_concat_different_keys_raises():
|
|
521
|
+
def test_concat_different_keys_raises() -> None:
|
|
522
522
|
sweep1 = cirq.Linspace('a', 0, 1, 3)
|
|
523
523
|
sweep2 = cirq.Points('b', [2, 3])
|
|
524
524
|
|
|
@@ -526,6 +526,30 @@ def test_concat_different_keys_raises():
|
|
|
526
526
|
_ = cirq.Concat(sweep1, sweep2)
|
|
527
527
|
|
|
528
528
|
|
|
529
|
-
def test_concat_empty_sweep_raises():
|
|
529
|
+
def test_concat_empty_sweep_raises() -> None:
|
|
530
530
|
with pytest.raises(ValueError, match="Concat requires at least one sweep."):
|
|
531
531
|
_ = cirq.Concat()
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
def test_list_of_dicts_to_zip_empty() -> None:
|
|
535
|
+
with pytest.raises(ValueError, match="empty"):
|
|
536
|
+
cirq.list_of_dicts_to_zip([])
|
|
537
|
+
|
|
538
|
+
|
|
539
|
+
def test_list_of_dicts_to_zip_mismatched_keys() -> None:
|
|
540
|
+
with pytest.raises(ValueError, match="Keys must be the same"):
|
|
541
|
+
cirq.list_of_dicts_to_zip([{'a': 4.0}, {'a': 2.0, 'b': 1.0}])
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+
def test_list_of_dicts_to_zip() -> None:
|
|
545
|
+
param_dict = [
|
|
546
|
+
{'a': 1.0, 'b': 2.0, 'c': 10.0},
|
|
547
|
+
{'a': 2.0, 'b': 4.0, 'c': 9.0},
|
|
548
|
+
{'a': 3.0, 'b': 8.0, 'c': 8.0},
|
|
549
|
+
]
|
|
550
|
+
param_zip = cirq.Zip(
|
|
551
|
+
cirq.Points('a', [1.0, 2.0, 3.0]),
|
|
552
|
+
cirq.Points('b', [2.0, 4.0, 8.0]),
|
|
553
|
+
cirq.Points('c', [10.0, 9.0, 8.0]),
|
|
554
|
+
)
|
|
555
|
+
assert cirq.list_of_dicts_to_zip(param_dict) == param_zip
|
|
@@ -64,11 +64,11 @@ _compat.deprecated_submodule(
|
|
|
64
64
|
|
|
65
65
|
# simulates a move of child module to a top level module.
|
|
66
66
|
# this will be the case with cirq.google -> cirq_google
|
|
67
|
-
#
|
|
67
|
+
# fake_numpy -> numpy
|
|
68
68
|
_compat.deprecated_submodule(
|
|
69
|
-
new_module_name="
|
|
69
|
+
new_module_name="numpy",
|
|
70
70
|
old_parent=__name__,
|
|
71
|
-
old_child="
|
|
71
|
+
old_child="fake_numpy",
|
|
72
72
|
deadline="v0.20",
|
|
73
73
|
create_attribute=False,
|
|
74
74
|
)
|
cirq/testing/circuit_compare.py
CHANGED
|
@@ -17,7 +17,8 @@ from __future__ import annotations
|
|
|
17
17
|
import itertools
|
|
18
18
|
import random
|
|
19
19
|
from collections import defaultdict
|
|
20
|
-
from
|
|
20
|
+
from collections.abc import Iterable, Sequence
|
|
21
|
+
from typing import Any
|
|
21
22
|
|
|
22
23
|
import numpy as np
|
|
23
24
|
import sympy
|
|
@@ -21,7 +21,7 @@ import cirq
|
|
|
21
21
|
from cirq.testing.circuit_compare import _assert_apply_unitary_works_when_axes_transposed
|
|
22
22
|
|
|
23
23
|
|
|
24
|
-
def test_sensitive_to_phase():
|
|
24
|
+
def test_sensitive_to_phase() -> None:
|
|
25
25
|
q = cirq.NamedQubit('q')
|
|
26
26
|
|
|
27
27
|
cirq.testing.assert_circuits_with_terminal_measurements_are_equivalent(
|
|
@@ -38,7 +38,7 @@ def test_sensitive_to_phase():
|
|
|
38
38
|
)
|
|
39
39
|
|
|
40
40
|
|
|
41
|
-
def test_sensitive_to_measurement_but_not_measured_phase():
|
|
41
|
+
def test_sensitive_to_measurement_but_not_measured_phase() -> None:
|
|
42
42
|
q = cirq.NamedQubit('q')
|
|
43
43
|
|
|
44
44
|
with pytest.raises(AssertionError):
|
|
@@ -80,7 +80,7 @@ def test_sensitive_to_measurement_but_not_measured_phase():
|
|
|
80
80
|
)
|
|
81
81
|
|
|
82
82
|
|
|
83
|
-
def test_sensitive_to_measurement_toggle():
|
|
83
|
+
def test_sensitive_to_measurement_toggle() -> None:
|
|
84
84
|
q = cirq.NamedQubit('q')
|
|
85
85
|
|
|
86
86
|
with pytest.raises(AssertionError):
|
|
@@ -103,7 +103,7 @@ def test_sensitive_to_measurement_toggle():
|
|
|
103
103
|
)
|
|
104
104
|
|
|
105
105
|
|
|
106
|
-
def test_measuring_qubits():
|
|
106
|
+
def test_measuring_qubits() -> None:
|
|
107
107
|
a, b = cirq.LineQubit.range(2)
|
|
108
108
|
|
|
109
109
|
with pytest.raises(AssertionError):
|
|
@@ -126,7 +126,7 @@ def test_measuring_qubits():
|
|
|
126
126
|
@pytest.mark.parametrize(
|
|
127
127
|
'circuit', [cirq.testing.random_circuit(cirq.LineQubit.range(2), 4, 0.5) for _ in range(5)]
|
|
128
128
|
)
|
|
129
|
-
def test_random_same_matrix(circuit):
|
|
129
|
+
def test_random_same_matrix(circuit) -> None:
|
|
130
130
|
a, b = cirq.LineQubit.range(2)
|
|
131
131
|
same = cirq.Circuit(
|
|
132
132
|
cirq.MatrixGate(circuit.unitary(qubits_that_should_be_present=[a, b])).on(a, b)
|
|
@@ -140,7 +140,7 @@ def test_random_same_matrix(circuit):
|
|
|
140
140
|
cirq.testing.assert_circuits_with_terminal_measurements_are_equivalent(mutable_circuit, same)
|
|
141
141
|
|
|
142
142
|
|
|
143
|
-
def test_correct_qubit_ordering():
|
|
143
|
+
def test_correct_qubit_ordering() -> None:
|
|
144
144
|
a, b = cirq.LineQubit.range(2)
|
|
145
145
|
cirq.testing.assert_circuits_with_terminal_measurements_are_equivalent(
|
|
146
146
|
cirq.Circuit(cirq.Z(a), cirq.Z(b), cirq.measure(b)),
|
|
@@ -154,7 +154,7 @@ def test_correct_qubit_ordering():
|
|
|
154
154
|
)
|
|
155
155
|
|
|
156
156
|
|
|
157
|
-
def test_known_old_failure():
|
|
157
|
+
def test_known_old_failure() -> None:
|
|
158
158
|
a, b = cirq.LineQubit.range(2)
|
|
159
159
|
cirq.testing.assert_circuits_with_terminal_measurements_are_equivalent(
|
|
160
160
|
actual=cirq.Circuit(
|
|
@@ -170,7 +170,7 @@ def test_known_old_failure():
|
|
|
170
170
|
)
|
|
171
171
|
|
|
172
172
|
|
|
173
|
-
def test_assert_same_circuits():
|
|
173
|
+
def test_assert_same_circuits() -> None:
|
|
174
174
|
a, b = cirq.LineQubit.range(2)
|
|
175
175
|
|
|
176
176
|
cirq.testing.assert_same_circuits(cirq.Circuit(cirq.H(a)), cirq.Circuit(cirq.H(a)))
|
|
@@ -191,7 +191,7 @@ def test_assert_same_circuits():
|
|
|
191
191
|
)
|
|
192
192
|
|
|
193
193
|
|
|
194
|
-
def test_assert_circuits_have_same_unitary_given_final_permutation():
|
|
194
|
+
def test_assert_circuits_have_same_unitary_given_final_permutation() -> None:
|
|
195
195
|
q = cirq.LineQubit.range(5)
|
|
196
196
|
expected = cirq.Circuit([cirq.Moment(cirq.CNOT(q[2], q[1]), cirq.CNOT(q[3], q[0]))])
|
|
197
197
|
actual = cirq.Circuit(
|
|
@@ -202,6 +202,7 @@ def test_assert_circuits_have_same_unitary_given_final_permutation():
|
|
|
202
202
|
cirq.Moment(cirq.CNOT(q[3], q[2])),
|
|
203
203
|
]
|
|
204
204
|
)
|
|
205
|
+
qubit_map: dict[cirq.Qid, cirq.Qid]
|
|
205
206
|
qubit_map = {q[0]: q[2], q[2]: q[1], q[1]: q[0]}
|
|
206
207
|
cirq.testing.assert_circuits_have_same_unitary_given_final_permutation(
|
|
207
208
|
actual, expected, qubit_map
|
|
@@ -213,6 +214,7 @@ def test_assert_circuits_have_same_unitary_given_final_permutation():
|
|
|
213
214
|
actual, expected, qubit_map=qubit_map
|
|
214
215
|
)
|
|
215
216
|
|
|
217
|
+
bad_qubit_map: dict[cirq.Qid, cirq.Qid]
|
|
216
218
|
bad_qubit_map = {q[0]: q[2], q[2]: q[4], q[4]: q[0]}
|
|
217
219
|
with pytest.raises(ValueError, match="'qubit_map' must be a mapping"):
|
|
218
220
|
cirq.testing.assert_circuits_have_same_unitary_given_final_permutation(
|
|
@@ -220,7 +222,7 @@ def test_assert_circuits_have_same_unitary_given_final_permutation():
|
|
|
220
222
|
)
|
|
221
223
|
|
|
222
224
|
|
|
223
|
-
def test_assert_has_diagram():
|
|
225
|
+
def test_assert_has_diagram() -> None:
|
|
224
226
|
a, b = cirq.LineQubit.range(2)
|
|
225
227
|
circuit = cirq.Circuit(cirq.CNOT(a, b))
|
|
226
228
|
cirq.testing.assert_has_diagram(
|
|
@@ -263,7 +265,7 @@ Highlighted differences:
|
|
|
263
265
|
assert expected_error in ex_info.value.args[0]
|
|
264
266
|
|
|
265
267
|
|
|
266
|
-
def test_assert_has_consistent_apply_channel():
|
|
268
|
+
def test_assert_has_consistent_apply_channel() -> None:
|
|
267
269
|
class Correct:
|
|
268
270
|
def _apply_channel_(self, args: cirq.ApplyChannelArgs):
|
|
269
271
|
args.target_tensor[...] = 0
|
|
@@ -329,7 +331,7 @@ def test_assert_has_consistent_apply_channel():
|
|
|
329
331
|
cirq.testing.assert_has_consistent_apply_channel(NoApply())
|
|
330
332
|
|
|
331
333
|
|
|
332
|
-
def test_assert_has_consistent_apply_unitary():
|
|
334
|
+
def test_assert_has_consistent_apply_unitary() -> None:
|
|
333
335
|
class IdentityReturningUnalteredWorkspace:
|
|
334
336
|
def _apply_unitary_(self, args: cirq.ApplyUnitaryArgs) -> np.ndarray:
|
|
335
337
|
return args.available_buffer
|
|
@@ -461,7 +463,7 @@ def test_assert_has_consistent_apply_unitary():
|
|
|
461
463
|
cirq.testing.assert_has_consistent_apply_unitary(cirq.X.on(cirq.NamedQubit('q')))
|
|
462
464
|
|
|
463
465
|
|
|
464
|
-
def test_assert_has_consistent_qid_shape():
|
|
466
|
+
def test_assert_has_consistent_qid_shape() -> None:
|
|
465
467
|
class ConsistentGate(cirq.Gate):
|
|
466
468
|
def _num_qubits_(self):
|
|
467
469
|
return 4
|
|
@@ -560,7 +562,7 @@ def test_assert_has_consistent_qid_shape():
|
|
|
560
562
|
cirq.testing.assert_has_consistent_qid_shape(NoProtocol())
|
|
561
563
|
|
|
562
564
|
|
|
563
|
-
def test_assert_apply_unitary_works_when_axes_transposed_failure():
|
|
565
|
+
def test_assert_apply_unitary_works_when_axes_transposed_failure() -> None:
|
|
564
566
|
class BadOp:
|
|
565
567
|
def _apply_unitary_(self, args: cirq.ApplyUnitaryArgs):
|
|
566
568
|
# Get a more convenient view of the data.
|
|
@@ -21,7 +21,7 @@ import numpy as np
|
|
|
21
21
|
import cirq
|
|
22
22
|
|
|
23
23
|
|
|
24
|
-
def assert_consistent_channel(gate: Any, rtol: float = 1e-5, atol: float = 1e-8):
|
|
24
|
+
def assert_consistent_channel(gate: Any, rtol: float = 1e-5, atol: float = 1e-8) -> None:
|
|
25
25
|
"""Asserts that a given gate has Kraus operators and that they are properly normalized."""
|
|
26
26
|
assert cirq.has_kraus(gate), f"Given gate {gate!r} does not return True for cirq.has_kraus."
|
|
27
27
|
kraus_ops = cirq.kraus(gate)
|
|
@@ -31,7 +31,7 @@ def assert_consistent_channel(gate: Any, rtol: float = 1e-5, atol: float = 1e-8)
|
|
|
31
31
|
)
|
|
32
32
|
|
|
33
33
|
|
|
34
|
-
def assert_consistent_mixture(gate: Any, rtol: float = 1e-5, atol: float = 1e-8):
|
|
34
|
+
def assert_consistent_mixture(gate: Any, rtol: float = 1e-5, atol: float = 1e-8) -> None:
|
|
35
35
|
"""Asserts that a given gate is a mixture and the mixture probabilities sum to one."""
|
|
36
36
|
assert cirq.has_mixture(gate), f"Give gate {gate!r} does not return for cirq.has_mixture."
|
|
37
37
|
mixture = cirq.mixture(gate)
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
|
-
from
|
|
17
|
+
from collections.abc import Collection, Sequence
|
|
18
18
|
|
|
19
19
|
import numpy as np
|
|
20
20
|
|
|
@@ -38,7 +38,7 @@ def assert_controlled_and_controlled_by_identical(
|
|
|
38
38
|
_assert_gate_consistent(gate, num_control, control_value)
|
|
39
39
|
|
|
40
40
|
|
|
41
|
-
def assert_controlled_unitary_consistent(gate: ops.Gate):
|
|
41
|
+
def assert_controlled_unitary_consistent(gate: ops.Gate) -> None:
|
|
42
42
|
"""Checks that unitary of ControlledGate(gate) is consistent with gate.controlled()."""
|
|
43
43
|
|
|
44
44
|
u_orig = protocols.unitary(ops.ControlledGate(gate))
|
|
@@ -22,7 +22,9 @@ from cirq import circuits, devices, ops, protocols
|
|
|
22
22
|
from cirq.testing import lin_alg_utils
|
|
23
23
|
|
|
24
24
|
|
|
25
|
-
def assert_decompose_is_consistent_with_unitary(
|
|
25
|
+
def assert_decompose_is_consistent_with_unitary(
|
|
26
|
+
val: Any, ignoring_global_phase: bool = False
|
|
27
|
+
) -> None:
|
|
26
28
|
"""Uses `val._unitary_` to check `val._phase_by_`'s behavior."""
|
|
27
29
|
__tracebackhide__ = True
|
|
28
30
|
|
|
@@ -76,7 +78,7 @@ def _known_gate_with_no_decomposition(val: Any):
|
|
|
76
78
|
return False
|
|
77
79
|
|
|
78
80
|
|
|
79
|
-
def assert_decompose_ends_at_default_gateset(val: Any, ignore_known_gates: bool = True):
|
|
81
|
+
def assert_decompose_ends_at_default_gateset(val: Any, ignore_known_gates: bool = True) -> None:
|
|
80
82
|
"""Asserts that cirq.decompose(val) ends at default cirq gateset or a known gate."""
|
|
81
83
|
args = () if isinstance(val, ops.Operation) else (tuple(devices.LineQid.for_gate(val)),)
|
|
82
84
|
dec_once = protocols.decompose_once(val, [val(*args[0]) if args else val], *args)
|
|
@@ -23,7 +23,7 @@ from cirq import linalg, protocols
|
|
|
23
23
|
from cirq.testing import lin_alg_utils
|
|
24
24
|
|
|
25
25
|
|
|
26
|
-
def assert_phase_by_is_consistent_with_unitary(val: Any):
|
|
26
|
+
def assert_phase_by_is_consistent_with_unitary(val: Any) -> None:
|
|
27
27
|
"""Uses `val._unitary_` to check `val._phase_by_`'s behavior."""
|
|
28
28
|
|
|
29
29
|
original = protocols.unitary(val, None)
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
|
+
from collections.abc import Sequence, Set
|
|
17
18
|
from types import NotImplementedType
|
|
18
|
-
from typing import AbstractSet, Sequence
|
|
19
19
|
|
|
20
20
|
import numpy as np
|
|
21
21
|
import pytest
|
|
@@ -100,7 +100,7 @@ class GoodGate(cirq.testing.SingleQubitGate):
|
|
|
100
100
|
def _is_parameterized_(self) -> bool:
|
|
101
101
|
return cirq.is_parameterized(self.exponent) or cirq.is_parameterized(self.phase_exponent)
|
|
102
102
|
|
|
103
|
-
def _parameter_names_(self) ->
|
|
103
|
+
def _parameter_names_(self) -> Set[str]:
|
|
104
104
|
return cirq.parameter_names(self.exponent) | cirq.parameter_names(self.phase_exponent)
|
|
105
105
|
|
|
106
106
|
def _resolve_parameters_(self, resolver, recursive) -> GoodGate:
|
|
@@ -124,7 +124,7 @@ class BadGateIsParameterized(GoodGate):
|
|
|
124
124
|
|
|
125
125
|
|
|
126
126
|
class BadGateParameterNames(GoodGate):
|
|
127
|
-
def _parameter_names_(self) ->
|
|
127
|
+
def _parameter_names_(self) -> Set[str]:
|
|
128
128
|
return super()._parameter_names_() | {'not_a_param'}
|
|
129
129
|
|
|
130
130
|
|
cirq/testing/consistent_qasm.py
CHANGED
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
17
|
import warnings
|
|
18
|
-
from
|
|
18
|
+
from collections.abc import Sequence
|
|
19
|
+
from typing import Any
|
|
19
20
|
|
|
20
21
|
import numpy as np
|
|
21
22
|
|
|
@@ -23,7 +24,7 @@ from cirq import devices, linalg, ops, protocols
|
|
|
23
24
|
from cirq.testing import lin_alg_utils
|
|
24
25
|
|
|
25
26
|
|
|
26
|
-
def assert_qasm_is_consistent_with_unitary(val: Any):
|
|
27
|
+
def assert_qasm_is_consistent_with_unitary(val: Any) -> None:
|
|
27
28
|
"""Uses `val._unitary_` to check `val._qasm_`'s behavior."""
|
|
28
29
|
|
|
29
30
|
# Only test if qiskit is installed.
|
|
@@ -106,7 +107,7 @@ qreg q[{num_qubits}];
|
|
|
106
107
|
)
|
|
107
108
|
|
|
108
109
|
|
|
109
|
-
def assert_qiskit_parsed_qasm_consistent_with_unitary(qasm, unitary): # pragma: no cover
|
|
110
|
+
def assert_qiskit_parsed_qasm_consistent_with_unitary(qasm, unitary) -> None: # pragma: no cover
|
|
110
111
|
try:
|
|
111
112
|
# We don't want to require qiskit as a dependency but
|
|
112
113
|
# if Qiskit is installed, test QASM output against it.
|