qiskit-nature icon indicating copy to clipboard operation
qiskit-nature copied to clipboard

Support VQEClient.retrieve_job()

Open ikkoham opened this issue 3 years ago • 9 comments

What is the expected enhancement?

I want this method because I sometimes want to retrieve a runtime job later. Is there another way?

ikkoham avatar Dec 22 '21 03:12 ikkoham

You can retrieve runtime jobs using the following code. See also: https://qiskit.org/documentation/partners/qiskit_runtime/tutorials/00_introduction.html It's retrieved on the provider level not backend level as it is done for normal circuit / Qobj jobs.

from qiskit import IBMQ
IBMQ.load_account()
provider = IBMQ.get_provider(hub='HUB_NAME', group='GROUP_NAME', project='PROJECT_NAME')
job = provider.runtime.job('JOB_ID')

But I agree that it would be a good idea to add VQEClient.retrieve_job() API.

HuangJunye avatar Jan 10 '22 11:01 HuangJunye

May I work on this issue?

iuliazidaru avatar Jan 14 '22 11:01 iuliazidaru

@iuliazidaru Sure thing! Maybe you can sync with @Cryoris who originally wrote the VQEClient :+1:

mrossinek avatar Jan 18 '22 13:01 mrossinek

We already store the job_id in the result you get back from the VQEClient, so retrieving the job would be as easy as doing

provider = ...
my_vqe = VQEClient(ansatz, ..., provider=provider)
my_result = my_vqe.compute_minimum_eigenvalue(...)

# retrieve job
job = provider.runtime.job(my_result.job_id)

Since we design our algorithms to be stateless we also wouldn't want to store the last job ID in the VQEClient. @ikkoham do you have a use-case in mind where calling something like

job = my_vqe.retrieve_job(my_result.job_id)  # or just my_result

would be more useful than just directly calling

job = provider.runtime.job(my_result.job_id)

?

Cryoris avatar Jan 20 '22 20:01 Cryoris

@Cryoris Thanks. You are right. I certainly don't think that VQE.retrieve_job is necessary. What I really want is something that makes it easy to make a MinimumEigensolverResult from the job_id.

ikkoham avatar Jan 26 '22 10:01 ikkoham

Ah I see! Yes I think this should be possible -- as long as the job result is still stored on our servers. From the job ID we can query both the result and the inputs which should enable us to construct the results object.

@iuliazidaru are you still interested in tackling this issue? 🙂

Cryoris avatar Jan 26 '22 20:01 Cryoris

@Cryoris Yes. I'll implement it.

iuliazidaru avatar Jan 28 '22 12:01 iuliazidaru

Great 🙂 let me know if I can help you out!

Since it's not about the job but about the result I think we should call the function retrieve_result that takes a provider and a job_id and returns a VQEResult. You should be able to get the job associated with the job_id via

job = provider.runtime.job(job_id)

and then the properties of the VQEResult should be reconstructable from what's in job.inputs and job.result().

It might be good to make this function a staticmethod as it doesn't have anything to do with the algorithm setup, such as the ansatz or backend.

Cryoris avatar Jan 28 '22 15:01 Cryoris

@Cryoris Thanks. It might be better to name the method differently.

ikkoham avatar Jan 31 '22 02:01 ikkoham

Closing this as per https://github.com/Qiskit/qiskit-nature/pull/1124

mrossinek avatar Apr 12 '23 14:04 mrossinek