question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WarmStartQAOAOptimizer fails with initial point length mismatch

See original GitHub issue

The 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:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
lasyscommented, Sep 15, 2021

@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!

0reactions
t-imamichicommented, Oct 13, 2021

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.

Using reps 2 with initial point [0, 0, 1, 1]
/Users/ima/tasks/1_2021/qiskit/terra/qiskit/opflow/primitive_ops/pauli_sum_op.py:362: DeprecationWarning: The SparsePauliOp.table method is deprecated as of Qiskit Terra 0.19.0 and will be removed no sooner than 3 months after the releasedate. Use SparsePauliOp.paulis method instead.
  tables = self.primitive.table
optimal function value: 35.0
optimal value: [0. 1. 0. 1. 0.]
status: SUCCESS
Read more comments on GitHub >

github_iconTop Results From Across the Web

WarmStartQAOAOptimizer - Qiskit
A meta-algorithm that uses a pre-solver to solve a relaxed version of the problem. Users must implement their own pre solvers by inheriting...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found