Skip to main content
IBM Quantum Platform
This page is from the dev version of Qiskit SDK. Go to the stable version.

BasePrimitiveJob

class qiskit.primitives.BasePrimitiveJob(job_id, **kwargs)

GitHub

Bases: ABC, Generic[ResultT, StatusT]

Primitive job abstract base class.

This defines the functionality of the “job handle” object you get by a call to primitive.run(). Typically this object represents a handle to an asynchronous task, where the status(), done(), running(), cancelled() and in_final_state() methods return non-blocking information on the state of the task.

The method result() is typically implemented as a blocking call that waits for the execution result to return. Use of this job object almost invariably ends in a call to result().

Note

This is an abstract base class, defining an interface. Each primitives provider (for example, qiskit_aer or qiskit_ibm_runtime) will have its own subclass of this object, which may provide additional functionality on top of this interface.


Subclassing

Each implementer of the primitives should provide a concrete implementation of this interface. There are no provided methods on the base implementation, other than the job_id() getter, since a string key uniquely identifying jobs is a requirement of all primitives.

The ResultT generic type should be set to a subclass of the appropriate versioned primitive result. This typically will mean setting it to PrimitiveResult (for V2), or an implementation-specific subclass of this.

The StatusT generic type is completely freeform; your implementation can provide any status object you like and there is no defined interface. Instead, the done(), running(), cancelled() and in_final_state() methods of this interface should be implemented to give the user simple programmatic access to coarse-grained status information. You can provide additional details in the complete StatusT generic.

Creating this “job” handle is conventionally expected (but not strictly required) to be fast and non-blocking, and for this object to hold an internal asynchronous handle to the actual job. The result() method should typically block until ready, if called before the job has completed.

Initializes the primitive job.

param job_id

A unique id in the context of the primitive used to run the job.

param kwargs

Any key value metadata to associate with this job.


Methods

cancel

abstract cancel()

GitHub

Attempt to cancel the job.

cancelled

abstract cancelled()

GitHub

Return whether the job has been cancelled.

Return type

bool

done

abstract done()

GitHub

Return whether the job has successfully run.

Return type

bool

in_final_state

abstract in_final_state()

GitHub

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

Return type

bool

job_id

job_id()

GitHub

Return a unique id identifying the job.

Return type

str

result

abstract result()

GitHub

Return the results of the job.

Return type

ResultT

running

abstract running()

GitHub

Return whether the job is actively running.

Return type

bool

status

abstract status()

GitHub

Return the status of the job.

Return type

StatusT

Parameters

job_id (str) –

Was this page helpful?
Report a bug, typo, or request content on GitHub.