API documentation for the registry module#
The registry module is used to populate the
MODULE_REGISTRY.
The registry is a dictionary, keyed using the short names of models, such as core or
plants. Each entry provides a ModuleInfo
dataclass, which provides the BaseModel subclass for each model and its configuration
model. The core model has a configuration model but has no BaseModel subclass.
The module also provides the register_module()
function, which is used to populate the registry with the components of a given module.
Data:
The global disturbance module registry. |
|
The global module registry. |
Classes:
|
Dataclass for module information. |
Functions:
|
Get the root configuration class for a model. |
|
Register module components. |
|
Register module components. |
- virtual_ecosystem.core.registry.DISTURBANCE_REGISTRY: dict[str, ModuleInfo] = {}#
The global disturbance module registry.
As each module is registered using
register_disturbance(), aModuleInfodataclass will be added to this registry using the short name of the module being registered.
- virtual_ecosystem.core.registry.MODULE_REGISTRY: dict[str, ModuleInfo] = {}#
The global module registry.
As each module is registered using
register_module(), aModuleInfodataclass will be added to this registry using the short name of the module being registered.
- class virtual_ecosystem.core.registry.ModuleInfo(model: Any, config: type[Configuration], is_core: bool)[source]#
Dataclass for module information.
This dataclass holds references to Base subclasses and configuration class for a model or disturbance and is used to hold that information with the corresponding registry. Note that the
virtual_ecosystem.coremodule does not have an associated BaseModel subclass and themodelattribute for thecoremodule will be None.Attributes:
A Configuration subclass that provides a pydantic model to populate and validate the model configuration.
Logical flag indicating if an instance contains registration information for the core module.
The Base subclass associated with the module.
- config: type[Configuration]#
A Configuration subclass that provides a pydantic model to populate and validate the model configuration.
- virtual_ecosystem.core.registry.get_model_configuration_class(module_name: str, module_name_short: str)[source]#
Get the root configuration class for a model.
Discovery is name based, with the function attempting to retrieve a class based on the model short name:
plants->PlantsConfiguration,abiotic_simple->AbioticSimpleConfiguration
- Parameters:
module_name – The full module name (e.g.
virtual_ecosystem.models.plants)module_name_short – The short module name (e.g
plants)
- virtual_ecosystem.core.registry.register_disturbance(module_name: str) None[source]#
Register module components.
This function loads the
BaseDisturbance()subclass for a module and its root configuration object. It then adds aModuleInfodataclass instance to theDISTURBANCE_REGISTRYcontaining references to those classes. Thecoremodule does not have an associated module.This function is primarily used within the
generate_configuration()method to register the components required to validate and setup the model configuration for a particular simulation.- Parameters:
module_name – The full name of the module to be registered (e.g. ‘virtual_ecosystem.disturbances.logging’).
- Raises:
RuntimeError – if the requested module cannot be found or where a module does not provide a single subclass of the
BaseDisturbanceclass.Exception – other exceptions can occur when loading the JSON schema fails.
- virtual_ecosystem.core.registry.register_module(module_name: str) None[source]#
Register module components.
This function loads the main
BaseModel()subclass for a module and the root configuration object for a module. It then adds aModuleInfodataclass instance to theMODULE_REGISTRYcontaining references to those classes. Thecoremodule does not have an associated module.This function is primarily used within the
generate_configuration()method to register the components required to validate and setup the model configuration for a particular simulation.- Parameters:
module_name – The full name of the module to be registered (e.g. ‘virtual_ecosystem.models.animal’).
- Raises:
RuntimeError – if the requested module cannot be found or where a module does not provide a single subclass of the
BaseModelclass.