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:

MODULE_REGISTRY

The global module registry.

Classes:

ModuleInfo(model, schema, constants_classes, ...)

Dataclass for module information.

Functions:

register_module(module_name)

Register module components.

virtual_ecosystem.core.registry.MODULE_REGISTRY: dict[str, ModuleInfo] = {}

The global module registry.

As each module is registered using register_module(), a ModuleInfo 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 of schema, model and constant_classes.

Note that the virtual_ecosystem.core module does not have an associated BaseModel subclass and the model attribute for the core module will be None.

Attributes:

constants_classes

A dictionary of module constants classes.

is_core

Logical flag indicating if an instance contains registration information for the core module.

model

The BaseModel subclass associated with the module.

schema

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.

is_core: bool

Logical flag indicating if an instance contains registration information for the core module.

model: Any

The BaseModel subclass associated with the module.

schema: dict[str, Any]

The module JSON schema as a dictionary, used to validate configuration data for running a simulation.

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 a ModuleInfo dataclass instance to the MODULE_REGISTRY containing those details. The core 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.