Skip to content

qubosolver.protocols

qubosolver.protocols

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

Unlike nominal typing (C++/Java), where a class must explicitly inherit from an interface, Python's Protocol 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 checks against the protocol are also supported (see typing.Protocol).

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.

Backend

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

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.
    """
    ...