WarmStartQAOAOptimizer fails with initial point length mismatch
See original GitHub issueThe issue was originally raised on Qiskit Slack #aqua channel here
The following code sample, based on what was provided in that discussion, works at reps=1 (or at least it does for me but gave the originator of the message this error ValueError: array must not contain infs or NaNs
that I could not reproduce). At reps > 1 then it fails with an error like this
qiskit/algorithms/minimum_eigen_solvers/vqe.py", line 716, in _validate_initial_point f"The dimension of the initial point ({len(point)}) does not match the " ValueError: The dimension of the initial point (4) does not match the number of parameters in the circuit (3).
but was stated that it worked on prior version (I did not check).
I will note that if initial_point is set to None (a line in the sample code does that but is commented out so it will fail at present) then things work fine.
Also if you run qaoa itself it proves the initial_point is being passed in correctly in terms of at least an initial length that matches. And you then go onto re-use the same qaoa instance for the WarmStart algo, it works fine (the block with the do_qaoa that is set False at present again so it the sample will fail).
I will note I reduced SPSA max_iter down from the 500 of the original sample to 5 just for testing whether it failed or not.
import networkx as nx
import numpy as np
from qiskit import Aer
from qiskit.algorithms import QAOA
from qiskit.algorithms.optimizers import SPSA
from qiskit_optimization.algorithms import WarmStartQAOAOptimizer
from qiskit_optimization.algorithms import CobylaOptimizer
from qiskit_optimization.applications.max_cut import Maxcut
from qiskit.utils import QuantumInstance
n = 5
graph = nx.Graph()
graph.add_nodes_from(np.arange(0, n, 1))
elist = [(0, 3, 9), (0, 4, 6), (1, 2, 9), (1, 4, 10), (2, 4, 7), (3, 4, 7)]
graph.add_weighted_edges_from(elist)
max_cut_quadr_program = Maxcut(graph).to_quadratic_program()
reps = 2
init_pt = [0]*reps + [1]*reps
#init_pt = None
print(f'Using reps {reps} with initial point {init_pt}')
qaoa = QAOA(optimizer=SPSA(maxiter=5),
quantum_instance=QuantumInstance(backend=Aer.get_backend('qasm_simulator'),shots=8000),
reps=reps,
initial_point=init_pt)
do_qaoa = False
if do_qaoa:
qubit_op, _ = max_cut_quadr_program.to_ising()
qaoa_res = qaoa.compute_minimum_eigenvalue(qubit_op)
print(qaoa_res)
ws_qaoa = WarmStartQAOAOptimizer(pre_solver=CobylaOptimizer(),
relax_for_pre_solver=True,
qaoa=qaoa)
ws_result = ws_qaoa.solve(max_cut_quadr_program)
print(ws_result)
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top GitHub Comments
@t-imamichi could you please also check, if all beta values are set correctly? i’m not sure if that the parameter beta here: WarmStartQAOAFactory is considered in the PR you mentioned. Thanks!
Because https://github.com/Qiskit/qiskit-terra/pull/6828 is merged, I think this issue is fixed. This is the output in my environment with the latest terra and opt.