def test_occupation_basis(qvm): prog = Program().inst([Xgate(0), Xgate(1), Igate(2), Igate(3)]) state = np.zeros(2**4) state[3] = 1.0 meanfield_state, _ = qvm.wavefunction(prog) assert np.allclose(meanfield_state.amplitudes, state)
def test_larger_qaoa_circuit(qvm): square_qaoa_circuit = [ Hgate(0), Hgate(1), Hgate(2), Hgate(3), Xgate(0), PHASEgate(0.3928244130249029)(0), Xgate(0), PHASEgate(0.3928244130249029)(0), CNOTgate(0, 1), RZgate(0.78564882604980579)(1), CNOTgate(0, 1), Xgate(0), PHASEgate(0.3928244130249029)(0), Xgate(0), PHASEgate(0.3928244130249029)(0), CNOTgate(0, 3), RZgate(0.78564882604980579)(3), CNOTgate(0, 3), Xgate(0), PHASEgate(0.3928244130249029)(0), Xgate(0), PHASEgate(0.3928244130249029)(0), CNOTgate(1, 2), RZgate(0.78564882604980579)(2), CNOTgate(1, 2), Xgate(0), PHASEgate(0.3928244130249029)(0), Xgate(0), PHASEgate(0.3928244130249029)(0), CNOTgate(2, 3), RZgate(0.78564882604980579)(3), CNOTgate(2, 3), Hgate(0), RZgate(-0.77868204192240842)(0), Hgate(0), Hgate(1), RZgate(-0.77868204192240842)(1), Hgate(1), Hgate(2), RZgate(-0.77868204192240842)(2), Hgate(2), Hgate(3), RZgate(-0.77868204192240842)(3), Hgate(3) ] prog = Program(square_qaoa_circuit) wf_test, _ = qvm.wavefunction(prog) wf_true = np.array([ 8.43771693e-05 - 0.1233845 * 1j, -1.24927731e-01 + 0.00329533 * 1j, -1.24927731e-01 + 0.00329533 * 1j, -2.50040954e-01 + 0.12661547 * 1j, -1.24927731e-01 + 0.00329533 * 1j, -4.99915497e-01 - 0.12363516 * 1j, -2.50040954e-01 + 0.12661547 * 1j, -1.24927731e-01 + 0.00329533 * 1j, -1.24927731e-01 + 0.00329533 * 1j, -2.50040954e-01 + 0.12661547 * 1j, -4.99915497e-01 - 0.12363516 * 1j, -1.24927731e-01 + 0.00329533 * 1j, -2.50040954e-01 + 0.12661547 * 1j, -1.24927731e-01 + 0.00329533 * 1j, -1.24927731e-01 + 0.00329533 * 1j, 8.43771693e-05 - 0.1233845 * 1j ]) assert np.allclose(wf_test.amplitudes, wf_true)
def test_larger_qaoa_density(): square_qaoa_circuit = [ Hgate(0), Hgate(1), Hgate(2), Hgate(3), Xgate(0), PHASEgate(0.3928244130249029)(0), Xgate(0), PHASEgate(0.3928244130249029)(0), CNOTgate(0, 1), RZgate(0.78564882604980579)(1), CNOTgate(0, 1), Xgate(0), PHASEgate(0.3928244130249029)(0), Xgate(0), PHASEgate(0.3928244130249029)(0), CNOTgate(0, 3), RZgate(0.78564882604980579)(3), CNOTgate(0, 3), Xgate(0), PHASEgate(0.3928244130249029)(0), Xgate(0), PHASEgate(0.3928244130249029)(0), CNOTgate(1, 2), RZgate(0.78564882604980579)(2), CNOTgate(1, 2), Xgate(0), PHASEgate(0.3928244130249029)(0), Xgate(0), PHASEgate(0.3928244130249029)(0), CNOTgate(2, 3), RZgate(0.78564882604980579)(3), CNOTgate(2, 3), Hgate(0), RZgate(-0.77868204192240842)(0), Hgate(0), Hgate(1), RZgate(-0.77868204192240842)(1), Hgate(1), Hgate(2), RZgate(-0.77868204192240842)(2), Hgate(2), Hgate(3), RZgate(-0.77868204192240842)(3), Hgate(3) ] prog = Program(square_qaoa_circuit) qvm = QVMConnection(type_trans='density') rho_test = qvm.density(prog) wf_true = np.array([ 8.43771693e-05 - 0.1233845 * 1j, -1.24927731e-01 + 0.00329533 * 1j, -1.24927731e-01 + 0.00329533 * 1j, -2.50040954e-01 + 0.12661547 * 1j, -1.24927731e-01 + 0.00329533 * 1j, -4.99915497e-01 - 0.12363516 * 1j, -2.50040954e-01 + 0.12661547 * 1j, -1.24927731e-01 + 0.00329533 * 1j, -1.24927731e-01 + 0.00329533 * 1j, -2.50040954e-01 + 0.12661547 * 1j, -4.99915497e-01 - 0.12363516 * 1j, -1.24927731e-01 + 0.00329533 * 1j, -2.50040954e-01 + 0.12661547 * 1j, -1.24927731e-01 + 0.00329533 * 1j, -1.24927731e-01 + 0.00329533 * 1j, 8.43771693e-05 - 0.1233845 * 1j ]) wf_true = np.reshape(wf_true, (2**4, 1)) rho_true = np.dot(wf_true, np.conj(wf_true).T) assert np.isclose(rho_test.todense(), rho_true).all()