Core Registry#
registry
#
| CLASS | DESCRIPTION |
|---|---|
Registry |
Generic registry for classes with factory pattern support. |
Classes#
Registry
#
Generic registry for classes with factory pattern support.
Subclasses must define _base_class and _registry_name class attributes.
| ATTRIBUTE | DESCRIPTION |
|---|---|
_base_class |
Base class that all registered classes must inherit from.
TYPE:
|
_registry_name |
Human-readable name for error messages (e.g., "kernel", "loss").
TYPE:
|
_registry |
Internal storage for registered classes.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
register |
Register a class with the given name. |
build |
Instantiate a class from the registry. |
get |
Get a class from the registry without instantiation. |
available |
Return a list of available registered names. |
is_registered |
Check if a name is registered. |
Functions#
register(name: str)
classmethod
#
Register a class with the given name.
The registration name is stored on the class as _registry_key attribute.
Arguments
name : str Name to register the class under.
| RETURNS | DESCRIPTION |
|---|---|
Callable
|
Decorator that registers the class. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the decorated class is not a subclass of |
ValueError
|
If a class with the given name is already registered. |
Source code in spectre/core/registry.py
build(name: str, **kwargs)
classmethod
#
Instantiate a class from the registry.
Arguments
name : str Name of the registered class. **kwargs Keyword arguments passed to the class constructor.
| RETURNS | DESCRIPTION |
|---|---|
object
|
Instantiated object. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If no class is registered with the given name. |
Source code in spectre/core/registry.py
get(name: str) -> type
classmethod
#
Get a class from the registry without instantiation.
Arguments
name : str Name of the registered class.
| RETURNS | DESCRIPTION |
|---|---|
type
|
The registered class. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If no class is registered with the given name. |