qrunch.quantum.backends.backends_protocols
Protocols used for backends.
Classes
Class for handling backends. |
|
Job class for handling quantum jobs, both quantum and simulated. |
|
Class with all possible job statuses. |
|
Class for backend results. |
|
Job class for handling simulated jobs using Qiskit. |
- class Backend
Bases:
ProtocolClass for handling backends.
- __init__(*args, **kwargs)
- property name: str
Return the name of the backend.
- run(circuits: Circuit | Sequence[Circuit], shots: int | None) BackendJob
Run circuit on the backend.
- Parameters:
- Return type:
Returns: A backend job which can fetch the result when done.
- supports_shots_equals_none() bool
Return whether the backend supports shots = None.
Shots = None means that a full state vector simulation is done.
- Return type:
bool
- class BackendJob
Bases:
ABCJob class for handling quantum jobs, both quantum and simulated.
- abstractmethod cancel() None
Cancel the job.
- Return type:
None
- abstract property job_id: str
ID of the job.
- abstractmethod result() BackendResult
Return the results of the job.
- Return type:
- abstractmethod status() BackendJobStatus
Return the status of the job.
- Return type:
- wait_for_final_state(timeout: float | None = None) None
Wait until the job status is in a final state, i.e.,
DONE,CANCELLED, orFAILED.- Parameters:
timeout (float | None) – Seconds to wait for the job. If
None, wait forever.- Raises:
TimeoutError – If the job does not reach a final state before the specified timeout.
- Return type:
None
- class BackendJobStatus
Bases:
EnumClass with all possible job statuses.
- CANCELLED = 'job is cancelled'
- DONE = 'job has run successfully'
- FAILED = 'job has failed'
- QUEUED = 'job is queued'
- RUNNING = 'job is running'
- done() bool
Return True if the status is
DONE.- Return type:
bool
- is_final_state() bool
Return whether the status is in a final state, i.e.,
DONE,CANCELLED, orFAILED.- Return type:
bool
- is_queuing() bool
Return whether the status is
QUEUED.- Return type:
bool
- class BackendResult
Bases:
objectClass for backend results.
- __init__(backend_name: str, job_id: str, measurements: Sequence[QuantumMeasurement], success: bool, exception: Exception | None = None) None
- Parameters:
backend_name (str)
job_id (str)
measurements (Sequence[QuantumMeasurement])
success (bool)
exception (Exception | None)
- Return type:
None
- backend_name: str
name of the backend
- exception: Exception | None = None
- job_id: str
identifier for the job
- measurements: Sequence[QuantumMeasurement]
sequence of measurements
- success: bool
True if the task is successful
- class SimulatedJob
Bases:
BackendJobJob class for handling simulated jobs using Qiskit.
- __init__(backend: Backend, job_id: str, result: BackendResult) None
Initialize a simulated job.
- Parameters:
backend (Backend) – Backend used for the job
job_id (str) – id of the job as a string
result (BackendResult) – Result of the job.
- Return type:
None
- cancel() None
Just a simulated job, so nothing to cancel.
- Return type:
None
- property job_id: str
ID of the job.
- result() BackendResult
Get the results of the simulation.
- Return type:
- status() BackendJobStatus
Return the status of the job.
- Return type:
- wait_for_final_state(timeout: float | None = None) None
Wait until the job status is in a final state, i.e.,
DONE,CANCELLED, orFAILED.- Parameters:
timeout (float | None) – Seconds to wait for the job. If
None, wait forever.- Raises:
TimeoutError – If the job does not reach a final state before the specified timeout.
- Return type:
None