def test_trotterize_noiseless(self): # Noiseless simulations # Compare that the integrator adiabatic results match the trotterized results # First, compare the non-IS subspace results simulation = adiabatic_simulation(sample_graph(), IS_subspace=False) res_trotterize = simulation.performance_vs_total_time( np.arange(1, 5, 1), metric='optimum_overlap', initial_state=State(equal_superposition(6)), schedule=lambda t, tf: simulation.linear_schedule( t, tf, coefficients=[10, 10]), plot=False, verbose=True, method='trotterize') res_RK45 = simulation.performance_vs_total_time( np.arange(1, 5, 1), metric='optimum_overlap', initial_state=State(equal_superposition(6)), schedule=lambda t, tf: simulation.linear_schedule( t, tf, coefficients=[10, 10]), plot=False, verbose=True, method='RK45') # Now test in the IS subspace self.assertTrue( np.allclose(res_trotterize[0]['trotterize']['optimum_overlap'], res_RK45[0]['RK45']['optimum_overlap'], atol=1e-2)) simulation = adiabatic_simulation(sample_graph(), IS_subspace=True) res_trotterize = simulation.performance_vs_total_time( np.arange(1, 4, 1), metric='optimum_overlap', schedule=lambda t, tf: simulation.linear_schedule( t, tf, coefficients=[10, 10]), plot=False, verbose=True, method='trotterize') res_RK45 = simulation.performance_vs_total_time( np.arange(1, 4, 1), metric='optimum_overlap', schedule=lambda t, tf: simulation.linear_schedule( t, tf, coefficients=[10, 10]), plot=False, verbose=True, method='RK45') self.assertTrue( np.allclose(res_trotterize[0]['trotterize']['optimum_overlap'], res_RK45[0]['RK45']['optimum_overlap'], atol=1e-2))
plt.scatter(depths, [i / (i + 1) for i in depths], label='maxcut') plt.scatter(depths, mis, label='mis with $n=$' + str(n)) plt.plot(depths, mis) plt.legend() if show: plt.show() if __name__ == "__main__": i, j = 4, 4 graph = node_defect_torus(i, j) #simulation = adiabatic_simulation(graph, IS_subspace=True) #t0 = time.time() #res = simulation.performance_vs_total_time(np.arange(0, 0), metric='optimum_overlap', # schedule=lambda t, tf: experiment_rydberg_MIS_schedule(t, tf, simulation, # coefficients=[10, # 10]), # plot=True, verbose=True, method='trotterize') #print('results: ', res, flush=True) #simulation = mis_qaoa(4, IS_subspace=True, method='basinhopping') simulation = adiabatic_simulation(graph, IS_subspace=False) res = simulation.performance_vs_total_time(np.arange(40, 95, 5), metric='optimum_overlap', initial_state=State(equal_superposition(i * j)), schedule=lambda t, tf: simulation.linear_schedule(t, tf, coefficients=[1, 1]), plot=True, verbose=True, method='trotterize') print('results: ', res, flush=True)
hb = hamiltonian.HamiltonianDriver() hamiltonians = [hc, hb] ring_hamiltonians = [hc_ring, hb] sim = qaoa.SimulateQAOA(g, cost_hamiltonian=hc, hamiltonian=hamiltonians) sim_ring = qaoa.SimulateQAOA(ring, cost_hamiltonian=hc_ring, hamiltonian=ring_hamiltonians) sim_ket = qaoa.SimulateQAOA(g, cost_hamiltonian=hc, hamiltonian=hamiltonians) sim_noisy = qaoa.SimulateQAOA(g, cost_hamiltonian=hc, hamiltonian=hamiltonians, noise_model='channel') # Initialize in |000000> psi0 = State(equal_superposition(N)) rho0 = State(outer_product(psi0, psi0)) noises = [quantum_channels.DepolarizingChannel(rates=(.001, ))] sim_noisy.noise = noises * 2 class TestSimulateQAOA(unittest.TestCase): def test_variational_grad(self): # Test that the calculated objective function and gradients are correct # p = 1 sim_ket.hamiltonian = hamiltonians F, Fgrad = sim_ket.variational_grad(np.array([1, 0.5]), initial_state=psi0) self.assertTrue(np.abs(F - 5.066062984904652) <= 1e-5) self.assertTrue(