Backend Registry#

Backend Registry#

Lightweight in-memory registry for discoverable quantum backends and their factory constructors. Provides a unified mechanism to register, query, instantiate, and list available backends through a global module-level API.

class qmlhc.core.registry.BackendRegistry[source]#

Bases: object

In-memory registry that stores and manages backend entries.

Methods allow registration, lookup, creation, and listing of all available backends.

__init__()[source]#

Initialize an empty backend registry.

create(name, config)[source]#

Instantiate a backend by name.

Parameters:
  • name (str) – Backend name to instantiate.

  • config (BackendConfig) – Configuration object to pass to the backend constructor.

Returns:

New backend instance.

Return type:

QuantumBackendProtocol

exists(name)[source]#

Check whether a backend with the given name exists.

Parameters:

name (str) – Backend name.

Returns:

True if the backend is registered, False otherwise.

Return type:

bool

get(name)[source]#

Retrieve a backend entry by name.

Parameters:

name (str) – Backend name.

Returns:

Registry entry containing constructor and capabilities.

Return type:

Entry

Raises:

KeyError – If the backend is not registered.

list()[source]#

List all registered backends and their capabilities.

Returns:

Dictionary mapping backend names to their capability metadata.

Return type:

dict[str, Capabilities]

register(name, constructor, capabilities, overwrite=False)[source]#

Register a new backend with the given name and constructor.

Parameters:
  • name (str) – Unique backend name.

  • constructor (Callable[[BackendConfig], QuantumBackendProtocol]) – Constructor function returning a backend instance.

  • capabilities (Capabilities) – Metadata describing backend features and limits.

  • overwrite (bool, optional) – Whether to overwrite an existing entry with the same name. Default is False.

Raises:
  • ValueError – If name is empty.

  • KeyError – If the backend name already exists and overwrite=False.

Return type:

None

class qmlhc.core.registry.Entry(name, constructor, capabilities)[source]#

Bases: object

Represents a registry entry describing a backend constructor and its metadata.

Parameters:
  • name (str) – Human-readable backend name.

  • constructor (Callable[[BackendConfig], QuantumBackendProtocol]) – Callable that returns an initialized backend instance when given a BackendConfig.

  • capabilities (Capabilities) – Static metadata describing backend capabilities.

capabilities: Capabilities#
constructor: Callable[[BackendConfig], QuantumBackend]#
name: str#
qmlhc.core.registry.backend_exists(name)[source]#

Check whether a backend is registered.

Parameters:

name (str) – Backend name.

Returns:

True if the backend exists, False otherwise.

Return type:

bool

qmlhc.core.registry.create_backend(name, config)[source]#

Instantiate a registered backend by name.

Parameters:
  • name (str) – Backend name.

  • config (BackendConfig) – Configuration for backend creation.

Returns:

Instantiated backend object.

Return type:

QuantumBackendProtocol

qmlhc.core.registry.list_backends()[source]#

List all registered backends.

Returns:

Mapping of backend names to their declared capabilities.

Return type:

dict[str, Capabilities]

qmlhc.core.registry.register_backend(name, constructor, capabilities, overwrite=False)[source]#

Register a backend globally.

Parameters:
  • name (str) – Backend name.

  • constructor (Callable[[BackendConfig], QuantumBackendProtocol]) – Constructor function returning a backend instance.

  • capabilities (Capabilities) – Backend capabilities metadata.

  • overwrite (bool, optional) – Whether to overwrite an existing entry, by default False.

Return type:

None