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,7 @@
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
17
|
import random
|
|
18
|
-
from
|
|
18
|
+
from collections.abc import Sequence
|
|
19
19
|
|
|
20
20
|
import numpy as np
|
|
21
21
|
import pytest
|
|
@@ -25,13 +25,13 @@ import cirq
|
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
def assert_gates_implement_unitary(
|
|
28
|
-
gates: Sequence[cirq.
|
|
29
|
-
):
|
|
28
|
+
gates: Sequence[cirq.Gate], intended_effect: np.ndarray, atol: float
|
|
29
|
+
) -> None:
|
|
30
30
|
actual_effect = cirq.dot(*[cirq.unitary(g) for g in reversed(gates)])
|
|
31
31
|
cirq.testing.assert_allclose_up_to_global_phase(actual_effect, intended_effect, atol=atol)
|
|
32
32
|
|
|
33
33
|
|
|
34
|
-
def test_is_negligible_turn():
|
|
34
|
+
def test_is_negligible_turn() -> None:
|
|
35
35
|
assert cirq.is_negligible_turn(0, 1e-5)
|
|
36
36
|
assert cirq.is_negligible_turn(1e-6, 1e-5)
|
|
37
37
|
assert cirq.is_negligible_turn(1, 1e-5)
|
|
@@ -57,37 +57,37 @@ def test_is_negligible_turn():
|
|
|
57
57
|
assert not cirq.is_negligible_turn(sympy.Symbol('a') * 0 + 1.5 - 1e-6, 1e-5)
|
|
58
58
|
|
|
59
59
|
|
|
60
|
-
def test_single_qubit_matrix_to_gates_known_x():
|
|
60
|
+
def test_single_qubit_matrix_to_gates_known_x() -> None:
|
|
61
61
|
actual = cirq.single_qubit_matrix_to_gates(np.array([[0, 1], [1, 0]]), tolerance=0.01)
|
|
62
62
|
|
|
63
63
|
assert cirq.approx_eq(actual, [cirq.X], atol=1e-9)
|
|
64
64
|
|
|
65
65
|
|
|
66
|
-
def test_single_qubit_matrix_to_gates_known_y():
|
|
66
|
+
def test_single_qubit_matrix_to_gates_known_y() -> None:
|
|
67
67
|
actual = cirq.single_qubit_matrix_to_gates(np.array([[0, -1j], [1j, 0]]), tolerance=0.01)
|
|
68
68
|
|
|
69
69
|
assert cirq.approx_eq(actual, [cirq.Y], atol=1e-9)
|
|
70
70
|
|
|
71
71
|
|
|
72
|
-
def test_single_qubit_matrix_to_gates_known_z():
|
|
72
|
+
def test_single_qubit_matrix_to_gates_known_z() -> None:
|
|
73
73
|
actual = cirq.single_qubit_matrix_to_gates(np.array([[1, 0], [0, -1]]), tolerance=0.01)
|
|
74
74
|
|
|
75
75
|
assert cirq.approx_eq(actual, [cirq.Z], atol=1e-9)
|
|
76
76
|
|
|
77
77
|
|
|
78
|
-
def test_single_qubit_matrix_to_gates_known_s():
|
|
78
|
+
def test_single_qubit_matrix_to_gates_known_s() -> None:
|
|
79
79
|
actual = cirq.single_qubit_matrix_to_gates(np.array([[1, 0], [0, 1j]]), tolerance=0.01)
|
|
80
80
|
|
|
81
81
|
assert cirq.approx_eq(actual, [cirq.Z**0.5], atol=1e-9)
|
|
82
82
|
|
|
83
83
|
|
|
84
|
-
def test_known_s_dag():
|
|
84
|
+
def test_known_s_dag() -> None:
|
|
85
85
|
actual = cirq.single_qubit_matrix_to_gates(np.array([[1, 0], [0, -1j]]), tolerance=0.01)
|
|
86
86
|
|
|
87
87
|
assert cirq.approx_eq(actual, [cirq.Z**-0.5], atol=1e-9)
|
|
88
88
|
|
|
89
89
|
|
|
90
|
-
def test_known_h():
|
|
90
|
+
def test_known_h() -> None:
|
|
91
91
|
actual = cirq.single_qubit_matrix_to_gates(
|
|
92
92
|
np.array([[1, 1], [1, -1]]) * np.sqrt(0.5), tolerance=0.001
|
|
93
93
|
)
|
|
@@ -109,7 +109,7 @@ def test_known_h():
|
|
|
109
109
|
]
|
|
110
110
|
+ [cirq.testing.random_unitary(2) for _ in range(10)],
|
|
111
111
|
)
|
|
112
|
-
def test_single_qubit_matrix_to_gates_cases(intended_effect):
|
|
112
|
+
def test_single_qubit_matrix_to_gates_cases(intended_effect) -> None:
|
|
113
113
|
for atol in [1e-1, 1e-8]:
|
|
114
114
|
gates = cirq.single_qubit_matrix_to_gates(intended_effect, tolerance=atol / 10)
|
|
115
115
|
assert len(gates) <= 3
|
|
@@ -120,7 +120,7 @@ def test_single_qubit_matrix_to_gates_cases(intended_effect):
|
|
|
120
120
|
@pytest.mark.parametrize(
|
|
121
121
|
'pre_turns,post_turns', [(random.random(), random.random()) for _ in range(10)]
|
|
122
122
|
)
|
|
123
|
-
def test_single_qubit_matrix_to_gates_fuzz_half_turns_merge_z_gates(pre_turns, post_turns):
|
|
123
|
+
def test_single_qubit_matrix_to_gates_fuzz_half_turns_merge_z_gates(pre_turns, post_turns) -> None:
|
|
124
124
|
intended_effect = cirq.dot(
|
|
125
125
|
cirq.unitary(cirq.Z ** (2 * pre_turns)),
|
|
126
126
|
cirq.unitary(cirq.X),
|
|
@@ -133,7 +133,7 @@ def test_single_qubit_matrix_to_gates_fuzz_half_turns_merge_z_gates(pre_turns, p
|
|
|
133
133
|
assert_gates_implement_unitary(gates, intended_effect, atol=1e-6)
|
|
134
134
|
|
|
135
135
|
|
|
136
|
-
def test_single_qubit_matrix_to_gates_tolerance_z():
|
|
136
|
+
def test_single_qubit_matrix_to_gates_tolerance_z() -> None:
|
|
137
137
|
z = np.diag([1, np.exp(1j * 0.01)])
|
|
138
138
|
|
|
139
139
|
optimized_away = cirq.single_qubit_matrix_to_gates(z, tolerance=0.1)
|
|
@@ -143,7 +143,7 @@ def test_single_qubit_matrix_to_gates_tolerance_z():
|
|
|
143
143
|
assert len(kept) == 1
|
|
144
144
|
|
|
145
145
|
|
|
146
|
-
def test_single_qubit_matrix_to_gates_tolerance_xy():
|
|
146
|
+
def test_single_qubit_matrix_to_gates_tolerance_xy() -> None:
|
|
147
147
|
c, s = np.cos(0.01), np.sin(0.01)
|
|
148
148
|
xy = np.array([[c, -s], [s, c]])
|
|
149
149
|
|
|
@@ -154,7 +154,7 @@ def test_single_qubit_matrix_to_gates_tolerance_xy():
|
|
|
154
154
|
assert len(kept) == 1
|
|
155
155
|
|
|
156
156
|
|
|
157
|
-
def test_single_qubit_matrix_to_gates_tolerance_half_turn_phasing():
|
|
157
|
+
def test_single_qubit_matrix_to_gates_tolerance_half_turn_phasing() -> None:
|
|
158
158
|
a = np.pi / 2 + 0.01
|
|
159
159
|
c, s = np.cos(a), np.sin(a)
|
|
160
160
|
nearly_x = np.array([[c, -s], [s, c]])
|
|
@@ -189,13 +189,13 @@ def _random_unitary_with_close_eigenvalues():
|
|
|
189
189
|
]
|
|
190
190
|
+ [cirq.testing.random_unitary(2) for _ in range(10)],
|
|
191
191
|
)
|
|
192
|
-
def test_single_qubit_op_to_framed_phase_form_equivalent_on_known_and_random(mat):
|
|
192
|
+
def test_single_qubit_op_to_framed_phase_form_equivalent_on_known_and_random(mat) -> None:
|
|
193
193
|
u, t, g = cirq.single_qubit_op_to_framed_phase_form(mat)
|
|
194
194
|
z = np.diag([g, g * t])
|
|
195
195
|
assert np.allclose(mat, np.conj(u.T).dot(z).dot(u))
|
|
196
196
|
|
|
197
197
|
|
|
198
|
-
def test_single_qubit_matrix_to_phased_x_z_known():
|
|
198
|
+
def test_single_qubit_matrix_to_phased_x_z_known() -> None:
|
|
199
199
|
actual = cirq.single_qubit_matrix_to_phased_x_z(np.array([[0, 1], [1, 0]]), atol=0.01)
|
|
200
200
|
assert cirq.approx_eq(actual, [cirq.PhasedXPowGate(phase_exponent=1.0)], atol=1e-9)
|
|
201
201
|
|
|
@@ -223,7 +223,7 @@ def test_single_qubit_matrix_to_phased_x_z_known():
|
|
|
223
223
|
'intended_effect',
|
|
224
224
|
[np.array([[0, 1j], [1, 0]])] + [cirq.testing.random_unitary(2) for _ in range(10)],
|
|
225
225
|
)
|
|
226
|
-
def test_single_qubit_matrix_to_phased_x_z_cases(intended_effect):
|
|
226
|
+
def test_single_qubit_matrix_to_phased_x_z_cases(intended_effect) -> None:
|
|
227
227
|
gates = cirq.single_qubit_matrix_to_phased_x_z(intended_effect, atol=1e-6)
|
|
228
228
|
assert len(gates) <= 2
|
|
229
229
|
assert_gates_implement_unitary(gates, intended_effect, atol=1e-5)
|
|
@@ -232,7 +232,9 @@ def test_single_qubit_matrix_to_phased_x_z_cases(intended_effect):
|
|
|
232
232
|
@pytest.mark.parametrize(
|
|
233
233
|
'pre_turns,post_turns', [(random.random(), random.random()) for _ in range(10)]
|
|
234
234
|
)
|
|
235
|
-
def test_single_qubit_matrix_to_phased_x_z_fuzz_half_turns_always_one_gate(
|
|
235
|
+
def test_single_qubit_matrix_to_phased_x_z_fuzz_half_turns_always_one_gate(
|
|
236
|
+
pre_turns, post_turns
|
|
237
|
+
) -> None:
|
|
236
238
|
atol = 1e-6
|
|
237
239
|
aggr_atol = atol * 10.0
|
|
238
240
|
|
|
@@ -248,7 +250,7 @@ def test_single_qubit_matrix_to_phased_x_z_fuzz_half_turns_always_one_gate(pre_t
|
|
|
248
250
|
assert_gates_implement_unitary(gates, intended_effect, atol=aggr_atol)
|
|
249
251
|
|
|
250
252
|
|
|
251
|
-
def test_single_qubit_matrix_to_phased_x_z_tolerance_z():
|
|
253
|
+
def test_single_qubit_matrix_to_phased_x_z_tolerance_z() -> None:
|
|
252
254
|
z = np.diag([1, np.exp(1j * 0.01)])
|
|
253
255
|
|
|
254
256
|
optimized_away = cirq.single_qubit_matrix_to_phased_x_z(z, atol=0.1)
|
|
@@ -258,7 +260,7 @@ def test_single_qubit_matrix_to_phased_x_z_tolerance_z():
|
|
|
258
260
|
assert len(kept) == 1
|
|
259
261
|
|
|
260
262
|
|
|
261
|
-
def test_single_qubit_matrix_to_phased_x_z_tolerance_xy():
|
|
263
|
+
def test_single_qubit_matrix_to_phased_x_z_tolerance_xy() -> None:
|
|
262
264
|
c, s = np.cos(0.01), np.sin(0.01)
|
|
263
265
|
xy = np.array([[c, -s], [s, c]])
|
|
264
266
|
|
|
@@ -269,7 +271,7 @@ def test_single_qubit_matrix_to_phased_x_z_tolerance_xy():
|
|
|
269
271
|
assert len(kept) == 1
|
|
270
272
|
|
|
271
273
|
|
|
272
|
-
def test_single_qubit_matrix_to_phased_x_z_tolerance_half_turn_phasing():
|
|
274
|
+
def test_single_qubit_matrix_to_phased_x_z_tolerance_half_turn_phasing() -> None:
|
|
273
275
|
a = np.pi / 2 + 0.01
|
|
274
276
|
c, s = np.cos(a), np.sin(a)
|
|
275
277
|
nearly_x = np.array([[c, -s], [s, c]])
|
|
@@ -297,15 +299,16 @@ def test_single_qubit_matrix_to_phased_x_z_tolerance_half_turn_phasing():
|
|
|
297
299
|
*[cirq.testing.random_unitary(2) for _ in range(10)],
|
|
298
300
|
],
|
|
299
301
|
)
|
|
300
|
-
def test_single_qubit_matrix_to_phxz_cases(intended_effect):
|
|
302
|
+
def test_single_qubit_matrix_to_phxz_cases(intended_effect) -> None:
|
|
301
303
|
gate = cirq.single_qubit_matrix_to_phxz(intended_effect, atol=1e-6)
|
|
304
|
+
assert gate is not None
|
|
302
305
|
assert_gates_implement_unitary([gate], intended_effect, atol=1e-5)
|
|
303
306
|
|
|
304
307
|
|
|
305
308
|
@pytest.mark.parametrize(
|
|
306
309
|
'pre_turns,post_turns', [(random.random(), random.random()) for _ in range(10)]
|
|
307
310
|
)
|
|
308
|
-
def test_single_qubit_matrix_to_phxz_fuzz_half_turns_always_one_gate(pre_turns, post_turns):
|
|
311
|
+
def test_single_qubit_matrix_to_phxz_fuzz_half_turns_always_one_gate(pre_turns, post_turns) -> None:
|
|
309
312
|
atol = 1e-6
|
|
310
313
|
aggr_atol = atol * 10.0
|
|
311
314
|
|
|
@@ -317,11 +320,12 @@ def test_single_qubit_matrix_to_phxz_fuzz_half_turns_always_one_gate(pre_turns,
|
|
|
317
320
|
|
|
318
321
|
gate = cirq.single_qubit_matrix_to_phxz(intended_effect, atol=atol)
|
|
319
322
|
|
|
323
|
+
assert gate is not None
|
|
320
324
|
assert gate.z_exponent == 0
|
|
321
325
|
assert_gates_implement_unitary([gate], intended_effect, atol=aggr_atol)
|
|
322
326
|
|
|
323
327
|
|
|
324
|
-
def test_single_qubit_matrix_to_phxz_tolerance_z():
|
|
328
|
+
def test_single_qubit_matrix_to_phxz_tolerance_z() -> None:
|
|
325
329
|
z = np.diag([1, np.exp(1j * 0.01)])
|
|
326
330
|
|
|
327
331
|
optimized_away = cirq.single_qubit_matrix_to_phxz(z, atol=0.1)
|
|
@@ -331,7 +335,7 @@ def test_single_qubit_matrix_to_phxz_tolerance_z():
|
|
|
331
335
|
assert kept is not None
|
|
332
336
|
|
|
333
337
|
|
|
334
|
-
def test_single_qubit_matrix_to_phxz_tolerance_xy():
|
|
338
|
+
def test_single_qubit_matrix_to_phxz_tolerance_xy() -> None:
|
|
335
339
|
c, s = np.cos(0.01), np.sin(0.01)
|
|
336
340
|
xy = np.array([[c, -s], [s, c]])
|
|
337
341
|
|
|
@@ -342,7 +346,7 @@ def test_single_qubit_matrix_to_phxz_tolerance_xy():
|
|
|
342
346
|
assert kept is not None
|
|
343
347
|
|
|
344
348
|
|
|
345
|
-
def test_single_qubit_matrix_to_phxz_tolerance_half_turn_phasing():
|
|
349
|
+
def test_single_qubit_matrix_to_phxz_tolerance_half_turn_phasing() -> None:
|
|
346
350
|
a = np.pi / 2 + 0.01
|
|
347
351
|
c, s = np.cos(a), np.sin(a)
|
|
348
352
|
nearly_x = np.array([[c, -s], [s, c]])
|
|
@@ -351,7 +355,9 @@ def test_single_qubit_matrix_to_phxz_tolerance_half_turn_phasing():
|
|
|
351
355
|
phased_nearly_x = z1.dot(nearly_x).dot(z2)
|
|
352
356
|
|
|
353
357
|
optimized_away = cirq.single_qubit_matrix_to_phxz(phased_nearly_x, atol=0.1)
|
|
358
|
+
assert optimized_away is not None
|
|
354
359
|
assert optimized_away.z_exponent == 0
|
|
355
360
|
|
|
356
361
|
kept = cirq.single_qubit_matrix_to_phxz(phased_nearly_x, atol=0.0001)
|
|
362
|
+
assert kept is not None
|
|
357
363
|
assert kept.z_exponent != 0
|
|
@@ -43,7 +43,7 @@ INVALID_INITIAL_STATES = [
|
|
|
43
43
|
@pytest.mark.parametrize('allow_partial_czs', [True, False])
|
|
44
44
|
def test_two_qubit_matrix_to_cz_isometry(
|
|
45
45
|
initial_state, is_valid, unitary_matrix, allow_partial_czs
|
|
46
|
-
):
|
|
46
|
+
) -> None:
|
|
47
47
|
a, b, c = cirq.LineQubit.range(3)
|
|
48
48
|
decomposed_ops = cirq.two_qubit_matrix_to_cz_isometry(
|
|
49
49
|
a, b, unitary_matrix, allow_partial_czs=allow_partial_czs
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
from __future__ import annotations
|
|
18
18
|
|
|
19
19
|
import copy
|
|
20
|
+
from collections.abc import Iterator
|
|
20
21
|
|
|
21
22
|
import numpy as np
|
|
22
23
|
import pytest
|
|
@@ -24,11 +25,11 @@ import pytest
|
|
|
24
25
|
import cirq
|
|
25
26
|
|
|
26
27
|
|
|
27
|
-
def random_state(seed: float):
|
|
28
|
+
def random_state(seed: float) -> np.ndarray:
|
|
28
29
|
return cirq.testing.random_superposition(4, random_state=seed)
|
|
29
30
|
|
|
30
31
|
|
|
31
|
-
def states_with_phases(st: np.ndarray):
|
|
32
|
+
def states_with_phases(st: np.ndarray) -> Iterator[np.ndarray]:
|
|
32
33
|
"""Returns several states similar to st with modified global phases."""
|
|
33
34
|
st = np.array(st, dtype="complex64")
|
|
34
35
|
yield st
|
|
@@ -61,10 +62,10 @@ STATES_TO_PREPARE = [
|
|
|
61
62
|
|
|
62
63
|
|
|
63
64
|
@pytest.mark.parametrize("state", STATES_TO_PREPARE)
|
|
64
|
-
def test_prepare_two_qubit_state_using_cz(state):
|
|
65
|
+
def test_prepare_two_qubit_state_using_cz(state) -> None:
|
|
65
66
|
state = cirq.to_valid_state_vector(state, num_qubits=2)
|
|
66
|
-
|
|
67
|
-
circuit = cirq.Circuit(cirq.prepare_two_qubit_state_using_cz(
|
|
67
|
+
q0, q1 = cirq.LineQubit.range(2)
|
|
68
|
+
circuit = cirq.Circuit(cirq.prepare_two_qubit_state_using_cz(q0, q1, state))
|
|
68
69
|
ops_cz = [*circuit.findall_operations(lambda op: op.gate == cirq.CZ)]
|
|
69
70
|
ops_2q = [*circuit.findall_operations(lambda op: cirq.num_qubits(op) > 1)]
|
|
70
71
|
assert ops_cz == ops_2q
|
|
@@ -76,11 +77,11 @@ def test_prepare_two_qubit_state_using_cz(state):
|
|
|
76
77
|
|
|
77
78
|
@pytest.mark.parametrize("state", STATES_TO_PREPARE)
|
|
78
79
|
@pytest.mark.parametrize("use_iswap_inv", [True, False])
|
|
79
|
-
def test_prepare_two_qubit_state_using_iswap(state, use_iswap_inv):
|
|
80
|
+
def test_prepare_two_qubit_state_using_iswap(state, use_iswap_inv) -> None:
|
|
80
81
|
state = cirq.to_valid_state_vector(state, num_qubits=2)
|
|
81
|
-
|
|
82
|
+
q0, q1 = cirq.LineQubit.range(2)
|
|
82
83
|
circuit = cirq.Circuit(
|
|
83
|
-
cirq.prepare_two_qubit_state_using_iswap(
|
|
84
|
+
cirq.prepare_two_qubit_state_using_iswap(q0, q1, state, use_iswap_inv=use_iswap_inv)
|
|
84
85
|
)
|
|
85
86
|
iswap_gate = cirq.ISWAP_INV if use_iswap_inv else cirq.ISWAP
|
|
86
87
|
ops_iswap = [*circuit.findall_operations(lambda op: op.gate == iswap_gate)]
|
|
@@ -94,12 +95,12 @@ def test_prepare_two_qubit_state_using_iswap(state, use_iswap_inv):
|
|
|
94
95
|
|
|
95
96
|
@pytest.mark.parametrize("state", STATES_TO_PREPARE)
|
|
96
97
|
@pytest.mark.parametrize("use_sqrt_iswap_inv", [True, False])
|
|
97
|
-
def test_prepare_two_qubit_state_using_sqrt_iswap(state, use_sqrt_iswap_inv):
|
|
98
|
+
def test_prepare_two_qubit_state_using_sqrt_iswap(state, use_sqrt_iswap_inv) -> None:
|
|
98
99
|
state = cirq.to_valid_state_vector(state, num_qubits=2)
|
|
99
|
-
|
|
100
|
+
q0, q1 = cirq.LineQubit.range(2)
|
|
100
101
|
circuit = cirq.Circuit(
|
|
101
102
|
cirq.prepare_two_qubit_state_using_sqrt_iswap(
|
|
102
|
-
|
|
103
|
+
q0, q1, state, use_sqrt_iswap_inv=use_sqrt_iswap_inv
|
|
103
104
|
)
|
|
104
105
|
)
|
|
105
106
|
sqrt_iswap_gate = cirq.SQRT_ISWAP_INV if use_sqrt_iswap_inv else cirq.SQRT_ISWAP
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
|
|
17
17
|
from __future__ import annotations
|
|
18
18
|
|
|
19
|
-
from
|
|
19
|
+
from collections.abc import Iterable, Sequence
|
|
20
|
+
from typing import cast, TYPE_CHECKING
|
|
20
21
|
|
|
21
22
|
import numpy as np
|
|
22
23
|
|
|
@@ -181,7 +182,9 @@ def _xx_yy_zz_interaction_via_full_czs(q0: cirq.Qid, q1: cirq.Qid, x: float, y:
|
|
|
181
182
|
yield ops.H(q1)
|
|
182
183
|
|
|
183
184
|
|
|
184
|
-
def cleanup_operations(
|
|
185
|
+
def cleanup_operations(
|
|
186
|
+
operations: Sequence[ops.Operation], atol: float = 1e-8
|
|
187
|
+
) -> list[ops.Operation]:
|
|
185
188
|
operations = _merge_single_qubit_gates(operations, atol=atol)
|
|
186
189
|
circuit = circuits.Circuit(operations)
|
|
187
190
|
circuit = eject_phased_paulis(circuit)
|
|
@@ -95,7 +95,7 @@ def _random_double_full_cz_effect():
|
|
|
95
95
|
)
|
|
96
96
|
|
|
97
97
|
|
|
98
|
-
def assert_cz_depth_below(operations, threshold, must_be_full):
|
|
98
|
+
def assert_cz_depth_below(operations, threshold, must_be_full) -> None:
|
|
99
99
|
total_cz = 0
|
|
100
100
|
|
|
101
101
|
for op in operations:
|
|
@@ -110,7 +110,7 @@ def assert_cz_depth_below(operations, threshold, must_be_full):
|
|
|
110
110
|
assert total_cz <= threshold
|
|
111
111
|
|
|
112
112
|
|
|
113
|
-
def assert_ops_implement_unitary(q0, q1, operations, intended_effect, atol=0.01):
|
|
113
|
+
def assert_ops_implement_unitary(q0, q1, operations, intended_effect, atol=0.01) -> None:
|
|
114
114
|
actual_effect = _operations_to_matrix(operations, (q0, q1))
|
|
115
115
|
assert cirq.allclose_up_to_global_phase(actual_effect, intended_effect, atol=atol)
|
|
116
116
|
|
|
@@ -273,7 +273,7 @@ def test_decompose_to_diagonal_and_circuit(v) -> None:
|
|
|
273
273
|
)
|
|
274
274
|
def test_decompose_to_diagonal_and_circuit_returns_circuit_with_expected_number_of_czs(
|
|
275
275
|
mat, num_czs
|
|
276
|
-
):
|
|
276
|
+
) -> None:
|
|
277
277
|
b, c = cirq.LineQubit.range(2)
|
|
278
278
|
_, ops = two_qubit_matrix_to_diagonal_and_cz_operations(b, c, mat, atol=1e-8)
|
|
279
279
|
circuit = cirq.Circuit(ops)
|
|
@@ -21,7 +21,8 @@ Gate compilation methods implemented here are following the paper below:
|
|
|
21
21
|
|
|
22
22
|
from __future__ import annotations
|
|
23
23
|
|
|
24
|
-
from
|
|
24
|
+
from collections.abc import Iterable
|
|
25
|
+
from typing import cast, TYPE_CHECKING
|
|
25
26
|
|
|
26
27
|
from cirq import linalg, ops, protocols
|
|
27
28
|
from cirq.transformers.analytical_decompositions import single_qubit_decompositions, two_qubit_to_cz
|
|
@@ -60,12 +60,12 @@ def _random_double_MS_effect():
|
|
|
60
60
|
)
|
|
61
61
|
|
|
62
62
|
|
|
63
|
-
def assert_ops_implement_unitary(q0, q1, operations, intended_effect, atol=0.01):
|
|
63
|
+
def assert_ops_implement_unitary(q0, q1, operations, intended_effect, atol=0.01) -> None:
|
|
64
64
|
actual_effect = _operations_to_matrix(operations, (q0, q1))
|
|
65
65
|
assert cirq.allclose_up_to_global_phase(actual_effect, intended_effect, atol=atol)
|
|
66
66
|
|
|
67
67
|
|
|
68
|
-
def assert_ms_depth_below(operations, threshold):
|
|
68
|
+
def assert_ms_depth_below(operations, threshold) -> None:
|
|
69
69
|
total_ms = 0
|
|
70
70
|
|
|
71
71
|
for op in operations:
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
17
|
import itertools
|
|
18
|
+
from collections.abc import Iterator
|
|
18
19
|
|
|
19
20
|
import numpy as np
|
|
20
21
|
import pytest
|
|
@@ -23,11 +24,11 @@ import sympy
|
|
|
23
24
|
import cirq
|
|
24
25
|
|
|
25
26
|
|
|
26
|
-
def random_unitary(seed):
|
|
27
|
+
def random_unitary(seed: cirq.RANDOM_STATE_OR_SEED_LIKE) -> np.ndarray:
|
|
27
28
|
return cirq.testing.random_unitary(4, random_state=seed)
|
|
28
29
|
|
|
29
30
|
|
|
30
|
-
def random_locals(x, y, z, seed=None):
|
|
31
|
+
def random_locals(x: float, y: float, z: float, seed=None) -> np.ndarray:
|
|
31
32
|
rng = np.random.RandomState(seed)
|
|
32
33
|
a0 = cirq.testing.random_unitary(2, random_state=rng)
|
|
33
34
|
a1 = cirq.testing.random_unitary(2, random_state=rng)
|
|
@@ -42,15 +43,14 @@ def random_locals(x, y, z, seed=None):
|
|
|
42
43
|
)
|
|
43
44
|
|
|
44
45
|
|
|
45
|
-
def perturbations_unitary(u, amount=1e-10):
|
|
46
|
+
def perturbations_unitary(u: np.ndarray, amount=1e-10) -> Iterator[np.ndarray]:
|
|
46
47
|
"""Returns several unitaries in the neighborhood of u to test for numerical
|
|
47
48
|
corner cases near critical values."""
|
|
48
49
|
kak = cirq.kak_decomposition(u)
|
|
49
50
|
yield u
|
|
50
51
|
for i in range(3):
|
|
51
52
|
for neg in (-1, 1):
|
|
52
|
-
perturb_xyz =
|
|
53
|
-
perturb_xyz[i] += neg * amount
|
|
53
|
+
perturb_xyz = tuple(c + neg * amount for c in kak.interaction_coefficients)
|
|
54
54
|
yield cirq.unitary(
|
|
55
55
|
cirq.KakDecomposition(
|
|
56
56
|
global_phase=kak.global_phase,
|
|
@@ -61,11 +61,11 @@ def perturbations_unitary(u, amount=1e-10):
|
|
|
61
61
|
)
|
|
62
62
|
|
|
63
63
|
|
|
64
|
-
def perturbations_gate(gate, amount=1e-10):
|
|
64
|
+
def perturbations_gate(gate: cirq.SupportsUnitary, amount=1e-10) -> Iterator[np.ndarray]:
|
|
65
65
|
return perturbations_unitary(cirq.unitary(gate), amount)
|
|
66
66
|
|
|
67
67
|
|
|
68
|
-
def perturbations_weyl(x, y, z, amount=1e-10):
|
|
68
|
+
def perturbations_weyl(x: float, y: float, z: float, amount: float = 1e-10) -> Iterator[np.ndarray]:
|
|
69
69
|
return perturbations_gate(cirq.KakDecomposition(interaction_coefficients=(x, y, z)), amount)
|
|
70
70
|
|
|
71
71
|
|
|
@@ -211,7 +211,7 @@ def assert_valid_decomp(
|
|
|
211
211
|
atol=1e-6,
|
|
212
212
|
rtol=0,
|
|
213
213
|
qubit_order=cirq.LineQubit.range(2),
|
|
214
|
-
):
|
|
214
|
+
) -> None:
|
|
215
215
|
# Check expected gates
|
|
216
216
|
for op in operations:
|
|
217
217
|
if len(op.qubits) == 0 and isinstance(op.gate, cirq.GlobalPhaseGate):
|
|
@@ -242,7 +242,7 @@ def assert_valid_decomp(
|
|
|
242
242
|
)
|
|
243
243
|
|
|
244
244
|
|
|
245
|
-
def assert_specific_sqrt_iswap_count(operations, count):
|
|
245
|
+
def assert_specific_sqrt_iswap_count(operations, count) -> None:
|
|
246
246
|
actual = sum(len(op.qubits) == 2 for op in operations)
|
|
247
247
|
assert actual == count, f'Incorrect sqrt-iSWAP count. Expected {count} but got {actual}.'
|
|
248
248
|
|
|
@@ -255,7 +255,7 @@ def assert_specific_sqrt_iswap_count(operations, count):
|
|
|
255
255
|
cirq.CZPowGate(exponent=sympy.Symbol('t')),
|
|
256
256
|
],
|
|
257
257
|
)
|
|
258
|
-
def test_two_qubit_gates_with_symbols(gate: cirq.Gate):
|
|
258
|
+
def test_two_qubit_gates_with_symbols(gate: cirq.Gate) -> None:
|
|
259
259
|
op = gate(*cirq.LineQubit.range(2))
|
|
260
260
|
c_new_sqrt_iswap = cirq.Circuit(
|
|
261
261
|
cirq.parameterized_2q_op_to_sqrt_iswap_operations(op) # type: ignore
|
|
@@ -279,12 +279,14 @@ def test_two_qubit_gates_with_symbols(gate: cirq.Gate):
|
|
|
279
279
|
)
|
|
280
280
|
|
|
281
281
|
|
|
282
|
-
def test_fsim_gate_with_symbols():
|
|
282
|
+
def test_fsim_gate_with_symbols() -> None:
|
|
283
283
|
theta, phi = sympy.symbols(['theta', 'phi'])
|
|
284
284
|
op = cirq.FSimGate(theta=theta, phi=phi).on(*cirq.LineQubit.range(2))
|
|
285
|
-
c_new_sqrt_iswap = cirq.Circuit(
|
|
285
|
+
c_new_sqrt_iswap = cirq.Circuit(
|
|
286
|
+
cirq.parameterized_2q_op_to_sqrt_iswap_operations(op) # type: ignore[arg-type]
|
|
287
|
+
)
|
|
286
288
|
c_new_sqrt_iswap_inv = cirq.Circuit(
|
|
287
|
-
cirq.parameterized_2q_op_to_sqrt_iswap_operations(op, use_sqrt_iswap_inv=True)
|
|
289
|
+
cirq.parameterized_2q_op_to_sqrt_iswap_operations(op, use_sqrt_iswap_inv=True) # type: ignore[arg-type]
|
|
288
290
|
)
|
|
289
291
|
for theta_val in np.linspace(0, 2 * np.pi, 4):
|
|
290
292
|
for phi_val in np.linspace(0, 2 * np.pi, 6):
|
|
@@ -307,7 +309,7 @@ def test_fsim_gate_with_symbols():
|
|
|
307
309
|
|
|
308
310
|
|
|
309
311
|
@pytest.mark.parametrize('cnt', [-1, 4, 10])
|
|
310
|
-
def test_invalid_required_sqrt_iswap_count(cnt):
|
|
312
|
+
def test_invalid_required_sqrt_iswap_count(cnt) -> None:
|
|
311
313
|
u = TWO_SQRT_ISWAP_UNITARIES[0]
|
|
312
314
|
q0, q1 = cirq.LineQubit.range(2)
|
|
313
315
|
with pytest.raises(ValueError, match='required_sqrt_iswap_count'):
|
|
@@ -315,7 +317,7 @@ def test_invalid_required_sqrt_iswap_count(cnt):
|
|
|
315
317
|
|
|
316
318
|
|
|
317
319
|
@pytest.mark.parametrize('u', ZERO_UNITARIES)
|
|
318
|
-
def test_decomp0(u):
|
|
320
|
+
def test_decomp0(u) -> None:
|
|
319
321
|
# Decompose unitaries into zero sqrt-iSWAP gates
|
|
320
322
|
q0, q1 = cirq.LineQubit.range(2)
|
|
321
323
|
ops = cirq.two_qubit_matrix_to_sqrt_iswap_operations(q0, q1, u, required_sqrt_iswap_count=0)
|
|
@@ -326,7 +328,7 @@ def test_decomp0(u):
|
|
|
326
328
|
@pytest.mark.parametrize(
|
|
327
329
|
'u', ONE_SQRT_ISWAP_UNITARIES + TWO_SQRT_ISWAP_UNITARIES + THREE_SQRT_ISWAP_UNITARIES
|
|
328
330
|
)
|
|
329
|
-
def test_decomp0_invalid(u):
|
|
331
|
+
def test_decomp0_invalid(u) -> None:
|
|
330
332
|
# Attempt to decompose other unitaries into zero SQRT_ISWAP gates
|
|
331
333
|
q0, q1 = cirq.LineQubit.range(2)
|
|
332
334
|
with pytest.raises(ValueError, match='cannot be decomposed into exactly 0 sqrt-iSWAP gates'):
|
|
@@ -334,7 +336,7 @@ def test_decomp0_invalid(u):
|
|
|
334
336
|
|
|
335
337
|
|
|
336
338
|
@pytest.mark.parametrize('u', ONE_SQRT_ISWAP_UNITARIES)
|
|
337
|
-
def test_decomp1(u):
|
|
339
|
+
def test_decomp1(u) -> None:
|
|
338
340
|
q0, q1 = cirq.LineQubit.range(2)
|
|
339
341
|
ops = cirq.two_qubit_matrix_to_sqrt_iswap_operations(q0, q1, u, required_sqrt_iswap_count=1)
|
|
340
342
|
assert_valid_decomp(u, ops)
|
|
@@ -344,14 +346,14 @@ def test_decomp1(u):
|
|
|
344
346
|
@pytest.mark.parametrize(
|
|
345
347
|
'u', ZERO_UNITARIES + TWO_SQRT_ISWAP_UNITARIES + THREE_SQRT_ISWAP_UNITARIES
|
|
346
348
|
)
|
|
347
|
-
def test_decomp1_invalid(u):
|
|
349
|
+
def test_decomp1_invalid(u) -> None:
|
|
348
350
|
q0, q1 = cirq.LineQubit.range(2)
|
|
349
351
|
with pytest.raises(ValueError, match='cannot be decomposed into exactly 1 sqrt-iSWAP gates'):
|
|
350
352
|
cirq.two_qubit_matrix_to_sqrt_iswap_operations(q0, q1, u, required_sqrt_iswap_count=1)
|
|
351
353
|
|
|
352
354
|
|
|
353
355
|
@pytest.mark.parametrize('u', ZERO_UNITARIES + ONE_SQRT_ISWAP_UNITARIES + TWO_SQRT_ISWAP_UNITARIES)
|
|
354
|
-
def test_decomp2(u):
|
|
356
|
+
def test_decomp2(u) -> None:
|
|
355
357
|
q0, q1 = cirq.LineQubit.range(2)
|
|
356
358
|
ops = cirq.two_qubit_matrix_to_sqrt_iswap_operations(q0, q1, u, required_sqrt_iswap_count=2)
|
|
357
359
|
assert_valid_decomp(u, ops)
|
|
@@ -359,7 +361,7 @@ def test_decomp2(u):
|
|
|
359
361
|
|
|
360
362
|
|
|
361
363
|
@pytest.mark.parametrize('u', THREE_SQRT_ISWAP_UNITARIES)
|
|
362
|
-
def test_decomp2_invalid(u):
|
|
364
|
+
def test_decomp2_invalid(u) -> None:
|
|
363
365
|
q0, q1 = cirq.LineQubit.range(2)
|
|
364
366
|
with pytest.raises(ValueError, match='cannot be decomposed into exactly 2 sqrt-iSWAP gates'):
|
|
365
367
|
cirq.two_qubit_matrix_to_sqrt_iswap_operations(q0, q1, u, required_sqrt_iswap_count=2)
|
|
@@ -372,14 +374,14 @@ def test_decomp2_invalid(u):
|
|
|
372
374
|
+ TWO_SQRT_ISWAP_UNITARIES
|
|
373
375
|
+ THREE_SQRT_ISWAP_UNITARIES,
|
|
374
376
|
)
|
|
375
|
-
def test_decomp3(u):
|
|
377
|
+
def test_decomp3(u) -> None:
|
|
376
378
|
q0, q1 = cirq.LineQubit.range(2)
|
|
377
379
|
ops = cirq.two_qubit_matrix_to_sqrt_iswap_operations(q0, q1, u, required_sqrt_iswap_count=3)
|
|
378
380
|
assert_valid_decomp(u, ops)
|
|
379
381
|
assert_specific_sqrt_iswap_count(ops, 3)
|
|
380
382
|
|
|
381
383
|
|
|
382
|
-
def test_decomp3_invalid():
|
|
384
|
+
def test_decomp3_invalid() -> None:
|
|
383
385
|
# All two-qubit gates can be synthesized with three SQRT_ISWAP gates
|
|
384
386
|
u = cirq.unitary(cirq.X**0.2) # Pass an invalid size unitary
|
|
385
387
|
q0, q1 = cirq.LineQubit.range(2)
|
|
@@ -388,7 +390,7 @@ def test_decomp3_invalid():
|
|
|
388
390
|
|
|
389
391
|
|
|
390
392
|
@pytest.mark.parametrize('u', TWO_SQRT_ISWAP_UNITARIES[:1])
|
|
391
|
-
def test_qubit_order(u):
|
|
393
|
+
def test_qubit_order(u) -> None:
|
|
392
394
|
q0, q1 = cirq.LineQubit.range(2)
|
|
393
395
|
ops = cirq.two_qubit_matrix_to_sqrt_iswap_operations(q1, q0, u, required_sqrt_iswap_count=2)
|
|
394
396
|
assert_valid_decomp(u, ops, qubit_order=(q1, q0))
|
|
@@ -396,7 +398,7 @@ def test_qubit_order(u):
|
|
|
396
398
|
|
|
397
399
|
|
|
398
400
|
@pytest.mark.parametrize('u', ZERO_UNITARIES)
|
|
399
|
-
def test_decomp_optimal0(u):
|
|
401
|
+
def test_decomp_optimal0(u) -> None:
|
|
400
402
|
q0, q1 = cirq.LineQubit.range(2)
|
|
401
403
|
ops = cirq.two_qubit_matrix_to_sqrt_iswap_operations(q0, q1, u)
|
|
402
404
|
assert_valid_decomp(u, ops)
|
|
@@ -404,7 +406,7 @@ def test_decomp_optimal0(u):
|
|
|
404
406
|
|
|
405
407
|
|
|
406
408
|
@pytest.mark.parametrize('u', ONE_SQRT_ISWAP_UNITARIES)
|
|
407
|
-
def test_decomp_optimal1(u):
|
|
409
|
+
def test_decomp_optimal1(u) -> None:
|
|
408
410
|
q0, q1 = cirq.LineQubit.range(2)
|
|
409
411
|
ops = cirq.two_qubit_matrix_to_sqrt_iswap_operations(q0, q1, u)
|
|
410
412
|
assert_valid_decomp(u, ops)
|
|
@@ -412,7 +414,7 @@ def test_decomp_optimal1(u):
|
|
|
412
414
|
|
|
413
415
|
|
|
414
416
|
@pytest.mark.parametrize('u', TWO_SQRT_ISWAP_UNITARIES)
|
|
415
|
-
def test_decomp_optimal2(u):
|
|
417
|
+
def test_decomp_optimal2(u) -> None:
|
|
416
418
|
q0, q1 = cirq.LineQubit.range(2)
|
|
417
419
|
ops = cirq.two_qubit_matrix_to_sqrt_iswap_operations(q0, q1, u)
|
|
418
420
|
assert_valid_decomp(u, ops)
|
|
@@ -420,7 +422,7 @@ def test_decomp_optimal2(u):
|
|
|
420
422
|
|
|
421
423
|
|
|
422
424
|
@pytest.mark.parametrize('u', THREE_SQRT_ISWAP_UNITARIES)
|
|
423
|
-
def test_decomp_optimal3(u):
|
|
425
|
+
def test_decomp_optimal3(u) -> None:
|
|
424
426
|
q0, q1 = cirq.LineQubit.range(2)
|
|
425
427
|
ops = cirq.two_qubit_matrix_to_sqrt_iswap_operations(q0, q1, u)
|
|
426
428
|
assert_valid_decomp(u, ops)
|
|
@@ -428,7 +430,7 @@ def test_decomp_optimal3(u):
|
|
|
428
430
|
|
|
429
431
|
|
|
430
432
|
@pytest.mark.parametrize('u', ALL_REGION_UNITARIES)
|
|
431
|
-
def test_all_weyl_regions(u):
|
|
433
|
+
def test_all_weyl_regions(u) -> None:
|
|
432
434
|
q0, q1 = cirq.LineQubit.range(2)
|
|
433
435
|
ops = cirq.two_qubit_matrix_to_sqrt_iswap_operations(q0, q1, u, clean_operations=True)
|
|
434
436
|
assert_valid_decomp(u, ops, single_qubit_gate_types=(cirq.PhasedXZGate,))
|
|
@@ -445,13 +447,13 @@ def test_all_weyl_regions(u):
|
|
|
445
447
|
THREE_SQRT_ISWAP_UNITARIES[0],
|
|
446
448
|
],
|
|
447
449
|
)
|
|
448
|
-
def test_decomp_sqrt_iswap_inv(u):
|
|
450
|
+
def test_decomp_sqrt_iswap_inv(u) -> None:
|
|
449
451
|
q0, q1 = cirq.LineQubit.range(2)
|
|
450
452
|
ops = cirq.two_qubit_matrix_to_sqrt_iswap_operations(q0, q1, u, use_sqrt_iswap_inv=True)
|
|
451
453
|
assert_valid_decomp(u, ops, two_qubit_gate=cirq.SQRT_ISWAP_INV)
|
|
452
454
|
|
|
453
455
|
|
|
454
|
-
def test_valid_check_raises():
|
|
456
|
+
def test_valid_check_raises() -> None:
|
|
455
457
|
q0 = cirq.LineQubit(0)
|
|
456
458
|
with pytest.raises(AssertionError, match='Unitaries are completely different'):
|
|
457
459
|
assert_valid_decomp(np.eye(4), [cirq.X(q0)], single_qubit_gate_types=(cirq.XPowGate,))
|