Job#
- class Job(backend: Backend, job_id: str | None = None, **kwargs)[source]#
Abstract handle for a (potentially asynchronous) backend execution.
A
Jobis returned byBackend.run_async()immediately after submission. The caller can then:call
result()to wait for the outcome and retrieve it, orpoll
status/done()/running()/queued()/cancelled()to check the current state, orcall
cancel()to attempt cancellation.
This follows the Future (or Promise) pattern: execution happens independently of the caller, and the caller decides when to wait for the outcome.
Design contract
The
Jobbase class defines only the observable contract. That is, the three abstract methods that every concrete job must implement. It deliberately prescribes no internal synchronisation mechanism (no threading, no asyncio, no polling loop). Each concrete subclass chooses whatever concurrency model suits its execution environment:A synchronous simulator may compute the result inline and make it available before
result()is ever called.An asynchronous hardware backend may submit to a remote queue and poll in a background thread until the result is ready.
From the caller’s perspective, all of the above are used identically.
- Parameters:
- backendBackend
The backend that created this job.
- job_idstr or None
Optional caller-supplied identifier (e.g. a remote job ID assigned by a vendor API). If
None, the concrete subclass is responsible for assigning one.- **kwargs
Additional backend-specific metadata to associate with this job. It can be used by any backend implementation as needed.
Properties#
Identifier for this job, or |
|
The |
|
The most recently cached |
Abstract Methods#
|
Block until the job reaches a terminal state and return its result. |
Attempt to cancel the job. |
|
Query and return the current |
Methods#
|
Initialize a Job instance. |
|
Return |
Return |
|
Return |
|
Return |
|
Return |
|
Fetch the latest status from the backend and return it. |
|
|
Raise the appropriate exception if the job did not complete successfully. |
Exceptions#
- exception JobFailureError[source]#
Raised by
Job.result()when the job terminated inERRORstate.
- exception JobCancelledError[source]#
Raised by
Job.result()when the job was cancelled (CANCELLED).