I am trying to optimize a Hamiltonian using QAOA in IBM Qiskit.

I used the following 'minimize' function to get my result. (I am not including the whole code because it will get unnecessarily long).

   res = minimize(cost_func, x0, args=(ansatz, hamiltonian, estimator), method="COBYLA")

When I ran the problem on a 'ibmq qasm simulator' I got the following result:

fun: -23.1424
   maxcv: 0.0
 message: 'Optimization terminated successfully.'
    nfev: 45
  status: 1
 success: True
       x: array([3.39824022, 4.17447906, 2.86297948, 3.1139919 ])

As you can see, I got multiple attributes in the solution.

But when I ran this on an actual quantum computer (ibm brisbane), I used the same code and same variable 'res'; it went on Queue and I had to wait for around 4-5 hours. But after the job was done, I cannot get the value for res which was defined in the previous line of code.

Traceback (most recent call last):
  Cell In[1], line 1
NameError: name 'res' is not defined

And I tried using job.result() but that doesn't have the required attributes I got from the results of the simulator stored in variable 'res'.

How can I get the attributes such as res.x from the already completed job? It is very much needed for my further work.

  • 1
    $\begingroup$ +1 and welcome to our community! Thanks for your contribution and we hope to see much more of you in the future! $\endgroup$ Nov 6 at 17:03
  • 1
    $\begingroup$ can you add the versions for qiskit and qiskit-ibm-provider/qiskit_ibm_runtime you are using? $\endgroup$
    – luciano
    Nov 24 at 9:58
  • $\begingroup$ I am using the versions: qiskit 0.44.1, qiskit_ibm_runtime 0.11.3, and qiskit_ibm_provider 0.6.3. $\endgroup$
    – Amrita
    Nov 25 at 11:07


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.