RuntimeJob¶
- class RuntimeJob(backend, api_client, client_params, job_id, program_id, service, params=None, creation_date=None, user_callback=None, result_decoder=None, image='', session_id=None, tags=None)[source]¶
Representation of a runtime program execution.
A new
RuntimeJob
instance is returned when you callQiskitRuntimeService.run
to execute a runtime program, orQiskitRuntimeService.job
to retrieve a previously executed job.If the program execution is successful, you can inspect the job’s status by calling
status()
. Job status can be one of theJobStatus
members.Some of the methods in this class are blocking, which means control may not be returned immediately.
result()
is an example of a blocking method:job = service.run(...) try: job_result = job.result() # It will block until the job finishes. print("The job finished with result {}".format(job_result)) except RuntimeJobFailureError as ex: print("Job failed!: {}".format(ex))
If the program has any interim results, you can use the
callback
parameter of therun()
method to stream the interim results along with the final result. Alternatively, you can use thestream_results()
method to stream the results at a later time, but before the job finishes.RuntimeJob constructor.
- Parameters:
backend (
Backend
) – The backend instance used to run this job.api_client (
RuntimeClient
) – Object for connecting to the server.client_params (
ClientParameters
) – Parameters used for server connection.job_id (
str
) – Job ID.program_id (
str
) – ID of the program this job is for.params (
Optional
[Dict
]) – Job parameters.creation_date (
Optional
[str
]) – Job creation date, in UTC.user_callback (
Optional
[Callable
]) – User callback function.result_decoder (
Union
[Type
[ResultDecoder
],Sequence
[Type
[ResultDecoder
]],None
]) – AResultDecoder
subclass used to decode job results.image (
Optional
[str
]) – Runtime image used for this job: image_name:tag.service (
QiskitRuntimeService
) – Runtime service.session_id (
Optional
[str
]) – Job ID of the first job in a runtime session.tags (
Optional
[List
]) – Tags assigned to the job.
Attributes
Job creation date in local time.
Return the runtime image used for the job.
Job input parameters.
Program ID.
Session ID.
Job tags.
Methods
Return the backend where this job was executed.
Cancel the job.
Cancel result streaming.
Return whether the job has been cancelled.
Return whether the job has successfully run.
Returns the reason if the job failed.
Return whether the job is in a final job state such as
DONE
orERROR
.RuntimeJob.interim_results
([decoder])Return the interim results of the job.
Return a unique id identifying the job.
Return job logs.
Return job metrics.
RuntimeJob.result
([timeout, decoder])Return the results of the job.
Return whether the job is actively running.
Return the status of the job.
RuntimeJob.stream_results
(callback[, decoder])Start streaming job results.
Unsupported method. .. note::.
RuntimeJob.wait_for_final_state
([timeout])Use the websocket server to wait for the final the state of a job.