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,6 +15,7 @@
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
17
|
import itertools
|
|
18
|
+
import random
|
|
18
19
|
|
|
19
20
|
import numpy as np
|
|
20
21
|
import pytest
|
|
@@ -24,7 +25,7 @@ import cirq
|
|
|
24
25
|
import cirq.testing
|
|
25
26
|
|
|
26
27
|
|
|
27
|
-
def test_simulate_no_circuit():
|
|
28
|
+
def test_simulate_no_circuit() -> None:
|
|
28
29
|
q0, q1 = cirq.LineQubit.range(2)
|
|
29
30
|
simulator = cirq.CliffordSimulator()
|
|
30
31
|
circuit = cirq.Circuit()
|
|
@@ -33,7 +34,7 @@ def test_simulate_no_circuit():
|
|
|
33
34
|
assert len(result.measurements) == 0
|
|
34
35
|
|
|
35
36
|
|
|
36
|
-
def test_run_no_repetitions():
|
|
37
|
+
def test_run_no_repetitions() -> None:
|
|
37
38
|
q0 = cirq.LineQubit(0)
|
|
38
39
|
simulator = cirq.CliffordSimulator()
|
|
39
40
|
circuit = cirq.Circuit(cirq.H(q0), cirq.measure(q0))
|
|
@@ -41,7 +42,7 @@ def test_run_no_repetitions():
|
|
|
41
42
|
assert sum(result.measurements['q(0)']) == 0
|
|
42
43
|
|
|
43
44
|
|
|
44
|
-
def test_run_hadamard():
|
|
45
|
+
def test_run_hadamard() -> None:
|
|
45
46
|
q0 = cirq.LineQubit(0)
|
|
46
47
|
simulator = cirq.CliffordSimulator()
|
|
47
48
|
circuit = cirq.Circuit(cirq.H(q0), cirq.measure(q0))
|
|
@@ -50,7 +51,7 @@ def test_run_hadamard():
|
|
|
50
51
|
assert sum(result.measurements['q(0)'])[0] > 20
|
|
51
52
|
|
|
52
53
|
|
|
53
|
-
def test_run_GHZ():
|
|
54
|
+
def test_run_GHZ() -> None:
|
|
54
55
|
(q0, q1) = (cirq.LineQubit(0), cirq.LineQubit(1))
|
|
55
56
|
simulator = cirq.CliffordSimulator()
|
|
56
57
|
circuit = cirq.Circuit(cirq.H(q0), cirq.H(q1), cirq.measure(q0))
|
|
@@ -59,7 +60,7 @@ def test_run_GHZ():
|
|
|
59
60
|
assert sum(result.measurements['q(0)'])[0] > 20
|
|
60
61
|
|
|
61
62
|
|
|
62
|
-
def test_run_correlations():
|
|
63
|
+
def test_run_correlations() -> None:
|
|
63
64
|
q0, q1 = cirq.LineQubit.range(2)
|
|
64
65
|
simulator = cirq.CliffordSimulator()
|
|
65
66
|
circuit = cirq.Circuit(cirq.H(q0), cirq.CNOT(q0, q1), cirq.measure(q0, q1))
|
|
@@ -69,7 +70,7 @@ def test_run_correlations():
|
|
|
69
70
|
assert bits[0] == bits[1]
|
|
70
71
|
|
|
71
72
|
|
|
72
|
-
def test_run_parameters_not_resolved():
|
|
73
|
+
def test_run_parameters_not_resolved() -> None:
|
|
73
74
|
a = cirq.LineQubit(0)
|
|
74
75
|
simulator = cirq.CliffordSimulator()
|
|
75
76
|
circuit = cirq.Circuit(cirq.XPowGate(exponent=sympy.Symbol('a'))(a), cirq.measure(a))
|
|
@@ -77,7 +78,7 @@ def test_run_parameters_not_resolved():
|
|
|
77
78
|
_ = simulator.run_sweep(circuit, cirq.ParamResolver({}))
|
|
78
79
|
|
|
79
80
|
|
|
80
|
-
def test_simulate_parameters_not_resolved():
|
|
81
|
+
def test_simulate_parameters_not_resolved() -> None:
|
|
81
82
|
a = cirq.LineQubit(0)
|
|
82
83
|
simulator = cirq.CliffordSimulator()
|
|
83
84
|
circuit = cirq.Circuit(cirq.XPowGate(exponent=sympy.Symbol('a'))(a), cirq.measure(a))
|
|
@@ -85,7 +86,7 @@ def test_simulate_parameters_not_resolved():
|
|
|
85
86
|
_ = simulator.simulate_sweep(circuit, cirq.ParamResolver({}))
|
|
86
87
|
|
|
87
88
|
|
|
88
|
-
def test_simulate():
|
|
89
|
+
def test_simulate() -> None:
|
|
89
90
|
q0, q1 = cirq.LineQubit.range(2)
|
|
90
91
|
simulator = cirq.CliffordSimulator()
|
|
91
92
|
circuit = cirq.Circuit(cirq.H(q0), cirq.H(q1))
|
|
@@ -94,7 +95,7 @@ def test_simulate():
|
|
|
94
95
|
assert len(result.measurements) == 0
|
|
95
96
|
|
|
96
97
|
|
|
97
|
-
def test_simulate_initial_state():
|
|
98
|
+
def test_simulate_initial_state() -> None:
|
|
98
99
|
q0, q1 = cirq.LineQubit.range(2)
|
|
99
100
|
simulator = cirq.CliffordSimulator()
|
|
100
101
|
for b0 in [0, 1]:
|
|
@@ -119,7 +120,7 @@ def test_simulate_initial_state():
|
|
|
119
120
|
)
|
|
120
121
|
|
|
121
122
|
|
|
122
|
-
def test_simulation_state():
|
|
123
|
+
def test_simulation_state() -> None:
|
|
123
124
|
q0, q1 = cirq.LineQubit.range(2)
|
|
124
125
|
simulator = cirq.CliffordSimulator()
|
|
125
126
|
for b0 in [0, 1]:
|
|
@@ -140,7 +141,7 @@ def test_simulation_state():
|
|
|
140
141
|
)
|
|
141
142
|
|
|
142
143
|
|
|
143
|
-
def test_simulate_qubit_order():
|
|
144
|
+
def test_simulate_qubit_order() -> None:
|
|
144
145
|
q0, q1 = cirq.LineQubit.range(2)
|
|
145
146
|
simulator = cirq.CliffordSimulator()
|
|
146
147
|
for b0 in [0, 1]:
|
|
@@ -160,7 +161,7 @@ def test_simulate_qubit_order():
|
|
|
160
161
|
)
|
|
161
162
|
|
|
162
163
|
|
|
163
|
-
def test_run_measure_multiple_qubits():
|
|
164
|
+
def test_run_measure_multiple_qubits() -> None:
|
|
164
165
|
q0, q1 = cirq.LineQubit.range(2)
|
|
165
166
|
simulator = cirq.CliffordSimulator()
|
|
166
167
|
for b0 in [0, 1]:
|
|
@@ -175,7 +176,7 @@ def test_run_measure_multiple_qubits():
|
|
|
175
176
|
np.testing.assert_equal(result.measurements, {'q(0),q(1)': [[b0, b1]] * 3})
|
|
176
177
|
|
|
177
178
|
|
|
178
|
-
def test_simulate_moment_steps():
|
|
179
|
+
def test_simulate_moment_steps() -> None:
|
|
179
180
|
q0, q1 = cirq.LineQubit.range(2)
|
|
180
181
|
circuit = cirq.Circuit(cirq.H(q0), cirq.H(q1), cirq.H(q0), cirq.H(q1))
|
|
181
182
|
simulator = cirq.CliffordSimulator()
|
|
@@ -186,7 +187,7 @@ def test_simulate_moment_steps():
|
|
|
186
187
|
np.testing.assert_almost_equal(step.state.to_numpy(), np.array([1, 0, 0, 0]))
|
|
187
188
|
|
|
188
189
|
|
|
189
|
-
def test_simulate_moment_steps_sample():
|
|
190
|
+
def test_simulate_moment_steps_sample() -> None:
|
|
190
191
|
q0, q1 = cirq.LineQubit.range(2)
|
|
191
192
|
circuit = cirq.Circuit(cirq.H(q0), cirq.CNOT(q0, q1))
|
|
192
193
|
simulator = cirq.CliffordSimulator()
|
|
@@ -206,7 +207,7 @@ def test_simulate_moment_steps_sample():
|
|
|
206
207
|
|
|
207
208
|
|
|
208
209
|
@pytest.mark.parametrize('split', [True, False])
|
|
209
|
-
def test_simulate_moment_steps_intermediate_measurement(split):
|
|
210
|
+
def test_simulate_moment_steps_intermediate_measurement(split) -> None:
|
|
210
211
|
q0 = cirq.LineQubit(0)
|
|
211
212
|
circuit = cirq.Circuit(cirq.H(q0), cirq.measure(q0), cirq.H(q0))
|
|
212
213
|
simulator = cirq.CliffordSimulator(split_untangled_states=split)
|
|
@@ -221,7 +222,7 @@ def test_simulate_moment_steps_intermediate_measurement(split):
|
|
|
221
222
|
np.testing.assert_almost_equal(step.state.to_numpy(), expected)
|
|
222
223
|
|
|
223
224
|
|
|
224
|
-
def test_clifford_state_initial_state():
|
|
225
|
+
def test_clifford_state_initial_state() -> None:
|
|
225
226
|
q0 = cirq.LineQubit(0)
|
|
226
227
|
with pytest.raises(ValueError, match='Out of range'):
|
|
227
228
|
_ = cirq.CliffordState(qubit_map={q0: 0}, initial_state=2)
|
|
@@ -231,7 +232,7 @@ def test_clifford_state_initial_state():
|
|
|
231
232
|
assert state.copy() == state
|
|
232
233
|
|
|
233
234
|
|
|
234
|
-
def test_clifford_trial_result_repr():
|
|
235
|
+
def test_clifford_trial_result_repr() -> None:
|
|
235
236
|
q0 = cirq.LineQubit(0)
|
|
236
237
|
final_simulator_state = cirq.StabilizerChFormSimulationState(qubits=[q0])
|
|
237
238
|
assert (
|
|
@@ -251,7 +252,7 @@ def test_clifford_trial_result_repr():
|
|
|
251
252
|
)
|
|
252
253
|
|
|
253
254
|
|
|
254
|
-
def test_clifford_trial_result_str():
|
|
255
|
+
def test_clifford_trial_result_str() -> None:
|
|
255
256
|
q0 = cirq.LineQubit(0)
|
|
256
257
|
final_simulator_state = cirq.StabilizerChFormSimulationState(qubits=[q0])
|
|
257
258
|
assert (
|
|
@@ -267,7 +268,7 @@ def test_clifford_trial_result_str():
|
|
|
267
268
|
)
|
|
268
269
|
|
|
269
270
|
|
|
270
|
-
def test_clifford_trial_result_repr_pretty():
|
|
271
|
+
def test_clifford_trial_result_repr_pretty() -> None:
|
|
271
272
|
q0 = cirq.LineQubit(0)
|
|
272
273
|
final_simulator_state = cirq.StabilizerChFormSimulationState(qubits=[q0])
|
|
273
274
|
result = cirq.CliffordTrialResult(
|
|
@@ -280,7 +281,7 @@ def test_clifford_trial_result_repr_pretty():
|
|
|
280
281
|
cirq.testing.assert_repr_pretty(result, "cirq.CliffordTrialResult(...)", cycle=True)
|
|
281
282
|
|
|
282
283
|
|
|
283
|
-
def test_clifford_step_result_str():
|
|
284
|
+
def test_clifford_step_result_str() -> None:
|
|
284
285
|
q0 = cirq.LineQubit(0)
|
|
285
286
|
result = next(
|
|
286
287
|
cirq.CliffordSimulator().simulate_moment_steps(cirq.Circuit(cirq.measure(q0, key='m')))
|
|
@@ -288,7 +289,7 @@ def test_clifford_step_result_str():
|
|
|
288
289
|
assert str(result) == "m=0\n|0⟩"
|
|
289
290
|
|
|
290
291
|
|
|
291
|
-
def test_clifford_step_result_repr_pretty():
|
|
292
|
+
def test_clifford_step_result_repr_pretty() -> None:
|
|
292
293
|
q0 = cirq.LineQubit(0)
|
|
293
294
|
result = next(
|
|
294
295
|
cirq.CliffordSimulator().simulate_moment_steps(cirq.Circuit(cirq.measure(q0, key='m')))
|
|
@@ -297,40 +298,40 @@ def test_clifford_step_result_repr_pretty():
|
|
|
297
298
|
cirq.testing.assert_repr_pretty(result, "cirq.CliffordSimulatorStateResult(...)", cycle=True)
|
|
298
299
|
|
|
299
300
|
|
|
300
|
-
def test_clifford_step_result_no_measurements_str():
|
|
301
|
+
def test_clifford_step_result_no_measurements_str() -> None:
|
|
301
302
|
q0 = cirq.LineQubit(0)
|
|
302
303
|
result = next(cirq.CliffordSimulator().simulate_moment_steps(cirq.Circuit(cirq.I(q0))))
|
|
303
304
|
assert str(result) == "|0⟩"
|
|
304
305
|
|
|
305
306
|
|
|
306
|
-
def test_clifford_state_str():
|
|
307
|
+
def test_clifford_state_str() -> None:
|
|
307
308
|
(q0, q1) = (cirq.LineQubit(0), cirq.LineQubit(1))
|
|
308
309
|
state = cirq.CliffordState(qubit_map={q0: 0, q1: 1})
|
|
309
310
|
|
|
310
311
|
assert str(state) == "|00⟩"
|
|
311
312
|
|
|
312
313
|
|
|
313
|
-
def test_clifford_state_state_vector():
|
|
314
|
+
def test_clifford_state_state_vector() -> None:
|
|
314
315
|
(q0, q1) = (cirq.LineQubit(0), cirq.LineQubit(1))
|
|
315
316
|
state = cirq.CliffordState(qubit_map={q0: 0, q1: 1})
|
|
316
317
|
|
|
317
318
|
np.testing.assert_equal(state.state_vector(), [1.0 + 0.0j, 0.0 + 0.0j, 0.0 + 0.0j, 0.0 + 0.0j])
|
|
318
319
|
|
|
319
320
|
|
|
320
|
-
def test_stabilizerStateChForm_H():
|
|
321
|
+
def test_stabilizerStateChForm_H() -> None:
|
|
321
322
|
(q0, q1) = (cirq.LineQubit(0), cirq.LineQubit(1))
|
|
322
323
|
state = cirq.CliffordState(qubit_map={q0: 0, q1: 1})
|
|
323
324
|
with pytest.raises(ValueError, match="|y> is equal to |z>"):
|
|
324
325
|
state.ch_form._H_decompose(0, 1, 1, 0)
|
|
325
326
|
|
|
326
327
|
|
|
327
|
-
def test_clifford_stabilizerStateChForm_repr():
|
|
328
|
+
def test_clifford_stabilizerStateChForm_repr() -> None:
|
|
328
329
|
(q0, q1) = (cirq.LineQubit(0), cirq.LineQubit(1))
|
|
329
330
|
state = cirq.CliffordState(qubit_map={q0: 0, q1: 1})
|
|
330
331
|
assert repr(state) == 'StabilizerStateChForm(num_qubits=2)'
|
|
331
332
|
|
|
332
333
|
|
|
333
|
-
def test_clifford_circuit_SHSYSHS():
|
|
334
|
+
def test_clifford_circuit_SHSYSHS() -> None:
|
|
334
335
|
q0 = cirq.LineQubit(0)
|
|
335
336
|
circuit = cirq.Circuit(
|
|
336
337
|
cirq.S(q0),
|
|
@@ -355,7 +356,7 @@ def test_clifford_circuit_SHSYSHS():
|
|
|
355
356
|
|
|
356
357
|
|
|
357
358
|
@pytest.mark.parametrize('split', [True, False])
|
|
358
|
-
def test_clifford_circuit(split):
|
|
359
|
+
def test_clifford_circuit(split) -> None:
|
|
359
360
|
(q0, q1) = (cirq.LineQubit(0), cirq.LineQubit(1))
|
|
360
361
|
circuit = cirq.Circuit()
|
|
361
362
|
|
|
@@ -363,15 +364,15 @@ def test_clifford_circuit(split):
|
|
|
363
364
|
x = np.random.randint(7)
|
|
364
365
|
|
|
365
366
|
if x == 0:
|
|
366
|
-
circuit.append(cirq.X(
|
|
367
|
+
circuit.append(cirq.X(random.choice((q0, q1))))
|
|
367
368
|
elif x == 1:
|
|
368
|
-
circuit.append(cirq.Z(
|
|
369
|
+
circuit.append(cirq.Z(random.choice((q0, q1))))
|
|
369
370
|
elif x == 2:
|
|
370
|
-
circuit.append(cirq.Y(
|
|
371
|
+
circuit.append(cirq.Y(random.choice((q0, q1))))
|
|
371
372
|
elif x == 3:
|
|
372
|
-
circuit.append(cirq.S(
|
|
373
|
+
circuit.append(cirq.S(random.choice((q0, q1))))
|
|
373
374
|
elif x == 4:
|
|
374
|
-
circuit.append(cirq.H(
|
|
375
|
+
circuit.append(cirq.H(random.choice((q0, q1))))
|
|
375
376
|
elif x == 5:
|
|
376
377
|
circuit.append(cirq.CNOT(q0, q1))
|
|
377
378
|
elif x == 6:
|
|
@@ -388,7 +389,7 @@ def test_clifford_circuit(split):
|
|
|
388
389
|
|
|
389
390
|
@pytest.mark.parametrize("qubits", [cirq.LineQubit.range(2), cirq.LineQubit.range(4)])
|
|
390
391
|
@pytest.mark.parametrize('split', [True, False])
|
|
391
|
-
def test_clifford_circuit_2(qubits, split):
|
|
392
|
+
def test_clifford_circuit_2(qubits, split) -> None:
|
|
392
393
|
circuit = cirq.Circuit()
|
|
393
394
|
|
|
394
395
|
np.random.seed(2)
|
|
@@ -419,7 +420,7 @@ def test_clifford_circuit_2(qubits, split):
|
|
|
419
420
|
|
|
420
421
|
|
|
421
422
|
@pytest.mark.parametrize('split', [True, False])
|
|
422
|
-
def test_clifford_circuit_3(split):
|
|
423
|
+
def test_clifford_circuit_3(split) -> None:
|
|
423
424
|
# This test tests the simulator on arbitrary 1-qubit Clifford gates.
|
|
424
425
|
(q0, q1) = (cirq.LineQubit(0), cirq.LineQubit(1))
|
|
425
426
|
circuit = cirq.Circuit()
|
|
@@ -435,7 +436,7 @@ def test_clifford_circuit_3(split):
|
|
|
435
436
|
if np.random.randint(5) == 0:
|
|
436
437
|
circuit.append(cirq.CNOT(q0, q1))
|
|
437
438
|
else:
|
|
438
|
-
circuit.append(random_clifford_gate()(
|
|
439
|
+
circuit.append(random_clifford_gate()(random.choice((q0, q1))))
|
|
439
440
|
|
|
440
441
|
clifford_simulator = cirq.CliffordSimulator(split_untangled_states=split)
|
|
441
442
|
state_vector_simulator = cirq.Simulator()
|
|
@@ -447,7 +448,7 @@ def test_clifford_circuit_3(split):
|
|
|
447
448
|
)
|
|
448
449
|
|
|
449
450
|
|
|
450
|
-
def test_non_clifford_circuit():
|
|
451
|
+
def test_non_clifford_circuit() -> None:
|
|
451
452
|
q0 = cirq.LineQubit(0)
|
|
452
453
|
circuit = cirq.Circuit()
|
|
453
454
|
circuit.append(cirq.T(q0))
|
|
@@ -455,7 +456,7 @@ def test_non_clifford_circuit():
|
|
|
455
456
|
cirq.CliffordSimulator().simulate(circuit)
|
|
456
457
|
|
|
457
458
|
|
|
458
|
-
def test_swap():
|
|
459
|
+
def test_swap() -> None:
|
|
459
460
|
a, b = cirq.LineQubit.range(2)
|
|
460
461
|
circuit = cirq.Circuit(
|
|
461
462
|
cirq.X(a),
|
|
@@ -469,10 +470,10 @@ def test_swap():
|
|
|
469
470
|
assert r["b"][0]
|
|
470
471
|
|
|
471
472
|
with pytest.raises(TypeError, match="CliffordSimulator doesn't support"):
|
|
472
|
-
cirq.CliffordSimulator().simulate(
|
|
473
|
+
cirq.CliffordSimulator().simulate(cirq.Circuit(cirq.SWAP(a, b) ** 3.5))
|
|
473
474
|
|
|
474
475
|
|
|
475
|
-
def test_sample_seed():
|
|
476
|
+
def test_sample_seed() -> None:
|
|
476
477
|
q = cirq.NamedQubit('q')
|
|
477
478
|
circuit = cirq.Circuit(cirq.H(q), cirq.measure(q))
|
|
478
479
|
simulator = cirq.CliffordSimulator(seed=1234)
|
|
@@ -482,7 +483,7 @@ def test_sample_seed():
|
|
|
482
483
|
assert result_string == '11010001111100100000'
|
|
483
484
|
|
|
484
485
|
|
|
485
|
-
def test_is_supported_operation():
|
|
486
|
+
def test_is_supported_operation() -> None:
|
|
486
487
|
class MultiQubitOp(cirq.Operation):
|
|
487
488
|
"""Multi-qubit operation with unitary.
|
|
488
489
|
|
|
@@ -514,7 +515,7 @@ def test_is_supported_operation():
|
|
|
514
515
|
assert not cirq.CliffordSimulator.is_supported_operation(MultiQubitOp())
|
|
515
516
|
|
|
516
517
|
|
|
517
|
-
def test_simulate_pauli_string():
|
|
518
|
+
def test_simulate_pauli_string() -> None:
|
|
518
519
|
q = cirq.NamedQubit('q')
|
|
519
520
|
circuit = cirq.Circuit([cirq.PauliString({q: 'X'}), cirq.PauliString({q: 'Z'})])
|
|
520
521
|
simulator = cirq.CliffordSimulator()
|
|
@@ -524,7 +525,7 @@ def test_simulate_pauli_string():
|
|
|
524
525
|
assert np.allclose(result, [0, -1])
|
|
525
526
|
|
|
526
527
|
|
|
527
|
-
def test_simulate_global_phase_operation():
|
|
528
|
+
def test_simulate_global_phase_operation() -> None:
|
|
528
529
|
q1, q2 = cirq.LineQubit.range(2)
|
|
529
530
|
circuit = cirq.Circuit([cirq.I(q1), cirq.I(q2), cirq.global_phase_operation(-1j)])
|
|
530
531
|
simulator = cirq.CliffordSimulator()
|
|
@@ -534,7 +535,7 @@ def test_simulate_global_phase_operation():
|
|
|
534
535
|
assert np.allclose(result, [-1j, 0, 0, 0])
|
|
535
536
|
|
|
536
537
|
|
|
537
|
-
def test_json_roundtrip():
|
|
538
|
+
def test_json_roundtrip() -> None:
|
|
538
539
|
(q0, q1, q2) = (cirq.LineQubit(0), cirq.LineQubit(1), cirq.LineQubit(2))
|
|
539
540
|
state = cirq.CliffordState(qubit_map={q0: 0, q1: 1, q2: 2})
|
|
540
541
|
|
|
@@ -557,19 +558,19 @@ def test_json_roundtrip():
|
|
|
557
558
|
assert np.allclose(state.ch_form.state_vector(), state_roundtrip.ch_form.state_vector())
|
|
558
559
|
|
|
559
560
|
|
|
560
|
-
def test_invalid_apply_measurement():
|
|
561
|
+
def test_invalid_apply_measurement() -> None:
|
|
561
562
|
q0 = cirq.LineQubit(0)
|
|
562
563
|
state = cirq.CliffordState(qubit_map={q0: 0})
|
|
563
|
-
measurements = {}
|
|
564
|
+
measurements: dict[str, list[int]] = {}
|
|
564
565
|
with pytest.raises(TypeError, match='only supports cirq.MeasurementGate'):
|
|
565
566
|
state.apply_measurement(cirq.H(q0), measurements, np.random.RandomState())
|
|
566
567
|
assert measurements == {}
|
|
567
568
|
|
|
568
569
|
|
|
569
|
-
def test_valid_apply_measurement():
|
|
570
|
+
def test_valid_apply_measurement() -> None:
|
|
570
571
|
q0 = cirq.LineQubit(0)
|
|
571
572
|
state = cirq.CliffordState(qubit_map={q0: 0}, initial_state=1)
|
|
572
|
-
measurements = {}
|
|
573
|
+
measurements: dict[str, list[int]] = {}
|
|
573
574
|
state.apply_measurement(
|
|
574
575
|
cirq.measure(q0), measurements, np.random.RandomState(), collapse_state_vector=False
|
|
575
576
|
)
|
|
@@ -579,7 +580,7 @@ def test_valid_apply_measurement():
|
|
|
579
580
|
|
|
580
581
|
|
|
581
582
|
@pytest.mark.parametrize('split', [True, False])
|
|
582
|
-
def test_reset(split):
|
|
583
|
+
def test_reset(split) -> None:
|
|
583
584
|
q = cirq.LineQubit(0)
|
|
584
585
|
c = cirq.Circuit(cirq.X(q), cirq.reset(q), cirq.measure(q, key="out"))
|
|
585
586
|
sim = cirq.CliffordSimulator(split_untangled_states=split)
|
|
@@ -590,7 +591,7 @@ def test_reset(split):
|
|
|
590
591
|
assert sim.sample(c)["out"][0] == 0
|
|
591
592
|
|
|
592
593
|
|
|
593
|
-
def test_state_copy():
|
|
594
|
+
def test_state_copy() -> None:
|
|
594
595
|
sim = cirq.CliffordSimulator()
|
|
595
596
|
|
|
596
597
|
q = cirq.LineQubit(0)
|
|
@@ -17,7 +17,8 @@ for Clifford Simulator."""
|
|
|
17
17
|
|
|
18
18
|
from __future__ import annotations
|
|
19
19
|
|
|
20
|
-
from
|
|
20
|
+
from collections.abc import Sequence
|
|
21
|
+
from typing import TYPE_CHECKING
|
|
21
22
|
|
|
22
23
|
from cirq.qis import clifford_tableau
|
|
23
24
|
from cirq.sim.clifford.stabilizer_simulation_state import StabilizerSimulationState
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
|
-
from
|
|
17
|
+
from collections.abc import Sequence
|
|
18
|
+
from typing import TYPE_CHECKING
|
|
18
19
|
|
|
19
20
|
from cirq._compat import proper_repr
|
|
20
21
|
from cirq.sim.clifford import stabilizer_state_ch_form
|
|
@@ -15,8 +15,9 @@
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
17
|
import abc
|
|
18
|
+
from collections.abc import Sequence
|
|
18
19
|
from types import NotImplementedType
|
|
19
|
-
from typing import Any, cast, Generic,
|
|
20
|
+
from typing import Any, cast, Generic, TYPE_CHECKING, TypeVar
|
|
20
21
|
|
|
21
22
|
import sympy
|
|
22
23
|
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
|
-
from
|
|
17
|
+
from collections.abc import Sequence
|
|
18
|
+
from typing import Any
|
|
18
19
|
|
|
19
20
|
import numpy as np
|
|
20
21
|
|
|
@@ -150,7 +151,7 @@ class StabilizerStateChForm(qis.StabilizerState):
|
|
|
150
151
|
self.F[:, r] ^= self.F[:, q]
|
|
151
152
|
self.M[:, q] ^= self.M[:, r]
|
|
152
153
|
|
|
153
|
-
def update_sum(self, t, u, delta=0, alpha=0):
|
|
154
|
+
def update_sum(self, t, u, delta=0, alpha=0) -> None:
|
|
154
155
|
"""Implements the transformation (Proposition 4 in Bravyi et al)
|
|
155
156
|
|
|
156
157
|
``i^alpha U_H (|t> + i^delta |u>) = omega W_C W_H |s'>``
|
|
@@ -214,7 +215,7 @@ class StabilizerStateChForm(qis.StabilizerState):
|
|
|
214
215
|
omega = (1j) ** (delta * int(y))
|
|
215
216
|
|
|
216
217
|
delta2 = ((-1) ** y * delta) % 4
|
|
217
|
-
c = bool(
|
|
218
|
+
c = bool(delta2 >> 1)
|
|
218
219
|
a = bool(delta2 & 1)
|
|
219
220
|
b = True
|
|
220
221
|
else:
|
|
@@ -255,7 +256,7 @@ class StabilizerStateChForm(qis.StabilizerState):
|
|
|
255
256
|
self.project_Z(q, x_i)
|
|
256
257
|
return x_i
|
|
257
258
|
|
|
258
|
-
def project_Z(self, q, z):
|
|
259
|
+
def project_Z(self, q, z) -> None:
|
|
259
260
|
"""Applies a Z projector on the q'th qubit.
|
|
260
261
|
|
|
261
262
|
Returns: a normalized state with Z_q |psi> = z |psi>
|
|
@@ -288,14 +289,14 @@ class StabilizerStateChForm(qis.StabilizerState):
|
|
|
288
289
|
copy = StabilizerStateChForm(self.n)
|
|
289
290
|
copy.G = self.G[axes][:, axes]
|
|
290
291
|
copy.F = self.F[axes][:, axes]
|
|
291
|
-
copy.M = self.M[axes][:, axes]
|
|
292
|
-
copy.gamma = self.gamma[axes]
|
|
293
|
-
copy.v = self.v[axes]
|
|
294
|
-
copy.s = self.s[axes]
|
|
292
|
+
copy.M = self.M[axes][:, axes]
|
|
293
|
+
copy.gamma = self.gamma[axes]
|
|
294
|
+
copy.v = self.v[axes]
|
|
295
|
+
copy.s = self.s[axes]
|
|
295
296
|
copy.omega = self.omega
|
|
296
297
|
return copy
|
|
297
298
|
|
|
298
|
-
def apply_x(self, axis: int, exponent: float = 1, global_shift: float = 0):
|
|
299
|
+
def apply_x(self, axis: int, exponent: float = 1, global_shift: float = 0) -> None:
|
|
299
300
|
if exponent % 2 != 0:
|
|
300
301
|
if exponent % 0.5 != 0.0:
|
|
301
302
|
raise ValueError('X exponent must be half integer') # pragma: no cover
|
|
@@ -304,7 +305,7 @@ class StabilizerStateChForm(qis.StabilizerState):
|
|
|
304
305
|
self.apply_h(axis)
|
|
305
306
|
self.omega *= _phase(exponent, global_shift)
|
|
306
307
|
|
|
307
|
-
def apply_y(self, axis: int, exponent: float = 1, global_shift: float = 0):
|
|
308
|
+
def apply_y(self, axis: int, exponent: float = 1, global_shift: float = 0) -> None:
|
|
308
309
|
if exponent % 0.5 != 0.0:
|
|
309
310
|
raise ValueError('Y exponent must be half integer') # pragma: no cover
|
|
310
311
|
shift = _phase(exponent, global_shift)
|
|
@@ -325,7 +326,7 @@ class StabilizerStateChForm(qis.StabilizerState):
|
|
|
325
326
|
self.apply_z(axis)
|
|
326
327
|
self.omega *= shift * (1 - 1j) / (2**0.5)
|
|
327
328
|
|
|
328
|
-
def apply_z(self, axis: int, exponent: float = 1, global_shift: float = 0):
|
|
329
|
+
def apply_z(self, axis: int, exponent: float = 1, global_shift: float = 0) -> None:
|
|
329
330
|
if exponent % 2 != 0:
|
|
330
331
|
if exponent % 0.5 != 0.0:
|
|
331
332
|
raise ValueError('Z exponent must be half integer') # pragma: no cover
|
|
@@ -337,7 +338,7 @@ class StabilizerStateChForm(qis.StabilizerState):
|
|
|
337
338
|
self.gamma[axis] = (self.gamma[axis] - 1) % 4
|
|
338
339
|
self.omega *= _phase(exponent, global_shift)
|
|
339
340
|
|
|
340
|
-
def apply_h(self, axis: int, exponent: float = 1, global_shift: float = 0):
|
|
341
|
+
def apply_h(self, axis: int, exponent: float = 1, global_shift: float = 0) -> None:
|
|
341
342
|
if exponent % 2 != 0:
|
|
342
343
|
if exponent % 1 != 0:
|
|
343
344
|
raise ValueError('H exponent must be integer') # pragma: no cover
|
|
@@ -357,7 +358,7 @@ class StabilizerStateChForm(qis.StabilizerState):
|
|
|
357
358
|
|
|
358
359
|
def apply_cz(
|
|
359
360
|
self, control_axis: int, target_axis: int, exponent: float = 1, global_shift: float = 0
|
|
360
|
-
):
|
|
361
|
+
) -> None:
|
|
361
362
|
if exponent % 2 != 0:
|
|
362
363
|
if exponent % 1 != 0:
|
|
363
364
|
raise ValueError('CZ exponent must be integer') # pragma: no cover
|
|
@@ -369,7 +370,7 @@ class StabilizerStateChForm(qis.StabilizerState):
|
|
|
369
370
|
|
|
370
371
|
def apply_cx(
|
|
371
372
|
self, control_axis: int, target_axis: int, exponent: float = 1, global_shift: float = 0
|
|
372
|
-
):
|
|
373
|
+
) -> None:
|
|
373
374
|
if exponent % 2 != 0:
|
|
374
375
|
if exponent % 1 != 0:
|
|
375
376
|
raise ValueError('CX exponent must be integer') # pragma: no cover
|
|
@@ -385,7 +386,7 @@ class StabilizerStateChForm(qis.StabilizerState):
|
|
|
385
386
|
self.M[control_axis, :] ^= self.M[target_axis, :]
|
|
386
387
|
self.omega *= _phase(exponent, global_shift)
|
|
387
388
|
|
|
388
|
-
def apply_global_phase(self, coefficient: value.Scalar):
|
|
389
|
+
def apply_global_phase(self, coefficient: value.Scalar) -> None:
|
|
389
390
|
self.omega *= coefficient
|
|
390
391
|
|
|
391
392
|
def measure(
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
|
|
17
17
|
from __future__ import annotations
|
|
18
18
|
|
|
19
|
-
from
|
|
19
|
+
from collections.abc import Callable, Sequence
|
|
20
|
+
from typing import Any, Self, TYPE_CHECKING
|
|
20
21
|
|
|
21
22
|
import numpy as np
|
|
22
23
|
|
|
@@ -284,7 +285,7 @@ class DensityMatrixSimulationState(SimulationState[_BufferedDensityMatrix]):
|
|
|
284
285
|
)
|
|
285
286
|
super().__init__(state=state, prng=prng, qubits=qubits, classical_data=classical_data)
|
|
286
287
|
|
|
287
|
-
def add_qubits(self, qubits: Sequence[cirq.Qid]):
|
|
288
|
+
def add_qubits(self, qubits: Sequence[cirq.Qid]) -> Self:
|
|
288
289
|
ret = super().add_qubits(qubits)
|
|
289
290
|
return (
|
|
290
291
|
self.kronecker_product(type(self)(qubits=qubits), inplace=True)
|
|
@@ -292,7 +293,7 @@ class DensityMatrixSimulationState(SimulationState[_BufferedDensityMatrix]):
|
|
|
292
293
|
else ret
|
|
293
294
|
)
|
|
294
295
|
|
|
295
|
-
def remove_qubits(self, qubits: Sequence[cirq.Qid]):
|
|
296
|
+
def remove_qubits(self, qubits: Sequence[cirq.Qid]) -> Self:
|
|
296
297
|
ret = super().remove_qubits(qubits)
|
|
297
298
|
if ret is not NotImplemented:
|
|
298
299
|
return ret
|
|
@@ -332,15 +333,15 @@ class DensityMatrixSimulationState(SimulationState[_BufferedDensityMatrix]):
|
|
|
332
333
|
)
|
|
333
334
|
|
|
334
335
|
@property
|
|
335
|
-
def target_tensor(self):
|
|
336
|
+
def target_tensor(self) -> np.ndarray:
|
|
336
337
|
return self._state._density_matrix
|
|
337
338
|
|
|
338
339
|
@property
|
|
339
|
-
def available_buffer(self):
|
|
340
|
+
def available_buffer(self) -> list[np.ndarray]:
|
|
340
341
|
return self._state._buffer
|
|
341
342
|
|
|
342
343
|
@property
|
|
343
|
-
def qid_shape(self):
|
|
344
|
+
def qid_shape(self) -> tuple[int, ...]:
|
|
344
345
|
return self._state._qid_shape
|
|
345
346
|
|
|
346
347
|
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
|
|
17
17
|
from __future__ import annotations
|
|
18
18
|
|
|
19
|
-
from
|
|
19
|
+
from collections.abc import Sequence
|
|
20
|
+
from typing import Any, TYPE_CHECKING
|
|
20
21
|
|
|
21
22
|
import numpy as np
|
|
22
23
|
|
|
@@ -258,7 +259,7 @@ class DensityMatrixStepResult(simulator_base.StepResultBase['cirq.DensityMatrixS
|
|
|
258
259
|
self._dtype = dtype
|
|
259
260
|
self._density_matrix: np.ndarray | None = None
|
|
260
261
|
|
|
261
|
-
def density_matrix(self, copy=True):
|
|
262
|
+
def density_matrix(self, copy=True) -> np.ndarray:
|
|
262
263
|
"""Returns the density matrix at this step in the simulation.
|
|
263
264
|
|
|
264
265
|
The density matrix that is stored in this result is returned in the
|