def test_quantum_simulator_switches_between_native_and_nonnative_modes_of_execution( circuit, ): simulator = SymbolicSimulatorWithNonSupportedOperations() reference_simulator = SymbolicSimulator() np.testing.assert_array_equal( simulator.get_wavefunction(circuit).amplitudes, reference_simulator.get_wavefunction(circuit).amplitudes, )
def test_wavefunction_works_as_expected_with_symbolic_circuits( self, simulator: SymbolicSimulator, circuit: Circuit, expected_wavefunction: Wavefunction, ): returned_wavefunction = simulator.get_wavefunction(circuit) assert returned_wavefunction == expected_wavefunction
@pytest.mark.parametrize("contract", ESTIMATOR_CONTRACTS) def test_estimator_contract(contract): estimator = CvarEstimator(alpha=0.2) assert contract(estimator) """ import numpy as np from openfermion import IsingOperator from zquantum.core.circuits import RX, RY, RZ, Circuit, H from zquantum.core.interfaces.estimation import ( EstimateExpectationValues, EstimationTask, ) from zquantum.core.symbolic_simulator import SymbolicSimulator _backend = SymbolicSimulator(seed=1997) _estimation_tasks = [ EstimationTask(IsingOperator("Z0"), Circuit([H(0)]), 10000), EstimationTask( IsingOperator("Z0") + IsingOperator("Z1") + IsingOperator("Z2"), Circuit([H(0), RX(np.pi / 3)(0), H(2)]), 10000, ), EstimationTask( IsingOperator("Z0") + IsingOperator("Z1", 4), Circuit([ RX(np.pi)(0), RY(0.12)(1), RZ(np.pi / 3)(1), RY(1.9213)(0),
sum_expectation_values, ) from zquantum.core.estimation import ( allocate_shots_uniformly, calculate_exact_expectation_values, estimate_expectation_values_by_averaging, ) from zquantum.core.gradients import finite_differences_gradient from zquantum.core.interfaces.mock_objects import MockAnsatz from zquantum.core.measurement import ExpectationValues from zquantum.core.symbolic_simulator import SymbolicSimulator from zquantum.core.utils import create_symbols_map RNGSEED = 1234 BACKEND = SymbolicSimulator() ESTIMATION_METHOD = estimate_expectation_values_by_averaging ESTIMATION_PREPROCESSORS = [ partial(allocate_shots_uniformly, number_of_shots=1) ] class TestGroundStateCostFunction: @pytest.fixture(params=["old", "new"]) def factory_type(self, request): return request.param @pytest.fixture(params=[ { "target_operator": QubitOperator("Z0"),
def wf_simulator() -> SymbolicSimulator: return SymbolicSimulator()
def backend(): return SymbolicSimulator()
def simulator(self): return SymbolicSimulator()