# Tweak the parameter p of QAOA in qiskit

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

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?

• 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
– Lena
Nov 17, 2021 at 13:23
• @Lena Thank you very much for the information.
– Sup
Nov 17, 2021 at 13:34
• @Sup is p here the layer of your QAOA's Ansatz (on a 15 qubit problem) ? It seems like you are having p = 2 ? Nov 17, 2021 at 15:19
• @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.
– Sup
Nov 18, 2021 at 17:57

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.])

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.