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)[源代码]
基类:
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)[源代码]
Initializes the Registry with a given name.
- 参数:
name (str) -- The name to identify this registry.
- register(module_name: str | None = None, module: Any | None = None)[源代码]
Registers module in the registry in a single call.
- 参数:
module_name (str) -- The name of module to be registered.
module (List[Any] | Dict[str, Any]) -- The module to be registered.
- 抛出:
NotImplementedError -- If the input is already registered.
- batch_register(modules: List[Any] | Dict[str, Any])[源代码]
- Registers multiple modules in the registry in a single call. Accepts either a list of modules or a dictionary
mapping names to modules.
- 参数:
modules (List[Any] | Dict[str, Any]) -- A list of modules or a dictionary mapping module names to the modules.
- 抛出:
NotImplementedError -- If the input is neither a list nor a dictionary.