API documentation for the registry
module
The registry
module is used to populate the
MODULE_REGISTRY
. This provides a dictionary
giving access to the key components (schema, constants classes and model) of Virtual
Ecosystem modules used in model setup and configuration. Those components are stored in
the dictionary as instances of the ModuleInfo
dataclass, which has schema
, model
and constant_classes
attributes. The
dictionary is keyed by either the model name or core
, which provides details on the
core schema and constants, but does not provide a model object.
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 module registry. |
Classes:
|
Dataclass for module information. |
Functions:
|
Register module components. |
- virtual_ecosystem.core.registry.MODULE_REGISTRY: dict[str, ModuleInfo] = {}
The global module registry.
As each module is registered using
register_module()
, aModuleInfo
dataclass will be added to this registry using the stem name of the module being registered.
- class virtual_ecosystem.core.registry.ModuleInfo(model: Any, schema: dict[str, Any], constants_classes: dict[str, ConstantsDataclass], is_core: bool)
Dataclass for module information.
This dataclass is used to hold the core components of individual modules within the
MODULE_REGISTRY
. Each class attribute contains one of the core components ofschema
,model
andconstant_classes
.Note that the
virtual_ecosystem.core
module does not have an associated BaseModel subclass and themodel
attribute for thecore
module will be None.Attributes:
A dictionary of module constants classes.
Logical flag indicating if an instance contains registration information for the core module.
The BaseModel subclass associated with the module.
The module JSON schema as a dictionary, used to validate configuration data for running a simulation.
- constants_classes: dict[str, ConstantsDataclass]
A dictionary of module constants classes. The individual ConstantsDataclass objects are keyed by their name.
- virtual_ecosystem.core.registry.register_module(module_name: str) None
Register module components.
This function loads the module schema, any constants classes and the main
BaseModel()
subclass for a module and then adds aModuleInfo
dataclass instance to theMODULE_REGISTRY
containing those details. Thecore
module does not have an associated module.This function is primarily used within the
build_schema()
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.model.animals’).
- Raises:
RuntimeError – if the requested module cannot be found or where a module does not provide a single subclass of the
BaseModel
class.Exception – other exceptions can occur when loading the JSON schema fails.