1
$\begingroup$

I'm running VQE algorithm on ibmq-qasm-simulator.
I'm trying to implement a restart mechanism in order to be able to start a new computation from the result of a previous one.

To do so I've tried to set VQE' s initial_point parameter to result['optimal_point'], where result is the return value of vqe.run(quinstance) of the previous computation.

The code has worked for a very small graph (4 nodes, 4 edges), anyway it continues to fail for little bigger graphs (5 and 6 nodes). It doesn't converge to a minimum energy state but continues to oscillate.

Is this the correct way to implement a restart?
Thanks

$\endgroup$
  • $\begingroup$ Just an intermediate question: there was a bug with the restarting algorithm in version 0.19.0, which was fixed in 0.19.2. Are you running this latest version? $\endgroup$ – Cryoris May 18 at 15:16
  • $\begingroup$ I don't know that algorithm, could you please show it to me? $\endgroup$ – Valentina May 18 at 15:35
  • $\begingroup$ Sorry, that was a typo. I meant "a bug with restarting the algorithm". What's the Qiskit version you are running? $\endgroup$ – Cryoris May 18 at 19:48
  • $\begingroup$ I'm running 0.19.1 $\endgroup$ – Valentina May 19 at 6:35
  • $\begingroup$ what do you mean by error? Is it the fact that the algorithm doesn't converge or anything else? $\endgroup$ – NABAT Jun 16 at 13:48
5
$\begingroup$

You can use a callback function to save the parameters for each iterations of your vqe algorithm and even store the mean, std. Below an example:

# Create the callback function to store intermediate values in vqe
counts = []
values = []
parameters_list=[]
std_list=[]
def store_intermediate_result(eval_count, parameters, mean, std):
    counts.append(eval_count)
    values.append(mean)
    parameters_list.append(parameters)
    std_list.append(std)
# Create your vqe instance by specifying the callback function and run it on the simulator
# You already created your operator, varational form and optimizer.

vqe = VQE(op, var_form, optimizer, callback=store_intermediate_result)
result=vqe.run(simulator)

Your parameters_list will be filled by the parameters used at each step of the algorithm. You can take the last parameters or others if you want and start a new vqe instance from them.

last_parameters=parameters_list[-1]
# The initial_point option allow to start from specific parameters.
vqe2=VQE(op, var_form, optimizer, callback=store_intermediate_result, initial_point=last_parameters)
# Run the algorithm from your last iteration
result2=vqe2.run(simulator)
| 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.