Backend Interface#

Core Backend Base#

Backend interface implementations wired to the core Protocols.

This module defines:

  • BackendConfig: immutable configuration for a backend instance.

  • QuantumBackend: abstract base class that enforces the backend contract and offers shared validation utilities for inputs, states, and future branches.

class qmlhc.core.backend.BackendConfig(output_dim, shots=None, seed=None)[source]#

Bases: object

Immutable configuration for a backend instance.

Parameters:
  • output_dim (int) – Dimensionality of the state vector produced by the backend.

  • shots (int or None, optional) – Number of execution shots (if the backend is stochastic). None means analytic mode. Default is None.

  • seed (int or None, optional) – Random seed used by stochastic backends. Default is None.

output_dim: int#
seed: Optional[int] = None#
shots: Optional[int] = None#
class qmlhc.core.backend.QuantumBackend(config)[source]#

Bases: QuantumBackend

Abstract base class with shared validation utilities.

Concrete adapters must implement run and project_future while using the helpers provided here to validate inputs and outputs.

__init__(config)[source]#

Initialize the backend with a given configuration.

Parameters:

config (BackendConfig) – Backend configuration (e.g., output_dim, shots).

Raises:

ValueError – If output_dim is not positive.

capabilities()[source]#

Return a conservative default set of backend capabilities.

Returns:

Dictionary describing the backend’s advertised features.

Return type:

Capabilities

encode(x)[source]#

Store and validate the last input vector x.

Parameters:

x (TensorLike) – Input vector of shape (output_dim,).

Raises:

ValueError – If the input dimension does not match output_dim.

Return type:

None

project_future(s_t, branches=2)[source]#

Generate future state projections from the current state s_t.

Notes

Must be overridden by concrete adapters.

Parameters:
  • s_t (TensorLike) – Current state vector.

  • branches (int, optional) – Number of future branches (K), by default 2.

Returns:

Future state matrix of shape (K, output_dim).

Return type:

Array

run(params=None)[source]#

Execute the backend on the last encoded input.

Notes

Must be overridden by concrete adapters.

Parameters:

params (Mapping[str, Any] or None, optional) – Optional parameter override for the backend execution.

Returns:

Current state vector s_t of shape (output_dim,).

Return type:

Array