Skip to content

Results are limited to QUBO Solver v0.9.1

Product news
You are reading QUBO Solver v0.9.1, an older version of this documentation. Go to the latest version (v0.10.0)

qubosolver.protocols

Structural protocols for the QUBO solver, using PEP 544 Protocol (external) typing.

Unlike nominal typing (C++/Java), where a class must explicitly inherit from an interface, Python's Protocol (external) allows "static duck typing": a class is compatible with a protocol if it implements the same methods with matching signatures, regardless of its inheritance tree. mypy validates the full method contract (argument names, types, and return type); when runtime type checking is enabled, isinstance (external) checks against the protocol are also supported (see typing.Protocol (external)).

Example
from typing import Protocol
class Speaker(Protocol):
def talk(self, message: str) -> str: ...
def process(entity: Speaker) -> None:
print(entity.talk("Hello"))
# Any class implementing `talk(self, message: str) -> str`
# is accepted by mypy here, without inheriting from Speaker.

Classes:

  • Backend –

    Structural protocol for quantum backends.

Structural protocol for quantum backends.

Any object that implements run with the expected signature is considered a Backend, without requiring explicit subclassing. This enables duck-typed compatibility checks (via isinstance (external) when beartype runtime checking is active, or static type checking via mypy/pyright).

Typical implementations wrap a remote or local quantum execution engine (e.g. a Qoolqit emulator or a real QPU) and return a handle to the asynchronous computation.

Methods:

  • run –

    Submit a quantum program for execution.

run(program: qoolqit.QuantumProgram) -> job.Job[Results]

Submit a quantum program for execution.

Parameters:

Returns:

Source code in qubosolver/types/protocols/backend.py
def run(self: Self, program: qoolqit.QuantumProgram) -> job.Job[Results]:
"""Submit a quantum program for execution.
Args:
program: The compiled quantum program to execute.
Returns:
A job wrapping the [`qoolqit.execution.Results`][]
that will be populated upon completion.
"""
...