English
Languages
English
Japanese
Spanish

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 call QiskitRuntimeService.run to execute a runtime program, or QiskitRuntimeService.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 the JobStatus 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 the run() method to stream the interim results along with the final result. Alternatively, you can use the stream_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]) – A ResultDecoder 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

RuntimeJob.creation_date

Job creation date in local time.

RuntimeJob.image

Return the runtime image used for the job.

RuntimeJob.inputs

Job input parameters.

RuntimeJob.program_id

Program ID.

RuntimeJob.session_id

Session ID.

RuntimeJob.tags

Job tags.

RuntimeJob.version

Methods

RuntimeJob.backend()

Return the backend where this job was executed.

RuntimeJob.cancel()

Cancel the job.

RuntimeJob.cancel_result_streaming()

Cancel result streaming.

RuntimeJob.cancelled()

Return whether the job has been cancelled.

RuntimeJob.done()

Return whether the job has successfully run.

RuntimeJob.error_message()

Returns the reason if the job failed.

RuntimeJob.in_final_state()

Return whether the job is in a final job state such as DONE or ERROR.

RuntimeJob.interim_results([decoder])

Return the interim results of the job.

RuntimeJob.job_id()

Return a unique id identifying the job.

RuntimeJob.logs()

Return job logs.

RuntimeJob.metrics()

Return job metrics.

RuntimeJob.result([timeout, decoder])

Return the results of the job.

RuntimeJob.running()

Return whether the job is actively running.

RuntimeJob.status()

Return the status of the job.

RuntimeJob.stream_results(callback[, decoder])

Start streaming job results.

RuntimeJob.submit()

Unsupported method. .. note::.

RuntimeJob.wait_for_final_state([timeout])

Use the websocket server to wait for the final the state of a job.