qiskit-community / qiskit-aqua

Quantum Algorithms & Applications (**DEPRECATED** since April 2021 - see readme for more info)
https://qiskit.org/aqua
Apache License 2.0
572 stars 376 forks source link

RQAOA erroring out #1429

Closed amitracal closed 3 years ago

amitracal commented 3 years ago

Information

What is the current behavior?

Recursive QAOA is erroring out

This is the code failing - rqaoa_result_q = rqaoa_qaoa.solve(qubo) print(rqaoa_result_q)

This is the bottom part of the error - AquaError: 'Circuit execution failed: ERROR: Failed to load qobj: Invalid parameterized qobj: instruction param position out of range

Steps to reproduce the problem

Run the notebook attached, pay special attention to the cells after the comment -# RecursiveMinimumEigenOptimizer

What is the expected behavior?

The code should run and produce the same optimized value was Cplex which is -20.5 (even qaoa is not producing it)

RQAOA small.zip

Suggested solutions

woodsp-ibm commented 3 years ago

@adekusar-drl This was running Aer backend but judging by the error message it seems more related to circuit parameterization circuits so perhaps I can ask @hhorii to take a look.

hhorii commented 3 years ago

I was able to reproduce this issue with the following script:

from qiskit import Aer
from qiskit.aqua.algorithms import QAOA
from qiskit.optimization.algorithms import MinimumEigenOptimizer, RecursiveMinimumEigenOptimizer
from qiskit.optimization import QuadraticProgram
from qiskit.aqua.components.optimizers import SLSQP
from qiskit.aqua import QuantumInstance
from qiskit.aqua import aqua_globals

qubo = QuadraticProgram()
qubo.binary_var('x1')
qubo.binary_var('x2')
qubo.binary_var('x3')
qubo.binary_var('x4')
qubo.binary_var('x5')
qubo.binary_var('x6')
qubo.binary_var('x7')
qubo.binary_var('x8')
qubo.binary_var('x9')
qubo.binary_var('x10')
qubo.binary_var('x11')
qubo.binary_var('x12')
qubo.binary_var('x13')

qubo.minimize(linear=[1,-2,3,-6,-1,2,3,4,-5,-6,-1,-3,1], 
              quadratic={('x1', 'x2'): 1, ('x1', 'x3'): -1, ('x1', 'x4'): 2, 
                                            ('x2' , 'x3'): 5, ('x2', 'x4'): 6, ('x3', 'x4'): 3,
                                            ('x4','x5'): 1, ('x2', 'x5'): 6, ('x3', 'x5'): 3, ('x1', 'x6'): 6, 
                                            ('x5', 'x6'): 0.5,
                                            ('x3', 'x7'): 36, ('x5', 'x7'): 0.5, ('x1', 'x8'): 6, ('x7', 'x8'): 0.5,
                                            ('x8', 'x9'): 1, ('x9', 'x10'): 0.5, ('x1', 'x11'): 6, ('x2', 'x11'): 0.5,
                                            ('x7', 'x12'): 6, ('x5', 'x12'): 0.5, ('x12', 'x13'): 0.5
                                            })

seed = 1
aqua_globals.random_seed = seed
backend = Aer.get_backend('qasm_simulator')
quantum_instance = QuantumInstance(backend, seed_simulator=seed, seed_transpiler=seed)
slsqp = SLSQP()
slsqp.set_options(maxiter=500)
qaoa_mes = QAOA(quantum_instance=quantum_instance,include_custom=True, optimizer = slsqp, p=10)
qaoa = MinimumEigenOptimizer(qaoa_mes) 
rqaoa_qaoa = RecursiveMinimumEigenOptimizer(min_eigen_optimizer=qaoa, min_num_vars=1, min_num_vars_optimizer=qaoa)
rqaoa_result_q = rqaoa_qaoa.solve(qubo)

Let me take a look.