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
|
@@ -25,14 +25,14 @@ import sympy
|
|
|
25
25
|
import cirq
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
def test_invalid_dtype():
|
|
28
|
+
def test_invalid_dtype() -> None:
|
|
29
29
|
with pytest.raises(ValueError, match='complex'):
|
|
30
|
-
cirq.Simulator(dtype=np.int32)
|
|
30
|
+
cirq.Simulator(dtype=np.int32) # type: ignore[arg-type]
|
|
31
31
|
|
|
32
32
|
|
|
33
33
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
34
34
|
@pytest.mark.parametrize('split', [True, False])
|
|
35
|
-
def test_run_no_measurements(dtype: type[np.complexfloating], split: bool):
|
|
35
|
+
def test_run_no_measurements(dtype: type[np.complexfloating], split: bool) -> None:
|
|
36
36
|
q0, q1 = cirq.LineQubit.range(2)
|
|
37
37
|
simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
|
|
38
38
|
|
|
@@ -43,7 +43,7 @@ def test_run_no_measurements(dtype: type[np.complexfloating], split: bool):
|
|
|
43
43
|
|
|
44
44
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
45
45
|
@pytest.mark.parametrize('split', [True, False])
|
|
46
|
-
def test_run_no_results(dtype: type[np.complexfloating], split: bool):
|
|
46
|
+
def test_run_no_results(dtype: type[np.complexfloating], split: bool) -> None:
|
|
47
47
|
q0, q1 = cirq.LineQubit.range(2)
|
|
48
48
|
simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
|
|
49
49
|
|
|
@@ -54,7 +54,7 @@ def test_run_no_results(dtype: type[np.complexfloating], split: bool):
|
|
|
54
54
|
|
|
55
55
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
56
56
|
@pytest.mark.parametrize('split', [True, False])
|
|
57
|
-
def test_run_empty_circuit(dtype: type[np.complexfloating], split: bool):
|
|
57
|
+
def test_run_empty_circuit(dtype: type[np.complexfloating], split: bool) -> None:
|
|
58
58
|
simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
|
|
59
59
|
with pytest.raises(ValueError, match="no measurements"):
|
|
60
60
|
simulator.run(cirq.Circuit())
|
|
@@ -62,7 +62,7 @@ def test_run_empty_circuit(dtype: type[np.complexfloating], split: bool):
|
|
|
62
62
|
|
|
63
63
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
64
64
|
@pytest.mark.parametrize('split', [True, False])
|
|
65
|
-
def test_run_reset(dtype: type[np.complexfloating], split: bool):
|
|
65
|
+
def test_run_reset(dtype: type[np.complexfloating], split: bool) -> None:
|
|
66
66
|
q0, q1 = cirq.LineQid.for_qid_shape((2, 3))
|
|
67
67
|
simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
|
|
68
68
|
circuit = cirq.Circuit(
|
|
@@ -82,7 +82,7 @@ def test_run_reset(dtype: type[np.complexfloating], split: bool):
|
|
|
82
82
|
|
|
83
83
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
84
84
|
@pytest.mark.parametrize('split', [True, False])
|
|
85
|
-
def test_run_bit_flips(dtype: type[np.complexfloating], split: bool):
|
|
85
|
+
def test_run_bit_flips(dtype: type[np.complexfloating], split: bool) -> None:
|
|
86
86
|
q0, q1 = cirq.LineQubit.range(2)
|
|
87
87
|
simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
|
|
88
88
|
for b0 in [0, 1]:
|
|
@@ -96,7 +96,7 @@ def test_run_bit_flips(dtype: type[np.complexfloating], split: bool):
|
|
|
96
96
|
|
|
97
97
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
98
98
|
@pytest.mark.parametrize('split', [True, False])
|
|
99
|
-
def test_run_measure_at_end_no_repetitions(dtype: type[np.complexfloating], split: bool):
|
|
99
|
+
def test_run_measure_at_end_no_repetitions(dtype: type[np.complexfloating], split: bool) -> None:
|
|
100
100
|
q0, q1 = cirq.LineQubit.range(2)
|
|
101
101
|
simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
|
|
102
102
|
with mock.patch.object(simulator, '_core_iterator', wraps=simulator._core_iterator) as mock_sim:
|
|
@@ -113,7 +113,7 @@ def test_run_measure_at_end_no_repetitions(dtype: type[np.complexfloating], spli
|
|
|
113
113
|
assert mock_sim.call_count == 0
|
|
114
114
|
|
|
115
115
|
|
|
116
|
-
def test_run_repetitions_terminal_measurement_stochastic():
|
|
116
|
+
def test_run_repetitions_terminal_measurement_stochastic() -> None:
|
|
117
117
|
q = cirq.LineQubit(0)
|
|
118
118
|
c = cirq.Circuit(cirq.H(q), cirq.measure(q, key='q'))
|
|
119
119
|
results = cirq.Simulator().run(c, repetitions=10000)
|
|
@@ -122,7 +122,7 @@ def test_run_repetitions_terminal_measurement_stochastic():
|
|
|
122
122
|
|
|
123
123
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
124
124
|
@pytest.mark.parametrize('split', [True, False])
|
|
125
|
-
def test_run_repetitions_measure_at_end(dtype: type[np.complexfloating], split: bool):
|
|
125
|
+
def test_run_repetitions_measure_at_end(dtype: type[np.complexfloating], split: bool) -> None:
|
|
126
126
|
q0, q1 = cirq.LineQubit.range(2)
|
|
127
127
|
simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
|
|
128
128
|
with mock.patch.object(simulator, '_core_iterator', wraps=simulator._core_iterator) as mock_sim:
|
|
@@ -142,7 +142,7 @@ def test_run_repetitions_measure_at_end(dtype: type[np.complexfloating], split:
|
|
|
142
142
|
|
|
143
143
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
144
144
|
@pytest.mark.parametrize('split', [True, False])
|
|
145
|
-
def test_run_invert_mask_measure_not_terminal(dtype: type[np.complexfloating], split: bool):
|
|
145
|
+
def test_run_invert_mask_measure_not_terminal(dtype: type[np.complexfloating], split: bool) -> None:
|
|
146
146
|
q0, q1 = cirq.LineQubit.range(2)
|
|
147
147
|
simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
|
|
148
148
|
with mock.patch.object(simulator, '_core_iterator', wraps=simulator._core_iterator) as mock_sim:
|
|
@@ -163,7 +163,9 @@ def test_run_invert_mask_measure_not_terminal(dtype: type[np.complexfloating], s
|
|
|
163
163
|
|
|
164
164
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
165
165
|
@pytest.mark.parametrize('split', [True, False])
|
|
166
|
-
def test_run_partial_invert_mask_measure_not_terminal(
|
|
166
|
+
def test_run_partial_invert_mask_measure_not_terminal(
|
|
167
|
+
dtype: type[np.complexfloating], split: bool
|
|
168
|
+
) -> None:
|
|
167
169
|
q0, q1 = cirq.LineQubit.range(2)
|
|
168
170
|
simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
|
|
169
171
|
with mock.patch.object(simulator, '_core_iterator', wraps=simulator._core_iterator) as mock_sim:
|
|
@@ -184,7 +186,9 @@ def test_run_partial_invert_mask_measure_not_terminal(dtype: type[np.complexfloa
|
|
|
184
186
|
|
|
185
187
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
186
188
|
@pytest.mark.parametrize('split', [True, False])
|
|
187
|
-
def test_run_measurement_not_terminal_no_repetitions(
|
|
189
|
+
def test_run_measurement_not_terminal_no_repetitions(
|
|
190
|
+
dtype: type[np.complexfloating], split: bool
|
|
191
|
+
) -> None:
|
|
188
192
|
q0, q1 = cirq.LineQubit.range(2)
|
|
189
193
|
simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
|
|
190
194
|
with mock.patch.object(simulator, '_core_iterator', wraps=simulator._core_iterator) as mock_sim:
|
|
@@ -208,7 +212,9 @@ def test_run_measurement_not_terminal_no_repetitions(dtype: type[np.complexfloat
|
|
|
208
212
|
|
|
209
213
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
210
214
|
@pytest.mark.parametrize('split', [True, False])
|
|
211
|
-
def test_run_repetitions_measurement_not_terminal(
|
|
215
|
+
def test_run_repetitions_measurement_not_terminal(
|
|
216
|
+
dtype: type[np.complexfloating], split: bool
|
|
217
|
+
) -> None:
|
|
212
218
|
q0, q1 = cirq.LineQubit.range(2)
|
|
213
219
|
simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
|
|
214
220
|
with mock.patch.object(simulator, '_core_iterator', wraps=simulator._core_iterator) as mock_sim:
|
|
@@ -233,7 +239,7 @@ def test_run_repetitions_measurement_not_terminal(dtype: type[np.complexfloating
|
|
|
233
239
|
|
|
234
240
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
235
241
|
@pytest.mark.parametrize('split', [True, False])
|
|
236
|
-
def test_run_param_resolver(dtype: type[np.complexfloating], split: bool):
|
|
242
|
+
def test_run_param_resolver(dtype: type[np.complexfloating], split: bool) -> None:
|
|
237
243
|
q0, q1 = cirq.LineQubit.range(2)
|
|
238
244
|
simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
|
|
239
245
|
for b0 in [0, 1]:
|
|
@@ -252,7 +258,7 @@ def test_run_param_resolver(dtype: type[np.complexfloating], split: bool):
|
|
|
252
258
|
|
|
253
259
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
254
260
|
@pytest.mark.parametrize('split', [True, False])
|
|
255
|
-
def test_run_mixture(dtype: type[np.complexfloating], split: bool):
|
|
261
|
+
def test_run_mixture(dtype: type[np.complexfloating], split: bool) -> None:
|
|
256
262
|
q0 = cirq.LineQubit(0)
|
|
257
263
|
simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
|
|
258
264
|
circuit = cirq.Circuit(cirq.bit_flip(0.5)(q0), cirq.measure(q0))
|
|
@@ -262,7 +268,7 @@ def test_run_mixture(dtype: type[np.complexfloating], split: bool):
|
|
|
262
268
|
|
|
263
269
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
264
270
|
@pytest.mark.parametrize('split', [True, False])
|
|
265
|
-
def test_run_mixture_with_gates(dtype: type[np.complexfloating], split: bool):
|
|
271
|
+
def test_run_mixture_with_gates(dtype: type[np.complexfloating], split: bool) -> None:
|
|
266
272
|
q0 = cirq.LineQubit(0)
|
|
267
273
|
simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split, seed=23)
|
|
268
274
|
circuit = cirq.Circuit(cirq.H(q0), cirq.phase_flip(0.5)(q0), cirq.H(q0), cirq.measure(q0))
|
|
@@ -273,7 +279,7 @@ def test_run_mixture_with_gates(dtype: type[np.complexfloating], split: bool):
|
|
|
273
279
|
|
|
274
280
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
275
281
|
@pytest.mark.parametrize('split', [True, False])
|
|
276
|
-
def test_run_correlations(dtype: type[np.complexfloating], split: bool):
|
|
282
|
+
def test_run_correlations(dtype: type[np.complexfloating], split: bool) -> None:
|
|
277
283
|
q0, q1 = cirq.LineQubit.range(2)
|
|
278
284
|
simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
|
|
279
285
|
circuit = cirq.Circuit(cirq.H(q0), cirq.CNOT(q0, q1), cirq.measure(q0, q1))
|
|
@@ -285,7 +291,7 @@ def test_run_correlations(dtype: type[np.complexfloating], split: bool):
|
|
|
285
291
|
|
|
286
292
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
287
293
|
@pytest.mark.parametrize('split', [True, False])
|
|
288
|
-
def test_run_measure_multiple_qubits(dtype: type[np.complexfloating], split: bool):
|
|
294
|
+
def test_run_measure_multiple_qubits(dtype: type[np.complexfloating], split: bool) -> None:
|
|
289
295
|
q0, q1 = cirq.LineQubit.range(2)
|
|
290
296
|
simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
|
|
291
297
|
for b0 in [0, 1]:
|
|
@@ -297,7 +303,7 @@ def test_run_measure_multiple_qubits(dtype: type[np.complexfloating], split: boo
|
|
|
297
303
|
|
|
298
304
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
299
305
|
@pytest.mark.parametrize('split', [True, False])
|
|
300
|
-
def test_run_sweeps_param_resolvers(dtype: type[np.complexfloating], split: bool):
|
|
306
|
+
def test_run_sweeps_param_resolvers(dtype: type[np.complexfloating], split: bool) -> None:
|
|
301
307
|
q0, q1 = cirq.LineQubit.range(2)
|
|
302
308
|
simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
|
|
303
309
|
for b0 in [0, 1]:
|
|
@@ -323,7 +329,7 @@ def test_run_sweeps_param_resolvers(dtype: type[np.complexfloating], split: bool
|
|
|
323
329
|
|
|
324
330
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
325
331
|
@pytest.mark.parametrize('split', [True, False])
|
|
326
|
-
def test_simulate_random_unitary(dtype: type[np.complexfloating], split: bool):
|
|
332
|
+
def test_simulate_random_unitary(dtype: type[np.complexfloating], split: bool) -> None:
|
|
327
333
|
q0, q1 = cirq.LineQubit.range(2)
|
|
328
334
|
simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
|
|
329
335
|
for _ in range(10):
|
|
@@ -341,7 +347,7 @@ def test_simulate_random_unitary(dtype: type[np.complexfloating], split: bool):
|
|
|
341
347
|
|
|
342
348
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
343
349
|
@pytest.mark.parametrize('split', [True, False])
|
|
344
|
-
def test_simulate_no_circuit(dtype: type[np.complexfloating], split: bool):
|
|
350
|
+
def test_simulate_no_circuit(dtype: type[np.complexfloating], split: bool) -> None:
|
|
345
351
|
q0, q1 = cirq.LineQubit.range(2)
|
|
346
352
|
simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
|
|
347
353
|
circuit = cirq.Circuit()
|
|
@@ -352,7 +358,7 @@ def test_simulate_no_circuit(dtype: type[np.complexfloating], split: bool):
|
|
|
352
358
|
|
|
353
359
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
354
360
|
@pytest.mark.parametrize('split', [True, False])
|
|
355
|
-
def test_simulate(dtype: type[np.complexfloating], split: bool):
|
|
361
|
+
def test_simulate(dtype: type[np.complexfloating], split: bool) -> None:
|
|
356
362
|
q0, q1 = cirq.LineQubit.range(2)
|
|
357
363
|
simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
|
|
358
364
|
circuit = cirq.Circuit(cirq.H(q0), cirq.H(q1))
|
|
@@ -374,7 +380,7 @@ class _TestMixture(cirq.Gate):
|
|
|
374
380
|
|
|
375
381
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
376
382
|
@pytest.mark.parametrize('split', [True, False])
|
|
377
|
-
def test_simulate_qudits(dtype: type[np.complexfloating], split: bool):
|
|
383
|
+
def test_simulate_qudits(dtype: type[np.complexfloating], split: bool) -> None:
|
|
378
384
|
q0, q1 = cirq.LineQid.for_qid_shape((3, 4))
|
|
379
385
|
simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
|
|
380
386
|
circuit = cirq.Circuit(cirq.XPowGate(dimension=3)(q0), cirq.XPowGate(dimension=4)(q1) ** 3)
|
|
@@ -387,7 +393,7 @@ def test_simulate_qudits(dtype: type[np.complexfloating], split: bool):
|
|
|
387
393
|
|
|
388
394
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
389
395
|
@pytest.mark.parametrize('split', [True, False])
|
|
390
|
-
def test_simulate_mixtures(dtype: type[np.complexfloating], split: bool):
|
|
396
|
+
def test_simulate_mixtures(dtype: type[np.complexfloating], split: bool) -> None:
|
|
391
397
|
q0 = cirq.LineQubit(0)
|
|
392
398
|
simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
|
|
393
399
|
circuit = cirq.Circuit(cirq.bit_flip(0.5)(q0), cirq.measure(q0))
|
|
@@ -405,7 +411,7 @@ def test_simulate_mixtures(dtype: type[np.complexfloating], split: bool):
|
|
|
405
411
|
@pytest.mark.parametrize(
|
|
406
412
|
'dtype, split', itertools.product([np.complex64, np.complex128], [True, False])
|
|
407
413
|
)
|
|
408
|
-
def test_simulate_qudit_mixtures(dtype: type[np.complexfloating], split: bool):
|
|
414
|
+
def test_simulate_qudit_mixtures(dtype: type[np.complexfloating], split: bool) -> None:
|
|
409
415
|
q0 = cirq.LineQid(0, 3)
|
|
410
416
|
simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
|
|
411
417
|
mixture = _TestMixture(
|
|
@@ -431,7 +437,7 @@ def test_simulate_qudit_mixtures(dtype: type[np.complexfloating], split: bool):
|
|
|
431
437
|
|
|
432
438
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
433
439
|
@pytest.mark.parametrize('split', [True, False])
|
|
434
|
-
def test_simulate_bit_flips(dtype: type[np.complexfloating], split: bool):
|
|
440
|
+
def test_simulate_bit_flips(dtype: type[np.complexfloating], split: bool) -> None:
|
|
435
441
|
q0, q1 = cirq.LineQubit.range(2)
|
|
436
442
|
simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
|
|
437
443
|
for b0 in [0, 1]:
|
|
@@ -456,7 +462,7 @@ def test_simulate_initial_state(
|
|
|
456
462
|
dtype: type[np.complexfloating],
|
|
457
463
|
split: bool,
|
|
458
464
|
initial_state: int | cirq.StateVectorSimulationState,
|
|
459
|
-
):
|
|
465
|
+
) -> None:
|
|
460
466
|
q0, q1 = cirq.LineQubit.range(2)
|
|
461
467
|
simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
|
|
462
468
|
for b0 in [0, 1]:
|
|
@@ -470,7 +476,7 @@ def test_simulate_initial_state(
|
|
|
470
476
|
|
|
471
477
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
472
478
|
@pytest.mark.parametrize('split', [True, False])
|
|
473
|
-
def test_simulation_state(dtype: type[np.complexfloating], split: bool):
|
|
479
|
+
def test_simulation_state(dtype: type[np.complexfloating], split: bool) -> None:
|
|
474
480
|
q0, q1 = cirq.LineQubit.range(2)
|
|
475
481
|
simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
|
|
476
482
|
for b0 in [0, 1]:
|
|
@@ -485,7 +491,7 @@ def test_simulation_state(dtype: type[np.complexfloating], split: bool):
|
|
|
485
491
|
|
|
486
492
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
487
493
|
@pytest.mark.parametrize('split', [True, False])
|
|
488
|
-
def test_simulate_qubit_order(dtype: type[np.complexfloating], split: bool):
|
|
494
|
+
def test_simulate_qubit_order(dtype: type[np.complexfloating], split: bool) -> None:
|
|
489
495
|
q0, q1 = cirq.LineQubit.range(2)
|
|
490
496
|
simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
|
|
491
497
|
for b0 in [0, 1]:
|
|
@@ -499,7 +505,7 @@ def test_simulate_qubit_order(dtype: type[np.complexfloating], split: bool):
|
|
|
499
505
|
|
|
500
506
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
501
507
|
@pytest.mark.parametrize('split', [True, False])
|
|
502
|
-
def test_simulate_param_resolver(dtype: type[np.complexfloating], split: bool):
|
|
508
|
+
def test_simulate_param_resolver(dtype: type[np.complexfloating], split: bool) -> None:
|
|
503
509
|
q0, q1 = cirq.LineQubit.range(2)
|
|
504
510
|
simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
|
|
505
511
|
for b0 in [0, 1]:
|
|
@@ -518,7 +524,7 @@ def test_simulate_param_resolver(dtype: type[np.complexfloating], split: bool):
|
|
|
518
524
|
|
|
519
525
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
520
526
|
@pytest.mark.parametrize('split', [True, False])
|
|
521
|
-
def test_simulate_measure_multiple_qubits(dtype: type[np.complexfloating], split: bool):
|
|
527
|
+
def test_simulate_measure_multiple_qubits(dtype: type[np.complexfloating], split: bool) -> None:
|
|
522
528
|
q0, q1 = cirq.LineQubit.range(2)
|
|
523
529
|
simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
|
|
524
530
|
for b0 in [0, 1]:
|
|
@@ -530,7 +536,7 @@ def test_simulate_measure_multiple_qubits(dtype: type[np.complexfloating], split
|
|
|
530
536
|
|
|
531
537
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
532
538
|
@pytest.mark.parametrize('split', [True, False])
|
|
533
|
-
def test_simulate_sweeps_param_resolver(dtype: type[np.complexfloating], split: bool):
|
|
539
|
+
def test_simulate_sweeps_param_resolver(dtype: type[np.complexfloating], split: bool) -> None:
|
|
534
540
|
q0, q1 = cirq.LineQubit.range(2)
|
|
535
541
|
simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
|
|
536
542
|
for b0 in [0, 1]:
|
|
@@ -557,7 +563,7 @@ def test_simulate_sweeps_param_resolver(dtype: type[np.complexfloating], split:
|
|
|
557
563
|
|
|
558
564
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
559
565
|
@pytest.mark.parametrize('split', [True, False])
|
|
560
|
-
def test_simulate_moment_steps(dtype: type[np.complexfloating], split: bool):
|
|
566
|
+
def test_simulate_moment_steps(dtype: type[np.complexfloating], split: bool) -> None:
|
|
561
567
|
q0, q1 = cirq.LineQubit.range(2)
|
|
562
568
|
circuit = cirq.Circuit(cirq.H(q0), cirq.H(q1), cirq.H(q0), cirq.H(q1))
|
|
563
569
|
simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
|
|
@@ -570,7 +576,7 @@ def test_simulate_moment_steps(dtype: type[np.complexfloating], split: bool):
|
|
|
570
576
|
|
|
571
577
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
572
578
|
@pytest.mark.parametrize('split', [True, False])
|
|
573
|
-
def test_simulate_moment_steps_empty_circuit(dtype: type[np.complexfloating], split: bool):
|
|
579
|
+
def test_simulate_moment_steps_empty_circuit(dtype: type[np.complexfloating], split: bool) -> None:
|
|
574
580
|
circuit = cirq.Circuit()
|
|
575
581
|
simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
|
|
576
582
|
for step in simulator.simulate_moment_steps(circuit):
|
|
@@ -581,7 +587,7 @@ def test_simulate_moment_steps_empty_circuit(dtype: type[np.complexfloating], sp
|
|
|
581
587
|
|
|
582
588
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
583
589
|
@pytest.mark.parametrize('split', [True, False])
|
|
584
|
-
def test_simulate_moment_steps_sample(dtype: type[np.complexfloating], split: bool):
|
|
590
|
+
def test_simulate_moment_steps_sample(dtype: type[np.complexfloating], split: bool) -> None:
|
|
585
591
|
q0, q1 = cirq.LineQubit.range(2)
|
|
586
592
|
circuit = cirq.Circuit(cirq.H(q0), cirq.CNOT(q0, q1))
|
|
587
593
|
simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
|
|
@@ -604,7 +610,7 @@ def test_simulate_moment_steps_sample(dtype: type[np.complexfloating], split: bo
|
|
|
604
610
|
@pytest.mark.parametrize('split', [True, False])
|
|
605
611
|
def test_simulate_moment_steps_intermediate_measurement(
|
|
606
612
|
dtype: type[np.complexfloating], split: bool
|
|
607
|
-
):
|
|
613
|
+
) -> None:
|
|
608
614
|
q0 = cirq.LineQubit(0)
|
|
609
615
|
circuit = cirq.Circuit(cirq.H(q0), cirq.measure(q0), cirq.H(q0))
|
|
610
616
|
simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
|
|
@@ -621,7 +627,7 @@ def test_simulate_moment_steps_intermediate_measurement(
|
|
|
621
627
|
|
|
622
628
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
623
629
|
@pytest.mark.parametrize('split', [True, False])
|
|
624
|
-
def test_simulate_expectation_values(dtype: type[np.complexfloating], split: bool):
|
|
630
|
+
def test_simulate_expectation_values(dtype: type[np.complexfloating], split: bool) -> None:
|
|
625
631
|
# Compare with test_expectation_from_state_vector_two_qubit_states
|
|
626
632
|
# in file: cirq/ops/linear_combinations_test.py
|
|
627
633
|
q0, q1 = cirq.LineQubit.range(2)
|
|
@@ -646,7 +652,9 @@ def test_simulate_expectation_values(dtype: type[np.complexfloating], split: boo
|
|
|
646
652
|
|
|
647
653
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
648
654
|
@pytest.mark.parametrize('split', [True, False])
|
|
649
|
-
def test_simulate_expectation_values_terminal_measure(
|
|
655
|
+
def test_simulate_expectation_values_terminal_measure(
|
|
656
|
+
dtype: type[np.complexfloating], split: bool
|
|
657
|
+
) -> None:
|
|
650
658
|
q0 = cirq.LineQubit(0)
|
|
651
659
|
circuit = cirq.Circuit(cirq.H(q0), cirq.measure(q0))
|
|
652
660
|
obs = cirq.Z(q0)
|
|
@@ -684,7 +692,9 @@ def test_simulate_expectation_values_terminal_measure(dtype: type[np.complexfloa
|
|
|
684
692
|
|
|
685
693
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
686
694
|
@pytest.mark.parametrize('split', [True, False])
|
|
687
|
-
def test_simulate_expectation_values_qubit_order(
|
|
695
|
+
def test_simulate_expectation_values_qubit_order(
|
|
696
|
+
dtype: type[np.complexfloating], split: bool
|
|
697
|
+
) -> None:
|
|
688
698
|
q0, q1, q2 = cirq.LineQubit.range(3)
|
|
689
699
|
circuit = cirq.Circuit(cirq.H(q0), cirq.H(q1), cirq.X(q2))
|
|
690
700
|
obs = cirq.X(q0) + cirq.X(q1) - cirq.Z(q2)
|
|
@@ -698,7 +708,7 @@ def test_simulate_expectation_values_qubit_order(dtype: type[np.complexfloating]
|
|
|
698
708
|
assert cirq.approx_eq(result_flipped[0], 3, atol=1e-6)
|
|
699
709
|
|
|
700
710
|
|
|
701
|
-
def test_invalid_run_no_unitary():
|
|
711
|
+
def test_invalid_run_no_unitary() -> None:
|
|
702
712
|
class NoUnitary(cirq.testing.SingleQubitGate):
|
|
703
713
|
pass
|
|
704
714
|
|
|
@@ -710,7 +720,7 @@ def test_invalid_run_no_unitary():
|
|
|
710
720
|
simulator.run(circuit)
|
|
711
721
|
|
|
712
722
|
|
|
713
|
-
def test_allocates_new_state():
|
|
723
|
+
def test_allocates_new_state() -> None:
|
|
714
724
|
class NoUnitary(cirq.testing.SingleQubitGate):
|
|
715
725
|
def _has_unitary_(self):
|
|
716
726
|
return True
|
|
@@ -728,7 +738,7 @@ def test_allocates_new_state():
|
|
|
728
738
|
assert not initial_state is result.state_vector()
|
|
729
739
|
|
|
730
740
|
|
|
731
|
-
def test_does_not_modify_initial_state():
|
|
741
|
+
def test_does_not_modify_initial_state() -> None:
|
|
732
742
|
q0 = cirq.LineQubit(0)
|
|
733
743
|
simulator = cirq.Simulator()
|
|
734
744
|
|
|
@@ -753,7 +763,7 @@ def test_does_not_modify_initial_state():
|
|
|
753
763
|
)
|
|
754
764
|
|
|
755
765
|
|
|
756
|
-
def test_simulator_step_state_mixin():
|
|
766
|
+
def test_simulator_step_state_mixin() -> None:
|
|
757
767
|
qubits = cirq.LineQubit.range(2)
|
|
758
768
|
args = cirq.StateVectorSimulationState(
|
|
759
769
|
available_buffer=np.array([0, 1, 0, 0]).reshape((2, 2)),
|
|
@@ -771,7 +781,7 @@ def test_simulator_step_state_mixin():
|
|
|
771
781
|
assert result.dirac_notation() == '|01⟩'
|
|
772
782
|
|
|
773
783
|
|
|
774
|
-
def test_sparse_simulator_repr():
|
|
784
|
+
def test_sparse_simulator_repr() -> None:
|
|
775
785
|
qubits = cirq.LineQubit.range(2)
|
|
776
786
|
args = cirq.StateVectorSimulationState(
|
|
777
787
|
available_buffer=np.array([0, 1, 0, 0]).reshape((2, 2)),
|
|
@@ -795,7 +805,7 @@ class MultiHTestGate(cirq.testing.TwoQubitGate):
|
|
|
795
805
|
return cirq.H.on_each(*qubits)
|
|
796
806
|
|
|
797
807
|
|
|
798
|
-
def test_simulates_composite():
|
|
808
|
+
def test_simulates_composite() -> None:
|
|
799
809
|
c = cirq.Circuit(MultiHTestGate().on(*cirq.LineQubit.range(2)))
|
|
800
810
|
expected = np.array([0.5] * 4)
|
|
801
811
|
np.testing.assert_allclose(
|
|
@@ -804,7 +814,7 @@ def test_simulates_composite():
|
|
|
804
814
|
np.testing.assert_allclose(cirq.Simulator().simulate(c).state_vector(), expected)
|
|
805
815
|
|
|
806
816
|
|
|
807
|
-
def test_simulate_measurement_inversions():
|
|
817
|
+
def test_simulate_measurement_inversions() -> None:
|
|
808
818
|
q = cirq.NamedQubit('q')
|
|
809
819
|
|
|
810
820
|
c = cirq.Circuit(cirq.measure(q, key='q', invert_mask=(True,)))
|
|
@@ -814,7 +824,7 @@ def test_simulate_measurement_inversions():
|
|
|
814
824
|
assert cirq.Simulator().simulate(c).measurements == {'q': np.array([False])}
|
|
815
825
|
|
|
816
826
|
|
|
817
|
-
def test_works_on_pauli_string_phasor():
|
|
827
|
+
def test_works_on_pauli_string_phasor() -> None:
|
|
818
828
|
a, b = cirq.LineQubit.range(2)
|
|
819
829
|
c = cirq.Circuit(np.exp(0.5j * np.pi * cirq.X(a) * cirq.X(b)))
|
|
820
830
|
sim = cirq.Simulator()
|
|
@@ -822,7 +832,7 @@ def test_works_on_pauli_string_phasor():
|
|
|
822
832
|
np.testing.assert_allclose(result.reshape(4), np.array([0, 0, 0, 1j]), atol=1e-8)
|
|
823
833
|
|
|
824
834
|
|
|
825
|
-
def test_works_on_pauli_string():
|
|
835
|
+
def test_works_on_pauli_string() -> None:
|
|
826
836
|
a, b = cirq.LineQubit.range(2)
|
|
827
837
|
c = cirq.Circuit(cirq.X(a) * cirq.X(b))
|
|
828
838
|
sim = cirq.Simulator()
|
|
@@ -830,7 +840,7 @@ def test_works_on_pauli_string():
|
|
|
830
840
|
np.testing.assert_allclose(result.reshape(4), np.array([0, 0, 0, 1]), atol=1e-8)
|
|
831
841
|
|
|
832
842
|
|
|
833
|
-
def test_measure_at_end_invert_mask():
|
|
843
|
+
def test_measure_at_end_invert_mask() -> None:
|
|
834
844
|
simulator = cirq.Simulator()
|
|
835
845
|
a = cirq.NamedQubit('a')
|
|
836
846
|
circuit = cirq.Circuit(cirq.measure(a, key='a', invert_mask=(True,)))
|
|
@@ -838,7 +848,7 @@ def test_measure_at_end_invert_mask():
|
|
|
838
848
|
np.testing.assert_equal(result.measurements['a'], np.array([[1]] * 4))
|
|
839
849
|
|
|
840
850
|
|
|
841
|
-
def test_measure_at_end_invert_mask_multiple_qubits():
|
|
851
|
+
def test_measure_at_end_invert_mask_multiple_qubits() -> None:
|
|
842
852
|
simulator = cirq.Simulator()
|
|
843
853
|
a, b, c = cirq.LineQubit.range(3)
|
|
844
854
|
circuit = cirq.Circuit(
|
|
@@ -850,7 +860,7 @@ def test_measure_at_end_invert_mask_multiple_qubits():
|
|
|
850
860
|
np.testing.assert_equal(result.measurements['bc'], np.array([[0, 1]] * 4))
|
|
851
861
|
|
|
852
862
|
|
|
853
|
-
def test_measure_at_end_invert_mask_partial():
|
|
863
|
+
def test_measure_at_end_invert_mask_partial() -> None:
|
|
854
864
|
simulator = cirq.Simulator()
|
|
855
865
|
a, _, c = cirq.LineQubit.range(3)
|
|
856
866
|
circuit = cirq.Circuit(cirq.measure(a, c, key='ac', invert_mask=(True,)))
|
|
@@ -858,7 +868,7 @@ def test_measure_at_end_invert_mask_partial():
|
|
|
858
868
|
np.testing.assert_equal(result.measurements['ac'], np.array([[1, 0]] * 4))
|
|
859
869
|
|
|
860
870
|
|
|
861
|
-
def test_qudit_invert_mask():
|
|
871
|
+
def test_qudit_invert_mask() -> None:
|
|
862
872
|
q0, q1, q2, q3, q4 = cirq.LineQid.for_qid_shape((2, 3, 3, 3, 4))
|
|
863
873
|
c = cirq.Circuit(
|
|
864
874
|
cirq.XPowGate(dimension=2)(q0),
|
|
@@ -870,7 +880,7 @@ def test_qudit_invert_mask():
|
|
|
870
880
|
assert np.all(cirq.Simulator().run(c).measurements['a'] == [[0, 1, 0, 2, 3]])
|
|
871
881
|
|
|
872
882
|
|
|
873
|
-
def test_compute_amplitudes():
|
|
883
|
+
def test_compute_amplitudes() -> None:
|
|
874
884
|
a, b = cirq.LineQubit.range(2)
|
|
875
885
|
c = cirq.Circuit(cirq.X(a), cirq.H(a), cirq.H(b))
|
|
876
886
|
sim = cirq.Simulator()
|
|
@@ -885,16 +895,16 @@ def test_compute_amplitudes():
|
|
|
885
895
|
np.testing.assert_allclose(np.array(result), np.array([-0.5, 0.5, -0.5]))
|
|
886
896
|
|
|
887
897
|
|
|
888
|
-
def test_compute_amplitudes_bad_input():
|
|
898
|
+
def test_compute_amplitudes_bad_input() -> None:
|
|
889
899
|
a, b = cirq.LineQubit.range(2)
|
|
890
900
|
c = cirq.Circuit(cirq.X(a), cirq.H(a), cirq.H(b))
|
|
891
901
|
sim = cirq.Simulator()
|
|
892
902
|
|
|
893
903
|
with pytest.raises(ValueError, match='1-dimensional'):
|
|
894
|
-
_ = sim.compute_amplitudes(c, np.array([[0, 0]]))
|
|
904
|
+
_ = sim.compute_amplitudes(c, np.array([[0, 0]])) # type: ignore[arg-type]
|
|
895
905
|
|
|
896
906
|
|
|
897
|
-
def test_sample_from_amplitudes():
|
|
907
|
+
def test_sample_from_amplitudes() -> None:
|
|
898
908
|
q0, q1 = cirq.LineQubit.range(2)
|
|
899
909
|
circuit = cirq.Circuit(cirq.H(q0), cirq.CNOT(q0, q1), cirq.X(q1))
|
|
900
910
|
sim = cirq.Simulator(seed=1)
|
|
@@ -905,7 +915,7 @@ def test_sample_from_amplitudes():
|
|
|
905
915
|
assert 3 not in result
|
|
906
916
|
|
|
907
917
|
|
|
908
|
-
def test_sample_from_amplitudes_teleport():
|
|
918
|
+
def test_sample_from_amplitudes_teleport() -> None:
|
|
909
919
|
q0, q1, q2 = cirq.LineQubit.range(3)
|
|
910
920
|
# Initialize q0 to some state, teleport it to q2, then clean up.
|
|
911
921
|
circuit = cirq.Circuit(
|
|
@@ -936,7 +946,7 @@ def test_sample_from_amplitudes_teleport():
|
|
|
936
946
|
assert result_c[1] < 20
|
|
937
947
|
|
|
938
948
|
|
|
939
|
-
def test_sample_from_amplitudes_nonunitary_fails():
|
|
949
|
+
def test_sample_from_amplitudes_nonunitary_fails() -> None:
|
|
940
950
|
q0, q1 = cirq.LineQubit.range(2)
|
|
941
951
|
sim = cirq.Simulator(seed=1)
|
|
942
952
|
|
|
@@ -951,7 +961,7 @@ def test_sample_from_amplitudes_nonunitary_fails():
|
|
|
951
961
|
_ = sim.sample_from_amplitudes(circuit2, {}, sim._prng)
|
|
952
962
|
|
|
953
963
|
|
|
954
|
-
def test_run_sweep_parameters_not_resolved():
|
|
964
|
+
def test_run_sweep_parameters_not_resolved() -> None:
|
|
955
965
|
a = cirq.LineQubit(0)
|
|
956
966
|
simulator = cirq.Simulator()
|
|
957
967
|
circuit = cirq.Circuit(cirq.XPowGate(exponent=sympy.Symbol('a'))(a), cirq.measure(a))
|
|
@@ -959,7 +969,7 @@ def test_run_sweep_parameters_not_resolved():
|
|
|
959
969
|
_ = simulator.run_sweep(circuit, cirq.ParamResolver({}))
|
|
960
970
|
|
|
961
971
|
|
|
962
|
-
def test_simulate_sweep_parameters_not_resolved():
|
|
972
|
+
def test_simulate_sweep_parameters_not_resolved() -> None:
|
|
963
973
|
a = cirq.LineQubit(0)
|
|
964
974
|
simulator = cirq.Simulator()
|
|
965
975
|
circuit = cirq.Circuit(cirq.XPowGate(exponent=sympy.Symbol('a'))(a), cirq.measure(a))
|
|
@@ -967,7 +977,7 @@ def test_simulate_sweep_parameters_not_resolved():
|
|
|
967
977
|
_ = simulator.simulate_sweep(circuit, cirq.ParamResolver({}))
|
|
968
978
|
|
|
969
979
|
|
|
970
|
-
def test_random_seed():
|
|
980
|
+
def test_random_seed() -> None:
|
|
971
981
|
a = cirq.NamedQubit('a')
|
|
972
982
|
circuit = cirq.Circuit(cirq.X(a) ** 0.5, cirq.measure(a))
|
|
973
983
|
|
|
@@ -986,7 +996,7 @@ def test_random_seed():
|
|
|
986
996
|
)
|
|
987
997
|
|
|
988
998
|
|
|
989
|
-
def test_random_seed_does_not_modify_global_state_terminal_measurements():
|
|
999
|
+
def test_random_seed_does_not_modify_global_state_terminal_measurements() -> None:
|
|
990
1000
|
a = cirq.NamedQubit('a')
|
|
991
1001
|
circuit = cirq.Circuit(cirq.X(a) ** 0.5, cirq.measure(a))
|
|
992
1002
|
|
|
@@ -1001,7 +1011,7 @@ def test_random_seed_does_not_modify_global_state_terminal_measurements():
|
|
|
1001
1011
|
assert result1 == result2
|
|
1002
1012
|
|
|
1003
1013
|
|
|
1004
|
-
def test_random_seed_does_not_modify_global_state_non_terminal_measurements():
|
|
1014
|
+
def test_random_seed_does_not_modify_global_state_non_terminal_measurements() -> None:
|
|
1005
1015
|
a = cirq.NamedQubit('a')
|
|
1006
1016
|
circuit = cirq.Circuit(
|
|
1007
1017
|
cirq.X(a) ** 0.5, cirq.measure(a, key='a0'), cirq.X(a) ** 0.5, cirq.measure(a, key='a1')
|
|
@@ -1018,7 +1028,7 @@ def test_random_seed_does_not_modify_global_state_non_terminal_measurements():
|
|
|
1018
1028
|
assert result1 == result2
|
|
1019
1029
|
|
|
1020
1030
|
|
|
1021
|
-
def test_random_seed_does_not_modify_global_state_mixture():
|
|
1031
|
+
def test_random_seed_does_not_modify_global_state_mixture() -> None:
|
|
1022
1032
|
a = cirq.NamedQubit('a')
|
|
1023
1033
|
circuit = cirq.Circuit(cirq.depolarize(0.5).on(a), cirq.measure(a))
|
|
1024
1034
|
|
|
@@ -1033,7 +1043,7 @@ def test_random_seed_does_not_modify_global_state_mixture():
|
|
|
1033
1043
|
assert result1 == result2
|
|
1034
1044
|
|
|
1035
1045
|
|
|
1036
|
-
def test_random_seed_terminal_measurements_deterministic():
|
|
1046
|
+
def test_random_seed_terminal_measurements_deterministic() -> None:
|
|
1037
1047
|
a = cirq.NamedQubit('a')
|
|
1038
1048
|
circuit = cirq.Circuit(cirq.X(a) ** 0.5, cirq.measure(a, key='a'))
|
|
1039
1049
|
sim = cirq.Simulator(seed=1234)
|
|
@@ -1111,7 +1121,7 @@ def test_random_seed_terminal_measurements_deterministic():
|
|
|
1111
1121
|
)
|
|
1112
1122
|
|
|
1113
1123
|
|
|
1114
|
-
def test_random_seed_non_terminal_measurements_deterministic():
|
|
1124
|
+
def test_random_seed_non_terminal_measurements_deterministic() -> None:
|
|
1115
1125
|
a = cirq.NamedQubit('a')
|
|
1116
1126
|
circuit = cirq.Circuit(
|
|
1117
1127
|
cirq.X(a) ** 0.5, cirq.measure(a, key='a'), cirq.X(a) ** 0.5, cirq.measure(a, key='b')
|
|
@@ -1190,7 +1200,7 @@ def test_random_seed_non_terminal_measurements_deterministic():
|
|
|
1190
1200
|
)
|
|
1191
1201
|
|
|
1192
1202
|
|
|
1193
|
-
def test_random_seed_mixture_deterministic():
|
|
1203
|
+
def test_random_seed_mixture_deterministic() -> None:
|
|
1194
1204
|
a = cirq.NamedQubit('a')
|
|
1195
1205
|
circuit = cirq.Circuit(
|
|
1196
1206
|
cirq.depolarize(0.9).on(a),
|
|
@@ -1239,7 +1249,7 @@ def test_random_seed_mixture_deterministic():
|
|
|
1239
1249
|
)
|
|
1240
1250
|
|
|
1241
1251
|
|
|
1242
|
-
def test_entangled_reset_does_not_break_randomness():
|
|
1252
|
+
def test_entangled_reset_does_not_break_randomness() -> None:
|
|
1243
1253
|
"""Test for bad assumptions on caching the wave function on general channels.
|
|
1244
1254
|
|
|
1245
1255
|
A previous version of cirq made the mistake of assuming that it was okay to
|
|
@@ -1258,7 +1268,7 @@ def test_entangled_reset_does_not_break_randomness():
|
|
|
1258
1268
|
assert 10 <= counts[1] <= 90
|
|
1259
1269
|
|
|
1260
1270
|
|
|
1261
|
-
def test_overlapping_measurements_at_end():
|
|
1271
|
+
def test_overlapping_measurements_at_end() -> None:
|
|
1262
1272
|
a, b = cirq.LineQubit.range(2)
|
|
1263
1273
|
circuit = cirq.Circuit(
|
|
1264
1274
|
cirq.H(a),
|
|
@@ -1282,7 +1292,7 @@ def test_overlapping_measurements_at_end():
|
|
|
1282
1292
|
assert 10 <= counts[1] <= 90
|
|
1283
1293
|
|
|
1284
1294
|
|
|
1285
|
-
def test_separated_measurements():
|
|
1295
|
+
def test_separated_measurements() -> None:
|
|
1286
1296
|
a, b = cirq.LineQubit.range(2)
|
|
1287
1297
|
c = cirq.Circuit(
|
|
1288
1298
|
[
|
|
@@ -1299,7 +1309,7 @@ def test_separated_measurements():
|
|
|
1299
1309
|
np.testing.assert_array_equal(sample['zero'].values, [0] * 10)
|
|
1300
1310
|
|
|
1301
1311
|
|
|
1302
|
-
def test_state_vector_copy():
|
|
1312
|
+
def test_state_vector_copy() -> None:
|
|
1303
1313
|
sim = cirq.Simulator(split_untangled_states=False)
|
|
1304
1314
|
|
|
1305
1315
|
class InplaceGate(cirq.testing.SingleQubitGate):
|
|
@@ -1329,7 +1339,7 @@ def test_state_vector_copy():
|
|
|
1329
1339
|
assert any(not np.array_equal(x, y) for x, y in zip(vectors, copy_of_vectors))
|
|
1330
1340
|
|
|
1331
1341
|
|
|
1332
|
-
def test_final_state_vector_is_not_last_object():
|
|
1342
|
+
def test_final_state_vector_is_not_last_object() -> None:
|
|
1333
1343
|
sim = cirq.Simulator()
|
|
1334
1344
|
|
|
1335
1345
|
q = cirq.LineQubit(0)
|
|
@@ -1341,7 +1351,7 @@ def test_final_state_vector_is_not_last_object():
|
|
|
1341
1351
|
np.testing.assert_equal(result.state_vector(), initial_state)
|
|
1342
1352
|
|
|
1343
1353
|
|
|
1344
|
-
def test_deterministic_gate_noise():
|
|
1354
|
+
def test_deterministic_gate_noise() -> None:
|
|
1345
1355
|
q = cirq.LineQubit(0)
|
|
1346
1356
|
circuit = cirq.Circuit(cirq.I(q), cirq.measure(q))
|
|
1347
1357
|
|
|
@@ -1359,7 +1369,7 @@ def test_deterministic_gate_noise():
|
|
|
1359
1369
|
assert result1 != result3
|
|
1360
1370
|
|
|
1361
1371
|
|
|
1362
|
-
def test_nondeterministic_mixture_noise():
|
|
1372
|
+
def test_nondeterministic_mixture_noise() -> None:
|
|
1363
1373
|
q = cirq.LineQubit(0)
|
|
1364
1374
|
circuit = cirq.Circuit(cirq.I(q), cirq.measure(q))
|
|
1365
1375
|
|
|
@@ -1370,12 +1380,12 @@ def test_nondeterministic_mixture_noise():
|
|
|
1370
1380
|
assert result1 != result2
|
|
1371
1381
|
|
|
1372
1382
|
|
|
1373
|
-
def test_pure_state_creation():
|
|
1383
|
+
def test_pure_state_creation() -> None:
|
|
1374
1384
|
sim = cirq.Simulator()
|
|
1375
1385
|
qids = cirq.LineQubit.range(3)
|
|
1376
1386
|
shape = cirq.qid_shape(qids)
|
|
1377
1387
|
args = sim._create_simulation_state(1, qids)
|
|
1378
|
-
values = list(args.values())
|
|
1388
|
+
values = list(args.values()) # type: ignore[attr-defined]
|
|
1379
1389
|
arg = (
|
|
1380
1390
|
values[0]
|
|
1381
1391
|
.kronecker_product(values[1])
|
|
@@ -1386,7 +1396,7 @@ def test_pure_state_creation():
|
|
|
1386
1396
|
np.testing.assert_allclose(arg.target_tensor, expected.reshape(shape))
|
|
1387
1397
|
|
|
1388
1398
|
|
|
1389
|
-
def test_noise_model():
|
|
1399
|
+
def test_noise_model() -> None:
|
|
1390
1400
|
q = cirq.LineQubit(0)
|
|
1391
1401
|
circuit = cirq.Circuit(cirq.H(q), cirq.measure(q))
|
|
1392
1402
|
|
|
@@ -1397,7 +1407,7 @@ def test_noise_model():
|
|
|
1397
1407
|
assert 20 <= sum(result.measurements['q(0)'])[0] < 80
|
|
1398
1408
|
|
|
1399
1409
|
|
|
1400
|
-
def test_separated_states_str_does_not_merge():
|
|
1410
|
+
def test_separated_states_str_does_not_merge() -> None:
|
|
1401
1411
|
q0, q1 = cirq.LineQubit.range(2)
|
|
1402
1412
|
circuit = cirq.Circuit(
|
|
1403
1413
|
cirq.measure(q0), cirq.measure(q1), cirq.H(q0), cirq.global_phase_operation(0 + 1j)
|
|
@@ -1419,7 +1429,7 @@ output vector: 1j|⟩"""
|
|
|
1419
1429
|
)
|
|
1420
1430
|
|
|
1421
1431
|
|
|
1422
|
-
def test_separable_non_dirac_str():
|
|
1432
|
+
def test_separable_non_dirac_str() -> None:
|
|
1423
1433
|
circuit = cirq.Circuit()
|
|
1424
1434
|
for i in range(4):
|
|
1425
1435
|
circuit.append(cirq.H(cirq.LineQubit(i)))
|
|
@@ -1429,7 +1439,7 @@ def test_separable_non_dirac_str():
|
|
|
1429
1439
|
assert '+0.j' in str(result)
|
|
1430
1440
|
|
|
1431
1441
|
|
|
1432
|
-
def test_unseparated_states_str():
|
|
1442
|
+
def test_unseparated_states_str() -> None:
|
|
1433
1443
|
q0, q1 = cirq.LineQubit.range(2)
|
|
1434
1444
|
circuit = cirq.Circuit(
|
|
1435
1445
|
cirq.measure(q0), cirq.measure(q1), cirq.H(q0), cirq.global_phase_operation(0 + 1j)
|
|
@@ -1446,7 +1456,7 @@ output vector: 0.707j|00⟩ + 0.707j|10⟩"""
|
|
|
1446
1456
|
|
|
1447
1457
|
|
|
1448
1458
|
@pytest.mark.parametrize('split', [True, False])
|
|
1449
|
-
def test_measurement_preserves_phase(split: bool):
|
|
1459
|
+
def test_measurement_preserves_phase(split: bool) -> None:
|
|
1450
1460
|
c1, c2, t = cirq.LineQubit.range(3)
|
|
1451
1461
|
circuit = cirq.Circuit(
|
|
1452
1462
|
cirq.H(t),
|