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
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
17
|
import dataclasses
|
|
18
|
-
from
|
|
18
|
+
from collections.abc import Iterable
|
|
19
|
+
from typing import cast
|
|
19
20
|
|
|
20
21
|
import numpy as np
|
|
21
22
|
import pytest
|
|
@@ -31,7 +32,7 @@ def assert_optimizes(
|
|
|
31
32
|
eject_parameterized: bool = False,
|
|
32
33
|
*,
|
|
33
34
|
with_context: bool = False,
|
|
34
|
-
):
|
|
35
|
+
) -> None:
|
|
35
36
|
context = cirq.TransformerContext(tags_to_ignore=("nocompile",)) if with_context else None
|
|
36
37
|
circuit = cirq.eject_phased_paulis(
|
|
37
38
|
before, eject_parameterized=eject_parameterized, context=context
|
cirq/transformers/eject_z.py
CHANGED
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
from __future__ import annotations
|
|
18
18
|
|
|
19
19
|
from collections import defaultdict
|
|
20
|
-
from
|
|
20
|
+
from collections.abc import Iterable, Iterator
|
|
21
|
+
from typing import TYPE_CHECKING
|
|
21
22
|
|
|
22
23
|
import numpy as np
|
|
23
24
|
|
|
@@ -29,11 +30,11 @@ if TYPE_CHECKING:
|
|
|
29
30
|
import cirq
|
|
30
31
|
|
|
31
32
|
|
|
32
|
-
def _is_integer(n):
|
|
33
|
+
def _is_integer(n) -> bool:
|
|
33
34
|
return np.isclose(n, np.round(n))
|
|
34
35
|
|
|
35
36
|
|
|
36
|
-
def _is_swaplike(gate: cirq.Gate):
|
|
37
|
+
def _is_swaplike(gate: cirq.Gate) -> bool:
|
|
37
38
|
if isinstance(gate, ops.SwapPowGate):
|
|
38
39
|
return gate.exponent == 1
|
|
39
40
|
|
|
@@ -119,6 +120,7 @@ def eject_z(
|
|
|
119
120
|
return []
|
|
120
121
|
|
|
121
122
|
# Try to move the tracked phases over the operation via protocols.phase_by(op)
|
|
123
|
+
phased_op: cirq.Operation | None
|
|
122
124
|
phased_op = op
|
|
123
125
|
for i, p in enumerate([qubit_phase[q] for q in op.qubits]):
|
|
124
126
|
if not single_qubit_decompositions.is_negligible_turn(p, atol):
|
|
@@ -30,7 +30,7 @@ def assert_optimizes(
|
|
|
30
30
|
eject_parameterized: bool = False,
|
|
31
31
|
*,
|
|
32
32
|
with_context: bool = False,
|
|
33
|
-
):
|
|
33
|
+
) -> None:
|
|
34
34
|
if cirq.has_unitary(before):
|
|
35
35
|
cirq.testing.assert_circuits_with_terminal_measurements_are_equivalent(
|
|
36
36
|
before, expected, atol=1e-8
|
|
@@ -72,7 +72,7 @@ def assert_optimizes(
|
|
|
72
72
|
cirq.testing.assert_same_circuits(c_nested, c_expected)
|
|
73
73
|
|
|
74
74
|
|
|
75
|
-
def assert_removes_all_z_gates(circuit: cirq.Circuit, eject_parameterized: bool = True):
|
|
75
|
+
def assert_removes_all_z_gates(circuit: cirq.Circuit, eject_parameterized: bool = True) -> None:
|
|
76
76
|
optimized = cirq.eject_z(circuit, eject_parameterized=eject_parameterized)
|
|
77
77
|
for op in optimized.all_operations():
|
|
78
78
|
# assert _try_get_known_z_half_turns(op, eject_parameterized) is None
|
|
@@ -96,7 +96,7 @@ def assert_removes_all_z_gates(circuit: cirq.Circuit, eject_parameterized: bool
|
|
|
96
96
|
)
|
|
97
97
|
|
|
98
98
|
|
|
99
|
-
def test_single_z_stays():
|
|
99
|
+
def test_single_z_stays() -> None:
|
|
100
100
|
q = cirq.NamedQubit('q')
|
|
101
101
|
assert_optimizes(
|
|
102
102
|
before=cirq.Circuit([cirq.Moment([cirq.Z(q) ** 0.5])]),
|
|
@@ -104,13 +104,13 @@ def test_single_z_stays():
|
|
|
104
104
|
)
|
|
105
105
|
|
|
106
106
|
|
|
107
|
-
def test_single_phased_xz_stays():
|
|
107
|
+
def test_single_phased_xz_stays() -> None:
|
|
108
108
|
gate = cirq.PhasedXZGate(axis_phase_exponent=0.2, x_exponent=0.3, z_exponent=0.4)
|
|
109
109
|
q = cirq.NamedQubit('q')
|
|
110
110
|
assert_optimizes(before=cirq.Circuit(gate(q)), expected=cirq.Circuit(gate(q)))
|
|
111
111
|
|
|
112
112
|
|
|
113
|
-
def test_ignores_xz_and_cz():
|
|
113
|
+
def test_ignores_xz_and_cz() -> None:
|
|
114
114
|
a = cirq.NamedQubit('a')
|
|
115
115
|
b = cirq.NamedQubit('b')
|
|
116
116
|
assert_optimizes(
|
|
@@ -135,7 +135,7 @@ def test_ignores_xz_and_cz():
|
|
|
135
135
|
)
|
|
136
136
|
|
|
137
137
|
|
|
138
|
-
def test_early_z():
|
|
138
|
+
def test_early_z() -> None:
|
|
139
139
|
q = cirq.NamedQubit('q')
|
|
140
140
|
assert_optimizes(
|
|
141
141
|
before=cirq.Circuit([cirq.Moment([cirq.Z(q) ** 0.5]), cirq.Moment(), cirq.Moment()]),
|
|
@@ -143,7 +143,7 @@ def test_early_z():
|
|
|
143
143
|
)
|
|
144
144
|
|
|
145
145
|
|
|
146
|
-
def test_multi_z_merges():
|
|
146
|
+
def test_multi_z_merges() -> None:
|
|
147
147
|
q = cirq.NamedQubit('q')
|
|
148
148
|
assert_optimizes(
|
|
149
149
|
before=cirq.Circuit([cirq.Moment([cirq.Z(q) ** 0.5]), cirq.Moment([cirq.Z(q) ** 0.25])]),
|
|
@@ -151,7 +151,7 @@ def test_multi_z_merges():
|
|
|
151
151
|
)
|
|
152
152
|
|
|
153
153
|
|
|
154
|
-
def test_z_pushes_past_xy_and_phases_it():
|
|
154
|
+
def test_z_pushes_past_xy_and_phases_it() -> None:
|
|
155
155
|
q = cirq.NamedQubit('q')
|
|
156
156
|
assert_optimizes(
|
|
157
157
|
before=cirq.Circuit([cirq.Moment([cirq.Z(q) ** 0.5]), cirq.Moment([cirq.Y(q) ** 0.25])]),
|
|
@@ -161,7 +161,7 @@ def test_z_pushes_past_xy_and_phases_it():
|
|
|
161
161
|
)
|
|
162
162
|
|
|
163
163
|
|
|
164
|
-
def test_z_pushes_past_cz():
|
|
164
|
+
def test_z_pushes_past_cz() -> None:
|
|
165
165
|
a = cirq.NamedQubit('a')
|
|
166
166
|
b = cirq.NamedQubit('b')
|
|
167
167
|
assert_optimizes(
|
|
@@ -174,7 +174,7 @@ def test_z_pushes_past_cz():
|
|
|
174
174
|
)
|
|
175
175
|
|
|
176
176
|
|
|
177
|
-
def test_measurement_consumes_zs():
|
|
177
|
+
def test_measurement_consumes_zs() -> None:
|
|
178
178
|
q = cirq.NamedQubit('q')
|
|
179
179
|
assert_optimizes(
|
|
180
180
|
before=cirq.Circuit(
|
|
@@ -188,7 +188,7 @@ def test_measurement_consumes_zs():
|
|
|
188
188
|
)
|
|
189
189
|
|
|
190
190
|
|
|
191
|
-
def test_unphaseable_causes_earlier_merge_without_size_increase():
|
|
191
|
+
def test_unphaseable_causes_earlier_merge_without_size_increase() -> None:
|
|
192
192
|
class UnknownGate(cirq.testing.SingleQubitGate):
|
|
193
193
|
pass
|
|
194
194
|
|
|
@@ -222,7 +222,7 @@ def test_unphaseable_causes_earlier_merge_without_size_increase():
|
|
|
222
222
|
|
|
223
223
|
|
|
224
224
|
@pytest.mark.parametrize('sym', [sympy.Symbol('a'), sympy.Symbol('a') + 1])
|
|
225
|
-
def test_symbols_block(sym):
|
|
225
|
+
def test_symbols_block(sym) -> None:
|
|
226
226
|
q = cirq.NamedQubit('q')
|
|
227
227
|
assert_optimizes(
|
|
228
228
|
before=cirq.Circuit(
|
|
@@ -239,7 +239,7 @@ def test_symbols_block(sym):
|
|
|
239
239
|
|
|
240
240
|
|
|
241
241
|
@pytest.mark.parametrize('sym', [sympy.Symbol('a'), sympy.Symbol('a') + 1])
|
|
242
|
-
def test_symbols_eject(sym):
|
|
242
|
+
def test_symbols_eject(sym) -> None:
|
|
243
243
|
q = cirq.NamedQubit('q')
|
|
244
244
|
assert_optimizes(
|
|
245
245
|
before=cirq.Circuit(
|
|
@@ -256,7 +256,7 @@ def test_symbols_eject(sym):
|
|
|
256
256
|
)
|
|
257
257
|
|
|
258
258
|
|
|
259
|
-
def test_removes_zs():
|
|
259
|
+
def test_removes_zs() -> None:
|
|
260
260
|
a = cirq.NamedQubit('a')
|
|
261
261
|
b = cirq.NamedQubit('b')
|
|
262
262
|
|
|
@@ -295,7 +295,7 @@ def test_removes_zs():
|
|
|
295
295
|
)
|
|
296
296
|
|
|
297
297
|
|
|
298
|
-
def test_unknown_operation_blocks():
|
|
298
|
+
def test_unknown_operation_blocks() -> None:
|
|
299
299
|
q = cirq.NamedQubit('q')
|
|
300
300
|
|
|
301
301
|
class UnknownOp(cirq.Operation):
|
|
@@ -314,7 +314,7 @@ def test_unknown_operation_blocks():
|
|
|
314
314
|
)
|
|
315
315
|
|
|
316
316
|
|
|
317
|
-
def test_tagged_nocompile_operation_blocks():
|
|
317
|
+
def test_tagged_nocompile_operation_blocks() -> None:
|
|
318
318
|
q = cirq.NamedQubit('q')
|
|
319
319
|
u = cirq.Z(q).with_tags("nocompile")
|
|
320
320
|
assert_optimizes(
|
|
@@ -324,7 +324,7 @@ def test_tagged_nocompile_operation_blocks():
|
|
|
324
324
|
)
|
|
325
325
|
|
|
326
326
|
|
|
327
|
-
def test_swap():
|
|
327
|
+
def test_swap() -> None:
|
|
328
328
|
a, b = cirq.LineQubit.range(2)
|
|
329
329
|
original = cirq.Circuit([cirq.rz(0.123).on(a), cirq.SWAP(a, b)])
|
|
330
330
|
optimized = original.copy()
|
|
@@ -341,13 +341,12 @@ def test_swap():
|
|
|
341
341
|
|
|
342
342
|
|
|
343
343
|
@pytest.mark.parametrize('exponent', (0, 2, 1.1, -2, -1.6))
|
|
344
|
-
def test_not_a_swap(exponent):
|
|
345
|
-
|
|
346
|
-
assert not _is_swaplike(cirq.SWAP(a, b) ** exponent)
|
|
344
|
+
def test_not_a_swap(exponent: float) -> None:
|
|
345
|
+
assert not _is_swaplike(cirq.SWAP**exponent)
|
|
347
346
|
|
|
348
347
|
|
|
349
348
|
@pytest.mark.parametrize('theta', (np.pi / 2, -np.pi / 2, np.pi / 2 + 5 * np.pi))
|
|
350
|
-
def test_swap_fsim(theta):
|
|
349
|
+
def test_swap_fsim(theta) -> None:
|
|
351
350
|
a, b = cirq.LineQubit.range(2)
|
|
352
351
|
original = cirq.Circuit([cirq.rz(0.123).on(a), cirq.FSimGate(theta=theta, phi=0.123).on(a, b)])
|
|
353
352
|
optimized = original.copy()
|
|
@@ -364,13 +363,12 @@ def test_swap_fsim(theta):
|
|
|
364
363
|
|
|
365
364
|
|
|
366
365
|
@pytest.mark.parametrize('theta', (0, 5 * np.pi, -np.pi))
|
|
367
|
-
def test_not_a_swap_fsim(theta):
|
|
368
|
-
|
|
369
|
-
assert not _is_swaplike(cirq.FSimGate(theta=theta, phi=0.456).on(a, b))
|
|
366
|
+
def test_not_a_swap_fsim(theta) -> None:
|
|
367
|
+
assert not _is_swaplike(cirq.FSimGate(theta=theta, phi=0.456))
|
|
370
368
|
|
|
371
369
|
|
|
372
370
|
@pytest.mark.parametrize('exponent', (1, -1))
|
|
373
|
-
def test_swap_iswap(exponent):
|
|
371
|
+
def test_swap_iswap(exponent) -> None:
|
|
374
372
|
a, b = cirq.LineQubit.range(2)
|
|
375
373
|
original = cirq.Circuit([cirq.rz(0.123).on(a), cirq.ISWAP(a, b) ** exponent])
|
|
376
374
|
optimized = original.copy()
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
|
|
17
17
|
from __future__ import annotations
|
|
18
18
|
|
|
19
|
-
from
|
|
19
|
+
from collections.abc import Callable
|
|
20
|
+
from typing import TYPE_CHECKING
|
|
20
21
|
|
|
21
22
|
from cirq import circuits, ops, protocols
|
|
22
23
|
from cirq.transformers import transformer_api, transformer_primitives
|
|
@@ -31,7 +32,7 @@ def expand_composite(
|
|
|
31
32
|
*,
|
|
32
33
|
context: cirq.TransformerContext | None = None,
|
|
33
34
|
no_decomp: Callable[[ops.Operation], bool] = (lambda _: False),
|
|
34
|
-
):
|
|
35
|
+
) -> cirq.Circuit:
|
|
35
36
|
"""A transformer that expands composite operations via `cirq.decompose`.
|
|
36
37
|
|
|
37
38
|
For each operation in the circuit, this pass examines if the operation can
|
|
@@ -19,24 +19,24 @@ from __future__ import annotations
|
|
|
19
19
|
import cirq
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
def assert_equal_mod_empty(expected, actual):
|
|
22
|
+
def assert_equal_mod_empty(expected, actual) -> None:
|
|
23
23
|
actual = cirq.drop_empty_moments(actual)
|
|
24
24
|
cirq.testing.assert_same_circuits(actual, expected)
|
|
25
25
|
|
|
26
26
|
|
|
27
|
-
def test_empty_circuit():
|
|
27
|
+
def test_empty_circuit() -> None:
|
|
28
28
|
circuit = cirq.Circuit()
|
|
29
29
|
circuit = cirq.expand_composite(circuit)
|
|
30
30
|
assert_equal_mod_empty(cirq.Circuit(), circuit)
|
|
31
31
|
|
|
32
32
|
|
|
33
|
-
def test_empty_moment():
|
|
33
|
+
def test_empty_moment() -> None:
|
|
34
34
|
circuit = cirq.Circuit([])
|
|
35
35
|
circuit = cirq.expand_composite(circuit)
|
|
36
36
|
assert_equal_mod_empty(cirq.Circuit([]), circuit)
|
|
37
37
|
|
|
38
38
|
|
|
39
|
-
def test_ignore_non_composite():
|
|
39
|
+
def test_ignore_non_composite() -> None:
|
|
40
40
|
q0, q1 = cirq.LineQubit.range(2)
|
|
41
41
|
circuit = cirq.Circuit()
|
|
42
42
|
circuit.append([cirq.X(q0), cirq.Y(q1), cirq.CZ(q0, q1), cirq.Z(q0)])
|
|
@@ -45,7 +45,7 @@ def test_ignore_non_composite():
|
|
|
45
45
|
assert_equal_mod_empty(expected, circuit)
|
|
46
46
|
|
|
47
47
|
|
|
48
|
-
def test_composite_default():
|
|
48
|
+
def test_composite_default() -> None:
|
|
49
49
|
q0, q1 = cirq.LineQubit.range(2)
|
|
50
50
|
cnot = cirq.CNOT(q0, q1)
|
|
51
51
|
circuit = cirq.Circuit()
|
|
@@ -56,7 +56,7 @@ def test_composite_default():
|
|
|
56
56
|
assert_equal_mod_empty(expected, circuit)
|
|
57
57
|
|
|
58
58
|
|
|
59
|
-
def test_multiple_composite_default():
|
|
59
|
+
def test_multiple_composite_default() -> None:
|
|
60
60
|
q0, q1 = cirq.LineQubit.range(2)
|
|
61
61
|
cnot = cirq.CNOT(q0, q1)
|
|
62
62
|
circuit = cirq.Circuit()
|
|
@@ -68,7 +68,7 @@ def test_multiple_composite_default():
|
|
|
68
68
|
assert_equal_mod_empty(expected, circuit)
|
|
69
69
|
|
|
70
70
|
|
|
71
|
-
def test_mix_composite_non_composite():
|
|
71
|
+
def test_mix_composite_non_composite() -> None:
|
|
72
72
|
q0, q1 = cirq.LineQubit.range(2)
|
|
73
73
|
|
|
74
74
|
circuit = cirq.Circuit(cirq.X(q0), cirq.CNOT(q0, q1), cirq.X(q1))
|
|
@@ -85,7 +85,7 @@ def test_mix_composite_non_composite():
|
|
|
85
85
|
assert_equal_mod_empty(expected, circuit)
|
|
86
86
|
|
|
87
87
|
|
|
88
|
-
def test_recursive_composite():
|
|
88
|
+
def test_recursive_composite() -> None:
|
|
89
89
|
q0, q1 = cirq.LineQubit.range(2)
|
|
90
90
|
swap = cirq.SWAP(q0, q1)
|
|
91
91
|
circuit = cirq.Circuit()
|
|
@@ -106,7 +106,7 @@ def test_recursive_composite():
|
|
|
106
106
|
assert_equal_mod_empty(expected, circuit)
|
|
107
107
|
|
|
108
108
|
|
|
109
|
-
def test_decompose_returns_not_flat_op_tree():
|
|
109
|
+
def test_decompose_returns_not_flat_op_tree() -> None:
|
|
110
110
|
class ExampleGate(cirq.testing.SingleQubitGate):
|
|
111
111
|
def _decompose_(self, qubits):
|
|
112
112
|
(q0,) = qubits
|
|
@@ -121,7 +121,7 @@ def test_decompose_returns_not_flat_op_tree():
|
|
|
121
121
|
assert_equal_mod_empty(expected, circuit)
|
|
122
122
|
|
|
123
123
|
|
|
124
|
-
def test_decompose_returns_deep_op_tree():
|
|
124
|
+
def test_decompose_returns_deep_op_tree() -> None:
|
|
125
125
|
class ExampleGate(cirq.testing.TwoQubitGate):
|
|
126
126
|
def _decompose_(self, qubits):
|
|
127
127
|
q0, q1 = qubits
|
|
@@ -162,7 +162,7 @@ def test_decompose_returns_deep_op_tree():
|
|
|
162
162
|
assert_equal_mod_empty(expected, circuit)
|
|
163
163
|
|
|
164
164
|
|
|
165
|
-
def test_non_recursive_expansion():
|
|
165
|
+
def test_non_recursive_expansion() -> None:
|
|
166
166
|
qubits = [cirq.NamedQubit(s) for s in 'xy']
|
|
167
167
|
no_decomp = lambda op: (isinstance(op, cirq.GateOperation) and op.gate == cirq.ISWAP)
|
|
168
168
|
unexpanded_circuit = cirq.Circuit(cirq.ISWAP(*qubits))
|
|
@@ -184,14 +184,14 @@ y: ───X───────@───────@───────
|
|
|
184
184
|
assert actual_text_diagram == expected_text_diagram
|
|
185
185
|
|
|
186
186
|
|
|
187
|
-
def test_do_not_decompose_no_compile():
|
|
187
|
+
def test_do_not_decompose_no_compile() -> None:
|
|
188
188
|
q0, q1 = cirq.LineQubit.range(2)
|
|
189
189
|
c = cirq.Circuit(cirq.CNOT(q0, q1).with_tags("no_compile"))
|
|
190
190
|
context = cirq.TransformerContext(tags_to_ignore=("no_compile",))
|
|
191
191
|
assert_equal_mod_empty(c, cirq.expand_composite(c, context=context))
|
|
192
192
|
|
|
193
193
|
|
|
194
|
-
def test_expands_composite_recursively_preserving_structure():
|
|
194
|
+
def test_expands_composite_recursively_preserving_structure() -> None:
|
|
195
195
|
q = cirq.LineQubit.range(2)
|
|
196
196
|
c_nested = cirq.FrozenCircuit(
|
|
197
197
|
cirq.SWAP(*q[:2]), cirq.SWAP(*q[:2]).with_tags("ignore"), cirq.SWAP(*q[:2])
|
|
@@ -256,7 +256,7 @@ def test_expands_composite_recursively_preserving_structure():
|
|
|
256
256
|
c_nested_expanded,
|
|
257
257
|
)
|
|
258
258
|
|
|
259
|
-
context = cirq.TransformerContext(tags_to_ignore=
|
|
259
|
+
context = cirq.TransformerContext(tags_to_ignore=("ignore",), deep=True)
|
|
260
260
|
c_expanded = cirq.expand_composite(
|
|
261
261
|
c_orig, no_decomp=lambda op: op.gate == cirq.CNOT, context=context
|
|
262
262
|
)
|
|
@@ -42,3 +42,16 @@ from cirq.transformers.gauge_compiling.sqrt_iswap_gauge import (
|
|
|
42
42
|
from cirq.transformers.gauge_compiling.cphase_gauge import (
|
|
43
43
|
CPhaseGaugeTransformer as CPhaseGaugeTransformer,
|
|
44
44
|
)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
from cirq.transformers.gauge_compiling.idle_moments_gauge import (
|
|
48
|
+
IdleMomentsGauge as IdleMomentsGauge,
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
from cirq.transformers.gauge_compiling.multi_moment_gauge_compiling import (
|
|
52
|
+
MultiMomentGaugeTransformer as MultiMomentGaugeTransformer,
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
from cirq.transformers.gauge_compiling.multi_moment_cphase_gauge import (
|
|
56
|
+
CPhaseGaugeTransformerMM as CPhaseGaugeTransformerMM,
|
|
57
|
+
)
|
|
@@ -19,9 +19,10 @@ from __future__ import annotations
|
|
|
19
19
|
import abc
|
|
20
20
|
import functools
|
|
21
21
|
import itertools
|
|
22
|
+
from collections.abc import Callable, Sequence
|
|
22
23
|
from dataclasses import dataclass
|
|
23
24
|
from numbers import Real
|
|
24
|
-
from typing import
|
|
25
|
+
from typing import TYPE_CHECKING
|
|
25
26
|
|
|
26
27
|
import numpy as np
|
|
27
28
|
import sympy
|
|
@@ -260,7 +261,7 @@ class GaugeTransformer:
|
|
|
260
261
|
N: int,
|
|
261
262
|
context: transformer_api.TransformerContext | None = None,
|
|
262
263
|
prng: np.random.Generator | None = None,
|
|
263
|
-
) -> tuple[circuits.AbstractCircuit, cirq.
|
|
264
|
+
) -> tuple[circuits.AbstractCircuit, cirq.Sweep]:
|
|
264
265
|
"""Generates a parameterized circuit with *N* sets of sweepable parameters.
|
|
265
266
|
|
|
266
267
|
Args:
|
|
@@ -33,29 +33,31 @@ from cirq.transformers.gauge_compiling import (
|
|
|
33
33
|
from cirq.transformers.gauge_compiling.sqrt_cz_gauge import SqrtCZGauge
|
|
34
34
|
|
|
35
35
|
|
|
36
|
-
def test_deep_transformation_not_supported():
|
|
36
|
+
def test_deep_transformation_not_supported() -> None:
|
|
37
|
+
|
|
38
|
+
empty_selector = GaugeSelector(gauges=())
|
|
37
39
|
|
|
38
40
|
with pytest.raises(ValueError, match="cannot be used with deep=True"):
|
|
39
|
-
_ = GaugeTransformer(target=cirq.CZ, gauge_selector=
|
|
41
|
+
_ = GaugeTransformer(target=cirq.CZ, gauge_selector=empty_selector)(
|
|
40
42
|
cirq.Circuit(), context=cirq.TransformerContext(deep=True)
|
|
41
43
|
)
|
|
42
44
|
|
|
43
45
|
with pytest.raises(ValueError, match="cannot be used with deep=True"):
|
|
44
|
-
_ = GaugeTransformer(target=cirq.CZ, gauge_selector=
|
|
46
|
+
_ = GaugeTransformer(target=cirq.CZ, gauge_selector=empty_selector).as_sweep(
|
|
45
47
|
cirq.Circuit(), context=cirq.TransformerContext(deep=True), N=1
|
|
46
48
|
)
|
|
47
49
|
|
|
48
50
|
|
|
49
|
-
def test_ignore_tags():
|
|
51
|
+
def test_ignore_tags() -> None:
|
|
50
52
|
c = cirq.Circuit(cirq.CZ(*cirq.LineQubit.range(2)).with_tags('foo'))
|
|
51
|
-
assert c == CZGaugeTransformer(c, context=cirq.TransformerContext(tags_to_ignore=
|
|
53
|
+
assert c == CZGaugeTransformer(c, context=cirq.TransformerContext(tags_to_ignore=("foo",)))
|
|
52
54
|
parameterized_circuit, _ = CZGaugeTransformer.as_sweep(
|
|
53
|
-
c, context=cirq.TransformerContext(tags_to_ignore=
|
|
55
|
+
c, context=cirq.TransformerContext(tags_to_ignore=("foo",)), N=1
|
|
54
56
|
)
|
|
55
57
|
assert c == parameterized_circuit
|
|
56
58
|
|
|
57
59
|
|
|
58
|
-
def test_target_can_be_gateset():
|
|
60
|
+
def test_target_can_be_gateset() -> None:
|
|
59
61
|
qs = cirq.LineQubit.range(2)
|
|
60
62
|
c = cirq.Circuit(cirq.CZ(*qs))
|
|
61
63
|
transformer = GaugeTransformer(
|
|
@@ -65,7 +67,7 @@ def test_target_can_be_gateset():
|
|
|
65
67
|
assert transformer(c, prng=np.random.default_rng(0)) == want
|
|
66
68
|
|
|
67
69
|
|
|
68
|
-
def test_as_sweep_multi_pre_or_multi_post():
|
|
70
|
+
def test_as_sweep_multi_pre_or_multi_post() -> None:
|
|
69
71
|
transformer = GaugeTransformer(
|
|
70
72
|
target=cirq.CZ,
|
|
71
73
|
gauge_selector=GaugeSelector(
|
|
@@ -91,7 +93,7 @@ def test_as_sweep_multi_pre_or_multi_post():
|
|
|
91
93
|
)
|
|
92
94
|
|
|
93
95
|
|
|
94
|
-
def test_as_sweep_invalid_gauge_sequence():
|
|
96
|
+
def test_as_sweep_invalid_gauge_sequence() -> None:
|
|
95
97
|
transfomer = GaugeTransformer(
|
|
96
98
|
target=cirq.CZ,
|
|
97
99
|
gauge_selector=GaugeSelector(
|
|
@@ -112,7 +114,7 @@ def test_as_sweep_invalid_gauge_sequence():
|
|
|
112
114
|
transfomer.as_sweep(c, N=1)
|
|
113
115
|
|
|
114
116
|
|
|
115
|
-
def test_as_sweep_convert_to_phxz_failed():
|
|
117
|
+
def test_as_sweep_convert_to_phxz_failed() -> None:
|
|
116
118
|
qs = cirq.LineQubit.range(2)
|
|
117
119
|
c = cirq.Circuit(cirq.CZ(*qs))
|
|
118
120
|
|
|
@@ -128,7 +130,7 @@ def test_as_sweep_convert_to_phxz_failed():
|
|
|
128
130
|
_ = CZGaugeTransformer.as_sweep(c, context=cirq.TransformerContext(), N=1)
|
|
129
131
|
|
|
130
132
|
|
|
131
|
-
def test_symbolize_2_qubits_gate_failed():
|
|
133
|
+
def test_symbolize_2_qubits_gate_failed() -> None:
|
|
132
134
|
qs = cirq.LineQubit.range(2)
|
|
133
135
|
c = cirq.Circuit(cirq.CZPowGate(exponent=0.5).on(*qs))
|
|
134
136
|
|
|
@@ -142,7 +144,7 @@ def test_symbolize_2_qubits_gate_failed():
|
|
|
142
144
|
_ = SqrtCZGaugeTransformer.as_sweep(c, N=1)
|
|
143
145
|
|
|
144
146
|
|
|
145
|
-
def test_symbolize_2_qubits_gate_failed_unmatched_symbol_length():
|
|
147
|
+
def test_symbolize_2_qubits_gate_failed_unmatched_symbol_length() -> None:
|
|
146
148
|
symbolizer = TwoQubitGateSymbolizer(symbolizer_fn=lambda gate, _: (gate, {}), n_symbols=2)
|
|
147
149
|
with pytest.raises(ValueError, match="Expect 2 symbols, but got 1 symbols"):
|
|
148
150
|
symbolizer(cirq.CZ, [sympy.Symbol('x')])
|
|
@@ -33,7 +33,7 @@ class GaugeTester:
|
|
|
33
33
|
['generation_seed', 'transformation_seed'],
|
|
34
34
|
np.random.RandomState(0).randint(2**31, size=(5, 2)).tolist(),
|
|
35
35
|
)
|
|
36
|
-
def test_gauge_transformer(self, generation_seed, transformation_seed):
|
|
36
|
+
def test_gauge_transformer(self, generation_seed, transformation_seed) -> None:
|
|
37
37
|
c = cirq.Circuit()
|
|
38
38
|
while not any(op.gate == self.two_qubit_gate for op in c.all_operations()):
|
|
39
39
|
c = cirq.testing.random_circuit(
|
|
@@ -57,7 +57,7 @@ class GaugeTester:
|
|
|
57
57
|
|
|
58
58
|
@patch('cirq.transformers.gauge_compiling.gauge_compiling._select', autospec=True)
|
|
59
59
|
@pytest.mark.parametrize('seed', range(5))
|
|
60
|
-
def test_all_gauges(self, mock_select, seed):
|
|
60
|
+
def test_all_gauges(self, mock_select, seed) -> None:
|
|
61
61
|
assert isinstance(
|
|
62
62
|
self.gauge_transformer.gauge_selector, GaugeSelector
|
|
63
63
|
), 'When using a custom selector, please override this method to properly test all gauges'
|
|
@@ -74,7 +74,7 @@ class GaugeTester:
|
|
|
74
74
|
else:
|
|
75
75
|
_check_equivalent_with_error_message(c, nc, gauge)
|
|
76
76
|
|
|
77
|
-
def test_sweep(self):
|
|
77
|
+
def test_sweep(self) -> None:
|
|
78
78
|
qubits = cirq.LineQubit.range(3)
|
|
79
79
|
|
|
80
80
|
input_circuit = cirq.Circuit(
|