4
$\begingroup$

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")
   res 

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
    res
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.

$\endgroup$
3
  • 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, 2023 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, 2023 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 P
    Nov 25, 2023 at 11:07

1 Answer 1

1
$\begingroup$

If the job was completed, you should be able to see the result on IBM Quantum Platform. If you would like to retrieve the result within the ipython notebook, something like this should work :

from qiskit_ibm_runtime import QiskitRuntimeService

# Initialize the account first.
service = QiskitRuntimeService()

jobs =service.jobs(backend_name="ibm_brisbane")

This will return all jobs you've run on ibm_brisbane.

Please see monitor a job for more info.

$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.