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
|
@@ -23,7 +23,7 @@ import cirq
|
|
|
23
23
|
from cirq.transformers.measurement_transformers import _ConfusionChannel, _MeasurementQid, _mod_add
|
|
24
24
|
|
|
25
25
|
|
|
26
|
-
def assert_equivalent_to_deferred(circuit: cirq.Circuit):
|
|
26
|
+
def assert_equivalent_to_deferred(circuit: cirq.Circuit) -> None:
|
|
27
27
|
qubits = list(circuit.all_qubits())
|
|
28
28
|
sim = cirq.Simulator()
|
|
29
29
|
num_qubits = len(qubits)
|
|
@@ -40,7 +40,7 @@ def assert_equivalent_to_deferred(circuit: cirq.Circuit):
|
|
|
40
40
|
np.testing.assert_equal(result.measurements, result1.measurements)
|
|
41
41
|
|
|
42
42
|
|
|
43
|
-
def test_basic():
|
|
43
|
+
def test_basic() -> None:
|
|
44
44
|
q0, q1 = cirq.LineQubit.range(2)
|
|
45
45
|
circuit = cirq.Circuit(
|
|
46
46
|
cirq.measure(q0, key='a'),
|
|
@@ -61,7 +61,7 @@ def test_basic():
|
|
|
61
61
|
)
|
|
62
62
|
|
|
63
63
|
|
|
64
|
-
def test_qudits():
|
|
64
|
+
def test_qudits() -> None:
|
|
65
65
|
q0, q1 = cirq.LineQid.range(2, dimension=3)
|
|
66
66
|
circuit = cirq.Circuit(
|
|
67
67
|
cirq.measure(q0, key='a'),
|
|
@@ -82,7 +82,7 @@ def test_qudits():
|
|
|
82
82
|
)
|
|
83
83
|
|
|
84
84
|
|
|
85
|
-
def test_sympy_control():
|
|
85
|
+
def test_sympy_control() -> None:
|
|
86
86
|
q0, q1 = cirq.LineQubit.range(2)
|
|
87
87
|
circuit = cirq.Circuit(
|
|
88
88
|
cirq.measure(q0, key='a'),
|
|
@@ -103,7 +103,7 @@ def test_sympy_control():
|
|
|
103
103
|
)
|
|
104
104
|
|
|
105
105
|
|
|
106
|
-
def test_sympy_qudits():
|
|
106
|
+
def test_sympy_qudits() -> None:
|
|
107
107
|
q0, q1 = cirq.LineQid.range(2, dimension=3)
|
|
108
108
|
circuit = cirq.Circuit(
|
|
109
109
|
cirq.measure(q0, key='a'),
|
|
@@ -124,7 +124,7 @@ def test_sympy_qudits():
|
|
|
124
124
|
)
|
|
125
125
|
|
|
126
126
|
|
|
127
|
-
def test_sympy_control_complex():
|
|
127
|
+
def test_sympy_control_complex() -> None:
|
|
128
128
|
q0, q1, q2 = cirq.LineQubit.range(3)
|
|
129
129
|
circuit = cirq.Circuit(
|
|
130
130
|
cirq.measure(q0, key='a'),
|
|
@@ -151,7 +151,7 @@ def test_sympy_control_complex():
|
|
|
151
151
|
)
|
|
152
152
|
|
|
153
153
|
|
|
154
|
-
def test_sympy_control_complex_qudit():
|
|
154
|
+
def test_sympy_control_complex_qudit() -> None:
|
|
155
155
|
q0, q1, q2 = cirq.LineQid.for_qid_shape((4, 2, 2))
|
|
156
156
|
circuit = cirq.Circuit(
|
|
157
157
|
cirq.measure(q0, key='a'),
|
|
@@ -180,7 +180,7 @@ def test_sympy_control_complex_qudit():
|
|
|
180
180
|
)
|
|
181
181
|
|
|
182
182
|
|
|
183
|
-
def test_multiple_sympy_control_complex():
|
|
183
|
+
def test_multiple_sympy_control_complex() -> None:
|
|
184
184
|
q0, q1, q2 = cirq.LineQubit.range(3)
|
|
185
185
|
circuit = cirq.Circuit(
|
|
186
186
|
cirq.measure(q0, key='a'),
|
|
@@ -209,7 +209,7 @@ def test_multiple_sympy_control_complex():
|
|
|
209
209
|
)
|
|
210
210
|
|
|
211
211
|
|
|
212
|
-
def test_sympy_and_key_control():
|
|
212
|
+
def test_sympy_and_key_control() -> None:
|
|
213
213
|
q0, q1 = cirq.LineQubit.range(2)
|
|
214
214
|
circuit = cirq.Circuit(
|
|
215
215
|
cirq.measure(q0, key='a'),
|
|
@@ -230,7 +230,7 @@ def test_sympy_and_key_control():
|
|
|
230
230
|
)
|
|
231
231
|
|
|
232
232
|
|
|
233
|
-
def test_sympy_control_multiqubit():
|
|
233
|
+
def test_sympy_control_multiqubit() -> None:
|
|
234
234
|
q0, q1, q2 = cirq.LineQubit.range(3)
|
|
235
235
|
circuit = cirq.Circuit(
|
|
236
236
|
cirq.measure(q0, q1, key='a'),
|
|
@@ -255,7 +255,7 @@ def test_sympy_control_multiqubit():
|
|
|
255
255
|
)
|
|
256
256
|
|
|
257
257
|
|
|
258
|
-
def test_nocompile_context():
|
|
258
|
+
def test_nocompile_context() -> None:
|
|
259
259
|
q0, q1 = cirq.LineQubit.range(2)
|
|
260
260
|
circuit = cirq.Circuit(
|
|
261
261
|
cirq.measure(q0, key='a').with_tags('nocompile'),
|
|
@@ -268,7 +268,7 @@ def test_nocompile_context():
|
|
|
268
268
|
cirq.testing.assert_same_circuits(deferred, circuit)
|
|
269
269
|
|
|
270
270
|
|
|
271
|
-
def test_nocompile_context_leaves_invalid_circuit():
|
|
271
|
+
def test_nocompile_context_leaves_invalid_circuit() -> None:
|
|
272
272
|
q0, q1 = cirq.LineQubit.range(2)
|
|
273
273
|
circuit = cirq.Circuit(
|
|
274
274
|
cirq.measure(q0, key='a').with_tags('nocompile'),
|
|
@@ -281,7 +281,7 @@ def test_nocompile_context_leaves_invalid_circuit():
|
|
|
281
281
|
)
|
|
282
282
|
|
|
283
283
|
|
|
284
|
-
def test_pauli():
|
|
284
|
+
def test_pauli() -> None:
|
|
285
285
|
q0, q1 = cirq.LineQubit.range(2)
|
|
286
286
|
circuit = cirq.Circuit(
|
|
287
287
|
cirq.PauliMeasurementGate(cirq.DensePauliString('Y'), key='a').on(q0),
|
|
@@ -303,7 +303,7 @@ def test_pauli():
|
|
|
303
303
|
)
|
|
304
304
|
|
|
305
305
|
|
|
306
|
-
def test_extra_measurements():
|
|
306
|
+
def test_extra_measurements() -> None:
|
|
307
307
|
q0, q1 = cirq.LineQubit.range(2)
|
|
308
308
|
circuit = cirq.Circuit(
|
|
309
309
|
cirq.measure(q0, key='a'),
|
|
@@ -326,7 +326,7 @@ def test_extra_measurements():
|
|
|
326
326
|
)
|
|
327
327
|
|
|
328
328
|
|
|
329
|
-
def test_extra_controlled_bits():
|
|
329
|
+
def test_extra_controlled_bits() -> None:
|
|
330
330
|
q0, q1 = cirq.LineQubit.range(2)
|
|
331
331
|
circuit = cirq.Circuit(
|
|
332
332
|
cirq.measure(q0, key='a'),
|
|
@@ -347,7 +347,7 @@ def test_extra_controlled_bits():
|
|
|
347
347
|
)
|
|
348
348
|
|
|
349
349
|
|
|
350
|
-
def test_extra_control_bits():
|
|
350
|
+
def test_extra_control_bits() -> None:
|
|
351
351
|
q0, q1 = cirq.LineQubit.range(2)
|
|
352
352
|
circuit = cirq.Circuit(
|
|
353
353
|
cirq.measure(q0, key='a'),
|
|
@@ -372,7 +372,7 @@ def test_extra_control_bits():
|
|
|
372
372
|
)
|
|
373
373
|
|
|
374
374
|
|
|
375
|
-
def test_subcircuit():
|
|
375
|
+
def test_subcircuit() -> None:
|
|
376
376
|
q0, q1 = cirq.LineQubit.range(2)
|
|
377
377
|
circuit = cirq.Circuit(
|
|
378
378
|
cirq.CircuitOperation(
|
|
@@ -397,7 +397,7 @@ def test_subcircuit():
|
|
|
397
397
|
)
|
|
398
398
|
|
|
399
399
|
|
|
400
|
-
def test_multi_qubit_measurements():
|
|
400
|
+
def test_multi_qubit_measurements() -> None:
|
|
401
401
|
q0, q1 = cirq.LineQubit.range(2)
|
|
402
402
|
circuit = cirq.Circuit(
|
|
403
403
|
cirq.measure(q0, q1, key='a'),
|
|
@@ -422,7 +422,7 @@ def test_multi_qubit_measurements():
|
|
|
422
422
|
)
|
|
423
423
|
|
|
424
424
|
|
|
425
|
-
def test_multi_qubit_control():
|
|
425
|
+
def test_multi_qubit_control() -> None:
|
|
426
426
|
q0, q1, q2 = cirq.LineQubit.range(3)
|
|
427
427
|
circuit = cirq.Circuit(
|
|
428
428
|
cirq.measure(q0, q1, key='a'),
|
|
@@ -448,7 +448,7 @@ def test_multi_qubit_control():
|
|
|
448
448
|
|
|
449
449
|
|
|
450
450
|
@pytest.mark.parametrize('index', [-3, -2, -1, 0, 1, 2])
|
|
451
|
-
def test_repeated(index: int):
|
|
451
|
+
def test_repeated(index: int) -> None:
|
|
452
452
|
q0, q1 = cirq.LineQubit.range(2)
|
|
453
453
|
circuit = cirq.Circuit(
|
|
454
454
|
cirq.measure(q0, key='a'), # The control measurement when `index` is 0 or -2
|
|
@@ -481,7 +481,7 @@ def test_repeated(index: int):
|
|
|
481
481
|
)
|
|
482
482
|
|
|
483
483
|
|
|
484
|
-
def test_diagram():
|
|
484
|
+
def test_diagram() -> None:
|
|
485
485
|
q0, q1, q2, q3 = cirq.LineQubit.range(4)
|
|
486
486
|
circuit = cirq.Circuit(
|
|
487
487
|
cirq.measure(q0, q2, key='a'),
|
|
@@ -515,7 +515,7 @@ M('b[0]', q=q(3)): ───────X────M────────
|
|
|
515
515
|
)
|
|
516
516
|
|
|
517
517
|
|
|
518
|
-
def test_repr():
|
|
518
|
+
def test_repr() -> None:
|
|
519
519
|
def test_repr(qid: _MeasurementQid):
|
|
520
520
|
cirq.testing.assert_equivalent_repr(qid, global_vals={'_MeasurementQid': _MeasurementQid})
|
|
521
521
|
|
|
@@ -526,7 +526,7 @@ def test_repr():
|
|
|
526
526
|
test_repr(_MeasurementQid('0:1:a', cirq.LineQid(9, 4)))
|
|
527
527
|
|
|
528
528
|
|
|
529
|
-
def test_confusion_map():
|
|
529
|
+
def test_confusion_map() -> None:
|
|
530
530
|
q0, q1 = cirq.LineQubit.range(2)
|
|
531
531
|
circuit = cirq.Circuit(
|
|
532
532
|
cirq.H(q0),
|
|
@@ -549,7 +549,7 @@ def test_confusion_map():
|
|
|
549
549
|
assert np.all(result['a'] == result['b'])
|
|
550
550
|
|
|
551
551
|
|
|
552
|
-
def test_confusion_map_density_matrix():
|
|
552
|
+
def test_confusion_map_density_matrix() -> None:
|
|
553
553
|
q0, q1 = cirq.LineQubit.range(2)
|
|
554
554
|
p_q0 = 0.3 # probability to measure 1 for q0
|
|
555
555
|
confusion = np.array([[0.8, 0.2], [0.1, 0.9]])
|
|
@@ -573,20 +573,20 @@ def test_confusion_map_density_matrix():
|
|
|
573
573
|
assert np.allclose(cirq.partial_trace(rho, [2]), expected)
|
|
574
574
|
|
|
575
575
|
|
|
576
|
-
def test_confusion_map_invert_mask_ordering():
|
|
576
|
+
def test_confusion_map_invert_mask_ordering() -> None:
|
|
577
577
|
q0 = cirq.LineQubit(0)
|
|
578
578
|
# Confusion map sets the measurement to zero, and the invert mask changes it to one.
|
|
579
579
|
# If these are run out of order then the result would be zero.
|
|
580
580
|
circuit = cirq.Circuit(
|
|
581
581
|
cirq.measure(
|
|
582
|
-
q0, key='a', confusion_map={(0,): np.array([[1, 0], [1, 0]])}, invert_mask=(
|
|
582
|
+
q0, key='a', confusion_map={(0,): np.array([[1, 0], [1, 0]])}, invert_mask=(True,)
|
|
583
583
|
),
|
|
584
584
|
cirq.I(q0),
|
|
585
585
|
)
|
|
586
586
|
assert_equivalent_to_deferred(circuit)
|
|
587
587
|
|
|
588
588
|
|
|
589
|
-
def test_confusion_map_qudits():
|
|
589
|
+
def test_confusion_map_qudits() -> None:
|
|
590
590
|
q0 = cirq.LineQid(0, dimension=3)
|
|
591
591
|
# First op takes q0 to superposed state, then confusion map measures 2 regardless.
|
|
592
592
|
circuit = cirq.Circuit(
|
|
@@ -599,7 +599,7 @@ def test_confusion_map_qudits():
|
|
|
599
599
|
assert_equivalent_to_deferred(circuit)
|
|
600
600
|
|
|
601
601
|
|
|
602
|
-
def test_multi_qubit_confusion_map():
|
|
602
|
+
def test_multi_qubit_confusion_map() -> None:
|
|
603
603
|
q0, q1, q2 = cirq.LineQubit.range(3)
|
|
604
604
|
circuit = cirq.Circuit(
|
|
605
605
|
cirq.measure(
|
|
@@ -638,7 +638,7 @@ def test_multi_qubit_confusion_map():
|
|
|
638
638
|
assert np.sum(result['b']) == 100
|
|
639
639
|
|
|
640
640
|
|
|
641
|
-
def test_confusion_map_errors():
|
|
641
|
+
def test_confusion_map_errors() -> None:
|
|
642
642
|
q0, q1 = cirq.LineQubit.range(2)
|
|
643
643
|
circuit = cirq.Circuit(
|
|
644
644
|
cirq.measure(q0, key='a', confusion_map={(0,): np.array([1])}),
|
|
@@ -676,7 +676,7 @@ def test_confusion_map_errors():
|
|
|
676
676
|
_ = cirq.defer_measurements(circuit)
|
|
677
677
|
|
|
678
678
|
|
|
679
|
-
def test_dephase():
|
|
679
|
+
def test_dephase() -> None:
|
|
680
680
|
q0, q1 = cirq.LineQubit.range(2)
|
|
681
681
|
circuit = cirq.Circuit(
|
|
682
682
|
cirq.CircuitOperation(
|
|
@@ -704,7 +704,7 @@ def test_dephase():
|
|
|
704
704
|
)
|
|
705
705
|
|
|
706
706
|
|
|
707
|
-
def test_dephase_classical_conditions():
|
|
707
|
+
def test_dephase_classical_conditions() -> None:
|
|
708
708
|
q0, q1 = cirq.LineQubit.range(2)
|
|
709
709
|
circuit = cirq.Circuit(
|
|
710
710
|
cirq.measure(q0, key='a'),
|
|
@@ -715,7 +715,7 @@ def test_dephase_classical_conditions():
|
|
|
715
715
|
_ = cirq.dephase_measurements(circuit)
|
|
716
716
|
|
|
717
717
|
|
|
718
|
-
def test_dephase_nocompile_context():
|
|
718
|
+
def test_dephase_nocompile_context() -> None:
|
|
719
719
|
q0, q1 = cirq.LineQubit.range(2)
|
|
720
720
|
circuit = cirq.Circuit(
|
|
721
721
|
cirq.CircuitOperation(
|
|
@@ -745,11 +745,13 @@ def test_dephase_nocompile_context():
|
|
|
745
745
|
)
|
|
746
746
|
|
|
747
747
|
|
|
748
|
-
def test_drop_terminal():
|
|
748
|
+
def test_drop_terminal() -> None:
|
|
749
749
|
q0, q1 = cirq.LineQubit.range(2)
|
|
750
750
|
circuit = cirq.Circuit(
|
|
751
751
|
cirq.CircuitOperation(
|
|
752
|
-
cirq.FrozenCircuit(
|
|
752
|
+
cirq.FrozenCircuit(
|
|
753
|
+
cirq.CX(q0, q1), cirq.measure(q0, q1, key='a~b', invert_mask=(False, True))
|
|
754
|
+
)
|
|
753
755
|
)
|
|
754
756
|
)
|
|
755
757
|
dropped = cirq.drop_terminal_measurements(circuit)
|
|
@@ -761,10 +763,12 @@ def test_drop_terminal():
|
|
|
761
763
|
)
|
|
762
764
|
|
|
763
765
|
|
|
764
|
-
def test_drop_terminal_qudit():
|
|
766
|
+
def test_drop_terminal_qudit() -> None:
|
|
765
767
|
q0, q1 = cirq.LineQid.range(2, dimension=3)
|
|
766
768
|
circuit = cirq.Circuit(
|
|
767
|
-
cirq.CircuitOperation(
|
|
769
|
+
cirq.CircuitOperation(
|
|
770
|
+
cirq.FrozenCircuit(cirq.measure(q0, q1, key='m', invert_mask=(False, True)))
|
|
771
|
+
)
|
|
768
772
|
)
|
|
769
773
|
dropped = cirq.drop_terminal_measurements(circuit)
|
|
770
774
|
expected_inversion_matrix = np.array([[0, 1, 0], [1, 0, 0], [0, 0, 1]])
|
|
@@ -796,11 +800,13 @@ def test_drop_terminal_qudit():
|
|
|
796
800
|
assert np.all(d2.measurements['m'] == [2, 2])
|
|
797
801
|
|
|
798
802
|
|
|
799
|
-
def test_drop_terminal_nonterminal_error():
|
|
803
|
+
def test_drop_terminal_nonterminal_error() -> None:
|
|
800
804
|
q0, q1 = cirq.LineQubit.range(2)
|
|
801
805
|
circuit = cirq.Circuit(
|
|
802
806
|
cirq.CircuitOperation(
|
|
803
|
-
cirq.FrozenCircuit(
|
|
807
|
+
cirq.FrozenCircuit(
|
|
808
|
+
cirq.measure(q0, q1, key='a~b', invert_mask=(False, True)), cirq.CX(q0, q1)
|
|
809
|
+
)
|
|
804
810
|
)
|
|
805
811
|
)
|
|
806
812
|
with pytest.raises(ValueError, match='Circuit contains a non-terminal measurement'):
|
|
@@ -813,7 +819,7 @@ def test_drop_terminal_nonterminal_error():
|
|
|
813
819
|
_ = cirq.drop_terminal_measurements(circuit, context=None)
|
|
814
820
|
|
|
815
821
|
|
|
816
|
-
def test_confusion_channel_consistency():
|
|
822
|
+
def test_confusion_channel_consistency() -> None:
|
|
817
823
|
two_d_chan = _ConfusionChannel(np.array([[0.5, 0.5], [0.4, 0.6]]), shape=(2,))
|
|
818
824
|
cirq.testing.assert_has_consistent_apply_channel(two_d_chan)
|
|
819
825
|
three_d_chan = _ConfusionChannel(
|
|
@@ -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 cast, TYPE_CHECKING
|
|
20
21
|
|
|
21
22
|
from cirq import circuits, ops, protocols
|
|
22
23
|
from cirq.transformers import transformer_api, transformer_primitives
|
|
@@ -20,7 +20,7 @@ import pytest
|
|
|
20
20
|
import cirq
|
|
21
21
|
|
|
22
22
|
|
|
23
|
-
def assert_optimizes(optimized: cirq.AbstractCircuit, expected: cirq.AbstractCircuit):
|
|
23
|
+
def assert_optimizes(optimized: cirq.AbstractCircuit, expected: cirq.AbstractCircuit) -> None:
|
|
24
24
|
# Ignore differences that would be caught by follow-up optimizations.
|
|
25
25
|
followup_transformers: list[cirq.TRANSFORMER] = [
|
|
26
26
|
cirq.drop_negligible_operations,
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
|
|
17
17
|
from __future__ import annotations
|
|
18
18
|
|
|
19
|
-
from
|
|
19
|
+
from collections.abc import Callable, Hashable
|
|
20
|
+
from typing import cast, TYPE_CHECKING
|
|
20
21
|
|
|
21
22
|
from cirq import circuits, ops, protocols
|
|
22
23
|
from cirq.study.resolver import ParamResolver
|
|
@@ -323,9 +324,12 @@ def merge_single_qubit_gates_to_phxz_symbolized(
|
|
|
323
324
|
)
|
|
324
325
|
|
|
325
326
|
# Step 3, get N sets of parameterizations as new_sweep.
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
327
|
+
if remaining_symbols:
|
|
328
|
+
new_sweep: Sweep = Zip(
|
|
329
|
+
_calc_phxz_sweeps(new_circuit, merged_circuits), # phxz sweeps
|
|
330
|
+
_sweep_on_symbols(sweep, remaining_symbols), # remaining sweeps
|
|
331
|
+
)
|
|
332
|
+
else:
|
|
333
|
+
new_sweep = _calc_phxz_sweeps(new_circuit, merged_circuits)
|
|
330
334
|
|
|
331
335
|
return align.align_right(new_circuit), new_sweep
|
|
@@ -21,7 +21,7 @@ import sympy
|
|
|
21
21
|
import cirq
|
|
22
22
|
|
|
23
23
|
|
|
24
|
-
def assert_optimizes(optimized: cirq.AbstractCircuit, expected: cirq.AbstractCircuit):
|
|
24
|
+
def assert_optimizes(optimized: cirq.AbstractCircuit, expected: cirq.AbstractCircuit) -> None:
|
|
25
25
|
# Ignore differences that would be caught by follow-up optimizations.
|
|
26
26
|
followup_transformers: list[cirq.TRANSFORMER] = [
|
|
27
27
|
cirq.drop_negligible_operations,
|
|
@@ -34,7 +34,7 @@ def assert_optimizes(optimized: cirq.AbstractCircuit, expected: cirq.AbstractCir
|
|
|
34
34
|
cirq.testing.assert_same_circuits(optimized, expected)
|
|
35
35
|
|
|
36
36
|
|
|
37
|
-
def test_merge_single_qubit_gates_to_phased_x_and_z():
|
|
37
|
+
def test_merge_single_qubit_gates_to_phased_x_and_z() -> None:
|
|
38
38
|
a, b = cirq.LineQubit.range(2)
|
|
39
39
|
c = cirq.Circuit(
|
|
40
40
|
cirq.X(a),
|
|
@@ -58,7 +58,7 @@ def test_merge_single_qubit_gates_to_phased_x_and_z():
|
|
|
58
58
|
)
|
|
59
59
|
|
|
60
60
|
|
|
61
|
-
def test_merge_single_qubit_gates_to_phased_x_and_z_deep():
|
|
61
|
+
def test_merge_single_qubit_gates_to_phased_x_and_z_deep() -> None:
|
|
62
62
|
a = cirq.NamedQubit("a")
|
|
63
63
|
c_nested = cirq.FrozenCircuit(cirq.H(a), cirq.Z(a), cirq.H(a).with_tags("ignore"))
|
|
64
64
|
c_nested_merged = cirq.FrozenCircuit(
|
|
@@ -80,7 +80,7 @@ def test_merge_single_qubit_gates_to_phased_x_and_z_deep():
|
|
|
80
80
|
c_nested_merged,
|
|
81
81
|
cirq.CircuitOperation(c_nested_merged).repeat(6),
|
|
82
82
|
)
|
|
83
|
-
context = cirq.TransformerContext(tags_to_ignore=
|
|
83
|
+
context = cirq.TransformerContext(tags_to_ignore=("ignore",), deep=True)
|
|
84
84
|
c_new = cirq.merge_single_qubit_gates_to_phased_x_and_z(c_orig, context=context)
|
|
85
85
|
cirq.testing.assert_same_circuits(c_new, c_expected)
|
|
86
86
|
|
|
@@ -89,7 +89,7 @@ def _phxz(a: float | sympy.Symbol, x: float | sympy.Symbol, z: float | sympy.Sym
|
|
|
89
89
|
return cirq.PhasedXZGate(axis_phase_exponent=a, x_exponent=x, z_exponent=z)
|
|
90
90
|
|
|
91
91
|
|
|
92
|
-
def test_merge_single_qubit_gates_to_phxz():
|
|
92
|
+
def test_merge_single_qubit_gates_to_phxz() -> None:
|
|
93
93
|
a, b = cirq.LineQubit.range(2)
|
|
94
94
|
c = cirq.Circuit(
|
|
95
95
|
cirq.X(a),
|
|
@@ -113,7 +113,7 @@ def test_merge_single_qubit_gates_to_phxz():
|
|
|
113
113
|
)
|
|
114
114
|
|
|
115
115
|
|
|
116
|
-
def test_merge_single_qubit_gates_to_phxz_deep():
|
|
116
|
+
def test_merge_single_qubit_gates_to_phxz_deep() -> None:
|
|
117
117
|
a = cirq.NamedQubit("a")
|
|
118
118
|
c_nested = cirq.FrozenCircuit(cirq.H(a), cirq.Z(a), cirq.H(a).with_tags("ignore"))
|
|
119
119
|
c_nested_merged = cirq.FrozenCircuit(_phxz(-0.5, 0.5, 0).on(a), cirq.H(a).with_tags("ignore"))
|
|
@@ -133,12 +133,12 @@ def test_merge_single_qubit_gates_to_phxz_deep():
|
|
|
133
133
|
c_nested_merged,
|
|
134
134
|
cirq.CircuitOperation(c_nested_merged).repeat(6),
|
|
135
135
|
)
|
|
136
|
-
context = cirq.TransformerContext(tags_to_ignore=
|
|
136
|
+
context = cirq.TransformerContext(tags_to_ignore=("ignore",), deep=True)
|
|
137
137
|
c_new = cirq.merge_single_qubit_gates_to_phxz(c_orig, context=context)
|
|
138
138
|
cirq.testing.assert_same_circuits(c_new, c_expected)
|
|
139
139
|
|
|
140
140
|
|
|
141
|
-
def test_merge_single_qubit_moments_to_phxz():
|
|
141
|
+
def test_merge_single_qubit_moments_to_phxz() -> None:
|
|
142
142
|
q = cirq.LineQubit.range(3)
|
|
143
143
|
c_orig = cirq.Circuit(
|
|
144
144
|
cirq.Moment(cirq.X.on_each(*q[:2])),
|
|
@@ -182,7 +182,7 @@ a: ═════════════════════════
|
|
|
182
182
|
)
|
|
183
183
|
|
|
184
184
|
|
|
185
|
-
def test_merge_single_qubit_moments_to_phxz_deep():
|
|
185
|
+
def test_merge_single_qubit_moments_to_phxz_deep() -> None:
|
|
186
186
|
q = cirq.LineQubit.range(3)
|
|
187
187
|
x_t_y = cirq.FrozenCircuit(
|
|
188
188
|
cirq.Moment(cirq.X.on_each(*q[:2])),
|
|
@@ -218,20 +218,20 @@ def test_merge_single_qubit_moments_to_phxz_deep():
|
|
|
218
218
|
c_nested_merged,
|
|
219
219
|
cirq.CircuitOperation(c_nested_merged).repeat(6),
|
|
220
220
|
)
|
|
221
|
-
context = cirq.TransformerContext(tags_to_ignore=
|
|
221
|
+
context = cirq.TransformerContext(tags_to_ignore=("ignore",), deep=True)
|
|
222
222
|
c_new = cirq.merge_single_qubit_moments_to_phxz(c_orig, context=context)
|
|
223
223
|
cirq.testing.assert_allclose_up_to_global_phase(
|
|
224
224
|
c_new.unitary(), c_expected.unitary(), atol=1e-7
|
|
225
225
|
)
|
|
226
226
|
|
|
227
227
|
|
|
228
|
-
def test_merge_single_qubit_gates_to_phxz_global_phase():
|
|
228
|
+
def test_merge_single_qubit_gates_to_phxz_global_phase() -> None:
|
|
229
229
|
c = cirq.Circuit(cirq.GlobalPhaseGate(1j).on())
|
|
230
230
|
c2 = cirq.merge_single_qubit_gates_to_phxz(c)
|
|
231
231
|
assert c == c2
|
|
232
232
|
|
|
233
233
|
|
|
234
|
-
def test_merge_single_qubit_gates_to_phased_x_and_z_global_phase():
|
|
234
|
+
def test_merge_single_qubit_gates_to_phased_x_and_z_global_phase() -> None:
|
|
235
235
|
c = cirq.Circuit(cirq.GlobalPhaseGate(1j).on())
|
|
236
236
|
c2 = cirq.merge_single_qubit_gates_to_phased_x_and_z(c)
|
|
237
237
|
assert c == c2
|
|
@@ -240,7 +240,7 @@ def test_merge_single_qubit_gates_to_phased_x_and_z_global_phase():
|
|
|
240
240
|
class TestMergeSingleQubitGatesSymbolized(TestCase):
|
|
241
241
|
"""Test suite for merge_single_qubit_gates_to_phxz_symbolized."""
|
|
242
242
|
|
|
243
|
-
def test_case1(self):
|
|
243
|
+
def test_case1(self) -> None:
|
|
244
244
|
"""Test case diagram.
|
|
245
245
|
Input circuit:
|
|
246
246
|
0: ───X─────────@────────H[ignore]─H──X──PhXZ(a=a0,x=x0,z=z0)──X──PhXZ(a=a1,x=x1,z=z1)───
|
|
@@ -265,7 +265,7 @@ class TestMergeSingleQubitGatesSymbolized(TestCase):
|
|
|
265
265
|
cirq.Moment(cirq.X(a)),
|
|
266
266
|
cirq.Moment(_phxz(sa1, sx1, sz1).on(a)),
|
|
267
267
|
)
|
|
268
|
-
context = cirq.TransformerContext(tags_to_ignore=
|
|
268
|
+
context = cirq.TransformerContext(tags_to_ignore=("ignore",))
|
|
269
269
|
sweep = cirq.Zip(
|
|
270
270
|
cirq.Points(key="h_exp", points=[0, 1]),
|
|
271
271
|
cirq.Points(key="cz_exp", points=[0, 1]),
|
|
@@ -295,7 +295,7 @@ class TestMergeSingleQubitGatesSymbolized(TestCase):
|
|
|
295
295
|
{q: q for q in input_circuit.all_qubits()},
|
|
296
296
|
)
|
|
297
297
|
|
|
298
|
-
def test_with_gauge_compiling_as_sweep_success(self):
|
|
298
|
+
def test_with_gauge_compiling_as_sweep_success(self) -> None:
|
|
299
299
|
qubits = cirq.LineQubit.range(7)
|
|
300
300
|
c = cirq.Circuit(
|
|
301
301
|
cirq.Moment(cirq.H(qubits[0]), cirq.H(qubits[3])),
|
|
@@ -318,7 +318,7 @@ class TestMergeSingleQubitGatesSymbolized(TestCase):
|
|
|
318
318
|
{q: q for q in qubits},
|
|
319
319
|
)
|
|
320
320
|
|
|
321
|
-
def test_case_non_parameterized_singles(self):
|
|
321
|
+
def test_case_non_parameterized_singles(self) -> None:
|
|
322
322
|
"""Test merge_single_qubit_gates_to_phxz_symbolized when all single qubit gates are not
|
|
323
323
|
parameterized."""
|
|
324
324
|
|
|
@@ -330,7 +330,7 @@ class TestMergeSingleQubitGatesSymbolized(TestCase):
|
|
|
330
330
|
)
|
|
331
331
|
assert_optimizes(output_circuit, expected_circuit)
|
|
332
332
|
|
|
333
|
-
def test_fail_different_structures_error(self):
|
|
333
|
+
def test_fail_different_structures_error(self) -> None:
|
|
334
334
|
"""Tests that the function raises a ValueError if merged structures of the circuit differ
|
|
335
335
|
for different parameterizations."""
|
|
336
336
|
q0, q1 = cirq.LineQubit.range(2)
|
|
@@ -347,7 +347,7 @@ class TestMergeSingleQubitGatesSymbolized(TestCase):
|
|
|
347
347
|
with pytest.raises(ValueError, match="Expect a PhasedXZGate or IdentityGate.*"):
|
|
348
348
|
cirq.merge_single_qubit_gates_to_phxz_symbolized(circuit, sweep=sweep)
|
|
349
349
|
|
|
350
|
-
def test_fail_unexpected_gate_error(self):
|
|
350
|
+
def test_fail_unexpected_gate_error(self) -> None:
|
|
351
351
|
"""Tests that the function raises a RuntimeError of unexpected gate."""
|
|
352
352
|
a, b = cirq.LineQubit.range(2)
|
|
353
353
|
circuit = cirq.Circuit(
|
|
@@ -373,7 +373,7 @@ class TestMergeSingleQubitGatesSymbolized(TestCase):
|
|
|
373
373
|
cirq.merge_single_qubit_gates_to_phxz_symbolized(circuit, sweep=sweep)
|
|
374
374
|
|
|
375
375
|
|
|
376
|
-
def test_merge_single_qubit_moments_to_phxz_with_global_phase_in_first_moment():
|
|
376
|
+
def test_merge_single_qubit_moments_to_phxz_with_global_phase_in_first_moment() -> None:
|
|
377
377
|
q0 = cirq.LineQubit(0)
|
|
378
378
|
c_orig = cirq.Circuit(
|
|
379
379
|
cirq.Moment(cirq.Y(q0) ** 0.5, cirq.GlobalPhaseGate(1j**0.5).on()), cirq.Moment(cirq.X(q0))
|
|
@@ -384,12 +384,12 @@ def test_merge_single_qubit_moments_to_phxz_with_global_phase_in_first_moment():
|
|
|
384
384
|
cirq.GlobalPhaseGate(1j**0.5).on(),
|
|
385
385
|
)
|
|
386
386
|
)
|
|
387
|
-
context = cirq.TransformerContext(tags_to_ignore=
|
|
387
|
+
context = cirq.TransformerContext(tags_to_ignore=("ignore",))
|
|
388
388
|
c_new = cirq.merge_single_qubit_moments_to_phxz(c_orig, context=context)
|
|
389
389
|
assert c_new == c_expected
|
|
390
390
|
|
|
391
391
|
|
|
392
|
-
def test_merge_single_qubit_moments_to_phxz_with_global_phase_in_second_moment():
|
|
392
|
+
def test_merge_single_qubit_moments_to_phxz_with_global_phase_in_second_moment() -> None:
|
|
393
393
|
q0 = cirq.LineQubit(0)
|
|
394
394
|
c_orig = cirq.Circuit(
|
|
395
395
|
cirq.Moment(cirq.Y(q0) ** 0.5), cirq.Moment(cirq.X(q0), cirq.GlobalPhaseGate(1j**0.5).on())
|
|
@@ -400,6 +400,6 @@ def test_merge_single_qubit_moments_to_phxz_with_global_phase_in_second_moment()
|
|
|
400
400
|
cirq.GlobalPhaseGate(1j**0.5).on(),
|
|
401
401
|
)
|
|
402
402
|
)
|
|
403
|
-
context = cirq.TransformerContext(tags_to_ignore=
|
|
403
|
+
context = cirq.TransformerContext(tags_to_ignore=("ignore",))
|
|
404
404
|
c_new = cirq.merge_single_qubit_moments_to_phxz(c_orig, context=context)
|
|
405
405
|
assert c_new == c_expected
|
|
@@ -20,7 +20,7 @@ import cirq.transformers.noise_adding as na
|
|
|
20
20
|
from cirq import circuits, devices, ops
|
|
21
21
|
|
|
22
22
|
|
|
23
|
-
def test_noise_adding():
|
|
23
|
+
def test_noise_adding() -> None:
|
|
24
24
|
qubits = devices.LineQubit.range(4)
|
|
25
25
|
one_layer = circuits.Circuit(ops.CZ(*qubits[:2]), ops.CZ(*qubits[2:]))
|
|
26
26
|
circuit = one_layer * 10
|
|
@@ -48,7 +48,7 @@ def test_noise_adding():
|
|
|
48
48
|
|
|
49
49
|
# test that supplying a dictionary for p works
|
|
50
50
|
transformed_circuit_p_dict = na.DepolarizingNoiseTransformer(
|
|
51
|
-
{
|
|
51
|
+
{(qubits[0], qubits[1]): 1.0, (qubits[2], qubits[3]): 0.0}
|
|
52
52
|
)(circuit)
|
|
53
53
|
assert len(transformed_circuit_p_dict) == 20 # depth should be doubled
|
|
54
54
|
assert transformed_circuit_p_dict[1::2].all_qubits() == frozenset(
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
|
|
17
17
|
from __future__ import annotations
|
|
18
18
|
|
|
19
|
-
from
|
|
19
|
+
from collections.abc import Callable, Hashable, Sequence
|
|
20
|
+
from typing import TYPE_CHECKING
|
|
20
21
|
|
|
21
22
|
from cirq import circuits
|
|
22
23
|
from cirq.protocols import decompose_protocol as dp
|
|
@@ -25,7 +25,7 @@ if TYPE_CHECKING:
|
|
|
25
25
|
from cirq.protocols.decompose_protocol import DecomposeResult
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
def test_decompose_operations_raises_on_stuck():
|
|
28
|
+
def test_decompose_operations_raises_on_stuck() -> None:
|
|
29
29
|
c_orig = cirq.Circuit(cirq.X(cirq.NamedQubit("q")).with_tags("ignore"))
|
|
30
30
|
gateset = cirq.Gateset(cirq.Y)
|
|
31
31
|
with pytest.raises(ValueError, match="Unable to convert"):
|
|
@@ -41,7 +41,7 @@ def test_decompose_operations_raises_on_stuck():
|
|
|
41
41
|
cirq.testing.assert_same_circuits(c_orig, c_new)
|
|
42
42
|
|
|
43
43
|
|
|
44
|
-
def test_decompose_operations_to_target_gateset_default():
|
|
44
|
+
def test_decompose_operations_to_target_gateset_default() -> None:
|
|
45
45
|
q = cirq.LineQubit.range(2)
|
|
46
46
|
c_orig = cirq.Circuit(
|
|
47
47
|
cirq.T(q[0]),
|
|
@@ -77,7 +77,7 @@ m: ═════════════════════════
|
|
|
77
77
|
)
|
|
78
78
|
|
|
79
79
|
|
|
80
|
-
def test_decompose_operations_to_target_gateset():
|
|
80
|
+
def test_decompose_operations_to_target_gateset() -> None:
|
|
81
81
|
q = cirq.LineQubit.range(2)
|
|
82
82
|
c_orig = cirq.Circuit(
|
|
83
83
|
cirq.T(q[0]),
|
|
@@ -130,7 +130,7 @@ class MatrixGateTargetGateset(cirq.CompilationTargetGateset):
|
|
|
130
130
|
return cirq.MatrixGate(cirq.unitary(op), name="M").on(*op.qubits)
|
|
131
131
|
|
|
132
132
|
|
|
133
|
-
def test_optimize_for_target_gateset_default():
|
|
133
|
+
def test_optimize_for_target_gateset_default() -> None:
|
|
134
134
|
q = cirq.LineQubit.range(2)
|
|
135
135
|
c_orig = cirq.Circuit(
|
|
136
136
|
cirq.T(q[0]), cirq.SWAP(*q), cirq.T(q[0]), cirq.SWAP(*q).with_tags("ignore")
|
|
@@ -148,7 +148,7 @@ def test_optimize_for_target_gateset_default():
|
|
|
148
148
|
cirq.testing.assert_circuits_with_terminal_measurements_are_equivalent(c_orig, c_new, atol=1e-6)
|
|
149
149
|
|
|
150
150
|
|
|
151
|
-
def test_optimize_for_target_gateset():
|
|
151
|
+
def test_optimize_for_target_gateset() -> None:
|
|
152
152
|
q = cirq.LineQubit.range(4)
|
|
153
153
|
c_orig = cirq.Circuit(
|
|
154
154
|
cirq.QuantumFourierTransformGate(4).on(*q),
|
|
@@ -201,7 +201,7 @@ m: ═════════════════════════
|
|
|
201
201
|
)
|
|
202
202
|
|
|
203
203
|
|
|
204
|
-
def test_optimize_for_target_gateset_deep():
|
|
204
|
+
def test_optimize_for_target_gateset_deep() -> None:
|
|
205
205
|
q0, q1 = cirq.LineQubit.range(2)
|
|
206
206
|
c_nested = cirq.FrozenCircuit(cirq.CX(q0, q1))
|
|
207
207
|
c_orig = cirq.Circuit(
|
|
@@ -209,10 +209,12 @@ def test_optimize_for_target_gateset_deep():
|
|
|
209
209
|
cirq.FrozenCircuit(cirq.H(q0), cirq.CircuitOperation(c_nested).repeat(3))
|
|
210
210
|
).repeat(5)
|
|
211
211
|
)
|
|
212
|
+
phxz_from_h_unitary = cirq.single_qubit_matrix_to_phxz(cirq.unitary(cirq.H(q0)))
|
|
213
|
+
assert phxz_from_h_unitary is not None
|
|
212
214
|
c_expected = cirq.Circuit(
|
|
213
215
|
cirq.CircuitOperation(
|
|
214
216
|
cirq.FrozenCircuit(
|
|
215
|
-
|
|
217
|
+
phxz_from_h_unitary.on(q0),
|
|
216
218
|
cirq.CircuitOperation(
|
|
217
219
|
cirq.FrozenCircuit(
|
|
218
220
|
cirq.MatrixGate(c_nested.unitary(qubit_order=[q0, q1]), name="M").on(q0, q1)
|
|
@@ -252,7 +254,7 @@ def test_optimize_for_target_gateset_deep():
|
|
|
252
254
|
|
|
253
255
|
|
|
254
256
|
@pytest.mark.parametrize('max_num_passes', [2, None])
|
|
255
|
-
def test_optimize_for_target_gateset_multiple_passes(max_num_passes: int | None):
|
|
257
|
+
def test_optimize_for_target_gateset_multiple_passes(max_num_passes: int | None) -> None:
|
|
256
258
|
gateset = cirq.CZTargetGateset()
|
|
257
259
|
|
|
258
260
|
input_circuit = cirq.Circuit(
|
|
@@ -332,7 +334,7 @@ def test_optimize_for_target_gateset_multiple_passes(max_num_passes: int | None)
|
|
|
332
334
|
@pytest.mark.parametrize('max_num_passes', [2, None])
|
|
333
335
|
def test_optimize_for_target_gateset_multiple_passes_dont_preserve_moment_structure(
|
|
334
336
|
max_num_passes: int | None,
|
|
335
|
-
):
|
|
337
|
+
) -> None:
|
|
336
338
|
gateset = cirq.CZTargetGateset(preserve_moment_structure=False)
|
|
337
339
|
|
|
338
340
|
input_circuit = cirq.Circuit(
|