memoryscope.core.utils.registry
Registry for different modules. Init class according to the class name and verify the input parameters.
- class memoryscope.core.utils.registry.Registry(name: str)[source]
Bases:
object
A registry to manage and instantiate various modules by their names, ensuring the uniqueness of registered entries. It supports both individual and bulk registration of modules, as well as retrieval of modules by name.
- name
The name of the registry.
- Type:
str
- module_dict
A dictionary holding registered modules where keys are module names and values are the modules themselves.
- Type:
Dict[str, Any]
- __init__(name: str)[source]
Initializes the Registry with a given name.
- Parameters:
name (str) – The name to identify this registry.
- register(module_name: str | None = None, module: Any | None = None)[source]
Registers module in the registry in a single call.
- Parameters:
module_name (str) – The name of module to be registered.
module (List[Any] | Dict[str, Any]) – The module to be registered.
- Raises:
NotImplementedError – If the input is already registered.
- batch_register(modules: List[Any] | Dict[str, Any])[source]
- Registers multiple modules in the registry in a single call. Accepts either a list of modules or a dictionary
mapping names to modules.
- Parameters:
modules (List[Any] | Dict[str, Any]) – A list of modules or a dictionary mapping module names to the modules.
- Raises:
NotImplementedError – If the input is neither a list nor a dictionary.