1
$\begingroup$

I'm running VQE algorithm from qiskit aqua on statevector_simulator and each time I run it I get different results which are sometimes correct and sometimes not. I'm not sure if I'm setting parameters correctly.

Here is my code:

The qubitOp is generated with DOcplex module.

max_trials = 80
depth = 1
entanglement='full'

slsqp = SLSQP(maxiter=max_trials)
ry = RY(qubitOp.num_qubits, depth=depth, entanglement=entanglement)
vqe = VQE(qubitOp, ry, slsqp)
provider = IBMQ.get_provider('ibm-q')
backend = Aer.get_backend('statevector_simulator')
quantum_instance = QuantumInstance(backend,seed_simulator=seed, seed_transpiler=seed, optimization_level=0)
res = vqe.run(quantum_instance)    
$\endgroup$
3
$\begingroup$

VQE has an initial_point parameter, which is the starting point it uses for the optimization. In the absence on one being provided (or suggested via the variational form) it will pick a random one. You can seed Aqua, like you did the simulator, so it will end up with the same random one each time, to get a predictable outcome. Add the following to do this before using any Aqua algorithms etc.

from qiskit.aqua import aqua_globals

aqua_globals.random_seed = seed

Now since your result varies it suggests anyway that you are not reaching a minimum and the optimization loop is ending early. More iterations of the optimizer may be needed and/or you may need to look at the variational form, say larger depth with what is being used.

|improve this answer|||||
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.