qiskit-nature
qiskit-nature copied to clipboard
Support VQEClient.retrieve_job()
What is the expected enhancement?
I want this method because I sometimes want to retrieve a runtime job later. Is there another way?
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.
May I work on this issue?
@iuliazidaru Sure thing! Maybe you can sync with @Cryoris who originally wrote the VQEClient
:+1:
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 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.
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 Yes. I'll implement it.
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 Thanks. It might be better to name the method differently.
Closing this as per https://github.com/Qiskit/qiskit-nature/pull/1124