2

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

Valentina
  • 31
  • 2

1 Answers1

5

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)
NABAT
  • 111
  • 4