qrunch.quantum.backends.backends_protocols

Protocols used for backends.

Classes

Backend

Class for handling backends.

BackendJob

Job class for handling quantum jobs, both quantum and simulated.

BackendJobStatus

Class with all possible job statuses.

BackendResult

Class for backend results.

SimulatedJob

Job class for handling simulated jobs using Qiskit.

class Backend

Bases: Protocol

Class 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:
  • circuits (Circuit | Sequence[Circuit]) – circuit to run on backend

  • shots (int | None) – number of shots

Return type:

BackendJob

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: ABC

Job class for handling quantum jobs, both quantum and simulated.

abstract property backend: Backend

Backend used to calculate the job on.

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:

BackendResult

abstractmethod status() BackendJobStatus

Return the status of the job.

Return type:

BackendJobStatus

wait_for_final_state(timeout: float | None = None) None

Wait until the job status is in a final state, i.e., DONE, CANCELLED, or FAILED.

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: Enum

Class 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, or FAILED.

Return type:

bool

is_queuing() bool

Return whether the status is QUEUED.

Return type:

bool

class BackendResult

Bases: object

Class 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: BackendJob

Job 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

property backend: Backend

Backend used for the job.

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:

BackendResult

status() BackendJobStatus

Return the status of the job.

Return type:

BackendJobStatus

wait_for_final_state(timeout: float | None = None) None

Wait until the job status is in a final state, i.e., DONE, CANCELLED, or FAILED.

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