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
|
@@ -48,14 +48,14 @@ class _TestDecomposingChannel(cirq.Gate):
|
|
|
48
48
|
return [chan.on(q) for chan, q in zip(self.channels, qubits)]
|
|
49
49
|
|
|
50
50
|
|
|
51
|
-
def test_invalid_dtype():
|
|
51
|
+
def test_invalid_dtype() -> None:
|
|
52
52
|
with pytest.raises(ValueError, match='complex'):
|
|
53
|
-
cirq.DensityMatrixSimulator(dtype=np.int32)
|
|
53
|
+
cirq.DensityMatrixSimulator(dtype=np.int32) # type: ignore[arg-type]
|
|
54
54
|
|
|
55
55
|
|
|
56
56
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
57
57
|
@pytest.mark.parametrize('split', [True, False])
|
|
58
|
-
def test_run_no_measurements(dtype: type[np.complexfloating], split: bool):
|
|
58
|
+
def test_run_no_measurements(dtype: type[np.complexfloating], split: bool) -> None:
|
|
59
59
|
q0, q1 = cirq.LineQubit.range(2)
|
|
60
60
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
61
61
|
|
|
@@ -66,7 +66,7 @@ def test_run_no_measurements(dtype: type[np.complexfloating], split: bool):
|
|
|
66
66
|
|
|
67
67
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
68
68
|
@pytest.mark.parametrize('split', [True, False])
|
|
69
|
-
def test_run_no_results(dtype: type[np.complexfloating], split: bool):
|
|
69
|
+
def test_run_no_results(dtype: type[np.complexfloating], split: bool) -> None:
|
|
70
70
|
q0, q1 = cirq.LineQubit.range(2)
|
|
71
71
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
72
72
|
|
|
@@ -77,7 +77,7 @@ def test_run_no_results(dtype: type[np.complexfloating], split: bool):
|
|
|
77
77
|
|
|
78
78
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
79
79
|
@pytest.mark.parametrize('split', [True, False])
|
|
80
|
-
def test_run_empty_circuit(dtype: type[np.complexfloating], split: bool):
|
|
80
|
+
def test_run_empty_circuit(dtype: type[np.complexfloating], split: bool) -> None:
|
|
81
81
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
82
82
|
with pytest.raises(ValueError, match="no measurements"):
|
|
83
83
|
simulator.run(cirq.Circuit())
|
|
@@ -85,7 +85,7 @@ def test_run_empty_circuit(dtype: type[np.complexfloating], split: bool):
|
|
|
85
85
|
|
|
86
86
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
87
87
|
@pytest.mark.parametrize('split', [True, False])
|
|
88
|
-
def test_run_bit_flips(dtype: type[np.complexfloating], split: bool):
|
|
88
|
+
def test_run_bit_flips(dtype: type[np.complexfloating], split: bool) -> None:
|
|
89
89
|
q0, q1 = cirq.LineQubit.range(2)
|
|
90
90
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
91
91
|
for b0 in [0, 1]:
|
|
@@ -99,7 +99,7 @@ def test_run_bit_flips(dtype: type[np.complexfloating], split: bool):
|
|
|
99
99
|
|
|
100
100
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
101
101
|
@pytest.mark.parametrize('split', [True, False])
|
|
102
|
-
def test_run_bit_flips_with_dephasing(dtype: type[np.complexfloating], split: bool):
|
|
102
|
+
def test_run_bit_flips_with_dephasing(dtype: type[np.complexfloating], split: bool) -> None:
|
|
103
103
|
q0, q1 = cirq.LineQubit.range(2)
|
|
104
104
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
105
105
|
for b0 in [0, 1]:
|
|
@@ -113,7 +113,7 @@ def test_run_bit_flips_with_dephasing(dtype: type[np.complexfloating], split: bo
|
|
|
113
113
|
|
|
114
114
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
115
115
|
@pytest.mark.parametrize('split', [True, False])
|
|
116
|
-
def test_run_qudit_increments(dtype: type[np.complexfloating], split: bool):
|
|
116
|
+
def test_run_qudit_increments(dtype: type[np.complexfloating], split: bool) -> None:
|
|
117
117
|
q0, q1 = cirq.LineQid.for_qid_shape((3, 4))
|
|
118
118
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
119
119
|
for b0 in [0, 1, 2]:
|
|
@@ -132,7 +132,7 @@ def test_run_qudit_increments(dtype: type[np.complexfloating], split: bool):
|
|
|
132
132
|
|
|
133
133
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
134
134
|
@pytest.mark.parametrize('split', [True, False])
|
|
135
|
-
def test_run_not_channel_op(dtype: type[np.complexfloating], split: bool):
|
|
135
|
+
def test_run_not_channel_op(dtype: type[np.complexfloating], split: bool) -> None:
|
|
136
136
|
class BadOp(cirq.Operation):
|
|
137
137
|
def __init__(self, qubits):
|
|
138
138
|
self._qubits = qubits
|
|
@@ -153,7 +153,7 @@ def test_run_not_channel_op(dtype: type[np.complexfloating], split: bool):
|
|
|
153
153
|
|
|
154
154
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
155
155
|
@pytest.mark.parametrize('split', [True, False])
|
|
156
|
-
def test_run_mixture(dtype: type[np.complexfloating], split: bool):
|
|
156
|
+
def test_run_mixture(dtype: type[np.complexfloating], split: bool) -> None:
|
|
157
157
|
q0, q1 = cirq.LineQubit.range(2)
|
|
158
158
|
circuit = cirq.Circuit(cirq.bit_flip(0.5)(q0), cirq.measure(q0), cirq.measure(q1))
|
|
159
159
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
@@ -167,7 +167,7 @@ def test_run_mixture(dtype: type[np.complexfloating], split: bool):
|
|
|
167
167
|
|
|
168
168
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
169
169
|
@pytest.mark.parametrize('split', [True, False])
|
|
170
|
-
def test_run_qudit_mixture(dtype: type[np.complexfloating], split: bool):
|
|
170
|
+
def test_run_qudit_mixture(dtype: type[np.complexfloating], split: bool) -> None:
|
|
171
171
|
q0, q1 = cirq.LineQid.for_qid_shape((3, 2))
|
|
172
172
|
mixture = _TestMixture(
|
|
173
173
|
[
|
|
@@ -188,7 +188,7 @@ def test_run_qudit_mixture(dtype: type[np.complexfloating], split: bool):
|
|
|
188
188
|
|
|
189
189
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
190
190
|
@pytest.mark.parametrize('split', [True, False])
|
|
191
|
-
def test_run_channel(dtype: type[np.complexfloating], split: bool):
|
|
191
|
+
def test_run_channel(dtype: type[np.complexfloating], split: bool) -> None:
|
|
192
192
|
q0, q1 = cirq.LineQubit.range(2)
|
|
193
193
|
circuit = cirq.Circuit(
|
|
194
194
|
cirq.X(q0), cirq.amplitude_damp(0.5)(q0), cirq.measure(q0), cirq.measure(q1)
|
|
@@ -205,7 +205,7 @@ def test_run_channel(dtype: type[np.complexfloating], split: bool):
|
|
|
205
205
|
|
|
206
206
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
207
207
|
@pytest.mark.parametrize('split', [True, False])
|
|
208
|
-
def test_run_decomposable_channel(dtype: type[np.complexfloating], split: bool):
|
|
208
|
+
def test_run_decomposable_channel(dtype: type[np.complexfloating], split: bool) -> None:
|
|
209
209
|
q0, q1 = cirq.LineQubit.range(2)
|
|
210
210
|
|
|
211
211
|
circuit = cirq.Circuit(
|
|
@@ -226,7 +226,7 @@ def test_run_decomposable_channel(dtype: type[np.complexfloating], split: bool):
|
|
|
226
226
|
|
|
227
227
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
228
228
|
@pytest.mark.parametrize('split', [True, False])
|
|
229
|
-
def test_run_qudit_channel(dtype: type[np.complexfloating], split: bool):
|
|
229
|
+
def test_run_qudit_channel(dtype: type[np.complexfloating], split: bool) -> None:
|
|
230
230
|
class TestChannel(cirq.Gate):
|
|
231
231
|
def _qid_shape_(self):
|
|
232
232
|
return (3,)
|
|
@@ -258,7 +258,7 @@ def test_run_qudit_channel(dtype: type[np.complexfloating], split: bool):
|
|
|
258
258
|
|
|
259
259
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
260
260
|
@pytest.mark.parametrize('split', [True, False])
|
|
261
|
-
def test_run_measure_at_end_no_repetitions(dtype: type[np.complexfloating], split: bool):
|
|
261
|
+
def test_run_measure_at_end_no_repetitions(dtype: type[np.complexfloating], split: bool) -> None:
|
|
262
262
|
q0, q1 = cirq.LineQubit.range(2)
|
|
263
263
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
264
264
|
with mock.patch.object(simulator, '_core_iterator', wraps=simulator._core_iterator) as mock_sim:
|
|
@@ -277,7 +277,7 @@ def test_run_measure_at_end_no_repetitions(dtype: type[np.complexfloating], spli
|
|
|
277
277
|
|
|
278
278
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
279
279
|
@pytest.mark.parametrize('split', [True, False])
|
|
280
|
-
def test_run_repetitions_measure_at_end(dtype: type[np.complexfloating], split: bool):
|
|
280
|
+
def test_run_repetitions_measure_at_end(dtype: type[np.complexfloating], split: bool) -> None:
|
|
281
281
|
q0, q1 = cirq.LineQubit.range(2)
|
|
282
282
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
283
283
|
with mock.patch.object(simulator, '_core_iterator', wraps=simulator._core_iterator) as mock_sim:
|
|
@@ -296,7 +296,9 @@ def test_run_repetitions_measure_at_end(dtype: type[np.complexfloating], split:
|
|
|
296
296
|
|
|
297
297
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
298
298
|
@pytest.mark.parametrize('split', [True, False])
|
|
299
|
-
def test_run_qudits_repetitions_measure_at_end(
|
|
299
|
+
def test_run_qudits_repetitions_measure_at_end(
|
|
300
|
+
dtype: type[np.complexfloating], split: bool
|
|
301
|
+
) -> None:
|
|
300
302
|
q0, q1 = cirq.LineQid.for_qid_shape((2, 3))
|
|
301
303
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
302
304
|
with mock.patch.object(simulator, '_core_iterator', wraps=simulator._core_iterator) as mock_sim:
|
|
@@ -318,7 +320,9 @@ def test_run_qudits_repetitions_measure_at_end(dtype: type[np.complexfloating],
|
|
|
318
320
|
|
|
319
321
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
320
322
|
@pytest.mark.parametrize('split', [True, False])
|
|
321
|
-
def test_run_measurement_not_terminal_no_repetitions(
|
|
323
|
+
def test_run_measurement_not_terminal_no_repetitions(
|
|
324
|
+
dtype: type[np.complexfloating], split: bool
|
|
325
|
+
) -> None:
|
|
322
326
|
q0, q1 = cirq.LineQubit.range(2)
|
|
323
327
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
324
328
|
with mock.patch.object(simulator, '_core_iterator', wraps=simulator._core_iterator) as mock_sim:
|
|
@@ -342,7 +346,9 @@ def test_run_measurement_not_terminal_no_repetitions(dtype: type[np.complexfloat
|
|
|
342
346
|
|
|
343
347
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
344
348
|
@pytest.mark.parametrize('split', [True, False])
|
|
345
|
-
def test_run_repetitions_measurement_not_terminal(
|
|
349
|
+
def test_run_repetitions_measurement_not_terminal(
|
|
350
|
+
dtype: type[np.complexfloating], split: bool
|
|
351
|
+
) -> None:
|
|
346
352
|
q0, q1 = cirq.LineQubit.range(2)
|
|
347
353
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
348
354
|
with mock.patch.object(simulator, '_core_iterator', wraps=simulator._core_iterator) as mock_sim:
|
|
@@ -368,7 +374,7 @@ def test_run_repetitions_measurement_not_terminal(dtype: type[np.complexfloating
|
|
|
368
374
|
@pytest.mark.parametrize('split', [True, False])
|
|
369
375
|
def test_run_qudits_repetitions_measurement_not_terminal(
|
|
370
376
|
dtype: type[np.complexfloating], split: bool
|
|
371
|
-
):
|
|
377
|
+
) -> None:
|
|
372
378
|
q0, q1 = cirq.LineQid.for_qid_shape((2, 3))
|
|
373
379
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
374
380
|
with mock.patch.object(simulator, '_core_iterator', wraps=simulator._core_iterator) as mock_sim:
|
|
@@ -392,7 +398,7 @@ def test_run_qudits_repetitions_measurement_not_terminal(
|
|
|
392
398
|
|
|
393
399
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
394
400
|
@pytest.mark.parametrize('split', [True, False])
|
|
395
|
-
def test_run_param_resolver(dtype: type[np.complexfloating], split: bool):
|
|
401
|
+
def test_run_param_resolver(dtype: type[np.complexfloating], split: bool) -> None:
|
|
396
402
|
q0, q1 = cirq.LineQubit.range(2)
|
|
397
403
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
398
404
|
for b0 in [0, 1]:
|
|
@@ -411,7 +417,7 @@ def test_run_param_resolver(dtype: type[np.complexfloating], split: bool):
|
|
|
411
417
|
|
|
412
418
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
413
419
|
@pytest.mark.parametrize('split', [True, False])
|
|
414
|
-
def test_run_correlations(dtype: type[np.complexfloating], split: bool):
|
|
420
|
+
def test_run_correlations(dtype: type[np.complexfloating], split: bool) -> None:
|
|
415
421
|
q0, q1 = cirq.LineQubit.range(2)
|
|
416
422
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
417
423
|
circuit = cirq.Circuit(cirq.H(q0), cirq.CNOT(q0, q1), cirq.measure(q0, q1))
|
|
@@ -423,7 +429,7 @@ def test_run_correlations(dtype: type[np.complexfloating], split: bool):
|
|
|
423
429
|
|
|
424
430
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
425
431
|
@pytest.mark.parametrize('split', [True, False])
|
|
426
|
-
def test_run_measure_multiple_qubits(dtype: type[np.complexfloating], split: bool):
|
|
432
|
+
def test_run_measure_multiple_qubits(dtype: type[np.complexfloating], split: bool) -> None:
|
|
427
433
|
q0, q1 = cirq.LineQubit.range(2)
|
|
428
434
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
429
435
|
for b0 in [0, 1]:
|
|
@@ -435,7 +441,7 @@ def test_run_measure_multiple_qubits(dtype: type[np.complexfloating], split: boo
|
|
|
435
441
|
|
|
436
442
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
437
443
|
@pytest.mark.parametrize('split', [True, False])
|
|
438
|
-
def test_run_measure_multiple_qudits(dtype: type[np.complexfloating], split: bool):
|
|
444
|
+
def test_run_measure_multiple_qudits(dtype: type[np.complexfloating], split: bool) -> None:
|
|
439
445
|
q0, q1 = cirq.LineQid.for_qid_shape((2, 3))
|
|
440
446
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
441
447
|
for b0 in [0, 1]:
|
|
@@ -449,7 +455,7 @@ def test_run_measure_multiple_qudits(dtype: type[np.complexfloating], split: boo
|
|
|
449
455
|
|
|
450
456
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
451
457
|
@pytest.mark.parametrize('split', [True, False])
|
|
452
|
-
def test_run_sweeps_param_resolvers(dtype: type[np.complexfloating], split: bool):
|
|
458
|
+
def test_run_sweeps_param_resolvers(dtype: type[np.complexfloating], split: bool) -> None:
|
|
453
459
|
q0, q1 = cirq.LineQubit.range(2)
|
|
454
460
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
455
461
|
for b0 in [0, 1]:
|
|
@@ -475,7 +481,7 @@ def test_run_sweeps_param_resolvers(dtype: type[np.complexfloating], split: bool
|
|
|
475
481
|
|
|
476
482
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
477
483
|
@pytest.mark.parametrize('split', [True, False])
|
|
478
|
-
def test_simulate_no_circuit(dtype: type[np.complexfloating], split: bool):
|
|
484
|
+
def test_simulate_no_circuit(dtype: type[np.complexfloating], split: bool) -> None:
|
|
479
485
|
q0, q1 = cirq.LineQubit.range(2)
|
|
480
486
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
481
487
|
circuit = cirq.Circuit()
|
|
@@ -488,7 +494,7 @@ def test_simulate_no_circuit(dtype: type[np.complexfloating], split: bool):
|
|
|
488
494
|
|
|
489
495
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
490
496
|
@pytest.mark.parametrize('split', [True, False])
|
|
491
|
-
def test_simulate(dtype: type[np.complexfloating], split: bool):
|
|
497
|
+
def test_simulate(dtype: type[np.complexfloating], split: bool) -> None:
|
|
492
498
|
q0, q1 = cirq.LineQubit.range(2)
|
|
493
499
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
494
500
|
circuit = cirq.Circuit(cirq.H(q0), cirq.H(q1))
|
|
@@ -499,7 +505,7 @@ def test_simulate(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_qudits(dtype: type[np.complexfloating], split: bool):
|
|
508
|
+
def test_simulate_qudits(dtype: type[np.complexfloating], split: bool) -> None:
|
|
503
509
|
q0, q1 = cirq.LineQid.for_qid_shape((2, 3))
|
|
504
510
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
505
511
|
circuit = cirq.Circuit(cirq.H(q0), cirq.XPowGate(dimension=3)(q1) ** 2)
|
|
@@ -514,7 +520,7 @@ def test_simulate_qudits(dtype: type[np.complexfloating], split: bool):
|
|
|
514
520
|
@pytest.mark.parametrize('split', [True, False])
|
|
515
521
|
def test_reset_one_qubit_does_not_affect_partial_trace_of_other_qubits(
|
|
516
522
|
dtype: type[np.complexfloating], split: bool
|
|
517
|
-
):
|
|
523
|
+
) -> None:
|
|
518
524
|
q0, q1 = cirq.LineQubit.range(2)
|
|
519
525
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
520
526
|
circuit = cirq.Circuit(cirq.H(q0), cirq.CX(q0, q1), cirq.reset(q0))
|
|
@@ -532,7 +538,9 @@ def test_reset_one_qubit_does_not_affect_partial_trace_of_other_qubits(
|
|
|
532
538
|
[cirq.testing.random_circuit(cirq.LineQubit.range(4), 5, 0.9) for _ in range(20)],
|
|
533
539
|
),
|
|
534
540
|
)
|
|
535
|
-
def test_simulate_compare_to_state_vector_simulator(
|
|
541
|
+
def test_simulate_compare_to_state_vector_simulator(
|
|
542
|
+
dtype: type[np.complexfloating], circuit
|
|
543
|
+
) -> None:
|
|
536
544
|
qubits = cirq.LineQubit.range(4)
|
|
537
545
|
pure_result = (
|
|
538
546
|
cirq.Simulator(dtype=dtype).simulate(circuit, qubit_order=qubits).density_matrix_of()
|
|
@@ -548,7 +556,7 @@ def test_simulate_compare_to_state_vector_simulator(dtype: type[np.complexfloati
|
|
|
548
556
|
|
|
549
557
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
550
558
|
@pytest.mark.parametrize('split', [True, False])
|
|
551
|
-
def test_simulate_bit_flips(dtype: type[np.complexfloating], split: bool):
|
|
559
|
+
def test_simulate_bit_flips(dtype: type[np.complexfloating], split: bool) -> None:
|
|
552
560
|
q0, q1 = cirq.LineQubit.range(2)
|
|
553
561
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
554
562
|
for b0 in [0, 1]:
|
|
@@ -565,7 +573,7 @@ def test_simulate_bit_flips(dtype: type[np.complexfloating], split: bool):
|
|
|
565
573
|
|
|
566
574
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
567
575
|
@pytest.mark.parametrize('split', [True, False])
|
|
568
|
-
def test_simulate_qudit_increments(dtype: type[np.complexfloating], split: bool):
|
|
576
|
+
def test_simulate_qudit_increments(dtype: type[np.complexfloating], split: bool) -> None:
|
|
569
577
|
q0, q1 = cirq.LineQid.for_qid_shape((2, 3))
|
|
570
578
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
571
579
|
for b0 in [0, 1]:
|
|
@@ -593,7 +601,7 @@ def test_simulate_initial_state(
|
|
|
593
601
|
dtype: type[np.complexfloating],
|
|
594
602
|
split: bool,
|
|
595
603
|
initial_state: int | cirq.DensityMatrixSimulationState,
|
|
596
|
-
):
|
|
604
|
+
) -> None:
|
|
597
605
|
q0, q1 = cirq.LineQubit.range(2)
|
|
598
606
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
599
607
|
for b0 in [0, 1]:
|
|
@@ -607,7 +615,7 @@ def test_simulate_initial_state(
|
|
|
607
615
|
|
|
608
616
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
609
617
|
@pytest.mark.parametrize('split', [True, False])
|
|
610
|
-
def test_simulation_state(dtype: type[np.complexfloating], split: bool):
|
|
618
|
+
def test_simulation_state(dtype: type[np.complexfloating], split: bool) -> None:
|
|
611
619
|
q0, q1 = cirq.LineQubit.range(2)
|
|
612
620
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
613
621
|
for b0 in [0, 1]:
|
|
@@ -620,7 +628,7 @@ def test_simulation_state(dtype: type[np.complexfloating], split: bool):
|
|
|
620
628
|
np.testing.assert_equal(result.final_density_matrix, expected_density_matrix)
|
|
621
629
|
|
|
622
630
|
|
|
623
|
-
def test_simulate_tps_initial_state():
|
|
631
|
+
def test_simulate_tps_initial_state() -> None:
|
|
624
632
|
q0, q1 = cirq.LineQubit.range(2)
|
|
625
633
|
simulator = cirq.DensityMatrixSimulator()
|
|
626
634
|
for b0 in [0, 1]:
|
|
@@ -634,7 +642,7 @@ def test_simulate_tps_initial_state():
|
|
|
634
642
|
|
|
635
643
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
636
644
|
@pytest.mark.parametrize('split', [True, False])
|
|
637
|
-
def test_simulate_initial_qudit_state(dtype: type[np.complexfloating], split: bool):
|
|
645
|
+
def test_simulate_initial_qudit_state(dtype: type[np.complexfloating], split: bool) -> None:
|
|
638
646
|
q0, q1 = cirq.LineQid.for_qid_shape((3, 4))
|
|
639
647
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
640
648
|
for b0 in [0, 1, 2]:
|
|
@@ -654,7 +662,7 @@ def test_simulate_initial_qudit_state(dtype: type[np.complexfloating], split: bo
|
|
|
654
662
|
|
|
655
663
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
656
664
|
@pytest.mark.parametrize('split', [True, False])
|
|
657
|
-
def test_simulate_qubit_order(dtype: type[np.complexfloating], split: bool):
|
|
665
|
+
def test_simulate_qubit_order(dtype: type[np.complexfloating], split: bool) -> None:
|
|
658
666
|
q0, q1 = cirq.LineQubit.range(2)
|
|
659
667
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
660
668
|
for b0 in [0, 1]:
|
|
@@ -668,7 +676,7 @@ def test_simulate_qubit_order(dtype: type[np.complexfloating], split: bool):
|
|
|
668
676
|
|
|
669
677
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
670
678
|
@pytest.mark.parametrize('split', [True, False])
|
|
671
|
-
def test_simulate_param_resolver(dtype: type[np.complexfloating], split: bool):
|
|
679
|
+
def test_simulate_param_resolver(dtype: type[np.complexfloating], split: bool) -> None:
|
|
672
680
|
q0, q1 = cirq.LineQubit.range(2)
|
|
673
681
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
674
682
|
for b0 in [0, 1]:
|
|
@@ -687,7 +695,7 @@ def test_simulate_param_resolver(dtype: type[np.complexfloating], split: bool):
|
|
|
687
695
|
|
|
688
696
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
689
697
|
@pytest.mark.parametrize('split', [True, False])
|
|
690
|
-
def test_simulate_measure_multiple_qubits(dtype: type[np.complexfloating], split: bool):
|
|
698
|
+
def test_simulate_measure_multiple_qubits(dtype: type[np.complexfloating], split: bool) -> None:
|
|
691
699
|
q0, q1 = cirq.LineQubit.range(2)
|
|
692
700
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
693
701
|
for b0 in [0, 1]:
|
|
@@ -699,7 +707,7 @@ def test_simulate_measure_multiple_qubits(dtype: type[np.complexfloating], split
|
|
|
699
707
|
|
|
700
708
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
701
709
|
@pytest.mark.parametrize('split', [True, False])
|
|
702
|
-
def test_simulate_measure_multiple_qudits(dtype: type[np.complexfloating], split: bool):
|
|
710
|
+
def test_simulate_measure_multiple_qudits(dtype: type[np.complexfloating], split: bool) -> None:
|
|
703
711
|
q0, q1 = cirq.LineQid.for_qid_shape((2, 3))
|
|
704
712
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
705
713
|
for b0 in [0, 1]:
|
|
@@ -713,7 +721,7 @@ def test_simulate_measure_multiple_qudits(dtype: type[np.complexfloating], split
|
|
|
713
721
|
|
|
714
722
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
715
723
|
@pytest.mark.parametrize('split', [True, False])
|
|
716
|
-
def test_simulate_sweeps_param_resolver(dtype: type[np.complexfloating], split: bool):
|
|
724
|
+
def test_simulate_sweeps_param_resolver(dtype: type[np.complexfloating], split: bool) -> None:
|
|
717
725
|
q0, q1 = cirq.LineQubit.range(2)
|
|
718
726
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
719
727
|
for b0 in [0, 1]:
|
|
@@ -740,7 +748,7 @@ def test_simulate_sweeps_param_resolver(dtype: type[np.complexfloating], split:
|
|
|
740
748
|
|
|
741
749
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
742
750
|
@pytest.mark.parametrize('split', [True, False])
|
|
743
|
-
def test_simulate_moment_steps(dtype: type[np.complexfloating], split: bool):
|
|
751
|
+
def test_simulate_moment_steps(dtype: type[np.complexfloating], split: bool) -> None:
|
|
744
752
|
q0, q1 = cirq.LineQubit.range(2)
|
|
745
753
|
circuit = cirq.Circuit(cirq.H(q0), cirq.H(q1), cirq.H(q0), cirq.H(q1))
|
|
746
754
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
@@ -754,7 +762,7 @@ def test_simulate_moment_steps(dtype: type[np.complexfloating], split: bool):
|
|
|
754
762
|
|
|
755
763
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
756
764
|
@pytest.mark.parametrize('split', [True, False])
|
|
757
|
-
def test_simulate_moment_steps_qudits(dtype: type[np.complexfloating], split: bool):
|
|
765
|
+
def test_simulate_moment_steps_qudits(dtype: type[np.complexfloating], split: bool) -> None:
|
|
758
766
|
q0, q1 = cirq.LineQid.for_qid_shape((2, 3))
|
|
759
767
|
circuit = cirq.Circuit(
|
|
760
768
|
cirq.XPowGate(dimension=2)(q0),
|
|
@@ -775,7 +783,7 @@ def test_simulate_moment_steps_qudits(dtype: type[np.complexfloating], split: bo
|
|
|
775
783
|
|
|
776
784
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
777
785
|
@pytest.mark.parametrize('split', [True, False])
|
|
778
|
-
def test_simulate_moment_steps_empty_circuit(dtype: type[np.complexfloating], split: bool):
|
|
786
|
+
def test_simulate_moment_steps_empty_circuit(dtype: type[np.complexfloating], split: bool) -> None:
|
|
779
787
|
circuit = cirq.Circuit()
|
|
780
788
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
781
789
|
for step in simulator.simulate_moment_steps(circuit):
|
|
@@ -786,7 +794,7 @@ def test_simulate_moment_steps_empty_circuit(dtype: type[np.complexfloating], sp
|
|
|
786
794
|
|
|
787
795
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
788
796
|
@pytest.mark.parametrize('split', [True, False])
|
|
789
|
-
def test_simulate_moment_steps_sample(dtype: type[np.complexfloating], split: bool):
|
|
797
|
+
def test_simulate_moment_steps_sample(dtype: type[np.complexfloating], split: bool) -> None:
|
|
790
798
|
q0, q1 = cirq.LineQubit.range(2)
|
|
791
799
|
circuit = cirq.Circuit(cirq.H(q0), cirq.CNOT(q0, q1))
|
|
792
800
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
@@ -807,7 +815,7 @@ def test_simulate_moment_steps_sample(dtype: type[np.complexfloating], split: bo
|
|
|
807
815
|
|
|
808
816
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
809
817
|
@pytest.mark.parametrize('split', [True, False])
|
|
810
|
-
def test_simulate_moment_steps_sample_qudits(dtype: type[np.complexfloating], split: bool):
|
|
818
|
+
def test_simulate_moment_steps_sample_qudits(dtype: type[np.complexfloating], split: bool) -> None:
|
|
811
819
|
class TestGate(cirq.Gate):
|
|
812
820
|
"""Swaps the 2nd qid |0> and |2> states when the 1st is |1>."""
|
|
813
821
|
|
|
@@ -838,7 +846,7 @@ def test_simulate_moment_steps_sample_qudits(dtype: type[np.complexfloating], sp
|
|
|
838
846
|
@pytest.mark.parametrize('split', [True, False])
|
|
839
847
|
def test_simulate_moment_steps_intermediate_measurement(
|
|
840
848
|
dtype: type[np.complexfloating], split: bool
|
|
841
|
-
):
|
|
849
|
+
) -> None:
|
|
842
850
|
q0 = cirq.LineQubit(0)
|
|
843
851
|
circuit = cirq.Circuit(cirq.H(q0), cirq.measure(q0), cirq.H(q0))
|
|
844
852
|
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
|
|
@@ -854,7 +862,7 @@ def test_simulate_moment_steps_intermediate_measurement(
|
|
|
854
862
|
|
|
855
863
|
|
|
856
864
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
857
|
-
def test_simulate_expectation_values(dtype):
|
|
865
|
+
def test_simulate_expectation_values(dtype) -> None:
|
|
858
866
|
# Compare with test_expectation_from_state_vector_two_qubit_states
|
|
859
867
|
# in file: cirq/ops/linear_combinations_test.py
|
|
860
868
|
q0, q1 = cirq.LineQubit.range(2)
|
|
@@ -878,7 +886,7 @@ def test_simulate_expectation_values(dtype):
|
|
|
878
886
|
|
|
879
887
|
|
|
880
888
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
881
|
-
def test_simulate_noisy_expectation_values(dtype):
|
|
889
|
+
def test_simulate_noisy_expectation_values(dtype) -> None:
|
|
882
890
|
q0 = cirq.LineQubit(0)
|
|
883
891
|
psums = [cirq.Z(q0), cirq.X(q0)]
|
|
884
892
|
c1 = cirq.Circuit(cirq.X(q0), cirq.amplitude_damp(gamma=0.1).on(q0))
|
|
@@ -896,7 +904,7 @@ def test_simulate_noisy_expectation_values(dtype):
|
|
|
896
904
|
|
|
897
905
|
|
|
898
906
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
899
|
-
def test_simulate_expectation_values_terminal_measure(dtype):
|
|
907
|
+
def test_simulate_expectation_values_terminal_measure(dtype) -> None:
|
|
900
908
|
q0 = cirq.LineQubit(0)
|
|
901
909
|
circuit = cirq.Circuit(cirq.H(q0), cirq.measure(q0))
|
|
902
910
|
obs = cirq.Z(q0)
|
|
@@ -933,7 +941,7 @@ def test_simulate_expectation_values_terminal_measure(dtype):
|
|
|
933
941
|
|
|
934
942
|
|
|
935
943
|
@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
|
|
936
|
-
def test_simulate_expectation_values_qubit_order(dtype):
|
|
944
|
+
def test_simulate_expectation_values_qubit_order(dtype) -> None:
|
|
937
945
|
q0, q1, q2 = cirq.LineQubit.range(3)
|
|
938
946
|
circuit = cirq.Circuit(cirq.H(q0), cirq.H(q1), cirq.X(q2))
|
|
939
947
|
obs = cirq.X(q0) + cirq.X(q1) - cirq.Z(q2)
|
|
@@ -947,7 +955,7 @@ def test_simulate_expectation_values_qubit_order(dtype):
|
|
|
947
955
|
assert cirq.approx_eq(result_flipped[0], 3, atol=1e-6)
|
|
948
956
|
|
|
949
957
|
|
|
950
|
-
def test_density_matrix_step_result_repr():
|
|
958
|
+
def test_density_matrix_step_result_repr() -> None:
|
|
951
959
|
q0 = cirq.LineQubit(0)
|
|
952
960
|
assert (
|
|
953
961
|
repr(
|
|
@@ -967,7 +975,7 @@ def test_density_matrix_step_result_repr():
|
|
|
967
975
|
)
|
|
968
976
|
|
|
969
977
|
|
|
970
|
-
def test_density_matrix_trial_result_eq():
|
|
978
|
+
def test_density_matrix_trial_result_eq() -> None:
|
|
971
979
|
q0 = cirq.LineQubit(0)
|
|
972
980
|
final_simulator_state = cirq.DensityMatrixSimulationState(
|
|
973
981
|
initial_state=np.ones((2, 2)) * 0.5, qubits=[q0]
|
|
@@ -1001,7 +1009,9 @@ def test_density_matrix_trial_result_eq():
|
|
|
1001
1009
|
)
|
|
1002
1010
|
|
|
1003
1011
|
|
|
1004
|
-
def test_density_matrix_trial_result_qid_shape():
|
|
1012
|
+
def test_density_matrix_trial_result_qid_shape() -> None:
|
|
1013
|
+
q0: cirq.Qid
|
|
1014
|
+
q1: cirq.Qid
|
|
1005
1015
|
q0, q1 = cirq.LineQubit.range(2)
|
|
1006
1016
|
final_simulator_state = cirq.DensityMatrixSimulationState(
|
|
1007
1017
|
initial_state=np.ones((4, 4)) / 4, qubits=[q0, q1]
|
|
@@ -1026,7 +1036,7 @@ def test_density_matrix_trial_result_qid_shape():
|
|
|
1026
1036
|
) == (3, 4)
|
|
1027
1037
|
|
|
1028
1038
|
|
|
1029
|
-
def test_density_matrix_trial_result_repr():
|
|
1039
|
+
def test_density_matrix_trial_result_repr() -> None:
|
|
1030
1040
|
q0 = cirq.LineQubit(0)
|
|
1031
1041
|
dtype = np.complex64
|
|
1032
1042
|
final_simulator_state = cirq.DensityMatrixSimulationState(
|
|
@@ -1060,17 +1070,17 @@ class XAsOp(cirq.Operation):
|
|
|
1060
1070
|
self.q = q # pragma: no cover
|
|
1061
1071
|
|
|
1062
1072
|
@property
|
|
1063
|
-
def qubits(self):
|
|
1073
|
+
def qubits(self) -> tuple[cirq.Qid, ...]:
|
|
1064
1074
|
return (self.q,) # pragma: no cover
|
|
1065
1075
|
|
|
1066
|
-
def with_qubits(self, *new_qubits):
|
|
1076
|
+
def with_qubits(self, *new_qubits) -> cirq.Operation:
|
|
1067
1077
|
return XAsOp(new_qubits[0]) # pragma: no cover
|
|
1068
1078
|
|
|
1069
1079
|
def _kraus_(self):
|
|
1070
1080
|
return cirq.kraus(cirq.X) # pragma: no cover
|
|
1071
1081
|
|
|
1072
1082
|
|
|
1073
|
-
def test_works_on_operation():
|
|
1083
|
+
def test_works_on_operation() -> None:
|
|
1074
1084
|
class XAsOp(cirq.Operation):
|
|
1075
1085
|
def __init__(self, q):
|
|
1076
1086
|
self.q = q
|
|
@@ -1090,7 +1100,7 @@ def test_works_on_operation():
|
|
|
1090
1100
|
np.testing.assert_allclose(s.simulate(c).final_density_matrix, np.diag([0, 1]), atol=1e-8)
|
|
1091
1101
|
|
|
1092
1102
|
|
|
1093
|
-
def test_works_on_pauli_string_phasor():
|
|
1103
|
+
def test_works_on_pauli_string_phasor() -> None:
|
|
1094
1104
|
a, b = cirq.LineQubit.range(2)
|
|
1095
1105
|
c = cirq.Circuit(np.exp(0.5j * np.pi * cirq.X(a) * cirq.X(b)))
|
|
1096
1106
|
sim = cirq.DensityMatrixSimulator()
|
|
@@ -1098,7 +1108,7 @@ def test_works_on_pauli_string_phasor():
|
|
|
1098
1108
|
np.testing.assert_allclose(result.reshape(4, 4), np.diag([0, 0, 0, 1]), atol=1e-8)
|
|
1099
1109
|
|
|
1100
1110
|
|
|
1101
|
-
def test_works_on_pauli_string():
|
|
1111
|
+
def test_works_on_pauli_string() -> None:
|
|
1102
1112
|
a, b = cirq.LineQubit.range(2)
|
|
1103
1113
|
c = cirq.Circuit(cirq.X(a) * cirq.X(b))
|
|
1104
1114
|
sim = cirq.DensityMatrixSimulator()
|
|
@@ -1106,7 +1116,7 @@ def test_works_on_pauli_string():
|
|
|
1106
1116
|
np.testing.assert_allclose(result.reshape(4, 4), np.diag([0, 0, 0, 1]), atol=1e-8)
|
|
1107
1117
|
|
|
1108
1118
|
|
|
1109
|
-
def test_density_matrix_trial_result_str():
|
|
1119
|
+
def test_density_matrix_trial_result_str() -> None:
|
|
1110
1120
|
q0 = cirq.LineQubit(0)
|
|
1111
1121
|
dtype = np.complex64
|
|
1112
1122
|
final_simulator_state = cirq.DensityMatrixSimulationState(
|
|
@@ -1130,7 +1140,7 @@ def test_density_matrix_trial_result_str():
|
|
|
1130
1140
|
)
|
|
1131
1141
|
|
|
1132
1142
|
|
|
1133
|
-
def test_density_matrix_trial_result_repr_pretty():
|
|
1143
|
+
def test_density_matrix_trial_result_repr_pretty() -> None:
|
|
1134
1144
|
q0 = cirq.LineQubit(0)
|
|
1135
1145
|
dtype = np.complex64
|
|
1136
1146
|
final_simulator_state = cirq.DensityMatrixSimulationState(
|
|
@@ -1158,7 +1168,7 @@ def test_density_matrix_trial_result_repr_pretty():
|
|
|
1158
1168
|
cirq.testing.assert_repr_pretty(result, "cirq.DensityMatrixTrialResult(...)", cycle=True)
|
|
1159
1169
|
|
|
1160
1170
|
|
|
1161
|
-
def test_run_sweep_parameters_not_resolved():
|
|
1171
|
+
def test_run_sweep_parameters_not_resolved() -> None:
|
|
1162
1172
|
a = cirq.LineQubit(0)
|
|
1163
1173
|
simulator = cirq.DensityMatrixSimulator()
|
|
1164
1174
|
circuit = cirq.Circuit(cirq.XPowGate(exponent=sympy.Symbol('a'))(a), cirq.measure(a))
|
|
@@ -1166,7 +1176,7 @@ def test_run_sweep_parameters_not_resolved():
|
|
|
1166
1176
|
_ = simulator.run_sweep(circuit, cirq.ParamResolver({}))
|
|
1167
1177
|
|
|
1168
1178
|
|
|
1169
|
-
def test_simulate_sweep_parameters_not_resolved():
|
|
1179
|
+
def test_simulate_sweep_parameters_not_resolved() -> None:
|
|
1170
1180
|
a = cirq.LineQubit(0)
|
|
1171
1181
|
simulator = cirq.DensityMatrixSimulator()
|
|
1172
1182
|
circuit = cirq.Circuit(cirq.XPowGate(exponent=sympy.Symbol('a'))(a), cirq.measure(a))
|
|
@@ -1174,7 +1184,7 @@ def test_simulate_sweep_parameters_not_resolved():
|
|
|
1174
1184
|
_ = simulator.simulate_sweep(circuit, cirq.ParamResolver({}))
|
|
1175
1185
|
|
|
1176
1186
|
|
|
1177
|
-
def test_random_seed():
|
|
1187
|
+
def test_random_seed() -> None:
|
|
1178
1188
|
a = cirq.NamedQubit('a')
|
|
1179
1189
|
circuit = cirq.Circuit(cirq.X(a) ** 0.5, cirq.measure(a))
|
|
1180
1190
|
|
|
@@ -1193,7 +1203,7 @@ def test_random_seed():
|
|
|
1193
1203
|
)
|
|
1194
1204
|
|
|
1195
1205
|
|
|
1196
|
-
def test_random_seed_does_not_modify_global_state_terminal_measurements():
|
|
1206
|
+
def test_random_seed_does_not_modify_global_state_terminal_measurements() -> None:
|
|
1197
1207
|
a = cirq.NamedQubit('a')
|
|
1198
1208
|
circuit = cirq.Circuit(cirq.X(a) ** 0.5, cirq.measure(a))
|
|
1199
1209
|
|
|
@@ -1208,7 +1218,7 @@ def test_random_seed_does_not_modify_global_state_terminal_measurements():
|
|
|
1208
1218
|
assert result1 == result2
|
|
1209
1219
|
|
|
1210
1220
|
|
|
1211
|
-
def test_random_seed_does_not_modify_global_state_non_terminal_measurements():
|
|
1221
|
+
def test_random_seed_does_not_modify_global_state_non_terminal_measurements() -> None:
|
|
1212
1222
|
a = cirq.NamedQubit('a')
|
|
1213
1223
|
circuit = cirq.Circuit(
|
|
1214
1224
|
cirq.X(a) ** 0.5, cirq.measure(a, key='a0'), cirq.X(a) ** 0.5, cirq.measure(a, key='a1')
|
|
@@ -1225,7 +1235,7 @@ def test_random_seed_does_not_modify_global_state_non_terminal_measurements():
|
|
|
1225
1235
|
assert result1 == result2
|
|
1226
1236
|
|
|
1227
1237
|
|
|
1228
|
-
def test_random_seed_terminal_measurements_deterministic():
|
|
1238
|
+
def test_random_seed_terminal_measurements_deterministic() -> None:
|
|
1229
1239
|
a = cirq.NamedQubit('a')
|
|
1230
1240
|
circuit = cirq.Circuit(cirq.X(a) ** 0.5, cirq.measure(a, key='a'))
|
|
1231
1241
|
sim = cirq.DensityMatrixSimulator(seed=1234)
|
|
@@ -1303,7 +1313,7 @@ def test_random_seed_terminal_measurements_deterministic():
|
|
|
1303
1313
|
)
|
|
1304
1314
|
|
|
1305
1315
|
|
|
1306
|
-
def test_random_seed_non_terminal_measurements_deterministic():
|
|
1316
|
+
def test_random_seed_non_terminal_measurements_deterministic() -> None:
|
|
1307
1317
|
a = cirq.NamedQubit('a')
|
|
1308
1318
|
circuit = cirq.Circuit(
|
|
1309
1319
|
cirq.X(a) ** 0.5, cirq.measure(a, key='a'), cirq.X(a) ** 0.5, cirq.measure(a, key='b')
|
|
@@ -1382,7 +1392,7 @@ def test_random_seed_non_terminal_measurements_deterministic():
|
|
|
1382
1392
|
)
|
|
1383
1393
|
|
|
1384
1394
|
|
|
1385
|
-
def test_simulate_with_invert_mask():
|
|
1395
|
+
def test_simulate_with_invert_mask() -> None:
|
|
1386
1396
|
q0, q1, q2, q3, q4 = cirq.LineQid.for_qid_shape((2, 3, 3, 3, 4))
|
|
1387
1397
|
c = cirq.Circuit(
|
|
1388
1398
|
cirq.XPowGate(dimension=2)(q0),
|
|
@@ -1394,7 +1404,7 @@ def test_simulate_with_invert_mask():
|
|
|
1394
1404
|
assert np.all(cirq.DensityMatrixSimulator().run(c).measurements['a'] == [[0, 1, 0, 2, 3]])
|
|
1395
1405
|
|
|
1396
1406
|
|
|
1397
|
-
def test_simulate_noise_with_terminal_measurements():
|
|
1407
|
+
def test_simulate_noise_with_terminal_measurements() -> None:
|
|
1398
1408
|
q = cirq.LineQubit(0)
|
|
1399
1409
|
circuit1 = cirq.Circuit(cirq.measure(q))
|
|
1400
1410
|
circuit2 = circuit1 + cirq.I(q)
|
|
@@ -1406,7 +1416,7 @@ def test_simulate_noise_with_terminal_measurements():
|
|
|
1406
1416
|
assert result1 == result2
|
|
1407
1417
|
|
|
1408
1418
|
|
|
1409
|
-
def test_simulate_noise_with_subcircuit_measurements():
|
|
1419
|
+
def test_simulate_noise_with_subcircuit_measurements() -> None:
|
|
1410
1420
|
q = cirq.LineQubit(0)
|
|
1411
1421
|
circuit1 = cirq.Circuit(cirq.measure(q))
|
|
1412
1422
|
circuit2 = cirq.Circuit(cirq.CircuitOperation(cirq.Circuit(cirq.measure(q)).freeze()))
|
|
@@ -1418,7 +1428,7 @@ def test_simulate_noise_with_subcircuit_measurements():
|
|
|
1418
1428
|
assert result1 == result2
|
|
1419
1429
|
|
|
1420
1430
|
|
|
1421
|
-
def test_nonmeasuring_subcircuits_do_not_cause_sweep_repeat():
|
|
1431
|
+
def test_nonmeasuring_subcircuits_do_not_cause_sweep_repeat() -> None:
|
|
1422
1432
|
q = cirq.LineQubit(0)
|
|
1423
1433
|
circuit = cirq.Circuit(
|
|
1424
1434
|
cirq.CircuitOperation(cirq.Circuit(cirq.H(q)).freeze()), cirq.measure(q, key='x')
|
|
@@ -1429,7 +1439,7 @@ def test_nonmeasuring_subcircuits_do_not_cause_sweep_repeat():
|
|
|
1429
1439
|
assert mock_sim.call_count == 2
|
|
1430
1440
|
|
|
1431
1441
|
|
|
1432
|
-
def test_measuring_subcircuits_cause_sweep_repeat():
|
|
1442
|
+
def test_measuring_subcircuits_cause_sweep_repeat() -> None:
|
|
1433
1443
|
q = cirq.LineQubit(0)
|
|
1434
1444
|
circuit = cirq.Circuit(
|
|
1435
1445
|
cirq.CircuitOperation(cirq.Circuit(cirq.measure(q)).freeze()), cirq.measure(q, key='x')
|
|
@@ -1440,7 +1450,7 @@ def test_measuring_subcircuits_cause_sweep_repeat():
|
|
|
1440
1450
|
assert mock_sim.call_count == 11
|
|
1441
1451
|
|
|
1442
1452
|
|
|
1443
|
-
def test_density_matrix_copy():
|
|
1453
|
+
def test_density_matrix_copy() -> None:
|
|
1444
1454
|
sim = cirq.DensityMatrixSimulator(split_untangled_states=False)
|
|
1445
1455
|
|
|
1446
1456
|
q = cirq.LineQubit(0)
|
|
@@ -1465,7 +1475,7 @@ def test_density_matrix_copy():
|
|
|
1465
1475
|
assert all(not np.shares_memory(x, y) for x, y in itertools.combinations(matrices, 2))
|
|
1466
1476
|
|
|
1467
1477
|
|
|
1468
|
-
def test_final_density_matrix_is_not_last_object():
|
|
1478
|
+
def test_final_density_matrix_is_not_last_object() -> None:
|
|
1469
1479
|
sim = cirq.DensityMatrixSimulator()
|
|
1470
1480
|
|
|
1471
1481
|
q = cirq.LineQubit(0)
|
|
@@ -1477,7 +1487,7 @@ def test_final_density_matrix_is_not_last_object():
|
|
|
1477
1487
|
np.testing.assert_equal(result.final_density_matrix, initial_state)
|
|
1478
1488
|
|
|
1479
1489
|
|
|
1480
|
-
def test_density_matrices_same_with_or_without_split_untangled_states():
|
|
1490
|
+
def test_density_matrices_same_with_or_without_split_untangled_states() -> None:
|
|
1481
1491
|
sim = cirq.DensityMatrixSimulator(split_untangled_states=False)
|
|
1482
1492
|
q0, q1 = cirq.LineQubit.range(2)
|
|
1483
1493
|
circuit = cirq.Circuit(cirq.H(q0), cirq.CX.on(q0, q1), cirq.reset(q1))
|
|
@@ -1487,7 +1497,7 @@ def test_density_matrices_same_with_or_without_split_untangled_states():
|
|
|
1487
1497
|
assert np.allclose(result1, result2)
|
|
1488
1498
|
|
|
1489
1499
|
|
|
1490
|
-
def test_large_untangled_okay():
|
|
1500
|
+
def test_large_untangled_okay() -> None:
|
|
1491
1501
|
circuit = cirq.Circuit()
|
|
1492
1502
|
for i in range(59):
|
|
1493
1503
|
for _ in range(9):
|
|
@@ -1499,9 +1509,9 @@ def test_large_untangled_okay():
|
|
|
1499
1509
|
_ = cirq.DensityMatrixSimulator(split_untangled_states=False).simulate(circuit)
|
|
1500
1510
|
|
|
1501
1511
|
# Validate a simulation run
|
|
1502
|
-
|
|
1503
|
-
assert set(
|
|
1504
|
-
# _ =
|
|
1512
|
+
sim_result = cirq.DensityMatrixSimulator().simulate(circuit)
|
|
1513
|
+
assert set(sim_result._final_simulator_state.qubits) == set(cirq.LineQubit.range(59))
|
|
1514
|
+
# _ = sim_result.final_density_matrix hangs (as expected)
|
|
1505
1515
|
|
|
1506
1516
|
# Validate a trial run and sampling
|
|
1507
1517
|
result = cirq.DensityMatrixSimulator().run(circuit, repetitions=1000)
|
|
@@ -1510,7 +1520,7 @@ def test_large_untangled_okay():
|
|
|
1510
1520
|
assert (result.measurements['q(0)'] == np.full(1000, 1)).all()
|
|
1511
1521
|
|
|
1512
1522
|
|
|
1513
|
-
def test_separated_states_str_does_not_merge():
|
|
1523
|
+
def test_separated_states_str_does_not_merge() -> None:
|
|
1514
1524
|
q0, q1 = cirq.LineQubit.range(2)
|
|
1515
1525
|
circuit = cirq.Circuit(cirq.measure(q0), cirq.measure(q1), cirq.X(q0))
|
|
1516
1526
|
|
|
@@ -1535,7 +1545,7 @@ final density matrix:
|
|
|
1535
1545
|
)
|
|
1536
1546
|
|
|
1537
1547
|
|
|
1538
|
-
def test_unseparated_states_str():
|
|
1548
|
+
def test_unseparated_states_str() -> None:
|
|
1539
1549
|
q0, q1 = cirq.LineQubit.range(2)
|
|
1540
1550
|
circuit = cirq.Circuit(cirq.measure(q0), cirq.measure(q1), cirq.X(q0))
|
|
1541
1551
|
|
|
@@ -1553,7 +1563,7 @@ final density matrix:
|
|
|
1553
1563
|
)
|
|
1554
1564
|
|
|
1555
1565
|
|
|
1556
|
-
def test_sweep_unparameterized_prefix_not_repeated_even_non_unitaries():
|
|
1566
|
+
def test_sweep_unparameterized_prefix_not_repeated_even_non_unitaries() -> None:
|
|
1557
1567
|
q = cirq.LineQubit(0)
|
|
1558
1568
|
|
|
1559
1569
|
class NonUnitaryOp(cirq.Operation):
|