cirq-core 1.7.0.dev20250825174419__py3-none-any.whl → 1.7.0.dev20251203004401__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cirq/__init__.py +1 -0
- cirq/_compat.py +3 -2
- cirq/_compat_test.py +16 -15
- cirq/_doc.py +4 -3
- cirq/_import.py +2 -1
- cirq/_version.py +1 -1
- cirq/_version_test.py +1 -1
- cirq/circuits/_bucket_priority_queue.py +2 -1
- cirq/circuits/circuit.py +19 -17
- cirq/circuits/circuit_operation.py +2 -1
- cirq/circuits/circuit_operation_test.py +19 -0
- cirq/circuits/circuit_test.py +31 -12
- cirq/circuits/frozen_circuit.py +3 -2
- cirq/circuits/moment.py +3 -15
- cirq/circuits/optimization_pass.py +2 -1
- cirq/circuits/qasm_output.py +39 -10
- cirq/circuits/qasm_output_test.py +51 -2
- cirq/circuits/text_diagram_drawer.py +2 -1
- cirq/contrib/acquaintance/bipartite.py +2 -1
- cirq/contrib/acquaintance/devices.py +1 -1
- cirq/contrib/acquaintance/executor.py +4 -5
- cirq/contrib/acquaintance/executor_test.py +2 -1
- cirq/contrib/acquaintance/gates.py +2 -1
- cirq/contrib/acquaintance/gates_test.py +1 -1
- cirq/contrib/acquaintance/inspection_utils.py +2 -1
- cirq/contrib/acquaintance/mutation_utils.py +2 -1
- cirq/contrib/acquaintance/optimizers.py +2 -1
- cirq/contrib/acquaintance/permutation.py +2 -1
- cirq/contrib/acquaintance/permutation_test.py +1 -1
- cirq/contrib/acquaintance/shift.py +2 -1
- cirq/contrib/acquaintance/shift_swap_network.py +2 -1
- cirq/contrib/acquaintance/strategies/complete.py +3 -2
- cirq/contrib/acquaintance/strategies/cubic.py +2 -1
- cirq/contrib/acquaintance/strategies/quartic_paired.py +2 -1
- cirq/contrib/acquaintance/strategies/quartic_paired_test.py +1 -1
- cirq/contrib/acquaintance/testing.py +2 -1
- cirq/contrib/acquaintance/topological_sort.py +2 -1
- cirq/contrib/bayesian_network/bayesian_network_gate.py +3 -2
- cirq/contrib/circuitdag/circuit_dag.py +4 -2
- cirq/contrib/custom_simulators/custom_state_simulator.py +2 -1
- cirq/contrib/custom_simulators/custom_state_simulator_test.py +1 -1
- cirq/contrib/graph_device/graph_device.py +2 -1
- cirq/contrib/graph_device/graph_device_test.py +2 -1
- cirq/contrib/graph_device/hypergraph.py +2 -1
- cirq/contrib/graph_device/uniform_graph_device.py +2 -1
- cirq/contrib/json.py +14 -2
- cirq/contrib/json_test_data/BayesianNetworkGate.json +10 -0
- cirq/contrib/json_test_data/BayesianNetworkGate.repr +3 -0
- cirq/contrib/json_test_data/QuantumVolumeResult.json +169 -0
- cirq/contrib/json_test_data/QuantumVolumeResult.repr +22 -0
- cirq/contrib/json_test_data/SwapPermutationGate.json +3 -0
- cirq/contrib/json_test_data/SwapPermutationGate.repr +1 -0
- cirq/contrib/json_test_data/spec.py +0 -2
- cirq/contrib/noise_models/noise_models.py +2 -1
- cirq/contrib/paulistring/clifford_optimize.py +20 -2
- cirq/contrib/paulistring/optimize.py +1 -1
- cirq/contrib/paulistring/pauli_string_measurement_with_readout_mitigation.py +146 -35
- cirq/contrib/paulistring/pauli_string_measurement_with_readout_mitigation_test.py +81 -178
- cirq/contrib/paulistring/recombine.py +5 -2
- cirq/contrib/paulistring/separate.py +1 -1
- cirq/contrib/qasm_import/_lexer.py +6 -1
- cirq/contrib/qasm_import/_lexer_test.py +1 -1
- cirq/contrib/qasm_import/_parser.py +24 -8
- cirq/contrib/qasm_import/_parser_test.py +44 -6
- cirq/contrib/qcircuit/qcircuit_pdf_test.py +6 -9
- cirq/contrib/quantikz/__init__.py +21 -0
- cirq/contrib/quantikz/circuit_to_latex_quantikz.py +680 -0
- cirq/contrib/quantikz/circuit_to_latex_quantikz_test.py +253 -0
- cirq/contrib/quantikz/circuit_to_latex_render.py +424 -0
- cirq/contrib/quantikz/circuit_to_latex_render_test.py +44 -0
- cirq/contrib/quantum_volume/quantum_volume.py +2 -1
- cirq/contrib/quimb/density_matrix.py +1 -1
- cirq/contrib/quimb/grid_circuits.py +2 -1
- cirq/contrib/quimb/grid_circuits_test.py +1 -1
- cirq/contrib/quimb/mps_simulator.py +4 -3
- cirq/contrib/quimb/state_vector.py +2 -1
- cirq/contrib/quirk/export_to_quirk.py +2 -1
- cirq/contrib/quirk/linearize_circuit.py +1 -1
- cirq/contrib/quirk/quirk_gate.py +2 -1
- cirq/contrib/routing/device.py +1 -1
- cirq/contrib/routing/greedy.py +2 -1
- cirq/contrib/routing/initialization.py +2 -1
- cirq/contrib/routing/router.py +2 -1
- cirq/contrib/routing/swap_network.py +2 -1
- cirq/contrib/routing/utils.py +2 -1
- cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking.py +7 -5
- cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking_test.py +6 -6
- cirq/devices/device.py +2 -1
- cirq/devices/grid_device_metadata.py +2 -1
- cirq/devices/grid_qubit.py +7 -6
- cirq/devices/insertion_noise_model.py +2 -1
- cirq/devices/line_qubit.py +2 -1
- cirq/devices/named_topologies.py +2 -1
- cirq/devices/noise_model.py +2 -1
- cirq/devices/noise_model_test.py +1 -1
- cirq/devices/noise_properties.py +2 -1
- cirq/devices/superconducting_qubits_noise_properties_test.py +2 -1
- cirq/devices/thermal_noise_model.py +2 -1
- cirq/experiments/__init__.py +2 -0
- cirq/experiments/benchmarking/parallel_xeb.py +2 -1
- cirq/experiments/benchmarking/parallel_xeb_test.py +1 -1
- cirq/experiments/fidelity_estimation.py +2 -1
- cirq/experiments/fidelity_estimation_test.py +1 -1
- cirq/experiments/ghz_2d.py +150 -0
- cirq/experiments/ghz_2d_test.py +155 -0
- cirq/experiments/n_qubit_tomography.py +2 -1
- cirq/experiments/n_qubit_tomography_test.py +1 -1
- cirq/experiments/purity_estimation.py +1 -1
- cirq/experiments/qubit_characterizations.py +33 -4
- cirq/experiments/qubit_characterizations_test.py +16 -0
- cirq/experiments/random_quantum_circuit_generation.py +2 -1
- cirq/experiments/random_quantum_circuit_generation_test.py +2 -1
- cirq/experiments/readout_confusion_matrix.py +2 -1
- cirq/experiments/readout_confusion_matrix_test.py +1 -1
- cirq/experiments/single_qubit_readout_calibration.py +2 -1
- cirq/experiments/single_qubit_readout_calibration_test.py +1 -1
- cirq/experiments/t1_decay_experiment.py +2 -1
- cirq/experiments/two_qubit_xeb.py +2 -1
- cirq/experiments/two_qubit_xeb_test.py +1 -1
- cirq/experiments/xeb_fitting.py +2 -1
- cirq/experiments/xeb_fitting_test.py +1 -1
- cirq/experiments/xeb_sampling.py +5 -3
- cirq/experiments/xeb_sampling_test.py +1 -1
- cirq/experiments/xeb_simulation.py +2 -1
- cirq/experiments/xeb_simulation_test.py +2 -1
- cirq/experiments/z_phase_calibration.py +2 -1
- cirq/experiments/z_phase_calibration_test.py +18 -3
- cirq/interop/quirk/cells/__init__.py +1 -2
- cirq/interop/quirk/cells/all_cells.py +2 -1
- cirq/interop/quirk/cells/arithmetic_cells.py +2 -1
- cirq/interop/quirk/cells/cell.py +2 -1
- cirq/interop/quirk/cells/composite_cell.py +2 -1
- cirq/interop/quirk/cells/composite_cell_test.py +1 -1
- cirq/interop/quirk/cells/control_cells.py +2 -1
- cirq/interop/quirk/cells/frequency_space_cells.py +1 -1
- cirq/interop/quirk/cells/ignored_cells.py +1 -1
- cirq/interop/quirk/cells/input_cells.py +2 -1
- cirq/interop/quirk/cells/input_rotation_cells.py +2 -1
- cirq/interop/quirk/cells/measurement_cells.py +2 -1
- cirq/interop/quirk/cells/parse.py +2 -11
- cirq/interop/quirk/cells/qubit_permutation_cells.py +2 -1
- cirq/interop/quirk/cells/scalar_cells.py +2 -1
- cirq/interop/quirk/cells/single_qubit_rotation_cells.py +2 -1
- cirq/interop/quirk/cells/swap_cell.py +2 -1
- cirq/interop/quirk/cells/unsupported_cells.py +1 -1
- cirq/interop/quirk/url_to_circuit.py +2 -1
- cirq/json_resolver_cache.py +0 -2
- cirq/linalg/decompositions.py +6 -2
- cirq/linalg/decompositions_test.py +1 -0
- cirq/linalg/diagonalize.py +1 -1
- cirq/linalg/predicates.py +2 -1
- cirq/linalg/tolerance.py +2 -1
- cirq/linalg/transformations.py +3 -2
- cirq/ops/arithmetic_operation.py +4 -3
- cirq/ops/arithmetic_operation_test.py +1 -1
- cirq/ops/boolean_hamiltonian.py +4 -3
- cirq/ops/classically_controlled_operation.py +11 -11
- cirq/ops/classically_controlled_operation_test.py +26 -2
- cirq/ops/clifford_gate.py +3 -2
- cirq/ops/clifford_gate_test.py +1 -2
- cirq/ops/common_channels.py +2 -1
- cirq/ops/common_gates.py +3 -2
- cirq/ops/control_values.py +2 -1
- cirq/ops/controlled_gate.py +3 -2
- cirq/ops/controlled_gate_test.py +2 -1
- cirq/ops/controlled_operation.py +3 -2
- cirq/ops/controlled_operation_test.py +2 -1
- cirq/ops/dense_pauli_string.py +44 -81
- cirq/ops/dense_pauli_string_test.py +21 -0
- cirq/ops/diagonal_gate.py +3 -2
- cirq/ops/eigen_gate.py +9 -7
- cirq/ops/fourier_transform.py +3 -2
- cirq/ops/fourier_transform_test.py +2 -4
- cirq/ops/fsim_gate.py +3 -2
- cirq/ops/gate_operation.py +23 -12
- cirq/ops/gateset.py +22 -2
- cirq/ops/global_phase_op.py +3 -2
- cirq/ops/greedy_qubit_manager.py +2 -1
- cirq/ops/identity.py +2 -1
- cirq/ops/kraus_channel.py +2 -1
- cirq/ops/linear_combinations.py +12 -17
- cirq/ops/linear_combinations_test.py +23 -1
- cirq/ops/matrix_gates.py +2 -1
- cirq/ops/measure_util.py +8 -6
- cirq/ops/measurement_gate.py +2 -1
- cirq/ops/mixed_unitary_channel.py +2 -1
- cirq/ops/named_qubit.py +2 -2
- cirq/ops/op_tree.py +2 -1
- cirq/ops/parallel_gate.py +3 -2
- cirq/ops/parity_gates.py +2 -1
- cirq/ops/parity_gates_test.py +35 -0
- cirq/ops/pauli_interaction_gate.py +2 -1
- cirq/ops/pauli_measurement_gate.py +2 -1
- cirq/ops/pauli_string.py +37 -57
- cirq/ops/pauli_string_phasor.py +6 -5
- cirq/ops/pauli_string_raw_types.py +2 -1
- cirq/ops/pauli_string_test.py +49 -6
- cirq/ops/pauli_sum_exponential.py +2 -1
- cirq/ops/permutation_gate.py +2 -1
- cirq/ops/phased_iswap_gate.py +3 -2
- cirq/ops/phased_x_gate.py +5 -4
- cirq/ops/phased_x_z_gate.py +12 -5
- cirq/ops/projector.py +2 -1
- cirq/ops/qubit_manager.py +2 -1
- cirq/ops/qubit_order.py +2 -1
- cirq/ops/qubit_order_or_list.py +1 -1
- cirq/ops/random_gate_channel.py +3 -2
- cirq/ops/raw_types.py +33 -16
- cirq/ops/raw_types_test.py +4 -3
- cirq/ops/state_preparation_channel.py +2 -1
- cirq/ops/three_qubit_gates.py +3 -2
- cirq/ops/two_qubit_diagonal_gate.py +3 -2
- cirq/ops/uniform_superposition_gate.py +2 -1
- cirq/ops/wait_gate.py +10 -4
- cirq/protocols/act_on_protocol.py +2 -1
- cirq/protocols/act_on_protocol_test.py +2 -1
- cirq/protocols/apply_channel_protocol.py +2 -1
- cirq/protocols/apply_mixture_protocol.py +2 -1
- cirq/protocols/apply_mixture_protocol_test.py +2 -1
- cirq/protocols/apply_unitary_protocol.py +2 -1
- cirq/protocols/apply_unitary_protocol_test.py +2 -0
- cirq/protocols/approximate_equality_protocol.py +2 -1
- cirq/protocols/circuit_diagram_info_protocol.py +2 -1
- cirq/protocols/control_key_protocol.py +7 -0
- cirq/protocols/decompose_protocol.py +2 -12
- cirq/protocols/has_stabilizer_effect_protocol.py +1 -1
- cirq/protocols/has_stabilizer_effect_protocol_test.py +11 -9
- cirq/protocols/has_unitary_protocol_test.py +3 -3
- cirq/protocols/hash_from_pickle_test.py +2 -2
- cirq/protocols/inverse_protocol.py +2 -1
- cirq/protocols/json_serialization.py +5 -4
- cirq/protocols/json_serialization_test.py +31 -31
- cirq/protocols/kraus_protocol.py +4 -3
- cirq/protocols/kraus_protocol_test.py +7 -7
- cirq/protocols/measurement_key_protocol.py +32 -8
- cirq/protocols/mixture_protocol.py +3 -2
- cirq/protocols/mixture_protocol_test.py +7 -7
- cirq/protocols/mul_protocol_test.py +4 -4
- cirq/protocols/phase_protocol.py +13 -4
- cirq/protocols/pow_protocol.py +2 -1
- cirq/protocols/pow_protocol_test.py +5 -5
- cirq/protocols/qasm.py +2 -1
- cirq/protocols/qid_shape_protocol.py +2 -1
- cirq/protocols/resolve_parameters.py +17 -15
- cirq/protocols/trace_distance_bound.py +2 -1
- cirq/protocols/unitary_protocol.py +21 -21
- cirq/protocols/unitary_protocol_test.py +31 -19
- cirq/qis/channels.py +1 -1
- cirq/qis/channels_test.py +1 -1
- cirq/qis/clifford_tableau.py +16 -15
- cirq/qis/clifford_tableau_test.py +17 -17
- cirq/qis/entropy.py +3 -3
- cirq/qis/entropy_test.py +1 -1
- cirq/qis/quantum_state_representation.py +2 -1
- cirq/qis/states.py +7 -2
- cirq/qis/states_test.py +54 -54
- cirq/sim/classical_simulator.py +25 -14
- cirq/sim/classical_simulator_test.py +85 -30
- cirq/sim/clifford/clifford_simulator.py +7 -6
- cirq/sim/clifford/clifford_simulator_test.py +51 -50
- cirq/sim/clifford/clifford_tableau_simulation_state.py +2 -1
- cirq/sim/clifford/stabilizer_ch_form_simulation_state.py +2 -1
- cirq/sim/clifford/stabilizer_sampler.py +1 -1
- cirq/sim/clifford/stabilizer_simulation_state.py +2 -1
- cirq/sim/clifford/stabilizer_state_ch_form.py +16 -15
- cirq/sim/clifford/stabilizer_state_ch_form_test.py +0 -1
- cirq/sim/density_matrix_simulation_state.py +7 -6
- cirq/sim/density_matrix_simulator.py +3 -2
- cirq/sim/density_matrix_simulator_test.py +94 -84
- cirq/sim/density_matrix_utils.py +2 -1
- cirq/sim/density_matrix_utils_test.py +1 -1
- cirq/sim/mux.py +35 -8
- cirq/sim/mux_test.py +39 -26
- cirq/sim/simulation_product_state.py +2 -1
- cirq/sim/simulation_product_state_test.py +8 -7
- cirq/sim/simulation_state.py +6 -5
- cirq/sim/simulation_state_base.py +3 -2
- cirq/sim/simulation_state_test.py +7 -6
- cirq/sim/simulation_utils.py +2 -1
- cirq/sim/simulator.py +4 -3
- cirq/sim/simulator_base.py +2 -1
- cirq/sim/simulator_base_test.py +51 -36
- cirq/sim/simulator_test.py +41 -36
- cirq/sim/sparse_simulator.py +3 -2
- cirq/sim/sparse_simulator_test.py +92 -82
- cirq/sim/state_vector.py +5 -6
- cirq/sim/state_vector_simulation_state.py +10 -9
- cirq/sim/state_vector_simulator.py +2 -1
- cirq/sim/state_vector_simulator_test.py +9 -9
- cirq/sim/state_vector_test.py +40 -39
- cirq/study/__init__.py +1 -0
- cirq/study/flatten_expressions.py +2 -1
- cirq/study/resolver.py +31 -18
- cirq/study/resolver_test.py +1 -1
- cirq/study/result.py +2 -1
- cirq/study/result_test.py +20 -20
- cirq/study/sweepable.py +2 -1
- cirq/study/sweepable_test.py +20 -20
- cirq/study/sweeps.py +26 -1
- cirq/study/sweeps_test.py +67 -43
- cirq/testing/_compat_test_data/__init__.py +3 -3
- cirq/testing/circuit_compare.py +2 -1
- cirq/testing/circuit_compare_test.py +16 -14
- cirq/testing/consistent_act_on_test.py +1 -1
- cirq/testing/consistent_channels.py +2 -2
- cirq/testing/consistent_controlled_gate_op.py +2 -2
- cirq/testing/consistent_controlled_gate_op_test.py +2 -1
- cirq/testing/consistent_decomposition.py +4 -2
- cirq/testing/consistent_phase_by.py +1 -1
- cirq/testing/consistent_protocols.py +2 -1
- cirq/testing/consistent_protocols_test.py +3 -3
- cirq/testing/consistent_qasm.py +4 -3
- cirq/testing/consistent_qasm_test.py +3 -3
- cirq/testing/consistent_resolve_parameters.py +1 -1
- cirq/testing/consistent_unitary.py +1 -1
- cirq/testing/consistent_unitary_test.py +1 -1
- cirq/testing/deprecation.py +1 -1
- cirq/testing/devices.py +3 -2
- cirq/testing/equals_tester.py +4 -3
- cirq/testing/equivalent_basis_map.py +4 -2
- cirq/testing/json.py +3 -2
- cirq/testing/lin_alg_utils.py +1 -1
- cirq/testing/logs.py +1 -1
- cirq/testing/op_tree.py +1 -1
- cirq/testing/order_tester.py +2 -2
- cirq/testing/pytest_utils.py +2 -1
- cirq/testing/random_circuit.py +2 -1
- cirq/testing/random_circuit_test.py +2 -1
- cirq/testing/repr_pretty_tester.py +3 -3
- cirq/transformers/__init__.py +1 -0
- cirq/transformers/_connected_component.py +231 -0
- cirq/transformers/_connected_component_test.py +200 -0
- cirq/transformers/align_test.py +13 -13
- cirq/transformers/analytical_decompositions/clifford_decomposition.py +8 -7
- cirq/transformers/analytical_decompositions/clifford_decomposition_test.py +5 -5
- cirq/transformers/analytical_decompositions/controlled_gate_decomposition.py +11 -10
- cirq/transformers/analytical_decompositions/controlled_gate_decomposition_test.py +6 -6
- cirq/transformers/analytical_decompositions/cphase_to_fsim.py +3 -2
- cirq/transformers/analytical_decompositions/cphase_to_fsim_test.py +11 -10
- cirq/transformers/analytical_decompositions/quantum_shannon_decomposition.py +8 -7
- cirq/transformers/analytical_decompositions/quantum_shannon_decomposition_test.py +17 -20
- cirq/transformers/analytical_decompositions/single_qubit_decompositions_test.py +33 -27
- cirq/transformers/analytical_decompositions/single_to_two_qubit_isometry_test.py +1 -1
- cirq/transformers/analytical_decompositions/three_qubit_decomposition.py +1 -1
- cirq/transformers/analytical_decompositions/two_qubit_state_preparation_test.py +12 -11
- cirq/transformers/analytical_decompositions/two_qubit_to_cz.py +5 -2
- cirq/transformers/analytical_decompositions/two_qubit_to_cz_test.py +3 -3
- cirq/transformers/analytical_decompositions/two_qubit_to_fsim.py +2 -1
- cirq/transformers/analytical_decompositions/two_qubit_to_ms.py +2 -1
- cirq/transformers/analytical_decompositions/two_qubit_to_ms_test.py +2 -2
- cirq/transformers/analytical_decompositions/two_qubit_to_sqrt_iswap.py +2 -1
- cirq/transformers/analytical_decompositions/two_qubit_to_sqrt_iswap_test.py +32 -30
- cirq/transformers/drop_negligible_operations_test.py +7 -7
- cirq/transformers/dynamical_decoupling.py +185 -112
- cirq/transformers/dynamical_decoupling_test.py +195 -201
- cirq/transformers/eject_phased_paulis.py +2 -1
- cirq/transformers/eject_phased_paulis_test.py +3 -2
- cirq/transformers/eject_z.py +5 -3
- cirq/transformers/eject_z_test.py +23 -25
- cirq/transformers/expand_composite.py +3 -2
- cirq/transformers/expand_composite_test.py +14 -14
- cirq/transformers/gauge_compiling/__init__.py +13 -0
- cirq/transformers/gauge_compiling/gauge_compiling.py +3 -2
- cirq/transformers/gauge_compiling/gauge_compiling_test.py +14 -12
- cirq/transformers/gauge_compiling/gauge_compiling_test_utils.py +3 -3
- cirq/transformers/gauge_compiling/idle_moments_gauge.py +225 -0
- cirq/transformers/gauge_compiling/idle_moments_gauge_test.py +193 -0
- cirq/transformers/gauge_compiling/multi_moment_cphase_gauge.py +242 -0
- cirq/transformers/gauge_compiling/multi_moment_cphase_gauge_test.py +243 -0
- cirq/transformers/gauge_compiling/multi_moment_gauge_compiling.py +151 -0
- cirq/transformers/gauge_compiling/sqrt_cz_gauge.py +2 -1
- cirq/transformers/heuristic_decompositions/gate_tabulation_math_utils.py +1 -1
- cirq/transformers/heuristic_decompositions/gate_tabulation_math_utils_test.py +6 -6
- cirq/transformers/heuristic_decompositions/two_qubit_gate_tabulation.py +3 -2
- cirq/transformers/measurement_transformers.py +2 -1
- cirq/transformers/measurement_transformers_test.py +45 -39
- cirq/transformers/merge_k_qubit_gates.py +2 -1
- cirq/transformers/merge_k_qubit_gates_test.py +1 -1
- cirq/transformers/merge_single_qubit_gates.py +9 -5
- cirq/transformers/merge_single_qubit_gates_test.py +22 -22
- cirq/transformers/noise_adding_test.py +2 -2
- cirq/transformers/optimize_for_target_gateset.py +2 -1
- cirq/transformers/optimize_for_target_gateset_test.py +11 -9
- cirq/transformers/qubit_management_transformers_test.py +6 -2
- cirq/transformers/routing/mapping_manager.py +2 -1
- cirq/transformers/routing/route_circuit_cqc.py +2 -1
- cirq/transformers/stratify.py +2 -1
- cirq/transformers/symbolize.py +2 -1
- cirq/transformers/tag_transformers.py +2 -1
- cirq/transformers/target_gatesets/compilation_target_gateset.py +2 -1
- cirq/transformers/target_gatesets/cz_gateset.py +2 -1
- cirq/transformers/target_gatesets/cz_gateset_test.py +1 -1
- cirq/transformers/target_gatesets/sqrt_iswap_gateset.py +2 -1
- cirq/transformers/transformer_api.py +2 -1
- cirq/transformers/transformer_primitives.py +271 -145
- cirq/transformers/transformer_primitives_test.py +185 -1
- cirq/value/abc_alt.py +2 -1
- cirq/value/classical_data.py +2 -1
- cirq/value/condition.py +2 -1
- cirq/value/digits.py +9 -2
- cirq/value/duration.py +6 -5
- cirq/value/linear_dict.py +4 -9
- cirq/value/measurement_key.py +2 -1
- cirq/value/periodic_value.py +3 -2
- cirq/value/product_state.py +2 -1
- cirq/value/value_equality_attr.py +2 -1
- cirq/vis/density_matrix.py +1 -1
- cirq/vis/heatmap.py +2 -1
- cirq/vis/histogram.py +2 -1
- cirq/vis/state_histogram.py +2 -1
- cirq/work/collector.py +2 -1
- cirq/work/observable_grouping.py +2 -1
- cirq/work/observable_measurement.py +2 -1
- cirq/work/observable_measurement_data.py +2 -1
- cirq/work/observable_measurement_test.py +1 -1
- cirq/work/observable_readout_calibration.py +2 -1
- cirq/work/observable_readout_calibration_test.py +1 -1
- cirq/work/observable_settings.py +2 -1
- cirq/work/sampler.py +2 -1
- cirq/work/sampler_test.py +1 -1
- {cirq_core-1.7.0.dev20250825174419.dist-info → cirq_core-1.7.0.dev20251203004401.dist-info}/METADATA +5 -6
- {cirq_core-1.7.0.dev20250825174419.dist-info → cirq_core-1.7.0.dev20251203004401.dist-info}/RECORD +425 -406
- cirq/contrib/json_test.py +0 -33
- {cirq_core-1.7.0.dev20250825174419.dist-info → cirq_core-1.7.0.dev20251203004401.dist-info}/WHEEL +0 -0
- {cirq_core-1.7.0.dev20250825174419.dist-info → cirq_core-1.7.0.dev20251203004401.dist-info}/licenses/LICENSE +0 -0
- {cirq_core-1.7.0.dev20250825174419.dist-info → cirq_core-1.7.0.dev20251203004401.dist-info}/top_level.txt +0 -0
cirq/sim/simulator_base_test.py
CHANGED
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
17
|
import math
|
|
18
|
-
from
|
|
18
|
+
from collections.abc import Sequence
|
|
19
|
+
from typing import Any
|
|
19
20
|
|
|
20
21
|
import numpy as np
|
|
21
22
|
import pytest
|
|
@@ -73,25 +74,25 @@ class CountingSimulationState(cirq.SimulationState[CountingState]):
|
|
|
73
74
|
return True
|
|
74
75
|
|
|
75
76
|
@property
|
|
76
|
-
def data(self):
|
|
77
|
+
def data(self) -> Any:
|
|
77
78
|
return self._state.data
|
|
78
79
|
|
|
79
80
|
@property
|
|
80
|
-
def gate_count(self):
|
|
81
|
+
def gate_count(self) -> int:
|
|
81
82
|
return self._state.gate_count
|
|
82
83
|
|
|
83
84
|
@property
|
|
84
|
-
def measurement_count(self):
|
|
85
|
+
def measurement_count(self) -> int:
|
|
85
86
|
return self._state.measurement_count
|
|
86
87
|
|
|
87
88
|
@property
|
|
88
|
-
def copy_count(self):
|
|
89
|
+
def copy_count(self) -> int:
|
|
89
90
|
return self._state.copy_count
|
|
90
91
|
|
|
91
92
|
|
|
92
93
|
class SplittableCountingSimulationState(CountingSimulationState):
|
|
93
94
|
@property
|
|
94
|
-
def allows_factoring(self):
|
|
95
|
+
def allows_factoring(self) -> bool:
|
|
95
96
|
return True
|
|
96
97
|
|
|
97
98
|
|
|
@@ -167,59 +168,64 @@ entangled_state_repr = np.array([[math.sqrt(0.5), 0], [0, math.sqrt(0.5)]])
|
|
|
167
168
|
|
|
168
169
|
|
|
169
170
|
class TestOp(cirq.Operation):
|
|
170
|
-
def with_qubits(self, *new_qubits):
|
|
171
|
-
|
|
171
|
+
def with_qubits(self, *new_qubits) -> cirq.Operation:
|
|
172
|
+
raise NotImplementedError()
|
|
172
173
|
|
|
173
174
|
@property
|
|
174
|
-
def qubits(self):
|
|
175
|
-
return
|
|
175
|
+
def qubits(self) -> tuple[cirq.Qid, ...]:
|
|
176
|
+
return (q0,)
|
|
176
177
|
|
|
177
178
|
|
|
178
|
-
def test_simulate_empty_circuit():
|
|
179
|
+
def test_simulate_empty_circuit() -> None:
|
|
179
180
|
sim = CountingSimulator()
|
|
180
181
|
r = sim.simulate(cirq.Circuit())
|
|
182
|
+
assert isinstance(r._final_simulator_state, CountingSimulationState)
|
|
181
183
|
assert r._final_simulator_state.gate_count == 0
|
|
182
184
|
assert r._final_simulator_state.measurement_count == 0
|
|
183
185
|
assert r._final_simulator_state.copy_count == 0
|
|
184
186
|
|
|
185
187
|
|
|
186
|
-
def test_simulate_one_gate_circuit():
|
|
188
|
+
def test_simulate_one_gate_circuit() -> None:
|
|
187
189
|
sim = CountingSimulator()
|
|
188
190
|
r = sim.simulate(cirq.Circuit(cirq.X(q0)))
|
|
191
|
+
assert isinstance(r._final_simulator_state, CountingSimulationState)
|
|
189
192
|
assert r._final_simulator_state.gate_count == 1
|
|
190
193
|
assert r._final_simulator_state.copy_count == 0
|
|
191
194
|
|
|
192
195
|
|
|
193
|
-
def test_simulate_one_measurement_circuit():
|
|
196
|
+
def test_simulate_one_measurement_circuit() -> None:
|
|
194
197
|
sim = CountingSimulator()
|
|
195
198
|
r = sim.simulate(cirq.Circuit(cirq.measure(q0)))
|
|
199
|
+
assert isinstance(r._final_simulator_state, CountingSimulationState)
|
|
196
200
|
assert r._final_simulator_state.gate_count == 0
|
|
197
201
|
assert r._final_simulator_state.measurement_count == 1
|
|
198
202
|
assert r._final_simulator_state.copy_count == 0
|
|
199
203
|
|
|
200
204
|
|
|
201
|
-
def test_empty_circuit_simulation_has_moment():
|
|
205
|
+
def test_empty_circuit_simulation_has_moment() -> None:
|
|
202
206
|
sim = CountingSimulator()
|
|
203
207
|
steps = list(sim.simulate_moment_steps(cirq.Circuit()))
|
|
204
208
|
assert len(steps) == 1
|
|
205
209
|
|
|
206
210
|
|
|
207
|
-
def test_noise_applied():
|
|
211
|
+
def test_noise_applied() -> None:
|
|
208
212
|
sim = CountingSimulator(noise=cirq.X)
|
|
209
213
|
r = sim.simulate(cirq.Circuit(cirq.X(q0)))
|
|
214
|
+
assert isinstance(r._final_simulator_state, CountingSimulationState)
|
|
210
215
|
assert r._final_simulator_state.gate_count == 2
|
|
211
216
|
assert r._final_simulator_state.copy_count == 0
|
|
212
217
|
|
|
213
218
|
|
|
214
|
-
def test_noise_applied_measurement_gate():
|
|
219
|
+
def test_noise_applied_measurement_gate() -> None:
|
|
215
220
|
sim = CountingSimulator(noise=cirq.X)
|
|
216
221
|
r = sim.simulate(cirq.Circuit(cirq.measure(q0)))
|
|
222
|
+
assert isinstance(r._final_simulator_state, CountingSimulationState)
|
|
217
223
|
assert r._final_simulator_state.gate_count == 1
|
|
218
224
|
assert r._final_simulator_state.measurement_count == 1
|
|
219
225
|
assert r._final_simulator_state.copy_count == 0
|
|
220
226
|
|
|
221
227
|
|
|
222
|
-
def test_parameterized_copies_all_but_last():
|
|
228
|
+
def test_parameterized_copies_all_but_last() -> None:
|
|
223
229
|
sim = CountingSimulator()
|
|
224
230
|
n = 4
|
|
225
231
|
rs = sim.simulate_sweep(
|
|
@@ -227,12 +233,13 @@ def test_parameterized_copies_all_but_last():
|
|
|
227
233
|
)
|
|
228
234
|
for i in range(n):
|
|
229
235
|
r = rs[i]
|
|
236
|
+
assert isinstance(r._final_simulator_state, CountingSimulationState)
|
|
230
237
|
assert r._final_simulator_state.gate_count == 1
|
|
231
238
|
assert r._final_simulator_state.measurement_count == 0
|
|
232
239
|
assert r._final_simulator_state.copy_count == 0 if i == n - 1 else 1
|
|
233
240
|
|
|
234
241
|
|
|
235
|
-
def test_cannot_act():
|
|
242
|
+
def test_cannot_act() -> None:
|
|
236
243
|
class BadOp(TestOp):
|
|
237
244
|
def _act_on_(self, sim_state):
|
|
238
245
|
raise TypeError()
|
|
@@ -242,25 +249,25 @@ def test_cannot_act():
|
|
|
242
249
|
sim.simulate(cirq.Circuit(BadOp()))
|
|
243
250
|
|
|
244
251
|
|
|
245
|
-
def test_run_one_gate_circuit():
|
|
252
|
+
def test_run_one_gate_circuit() -> None:
|
|
246
253
|
sim = CountingSimulator()
|
|
247
254
|
r = sim.run(cirq.Circuit(cirq.X(q0), cirq.measure(q0)), repetitions=2)
|
|
248
255
|
assert np.allclose(r.measurements['q(0)'], [[1], [1]])
|
|
249
256
|
|
|
250
257
|
|
|
251
|
-
def test_run_one_gate_circuit_noise():
|
|
258
|
+
def test_run_one_gate_circuit_noise() -> None:
|
|
252
259
|
sim = CountingSimulator(noise=cirq.X)
|
|
253
260
|
r = sim.run(cirq.Circuit(cirq.X(q0), cirq.measure(q0)), repetitions=2)
|
|
254
261
|
assert np.allclose(r.measurements['q(0)'], [[2], [2]])
|
|
255
262
|
|
|
256
263
|
|
|
257
|
-
def test_run_non_unitary_circuit():
|
|
264
|
+
def test_run_non_unitary_circuit() -> None:
|
|
258
265
|
sim = CountingSimulator()
|
|
259
266
|
r = sim.run(cirq.Circuit(cirq.phase_damp(1).on(q0), cirq.measure(q0)), repetitions=2)
|
|
260
267
|
assert np.allclose(r.measurements['q(0)'], [[1], [1]])
|
|
261
268
|
|
|
262
269
|
|
|
263
|
-
def test_run_non_unitary_circuit_non_unitary_state():
|
|
270
|
+
def test_run_non_unitary_circuit_non_unitary_state() -> None:
|
|
264
271
|
class DensityCountingSimulator(CountingSimulator):
|
|
265
272
|
def _can_be_in_run_prefix(self, val):
|
|
266
273
|
return not cirq.is_measurement(val)
|
|
@@ -270,15 +277,16 @@ def test_run_non_unitary_circuit_non_unitary_state():
|
|
|
270
277
|
assert np.allclose(r.measurements['q(0)'], [[1], [1]])
|
|
271
278
|
|
|
272
279
|
|
|
273
|
-
def test_run_non_terminal_measurement():
|
|
280
|
+
def test_run_non_terminal_measurement() -> None:
|
|
274
281
|
sim = CountingSimulator()
|
|
275
282
|
r = sim.run(cirq.Circuit(cirq.X(q0), cirq.measure(q0), cirq.X(q0)), repetitions=2)
|
|
276
283
|
assert np.allclose(r.measurements['q(0)'], [[1], [1]])
|
|
277
284
|
|
|
278
285
|
|
|
279
|
-
def test_integer_initial_state_is_split():
|
|
286
|
+
def test_integer_initial_state_is_split() -> None:
|
|
280
287
|
sim = SplittableCountingSimulator()
|
|
281
288
|
state = sim._create_simulation_state(2, (q0, q1))
|
|
289
|
+
assert isinstance(state, cirq.SimulationProductState)
|
|
282
290
|
assert len(set(state.values())) == 3
|
|
283
291
|
assert state[q0] is not state[q1]
|
|
284
292
|
assert state[q0].data == 1
|
|
@@ -286,7 +294,7 @@ def test_integer_initial_state_is_split():
|
|
|
286
294
|
assert state[None].data == 0
|
|
287
295
|
|
|
288
296
|
|
|
289
|
-
def test_integer_initial_state_is_not_split_if_disabled():
|
|
297
|
+
def test_integer_initial_state_is_not_split_if_disabled() -> None:
|
|
290
298
|
sim = SplittableCountingSimulator(split_untangled_states=False)
|
|
291
299
|
state = sim._create_simulation_state(2, (q0, q1))
|
|
292
300
|
assert isinstance(state, SplittableCountingSimulationState)
|
|
@@ -294,7 +302,7 @@ def test_integer_initial_state_is_not_split_if_disabled():
|
|
|
294
302
|
assert state.data == 2
|
|
295
303
|
|
|
296
304
|
|
|
297
|
-
def test_integer_initial_state_is_not_split_if_impossible():
|
|
305
|
+
def test_integer_initial_state_is_not_split_if_impossible() -> None:
|
|
298
306
|
sim = CountingSimulator()
|
|
299
307
|
state = sim._create_simulation_state(2, (q0, q1))
|
|
300
308
|
assert isinstance(state, CountingSimulationState)
|
|
@@ -303,18 +311,20 @@ def test_integer_initial_state_is_not_split_if_impossible():
|
|
|
303
311
|
assert state.data == 2
|
|
304
312
|
|
|
305
313
|
|
|
306
|
-
def test_non_integer_initial_state_is_not_split():
|
|
314
|
+
def test_non_integer_initial_state_is_not_split() -> None:
|
|
307
315
|
sim = SplittableCountingSimulator()
|
|
308
316
|
state = sim._create_simulation_state(entangled_state_repr, (q0, q1))
|
|
317
|
+
assert isinstance(state, cirq.SimulationProductState)
|
|
309
318
|
assert len(set(state.values())) == 2
|
|
310
319
|
assert (state[q0].data == entangled_state_repr).all()
|
|
311
320
|
assert state[q1] is state[q0]
|
|
312
321
|
assert state[None].data == 0
|
|
313
322
|
|
|
314
323
|
|
|
315
|
-
def test_entanglement_causes_join():
|
|
324
|
+
def test_entanglement_causes_join() -> None:
|
|
316
325
|
sim = SplittableCountingSimulator()
|
|
317
326
|
state = sim._create_simulation_state(2, (q0, q1))
|
|
327
|
+
assert isinstance(state, cirq.SimulationProductState)
|
|
318
328
|
assert len(set(state.values())) == 3
|
|
319
329
|
state.apply_operation(cirq.CNOT(q0, q1))
|
|
320
330
|
assert len(set(state.values())) == 2
|
|
@@ -322,9 +332,10 @@ def test_entanglement_causes_join():
|
|
|
322
332
|
assert state[None] is not state[q0]
|
|
323
333
|
|
|
324
334
|
|
|
325
|
-
def test_measurement_causes_split():
|
|
335
|
+
def test_measurement_causes_split() -> None:
|
|
326
336
|
sim = SplittableCountingSimulator()
|
|
327
337
|
state = sim._create_simulation_state(entangled_state_repr, (q0, q1))
|
|
338
|
+
assert isinstance(state, cirq.SimulationProductState)
|
|
328
339
|
assert len(set(state.values())) == 2
|
|
329
340
|
state.apply_operation(cirq.measure(q0))
|
|
330
341
|
assert len(set(state.values())) == 3
|
|
@@ -332,7 +343,7 @@ def test_measurement_causes_split():
|
|
|
332
343
|
assert state[q0] is not state[None]
|
|
333
344
|
|
|
334
345
|
|
|
335
|
-
def test_measurement_does_not_split_if_disabled():
|
|
346
|
+
def test_measurement_does_not_split_if_disabled() -> None:
|
|
336
347
|
sim = SplittableCountingSimulator(split_untangled_states=False)
|
|
337
348
|
state = sim._create_simulation_state(2, (q0, q1))
|
|
338
349
|
assert isinstance(state, SplittableCountingSimulationState)
|
|
@@ -341,7 +352,7 @@ def test_measurement_does_not_split_if_disabled():
|
|
|
341
352
|
assert state[q0] is state[q1]
|
|
342
353
|
|
|
343
354
|
|
|
344
|
-
def test_measurement_does_not_split_if_impossible():
|
|
355
|
+
def test_measurement_does_not_split_if_impossible() -> None:
|
|
345
356
|
sim = CountingSimulator()
|
|
346
357
|
state = sim._create_simulation_state(2, (q0, q1))
|
|
347
358
|
assert isinstance(state, CountingSimulationState)
|
|
@@ -352,7 +363,7 @@ def test_measurement_does_not_split_if_impossible():
|
|
|
352
363
|
assert state[q0] is state[q1]
|
|
353
364
|
|
|
354
365
|
|
|
355
|
-
def test_reorder_succeeds():
|
|
366
|
+
def test_reorder_succeeds() -> None:
|
|
356
367
|
sim = SplittableCountingSimulator()
|
|
357
368
|
state = sim._create_simulation_state(entangled_state_repr, (q0, q1))
|
|
358
369
|
reordered = state[q0].transpose_to_qubit_order([q1, q0])
|
|
@@ -360,7 +371,7 @@ def test_reorder_succeeds():
|
|
|
360
371
|
|
|
361
372
|
|
|
362
373
|
@pytest.mark.parametrize('split', [True, False])
|
|
363
|
-
def test_sim_state_instance_unchanged_during_normal_sim(split: bool):
|
|
374
|
+
def test_sim_state_instance_unchanged_during_normal_sim(split: bool) -> None:
|
|
364
375
|
sim = SplittableCountingSimulator(split_untangled_states=split)
|
|
365
376
|
state = sim._create_simulation_state(0, (q0, q1))
|
|
366
377
|
circuit = cirq.Circuit(cirq.H(q0), cirq.CNOT(q0, q1), cirq.reset(q1))
|
|
@@ -369,7 +380,7 @@ def test_sim_state_instance_unchanged_during_normal_sim(split: bool):
|
|
|
369
380
|
assert (step._merged_sim_state is not state) == split
|
|
370
381
|
|
|
371
382
|
|
|
372
|
-
def test_measurements_retained_in_step_results():
|
|
383
|
+
def test_measurements_retained_in_step_results() -> None:
|
|
373
384
|
sim = SplittableCountingSimulator()
|
|
374
385
|
circuit = cirq.Circuit(
|
|
375
386
|
cirq.measure(q0, key='a'), cirq.measure(q0, key='b'), cirq.measure(q0, key='c')
|
|
@@ -381,7 +392,7 @@ def test_measurements_retained_in_step_results():
|
|
|
381
392
|
assert not any(iterator)
|
|
382
393
|
|
|
383
394
|
|
|
384
|
-
def test_sweep_unparameterized_prefix_not_repeated_iff_unitary():
|
|
395
|
+
def test_sweep_unparameterized_prefix_not_repeated_iff_unitary() -> None:
|
|
385
396
|
q = cirq.LineQubit(0)
|
|
386
397
|
|
|
387
398
|
class TestOp(cirq.Operation):
|
|
@@ -410,6 +421,8 @@ def test_sweep_unparameterized_prefix_not_repeated_iff_unitary():
|
|
|
410
421
|
op2 = TestOp(has_unitary=True)
|
|
411
422
|
circuit = cirq.Circuit(op1, cirq.XPowGate(exponent=sympy.Symbol('a'))(q), op2)
|
|
412
423
|
rs = simulator.simulate_sweep(program=circuit, params=params)
|
|
424
|
+
assert isinstance(rs[0]._final_simulator_state, CountingSimulationState)
|
|
425
|
+
assert isinstance(rs[1]._final_simulator_state, CountingSimulationState)
|
|
413
426
|
assert rs[0]._final_simulator_state.copy_count == 1
|
|
414
427
|
assert rs[1]._final_simulator_state.copy_count == 0
|
|
415
428
|
assert op1.count == 1
|
|
@@ -419,13 +432,15 @@ def test_sweep_unparameterized_prefix_not_repeated_iff_unitary():
|
|
|
419
432
|
op2 = TestOp(has_unitary=False)
|
|
420
433
|
circuit = cirq.Circuit(op1, cirq.XPowGate(exponent=sympy.Symbol('a'))(q), op2)
|
|
421
434
|
rs = simulator.simulate_sweep(program=circuit, params=params)
|
|
435
|
+
assert isinstance(rs[0]._final_simulator_state, CountingSimulationState)
|
|
436
|
+
assert isinstance(rs[1]._final_simulator_state, CountingSimulationState)
|
|
422
437
|
assert rs[0]._final_simulator_state.copy_count == 1
|
|
423
438
|
assert rs[1]._final_simulator_state.copy_count == 0
|
|
424
439
|
assert op1.count == 2
|
|
425
440
|
assert op2.count == 2
|
|
426
441
|
|
|
427
442
|
|
|
428
|
-
def test_inhomogeneous_measurement_count_padding():
|
|
443
|
+
def test_inhomogeneous_measurement_count_padding() -> None:
|
|
429
444
|
q = cirq.LineQubit(0)
|
|
430
445
|
key = cirq.MeasurementKey('m')
|
|
431
446
|
sim = cirq.Simulator()
|
cirq/sim/simulator_test.py
CHANGED
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
from __future__ import annotations
|
|
18
18
|
|
|
19
19
|
import abc
|
|
20
|
-
from
|
|
20
|
+
from collections.abc import Iterator, Sequence
|
|
21
|
+
from typing import Any, Generic
|
|
21
22
|
from unittest import mock
|
|
22
23
|
|
|
23
24
|
import duet
|
|
@@ -56,13 +57,13 @@ class FakeStepResult(cirq.StepResult):
|
|
|
56
57
|
def _simulator_state(self):
|
|
57
58
|
return self._final_state # pragma: no cover
|
|
58
59
|
|
|
59
|
-
def state_vector(self):
|
|
60
|
+
def state_vector(self) -> None:
|
|
60
61
|
pass
|
|
61
62
|
|
|
62
63
|
def __setstate__(self, state):
|
|
63
64
|
pass
|
|
64
65
|
|
|
65
|
-
def sample(self, qubits, repetitions=1, seed=None):
|
|
66
|
+
def sample(self, qubits, repetitions=1, seed=None) -> np.ndarray:
|
|
66
67
|
return np.array([[qubit in self._ones_qubits for qubit in qubits]] * repetitions)
|
|
67
68
|
|
|
68
69
|
|
|
@@ -99,7 +100,7 @@ class SimulatesIntermediateStateImpl(
|
|
|
99
100
|
)
|
|
100
101
|
|
|
101
102
|
|
|
102
|
-
def test_run_simulator_run():
|
|
103
|
+
def test_run_simulator_run() -> None:
|
|
103
104
|
expected_records = {'a': np.array([[[1]]])}
|
|
104
105
|
simulator = FakeSimulatesSamples(expected_records)
|
|
105
106
|
circuit = cirq.Circuit(cirq.measure(cirq.LineQubit(0), key='k'))
|
|
@@ -110,7 +111,7 @@ def test_run_simulator_run():
|
|
|
110
111
|
)
|
|
111
112
|
|
|
112
113
|
|
|
113
|
-
def test_run_simulator_sweeps():
|
|
114
|
+
def test_run_simulator_sweeps() -> None:
|
|
114
115
|
expected_records = {'a': np.array([[[1]]])}
|
|
115
116
|
simulator = FakeSimulatesSamples(expected_records)
|
|
116
117
|
circuit = cirq.Circuit(cirq.measure(cirq.LineQubit(0), key='k'))
|
|
@@ -127,8 +128,8 @@ def test_run_simulator_sweeps():
|
|
|
127
128
|
@mock.patch.multiple(
|
|
128
129
|
SimulatesIntermediateStateImpl, __abstractmethods__=set(), simulate_moment_steps=mock.Mock()
|
|
129
130
|
)
|
|
130
|
-
def test_intermediate_simulator():
|
|
131
|
-
simulator = SimulatesIntermediateStateImpl()
|
|
131
|
+
def test_intermediate_simulator() -> None:
|
|
132
|
+
simulator: SimulatesIntermediateStateImpl = SimulatesIntermediateStateImpl()
|
|
132
133
|
|
|
133
134
|
final_simulator_state = np.array([1, 0, 0, 0])
|
|
134
135
|
|
|
@@ -141,7 +142,7 @@ def test_intermediate_simulator():
|
|
|
141
142
|
result._simulator_state.return_value = final_simulator_state
|
|
142
143
|
yield result
|
|
143
144
|
|
|
144
|
-
simulator.simulate_moment_steps.side_effect = steps
|
|
145
|
+
simulator.simulate_moment_steps.side_effect = steps # type: ignore[attr-defined]
|
|
145
146
|
circuit = mock.Mock(cirq.Circuit)
|
|
146
147
|
param_resolver = cirq.ParamResolver({})
|
|
147
148
|
qubit_order = mock.Mock(cirq.QubitOrder)
|
|
@@ -158,8 +159,8 @@ def test_intermediate_simulator():
|
|
|
158
159
|
@mock.patch.multiple(
|
|
159
160
|
SimulatesIntermediateStateImpl, __abstractmethods__=set(), simulate_moment_steps=mock.Mock()
|
|
160
161
|
)
|
|
161
|
-
def test_intermediate_sweeps():
|
|
162
|
-
simulator = SimulatesIntermediateStateImpl()
|
|
162
|
+
def test_intermediate_sweeps() -> None:
|
|
163
|
+
simulator: SimulatesIntermediateStateImpl = SimulatesIntermediateStateImpl()
|
|
163
164
|
|
|
164
165
|
final_state = np.array([1, 0, 0, 0])
|
|
165
166
|
|
|
@@ -169,7 +170,7 @@ def test_intermediate_sweeps():
|
|
|
169
170
|
result._simulator_state.return_value = final_state
|
|
170
171
|
yield result
|
|
171
172
|
|
|
172
|
-
simulator.simulate_moment_steps.side_effect = steps
|
|
173
|
+
simulator.simulate_moment_steps.side_effect = steps # type: ignore[attr-defined]
|
|
173
174
|
circuit = mock.Mock(cirq.Circuit)
|
|
174
175
|
param_resolvers = [cirq.ParamResolver({}), cirq.ParamResolver({})]
|
|
175
176
|
qubit_order = mock.Mock(cirq.QubitOrder)
|
|
@@ -192,7 +193,7 @@ def test_intermediate_sweeps():
|
|
|
192
193
|
assert results == expected_results
|
|
193
194
|
|
|
194
195
|
|
|
195
|
-
def test_step_sample_measurement_ops():
|
|
196
|
+
def test_step_sample_measurement_ops() -> None:
|
|
196
197
|
q0, q1, q2 = cirq.LineQubit.range(3)
|
|
197
198
|
measurement_ops = [cirq.measure(q0, q1), cirq.measure(q2)]
|
|
198
199
|
step_result = FakeStepResult(ones_qubits=[q1])
|
|
@@ -201,7 +202,7 @@ def test_step_sample_measurement_ops():
|
|
|
201
202
|
np.testing.assert_equal(measurements, {'q(0),q(1)': [[False, True]], 'q(2)': [[False]]})
|
|
202
203
|
|
|
203
204
|
|
|
204
|
-
def test_step_sample_measurement_ops_repetitions():
|
|
205
|
+
def test_step_sample_measurement_ops_repetitions() -> None:
|
|
205
206
|
q0, q1, q2 = cirq.LineQubit.range(3)
|
|
206
207
|
measurement_ops = [cirq.measure(q0, q1), cirq.measure(q2)]
|
|
207
208
|
step_result = FakeStepResult(ones_qubits=[q1])
|
|
@@ -210,7 +211,7 @@ def test_step_sample_measurement_ops_repetitions():
|
|
|
210
211
|
np.testing.assert_equal(measurements, {'q(0),q(1)': [[False, True]] * 3, 'q(2)': [[False]] * 3})
|
|
211
212
|
|
|
212
213
|
|
|
213
|
-
def test_step_sample_measurement_ops_invert_mask():
|
|
214
|
+
def test_step_sample_measurement_ops_invert_mask() -> None:
|
|
214
215
|
q0, q1, q2 = cirq.LineQubit.range(3)
|
|
215
216
|
measurement_ops = [
|
|
216
217
|
cirq.measure(q0, q1, invert_mask=(True,)),
|
|
@@ -222,9 +223,11 @@ def test_step_sample_measurement_ops_invert_mask():
|
|
|
222
223
|
np.testing.assert_equal(measurements, {'q(0),q(1)': [[True, True]], 'q(2)': [[False]]})
|
|
223
224
|
|
|
224
225
|
|
|
225
|
-
def test_step_sample_measurement_ops_confusion_map():
|
|
226
|
+
def test_step_sample_measurement_ops_confusion_map() -> None:
|
|
226
227
|
q0, q1, q2 = cirq.LineQubit.range(3)
|
|
228
|
+
cmap_01: dict[tuple[int, ...], np.ndarray]
|
|
227
229
|
cmap_01 = {(0, 1): np.array([[0, 1, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [0, 0, 1, 0]])}
|
|
230
|
+
cmap_2: dict[tuple[int, ...], np.ndarray]
|
|
228
231
|
cmap_2 = {(0,): np.array([[0, 1], [1, 0]])}
|
|
229
232
|
measurement_ops = [
|
|
230
233
|
cirq.measure(q0, q1, confusion_map=cmap_01),
|
|
@@ -236,21 +239,21 @@ def test_step_sample_measurement_ops_confusion_map():
|
|
|
236
239
|
np.testing.assert_equal(measurements, {'q(0),q(1)': [[False, True]], 'q(2)': [[False]]})
|
|
237
240
|
|
|
238
241
|
|
|
239
|
-
def test_step_sample_measurement_ops_no_measurements():
|
|
242
|
+
def test_step_sample_measurement_ops_no_measurements() -> None:
|
|
240
243
|
step_result = FakeStepResult(ones_qubits=[])
|
|
241
244
|
|
|
242
245
|
measurements = step_result.sample_measurement_ops([])
|
|
243
246
|
assert measurements == {}
|
|
244
247
|
|
|
245
248
|
|
|
246
|
-
def test_step_sample_measurement_ops_not_measurement():
|
|
249
|
+
def test_step_sample_measurement_ops_not_measurement() -> None:
|
|
247
250
|
q0 = cirq.LineQubit(0)
|
|
248
251
|
step_result = FakeStepResult(ones_qubits=[q0])
|
|
249
252
|
with pytest.raises(ValueError, match='MeasurementGate'):
|
|
250
253
|
step_result.sample_measurement_ops([cirq.X(q0)])
|
|
251
254
|
|
|
252
255
|
|
|
253
|
-
def test_step_sample_measurement_ops_repeated_qubit():
|
|
256
|
+
def test_step_sample_measurement_ops_repeated_qubit() -> None:
|
|
254
257
|
q0, q1, q2 = cirq.LineQubit.range(3)
|
|
255
258
|
step_result = FakeStepResult(ones_qubits=[q0])
|
|
256
259
|
with pytest.raises(ValueError, match=r'Measurement key q\(0\) repeated'):
|
|
@@ -259,7 +262,7 @@ def test_step_sample_measurement_ops_repeated_qubit():
|
|
|
259
262
|
)
|
|
260
263
|
|
|
261
264
|
|
|
262
|
-
def test_simulation_trial_result_equality():
|
|
265
|
+
def test_simulation_trial_result_equality() -> None:
|
|
263
266
|
eq = cirq.testing.EqualsTester()
|
|
264
267
|
eq.add_equality_group(
|
|
265
268
|
cirq.SimulationTrialResult(
|
|
@@ -290,7 +293,7 @@ def test_simulation_trial_result_equality():
|
|
|
290
293
|
)
|
|
291
294
|
|
|
292
295
|
|
|
293
|
-
def test_simulation_trial_result_repr():
|
|
296
|
+
def test_simulation_trial_result_repr() -> None:
|
|
294
297
|
assert repr(
|
|
295
298
|
cirq.SimulationTrialResult(
|
|
296
299
|
params=cirq.ParamResolver({'s': 1}),
|
|
@@ -305,7 +308,7 @@ def test_simulation_trial_result_repr():
|
|
|
305
308
|
)
|
|
306
309
|
|
|
307
310
|
|
|
308
|
-
def test_simulation_trial_result_str():
|
|
311
|
+
def test_simulation_trial_result_str() -> None:
|
|
309
312
|
assert (
|
|
310
313
|
str(
|
|
311
314
|
cirq.SimulationTrialResult(
|
|
@@ -349,7 +352,7 @@ def test_simulation_trial_result_str():
|
|
|
349
352
|
)
|
|
350
353
|
|
|
351
354
|
|
|
352
|
-
def test_pretty_print():
|
|
355
|
+
def test_pretty_print() -> None:
|
|
353
356
|
result = cirq.SimulationTrialResult(cirq.ParamResolver(), {}, np.array([1]))
|
|
354
357
|
|
|
355
358
|
# Test Jupyter console output from
|
|
@@ -371,7 +374,7 @@ def test_pretty_print():
|
|
|
371
374
|
|
|
372
375
|
|
|
373
376
|
@duet.sync
|
|
374
|
-
async def test_async_sample():
|
|
377
|
+
async def test_async_sample() -> None:
|
|
375
378
|
m = {'mock': np.array([[[0]], [[1]]])}
|
|
376
379
|
simulator = FakeSimulatesSamples(m)
|
|
377
380
|
|
|
@@ -381,16 +384,16 @@ async def test_async_sample():
|
|
|
381
384
|
np.testing.assert_equal(result.records, m)
|
|
382
385
|
|
|
383
386
|
|
|
384
|
-
def test_simulation_trial_result_qubit_map():
|
|
387
|
+
def test_simulation_trial_result_qubit_map() -> None:
|
|
385
388
|
q = cirq.LineQubit.range(2)
|
|
386
389
|
result = cirq.Simulator().simulate(cirq.Circuit([cirq.CZ(q[0], q[1])]))
|
|
387
390
|
assert result.qubit_map == {q[0]: 0, q[1]: 1}
|
|
388
391
|
|
|
389
|
-
|
|
390
|
-
assert
|
|
392
|
+
result2 = cirq.DensityMatrixSimulator().simulate(cirq.Circuit([cirq.CZ(q[0], q[1])]))
|
|
393
|
+
assert result2.qubit_map == {q[0]: 0, q[1]: 1}
|
|
391
394
|
|
|
392
395
|
|
|
393
|
-
def test_sample_repeated_measurement_keys():
|
|
396
|
+
def test_sample_repeated_measurement_keys() -> None:
|
|
394
397
|
q = cirq.LineQubit.range(2)
|
|
395
398
|
circuit = cirq.Circuit()
|
|
396
399
|
circuit.append(
|
|
@@ -408,7 +411,7 @@ def test_sample_repeated_measurement_keys():
|
|
|
408
411
|
assert len(result.records['b'][0]) == 2
|
|
409
412
|
|
|
410
413
|
|
|
411
|
-
def test_classical_controls_go_to_suffix_if_corresponding_measurement_does():
|
|
414
|
+
def test_classical_controls_go_to_suffix_if_corresponding_measurement_does() -> None:
|
|
412
415
|
subcircuit = cirq.CircuitOperation(cirq.FrozenCircuit()).with_classical_controls('a')
|
|
413
416
|
m = cirq.measure(cirq.LineQubit(0), key='a')
|
|
414
417
|
circuit = cirq.Circuit(m, subcircuit)
|
|
@@ -419,7 +422,7 @@ def test_classical_controls_go_to_suffix_if_corresponding_measurement_does():
|
|
|
419
422
|
assert suffix == circuit
|
|
420
423
|
|
|
421
424
|
|
|
422
|
-
def test_simulate_with_invert_mask():
|
|
425
|
+
def test_simulate_with_invert_mask() -> None:
|
|
423
426
|
q0, q1, q2, q3, q4 = cirq.LineQid.for_qid_shape((2, 3, 3, 3, 4))
|
|
424
427
|
c = cirq.Circuit(
|
|
425
428
|
cirq.XPowGate(dimension=2)(q0),
|
|
@@ -431,7 +434,7 @@ def test_simulate_with_invert_mask():
|
|
|
431
434
|
assert np.all(cirq.Simulator().run(c).measurements['a'] == [[0, 1, 0, 2, 3]])
|
|
432
435
|
|
|
433
436
|
|
|
434
|
-
def test_monte_carlo_on_unknown_channel():
|
|
437
|
+
def test_monte_carlo_on_unknown_channel() -> None:
|
|
435
438
|
class Reset11To00(cirq.Gate):
|
|
436
439
|
def num_qubits(self) -> int:
|
|
437
440
|
return 2
|
|
@@ -451,8 +454,10 @@ def test_monte_carlo_on_unknown_channel():
|
|
|
451
454
|
)
|
|
452
455
|
|
|
453
456
|
|
|
454
|
-
def test_iter_definitions():
|
|
455
|
-
mock_trial_result = SimulationTrialResult(
|
|
457
|
+
def test_iter_definitions() -> None:
|
|
458
|
+
mock_trial_result: SimulationTrialResult = SimulationTrialResult(
|
|
459
|
+
params=cirq.ParamResolver(), measurements={}, final_simulator_state=[]
|
|
460
|
+
)
|
|
456
461
|
|
|
457
462
|
class FakeNonIterSimulatorImpl(
|
|
458
463
|
SimulatesAmplitudes, SimulatesExpectationValues, SimulatesFinalState
|
|
@@ -495,7 +500,7 @@ def test_iter_definitions():
|
|
|
495
500
|
q0 = cirq.LineQubit(0)
|
|
496
501
|
circuit = cirq.Circuit(cirq.X(q0))
|
|
497
502
|
bitstrings = [0b0]
|
|
498
|
-
params = {}
|
|
503
|
+
params: cirq.ParamMappingType = {}
|
|
499
504
|
assert non_iter_sim.compute_amplitudes_sweep(circuit, bitstrings, params) == [[1.0]]
|
|
500
505
|
amp_iter = non_iter_sim.compute_amplitudes_sweep_iter(circuit, bitstrings, params)
|
|
501
506
|
assert next(amp_iter) == [1.0]
|
|
@@ -510,7 +515,7 @@ def test_iter_definitions():
|
|
|
510
515
|
assert next(state_iter) == mock_trial_result
|
|
511
516
|
|
|
512
517
|
|
|
513
|
-
def test_missing_iter_definitions():
|
|
518
|
+
def test_missing_iter_definitions() -> None:
|
|
514
519
|
class FakeMissingIterSimulatorImpl(
|
|
515
520
|
SimulatesAmplitudes, SimulatesExpectationValues, SimulatesFinalState
|
|
516
521
|
):
|
|
@@ -520,7 +525,7 @@ def test_missing_iter_definitions():
|
|
|
520
525
|
q0 = cirq.LineQubit(0)
|
|
521
526
|
circuit = cirq.Circuit(cirq.X(q0))
|
|
522
527
|
bitstrings = [0b0]
|
|
523
|
-
params = {}
|
|
528
|
+
params: cirq.ParamMappingType = {}
|
|
524
529
|
with pytest.raises(RecursionError):
|
|
525
530
|
missing_iter_sim.compute_amplitudes_sweep(circuit, bitstrings, params)
|
|
526
531
|
with pytest.raises(RecursionError):
|
|
@@ -541,7 +546,7 @@ def test_missing_iter_definitions():
|
|
|
541
546
|
next(state_iter)
|
|
542
547
|
|
|
543
548
|
|
|
544
|
-
def test_trial_result_initializer():
|
|
549
|
+
def test_trial_result_initializer() -> None:
|
|
545
550
|
resolver = cirq.ParamResolver()
|
|
546
551
|
state = 3
|
|
547
552
|
x = SimulationTrialResult(resolver, {}, state)
|
cirq/sim/sparse_simulator.py
CHANGED
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
|
|
17
17
|
from __future__ import annotations
|
|
18
18
|
|
|
19
|
-
from
|
|
19
|
+
from collections.abc import Iterator, Sequence
|
|
20
|
+
from typing import Any, TYPE_CHECKING
|
|
20
21
|
|
|
21
22
|
import numpy as np
|
|
22
23
|
|
|
@@ -239,7 +240,7 @@ class SparseSimulatorStep(
|
|
|
239
240
|
self._dtype = dtype
|
|
240
241
|
self._state_vector: np.ndarray | None = None
|
|
241
242
|
|
|
242
|
-
def state_vector(self, copy: bool = False):
|
|
243
|
+
def state_vector(self, copy: bool = False) -> np.ndarray:
|
|
243
244
|
"""Return the state vector at this point in the computation.
|
|
244
245
|
|
|
245
246
|
The state is returned in the computational basis with these basis
|