1
$\begingroup$

I am solving a QUBO using QAOA. It works flawlessly with default parameters for smaller instances of the problem, but my RAM is saturated when I try to solve a problem of size 15. I suspect this can be resolved by changing the parameter p. Don't mind if it generates a wrong result as output, at least don't wanna run out of resources and end abruptly. I even checked with different simulators, but it didn't work. Mainly, want to know how to play around with the number of layers p.

Here's the code for reference:

from qiskit import Aer
from qiskit.aqua import aqua_globals, QuantumInstance
from qiskit.aqua.algorithms import QAOA
from qiskit.optimization import QuadraticProgram

qp=QuadraticProgram()
qp.from_ising(op, offset, linear=True)
aqua_globals.random_seed = 123
quantum_instance = QuantumInstance(Aer.get_backend('aer_simulator'),
                               seed_simulator=aqua_globals.random_seed,
                               seed_transpiler=aqua_globals.random_seed)
qaoa_mes = QAOA(quantum_instance=quantum_instance, initial_point=[0., 0.])
qaoa = MinimumEigenOptimizer(qaoa_mes)
result = qaoa.solve(qubo)

Also, how to get the circuit?

$\endgroup$
4
  • 1
    $\begingroup$ Hello, I noticed you still use Aqua, I strongly suggest you move to the latest version of Qiskit because Aqua is deprecated for quite a few months now and is not updated anymore. Check the migration guide here $\endgroup$
    – Lena
    Nov 17 at 13:23
  • $\begingroup$ @Lena Thank you very much for the information. $\endgroup$
    – Sup
    Nov 17 at 13:34
  • $\begingroup$ @Sup is p here the layer of your QAOA's Ansatz (on a 15 qubit problem) ? It seems like you are having p = 2 ? $\endgroup$
    – KAJ226
    Nov 17 at 15:19
  • $\begingroup$ @KAJ226 Yeah, the number of layers that's mentioned in the original paper of QAOA. p is the number of times the interactions(CNOT+R_Z+CNOT) are performed in the circuit. Furthermore, as p tends to infinity, the probability of QAOA generating the correct solution increases. $\endgroup$
    – Sup
    Nov 18 at 17:57
2
$\begingroup$

You can set p when you create the QAOA instance e.g. (without explicitly specifying a value it defaults to 1)

qaoa_mes = QAOA(quantum_instance=quantum_instance, p=5, initial_point=[0., 0.])

you can refer to the API ref. documentation for QAOA here https://qiskit.org/documentation/stubs/qiskit.aqua.algorithms.QAOA.html

Note: the above link to to the now deprecated Aqua that you are using. When you migrate off Aqua the moved/refactored QAOA is here https://qiskit.org/documentation/stubs/qiskit.algorithms.QAOA.html - as we normally use reps for the number of layers in circuits etc p was renamed to reps but as noted it still performs the same function.

$\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.