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/ops/phased_x_z_gate.py
CHANGED
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
17
|
import numbers
|
|
18
|
-
from
|
|
18
|
+
from collections.abc import Iterator, Sequence, Set
|
|
19
|
+
from typing import Any, TYPE_CHECKING
|
|
19
20
|
|
|
20
21
|
import numpy as np
|
|
21
22
|
import sympy
|
|
@@ -140,6 +141,10 @@ class PhasedXZGate(raw_types.Gate):
|
|
|
140
141
|
return self._axis_phase_exponent
|
|
141
142
|
|
|
142
143
|
def _value_equality_values_(self):
|
|
144
|
+
if self._is_parameterized_():
|
|
145
|
+
# If this is parameterized, do not try to calculate the canonical exponents
|
|
146
|
+
# as this results in some slow sympy operations.
|
|
147
|
+
return (self._x_exponent, self._z_exponent, self._axis_phase_exponent)
|
|
143
148
|
c = self._canonical()
|
|
144
149
|
return (
|
|
145
150
|
value.PeriodicValue(c._x_exponent, 2),
|
|
@@ -216,7 +221,7 @@ class PhasedXZGate(raw_types.Gate):
|
|
|
216
221
|
or protocols.is_parameterized(self._axis_phase_exponent)
|
|
217
222
|
)
|
|
218
223
|
|
|
219
|
-
def _parameter_names_(self) ->
|
|
224
|
+
def _parameter_names_(self) -> Set[str]:
|
|
220
225
|
"""See `cirq.SupportsParameterization`."""
|
|
221
226
|
return (
|
|
222
227
|
protocols.parameter_names(self._x_exponent)
|
|
@@ -231,17 +236,19 @@ class PhasedXZGate(raw_types.Gate):
|
|
|
231
236
|
z_exponent = resolver.value_of(self._z_exponent, recursive)
|
|
232
237
|
x_exponent = resolver.value_of(self._x_exponent, recursive)
|
|
233
238
|
axis_phase_exponent = resolver.value_of(self._axis_phase_exponent, recursive)
|
|
234
|
-
if isinstance(z_exponent, numbers.Complex):
|
|
239
|
+
if not isinstance(z_exponent, float) and isinstance(z_exponent, numbers.Complex):
|
|
235
240
|
if isinstance(z_exponent, numbers.Real):
|
|
236
241
|
z_exponent = float(z_exponent)
|
|
237
242
|
else:
|
|
238
243
|
raise ValueError(f'Complex exponent {z_exponent} not allowed in cirq.PhasedXZGate')
|
|
239
|
-
if isinstance(x_exponent, numbers.Complex):
|
|
244
|
+
if not isinstance(x_exponent, float) and isinstance(x_exponent, numbers.Complex):
|
|
240
245
|
if isinstance(x_exponent, numbers.Real):
|
|
241
246
|
x_exponent = float(x_exponent)
|
|
242
247
|
else:
|
|
243
248
|
raise ValueError(f'Complex exponent {x_exponent} not allowed in cirq.PhasedXZGate')
|
|
244
|
-
if isinstance(axis_phase_exponent,
|
|
249
|
+
if not isinstance(axis_phase_exponent, float) and isinstance(
|
|
250
|
+
axis_phase_exponent, numbers.Complex
|
|
251
|
+
):
|
|
245
252
|
if isinstance(axis_phase_exponent, numbers.Real):
|
|
246
253
|
axis_phase_exponent = float(axis_phase_exponent)
|
|
247
254
|
else:
|
cirq/ops/projector.py
CHANGED
|
@@ -4,7 +4,8 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
import itertools
|
|
6
6
|
import math
|
|
7
|
-
from
|
|
7
|
+
from collections.abc import Iterable, Mapping
|
|
8
|
+
from typing import Any, TYPE_CHECKING
|
|
8
9
|
|
|
9
10
|
import numpy as np
|
|
10
11
|
from scipy.sparse import csr_matrix
|
cirq/ops/qubit_manager.py
CHANGED
cirq/ops/qubit_order.py
CHANGED
cirq/ops/qubit_order_or_list.py
CHANGED
cirq/ops/random_gate_channel.py
CHANGED
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
17
|
import numbers
|
|
18
|
-
from
|
|
18
|
+
from collections.abc import Set
|
|
19
|
+
from typing import Any, cast, SupportsFloat, TYPE_CHECKING
|
|
19
20
|
|
|
20
21
|
import numpy as np
|
|
21
22
|
|
|
@@ -74,7 +75,7 @@ class RandomGateChannel(raw_types.Gate):
|
|
|
74
75
|
self.sub_gate
|
|
75
76
|
)
|
|
76
77
|
|
|
77
|
-
def _parameter_names_(self) ->
|
|
78
|
+
def _parameter_names_(self) -> Set[str]:
|
|
78
79
|
return protocols.parameter_names(self.probability) | protocols.parameter_names(
|
|
79
80
|
self.sub_gate
|
|
80
81
|
)
|
cirq/ops/raw_types.py
CHANGED
|
@@ -18,19 +18,9 @@ from __future__ import annotations
|
|
|
18
18
|
|
|
19
19
|
import abc
|
|
20
20
|
import functools
|
|
21
|
+
from collections.abc import Callable, Collection, Hashable, Iterable, Mapping, Sequence, Set
|
|
21
22
|
from types import NotImplementedType
|
|
22
|
-
from typing import
|
|
23
|
-
AbstractSet,
|
|
24
|
-
Any,
|
|
25
|
-
Callable,
|
|
26
|
-
cast,
|
|
27
|
-
Collection,
|
|
28
|
-
Hashable,
|
|
29
|
-
Iterable,
|
|
30
|
-
Mapping,
|
|
31
|
-
Sequence,
|
|
32
|
-
TYPE_CHECKING,
|
|
33
|
-
)
|
|
23
|
+
from typing import Any, cast, overload, TYPE_CHECKING
|
|
34
24
|
|
|
35
25
|
import numpy as np
|
|
36
26
|
|
|
@@ -482,10 +472,18 @@ class Gate(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
482
472
|
|
|
483
473
|
def _mul_with_qubits(self, qubits: tuple[cirq.Qid, ...], other):
|
|
484
474
|
"""cirq.GateOperation.__mul__ delegates to this method."""
|
|
475
|
+
from cirq.ops.pauli_string import _try_interpret_as_pauli_string
|
|
476
|
+
|
|
477
|
+
if (as_pauli_string := _try_interpret_as_pauli_string(self.on(*qubits))) is not None:
|
|
478
|
+
return as_pauli_string * other
|
|
485
479
|
return NotImplemented
|
|
486
480
|
|
|
487
481
|
def _rmul_with_qubits(self, qubits: tuple[cirq.Qid, ...], other):
|
|
488
482
|
"""cirq.GateOperation.__rmul__ delegates to this method."""
|
|
483
|
+
from cirq.ops.pauli_string import _try_interpret_as_pauli_string
|
|
484
|
+
|
|
485
|
+
if (as_pauli_string := _try_interpret_as_pauli_string(self.on(*qubits))) is not None:
|
|
486
|
+
return other * as_pauli_string
|
|
489
487
|
return NotImplemented
|
|
490
488
|
|
|
491
489
|
def _json_dict_(self) -> dict[str, Any]:
|
|
@@ -519,6 +517,9 @@ class Operation(metaclass=abc.ABCMeta):
|
|
|
519
517
|
def _qid_shape_(self) -> tuple[int, ...]:
|
|
520
518
|
return protocols.qid_shape(self.qubits)
|
|
521
519
|
|
|
520
|
+
def __pow__(self, exponent: Any) -> Operation:
|
|
521
|
+
return NotImplemented # pragma: no cover
|
|
522
|
+
|
|
522
523
|
@abc.abstractmethod
|
|
523
524
|
def with_qubits(self, *new_qubits: cirq.Qid) -> cirq.Operation:
|
|
524
525
|
"""Returns the same operation, but applied to different qubits.
|
|
@@ -679,9 +680,17 @@ class Operation(metaclass=abc.ABCMeta):
|
|
|
679
680
|
"""The classical controls gating this operation."""
|
|
680
681
|
return frozenset()
|
|
681
682
|
|
|
683
|
+
@overload
|
|
684
|
+
def with_classical_controls(self) -> cirq.Operation:
|
|
685
|
+
pass
|
|
686
|
+
|
|
687
|
+
@overload
|
|
682
688
|
def with_classical_controls(
|
|
683
689
|
self, *conditions: str | cirq.MeasurementKey | cirq.Condition | sympy.Expr
|
|
684
|
-
) -> cirq.
|
|
690
|
+
) -> cirq.ClassicallyControlledOperation:
|
|
691
|
+
pass
|
|
692
|
+
|
|
693
|
+
def with_classical_controls(self, *conditions):
|
|
685
694
|
"""Returns a classically controlled version of this operation.
|
|
686
695
|
|
|
687
696
|
An operation that is classically controlled is executed iff all
|
|
@@ -892,7 +901,7 @@ class TaggedOperation(Operation):
|
|
|
892
901
|
return NotImplemented
|
|
893
902
|
|
|
894
903
|
@cached_method
|
|
895
|
-
def _parameter_names_(self) ->
|
|
904
|
+
def _parameter_names_(self) -> Set[str]:
|
|
896
905
|
tag_params = {name for tag in self.tags for name in protocols.parameter_names(tag)}
|
|
897
906
|
return protocols.parameter_names(self.sub_operation) | tag_params
|
|
898
907
|
|
|
@@ -949,9 +958,17 @@ class TaggedOperation(Operation):
|
|
|
949
958
|
new_sub_operation = self.sub_operation.without_classical_controls()
|
|
950
959
|
return self if new_sub_operation is self.sub_operation else new_sub_operation
|
|
951
960
|
|
|
961
|
+
@overload
|
|
962
|
+
def with_classical_controls(self) -> cirq.Operation:
|
|
963
|
+
pass
|
|
964
|
+
|
|
965
|
+
@overload
|
|
952
966
|
def with_classical_controls(
|
|
953
967
|
self, *conditions: str | cirq.MeasurementKey | cirq.Condition | sympy.Expr
|
|
954
|
-
) -> cirq.
|
|
968
|
+
) -> cirq.ClassicallyControlledOperation:
|
|
969
|
+
pass
|
|
970
|
+
|
|
971
|
+
def with_classical_controls(self, *conditions):
|
|
955
972
|
if not conditions:
|
|
956
973
|
return self
|
|
957
974
|
return self.sub_operation.with_classical_controls(*conditions)
|
|
@@ -998,7 +1015,7 @@ class _InverseCompositeGate(Gate):
|
|
|
998
1015
|
return protocols.is_parameterized(self._original)
|
|
999
1016
|
|
|
1000
1017
|
@cached_method
|
|
1001
|
-
def _parameter_names_(self) ->
|
|
1018
|
+
def _parameter_names_(self) -> Set[str]:
|
|
1002
1019
|
return protocols.parameter_names(self._original)
|
|
1003
1020
|
|
|
1004
1021
|
def _resolve_parameters_(
|
cirq/ops/raw_types_test.py
CHANGED
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
|
-
from
|
|
17
|
+
from collections.abc import Iterator, Set
|
|
18
|
+
from typing import Any, cast
|
|
18
19
|
|
|
19
20
|
import numpy as np
|
|
20
21
|
import pytest
|
|
@@ -739,7 +740,7 @@ class ParameterizableTag:
|
|
|
739
740
|
def _is_parameterized_(self) -> bool:
|
|
740
741
|
return cirq.is_parameterized(self.value)
|
|
741
742
|
|
|
742
|
-
def _parameter_names_(self) ->
|
|
743
|
+
def _parameter_names_(self) -> Set[str]:
|
|
743
744
|
return cirq.parameter_names(self.value)
|
|
744
745
|
|
|
745
746
|
def _resolve_parameters_(
|
|
@@ -781,7 +782,7 @@ def test_inverse_composite_standards() -> None:
|
|
|
781
782
|
def _value_equality_values_(self):
|
|
782
783
|
return (self._param,)
|
|
783
784
|
|
|
784
|
-
def _parameter_names_(self) ->
|
|
785
|
+
def _parameter_names_(self) -> Set[str]:
|
|
785
786
|
return cirq.parameter_names(self._param)
|
|
786
787
|
|
|
787
788
|
def _is_parameterized_(self) -> bool:
|
cirq/ops/three_qubit_gates.py
CHANGED
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
|
|
17
17
|
from __future__ import annotations
|
|
18
18
|
|
|
19
|
-
from
|
|
19
|
+
from collections.abc import Collection, Iterator, Sequence, Set
|
|
20
|
+
from typing import Any, TYPE_CHECKING
|
|
20
21
|
|
|
21
22
|
import numpy as np
|
|
22
23
|
import sympy
|
|
@@ -224,7 +225,7 @@ class ThreeQubitDiagonalGate(raw_types.Gate):
|
|
|
224
225
|
def _is_parameterized_(self) -> bool:
|
|
225
226
|
return any(protocols.is_parameterized(angle) for angle in self._diag_angles_radians)
|
|
226
227
|
|
|
227
|
-
def _parameter_names_(self) ->
|
|
228
|
+
def _parameter_names_(self) -> Set[str]:
|
|
228
229
|
return {
|
|
229
230
|
name for angle in self._diag_angles_radians for name in protocols.parameter_names(angle)
|
|
230
231
|
}
|
|
@@ -20,7 +20,8 @@ passed as a list.
|
|
|
20
20
|
|
|
21
21
|
from __future__ import annotations
|
|
22
22
|
|
|
23
|
-
from
|
|
23
|
+
from collections.abc import Iterator, Sequence, Set
|
|
24
|
+
from typing import Any, TYPE_CHECKING
|
|
24
25
|
|
|
25
26
|
import numpy as np
|
|
26
27
|
import sympy
|
|
@@ -76,7 +77,7 @@ class TwoQubitDiagonalGate(raw_types.Gate):
|
|
|
76
77
|
def _is_parameterized_(self) -> bool:
|
|
77
78
|
return any(protocols.is_parameterized(angle) for angle in self._diag_angles_radians)
|
|
78
79
|
|
|
79
|
-
def _parameter_names_(self) ->
|
|
80
|
+
def _parameter_names_(self) -> Set[str]:
|
|
80
81
|
return {
|
|
81
82
|
name for angle in self._diag_angles_radians for name in protocols.parameter_names(angle)
|
|
82
83
|
}
|
cirq/ops/wait_gate.py
CHANGED
|
@@ -14,7 +14,10 @@
|
|
|
14
14
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
|
-
from
|
|
17
|
+
from collections.abc import Set
|
|
18
|
+
from typing import Any, TYPE_CHECKING
|
|
19
|
+
|
|
20
|
+
import sympy
|
|
18
21
|
|
|
19
22
|
from cirq import protocols, value
|
|
20
23
|
from cirq.ops import raw_types
|
|
@@ -51,8 +54,11 @@ class WaitGate(raw_types.Gate):
|
|
|
51
54
|
ValueError: If the `qid_shape` provided is empty or `num_qubits` contradicts
|
|
52
55
|
`qid_shape`.
|
|
53
56
|
"""
|
|
54
|
-
self._duration =
|
|
55
|
-
|
|
57
|
+
self._duration = (
|
|
58
|
+
duration if isinstance(duration, value.Duration) else value.Duration(duration)
|
|
59
|
+
)
|
|
60
|
+
total_picos = self.duration.total_picos()
|
|
61
|
+
if not isinstance(total_picos, sympy.Basic) and total_picos < 0:
|
|
56
62
|
raise ValueError('duration < 0')
|
|
57
63
|
if qid_shape is None:
|
|
58
64
|
if num_qubits is None:
|
|
@@ -75,7 +81,7 @@ class WaitGate(raw_types.Gate):
|
|
|
75
81
|
def _is_parameterized_(self) -> bool:
|
|
76
82
|
return protocols.is_parameterized(self.duration)
|
|
77
83
|
|
|
78
|
-
def _parameter_names_(self) ->
|
|
84
|
+
def _parameter_names_(self) -> Set[str]:
|
|
79
85
|
return protocols.parameter_names(self.duration)
|
|
80
86
|
|
|
81
87
|
def _resolve_parameters_(self, resolver: cirq.ParamResolver, recursive: bool) -> WaitGate:
|
|
@@ -14,8 +14,9 @@
|
|
|
14
14
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
|
+
from collections.abc import Sequence
|
|
17
18
|
from types import NotImplementedType
|
|
18
|
-
from typing import Any, Protocol,
|
|
19
|
+
from typing import Any, Protocol, TYPE_CHECKING
|
|
19
20
|
|
|
20
21
|
from cirq import ops
|
|
21
22
|
from cirq._doc import doc_private
|
|
@@ -16,8 +16,9 @@
|
|
|
16
16
|
|
|
17
17
|
from __future__ import annotations
|
|
18
18
|
|
|
19
|
+
from collections.abc import Iterable, Sequence
|
|
19
20
|
from types import NotImplementedType
|
|
20
|
-
from typing import Any,
|
|
21
|
+
from typing import Any, Protocol, TypeVar
|
|
21
22
|
|
|
22
23
|
import numpy as np
|
|
23
24
|
|
|
@@ -16,8 +16,9 @@
|
|
|
16
16
|
|
|
17
17
|
from __future__ import annotations
|
|
18
18
|
|
|
19
|
+
from collections.abc import Iterable
|
|
19
20
|
from types import NotImplementedType
|
|
20
|
-
from typing import Any, cast,
|
|
21
|
+
from typing import Any, cast, Protocol, TypeVar
|
|
21
22
|
|
|
22
23
|
import numpy as np
|
|
23
24
|
|
|
@@ -17,8 +17,9 @@
|
|
|
17
17
|
from __future__ import annotations
|
|
18
18
|
|
|
19
19
|
import warnings
|
|
20
|
+
from collections.abc import Iterable, Sequence
|
|
20
21
|
from types import EllipsisType, NotImplementedType
|
|
21
|
-
from typing import Any, cast,
|
|
22
|
+
from typing import Any, cast, Protocol, TYPE_CHECKING, TypeVar
|
|
22
23
|
|
|
23
24
|
import numpy as np
|
|
24
25
|
|
|
@@ -240,6 +240,7 @@ def test_apply_unitary_args_tensor_manipulation() -> None:
|
|
|
240
240
|
op_indices, tuple(qid_shape[i] for i in op_indices)
|
|
241
241
|
)
|
|
242
242
|
sub_result = val._apply_unitary_(sub_args)
|
|
243
|
+
assert isinstance(sub_result, np.ndarray)
|
|
243
244
|
result = _incorporate_result_into_target(args, sub_args, sub_result)
|
|
244
245
|
np.testing.assert_allclose(result, expected, atol=1e-8)
|
|
245
246
|
|
|
@@ -258,6 +259,7 @@ def test_apply_unitary_args_tensor_manipulation() -> None:
|
|
|
258
259
|
op_indices, tuple(qid_shape[i] for i in op_indices)
|
|
259
260
|
)
|
|
260
261
|
sub_result = val._apply_unitary_(sub_args)
|
|
262
|
+
assert isinstance(sub_result, np.ndarray)
|
|
261
263
|
result = _incorporate_result_into_target(args, sub_args, sub_result)
|
|
262
264
|
np.testing.assert_allclose(result, expected, atol=1e-8, verbose=True)
|
|
263
265
|
|
|
@@ -15,9 +15,10 @@
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
17
|
import numbers
|
|
18
|
+
from collections.abc import Iterable
|
|
18
19
|
from decimal import Decimal
|
|
19
20
|
from fractions import Fraction
|
|
20
|
-
from typing import Any,
|
|
21
|
+
from typing import Any, Protocol
|
|
21
22
|
|
|
22
23
|
import numpy as np
|
|
23
24
|
import sympy
|
|
@@ -15,8 +15,9 @@
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
17
|
import re
|
|
18
|
+
from collections.abc import Iterable, Sequence
|
|
18
19
|
from fractions import Fraction
|
|
19
|
-
from typing import Any,
|
|
20
|
+
from typing import Any, overload, Protocol, Self, TYPE_CHECKING, TypeVar, Union
|
|
20
21
|
|
|
21
22
|
import numpy as np
|
|
22
23
|
import sympy
|
|
@@ -53,6 +53,13 @@ def control_keys(val: Any) -> frozenset[cirq.MeasurementKey]:
|
|
|
53
53
|
Returns:
|
|
54
54
|
The measurement keys the value is controlled by. If the value is not
|
|
55
55
|
classically controlled, the result is the empty tuple.
|
|
56
|
+
|
|
57
|
+
Notes:
|
|
58
|
+
For composite operations (e.g. CircuitOperation), only control keys that
|
|
59
|
+
have not already been measured earlier in the subcircuit are returned.
|
|
60
|
+
Control keys that are satisfied by measurements **after** their use in
|
|
61
|
+
the subcircuit are still required externally and thus appear in the
|
|
62
|
+
result.
|
|
56
63
|
"""
|
|
57
64
|
getter = getattr(val, '_control_keys_', None)
|
|
58
65
|
result = NotImplemented if getter is None else getter()
|
|
@@ -18,19 +18,9 @@ import dataclasses
|
|
|
18
18
|
import inspect
|
|
19
19
|
import itertools
|
|
20
20
|
from collections import defaultdict
|
|
21
|
+
from collections.abc import Callable, Iterable, Iterator, Sequence
|
|
21
22
|
from types import NotImplementedType
|
|
22
|
-
from typing import
|
|
23
|
-
Any,
|
|
24
|
-
Callable,
|
|
25
|
-
Iterable,
|
|
26
|
-
Iterator,
|
|
27
|
-
overload,
|
|
28
|
-
Protocol,
|
|
29
|
-
Sequence,
|
|
30
|
-
TYPE_CHECKING,
|
|
31
|
-
TypeVar,
|
|
32
|
-
Union,
|
|
33
|
-
)
|
|
23
|
+
from typing import Any, overload, Protocol, TYPE_CHECKING, TypeVar, Union
|
|
34
24
|
|
|
35
25
|
from cirq import devices, ops
|
|
36
26
|
from cirq._doc import doc_private
|
|
@@ -97,7 +97,7 @@ def _strat_has_stabilizer_effect_from_unitary(val: Any) -> bool | None:
|
|
|
97
97
|
ps = DensePauliString(pauli_string)
|
|
98
98
|
p = ps._unitary_()
|
|
99
99
|
if not pauli_string_decomposition.unitary_to_pauli_string(
|
|
100
|
-
|
|
100
|
+
unitary @ p @ unitary.T.conj()
|
|
101
101
|
):
|
|
102
102
|
return False
|
|
103
103
|
return True
|
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
|
+
from typing import Any
|
|
18
|
+
|
|
17
19
|
import numpy as np
|
|
18
20
|
|
|
19
21
|
import cirq
|
|
@@ -50,40 +52,40 @@ class EmptyOp(cirq.Operation):
|
|
|
50
52
|
self.q = q
|
|
51
53
|
|
|
52
54
|
@property
|
|
53
|
-
def qubits(self):
|
|
55
|
+
def qubits(self) -> tuple[cirq.Qid, ...]:
|
|
54
56
|
return (self.q,)
|
|
55
57
|
|
|
56
|
-
def with_qubits(self, *new_qubits): # pragma: no cover
|
|
58
|
+
def with_qubits(self, *new_qubits) -> cirq.Operation: # pragma: no cover
|
|
57
59
|
return self
|
|
58
60
|
|
|
59
61
|
|
|
60
62
|
class NoOp(EmptyOp):
|
|
61
63
|
@property
|
|
62
|
-
def gate(self):
|
|
64
|
+
def gate(self) -> Any:
|
|
63
65
|
return No()
|
|
64
66
|
|
|
65
67
|
|
|
66
68
|
class NoOp1(EmptyOp):
|
|
67
69
|
@property
|
|
68
|
-
def gate(self):
|
|
70
|
+
def gate(self) -> Any:
|
|
69
71
|
return No1()
|
|
70
72
|
|
|
71
73
|
|
|
72
74
|
class NoOp2(EmptyOp):
|
|
73
75
|
@property
|
|
74
|
-
def gate(self):
|
|
76
|
+
def gate(self) -> Any:
|
|
75
77
|
return No2()
|
|
76
78
|
|
|
77
79
|
|
|
78
80
|
class NoOp3(EmptyOp):
|
|
79
81
|
@property
|
|
80
|
-
def gate(self):
|
|
82
|
+
def gate(self) -> Any:
|
|
81
83
|
return No3()
|
|
82
84
|
|
|
83
85
|
|
|
84
86
|
class YesOp(EmptyOp):
|
|
85
87
|
@property
|
|
86
|
-
def gate(self):
|
|
88
|
+
def gate(self) -> Any:
|
|
87
89
|
return Yes()
|
|
88
90
|
|
|
89
91
|
|
|
@@ -95,8 +97,8 @@ class OpWithUnitary(EmptyOp):
|
|
|
95
97
|
return self.unitary
|
|
96
98
|
|
|
97
99
|
@property
|
|
98
|
-
def qubits(self):
|
|
99
|
-
return cirq.LineQubit.range(self.unitary.shape[0].bit_length() - 1)
|
|
100
|
+
def qubits(self) -> tuple[cirq.Qid, ...]:
|
|
101
|
+
return tuple(cirq.LineQubit.range(self.unitary.shape[0].bit_length() - 1))
|
|
100
102
|
|
|
101
103
|
|
|
102
104
|
class GateDecomposes(cirq.Gate):
|
|
@@ -218,8 +218,8 @@ class EmptyOp(cirq.Operation):
|
|
|
218
218
|
"""A trivial operation that will be recognized as `_apply_unitary_`-able."""
|
|
219
219
|
|
|
220
220
|
@property
|
|
221
|
-
def qubits(self):
|
|
221
|
+
def qubits(self) -> tuple[cirq.Qid, ...]:
|
|
222
222
|
return ()
|
|
223
223
|
|
|
224
|
-
def with_qubits(self, *new_qubits)
|
|
225
|
-
|
|
224
|
+
def with_qubits(self, *new_qubits) -> cirq.Operation:
|
|
225
|
+
raise NotImplementedError()
|
|
@@ -20,8 +20,9 @@ import gzip
|
|
|
20
20
|
import json
|
|
21
21
|
import numbers
|
|
22
22
|
import pathlib
|
|
23
|
+
from collections.abc import Callable, Iterable, Sequence
|
|
23
24
|
from types import NotImplementedType
|
|
24
|
-
from typing import Any,
|
|
25
|
+
from typing import Any, cast, IO, overload, Protocol
|
|
25
26
|
|
|
26
27
|
import attrs
|
|
27
28
|
import numpy as np
|
|
@@ -217,7 +218,7 @@ class CirqEncoder(json.JSONEncoder):
|
|
|
217
218
|
super().__init__(*args, **kwargs)
|
|
218
219
|
self._memo: dict[Any, dict] = {}
|
|
219
220
|
|
|
220
|
-
def default(self, o):
|
|
221
|
+
def default(self, o) -> dict[str, Any] | list[Any] | float | bool:
|
|
221
222
|
# Object with custom method?
|
|
222
223
|
if hasattr(o, '_json_dict_'):
|
|
223
224
|
json_dict = _json_dict_with_cirq_type(o)
|
|
@@ -519,7 +520,7 @@ def read_json(
|
|
|
519
520
|
*,
|
|
520
521
|
json_text: str | None = None,
|
|
521
522
|
resolvers: Sequence[JsonResolver] | None = None,
|
|
522
|
-
):
|
|
523
|
+
) -> Any:
|
|
523
524
|
"""Read a JSON file that optionally contains cirq objects.
|
|
524
525
|
|
|
525
526
|
Args:
|
|
@@ -605,7 +606,7 @@ def read_json_gzip(
|
|
|
605
606
|
*,
|
|
606
607
|
gzip_raw: bytes | None = None,
|
|
607
608
|
resolvers: Sequence[JsonResolver] | None = None,
|
|
608
|
-
):
|
|
609
|
+
) -> Any:
|
|
609
610
|
"""Read a gzipped JSON file that optionally contains cirq objects.
|
|
610
611
|
|
|
611
612
|
Args:
|