BasePrimitiveJob
class qiskit.primitives.BasePrimitiveJob(job_id, **kwargs)
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().
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
cancelled
done
in_final_state
abstract in_final_state()
Return whether the job is in a final job state such as DONE or ERROR.
Return type
job_id
result
running
status
Parameters
job_id (str) –