Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
c0ff179
Merge branch '1113-move-animals-over-to-the-new-configuration-system'…
davidorme Oct 27, 2025
e92590d
Merge branch '1112-move-abiotic_simple-over-to-the-new-configuration-…
davidorme Oct 27, 2025
a467a8d
Merge branch '1110-move-hydrology-over-to-the-new-configuration-syste…
davidorme Oct 27, 2025
daa28ed
Converted Data.load_from_config, fixed test
davidorme Oct 27, 2025
4be1369
Retooling config use in main.py
davidorme Oct 27, 2025
378cee7
Fixing issues from tests
davidorme Oct 27, 2025
0b7cb9c
Ready to remove old system
davidorme Oct 27, 2025
86e9b4e
Merge branch '1110-move-hydrology-over-to-the-new-configuration-syste…
davidorme Oct 28, 2025
a43bbb3
Merge branch '1112-move-abiotic_simple-over-to-the-new-configuration-…
davidorme Oct 28, 2025
e2f578f
Merge branch '1113-move-animals-over-to-the-new-configuration-system'…
davidorme Oct 28, 2025
9ec72f2
Merge branch '1113-move-animals-over-to-the-new-configuration-system'…
davidorme Oct 28, 2025
2cf23e3
Merge branch '1113-move-animals-over-to-the-new-configuration-system'…
davidorme Oct 28, 2025
8da91a8
Merge branch '1123-snagging-the-config-system-switch-over' into 1118-…
davidorme Oct 28, 2025
4c37215
Merge branch '1123-snagging-the-config-system-switch-over' into 1118-…
davidorme Oct 28, 2025
c121738
Merge branch '1123-snagging-the-config-system-switch-over' into 1118-…
davidorme Oct 28, 2025
a4ab5a7
Stripping registry of schema and constants, crippling Config use of s…
davidorme Oct 28, 2025
aeaad77
Updating registry testing
davidorme Oct 28, 2025
8a619ad
Docstring fix
davidorme Oct 28, 2025
7229e18
Removing old config from BaseModel.from_config
davidorme Oct 28, 2025
5d04d9e
De-config-ing soil model
davidorme Oct 28, 2025
694dc63
De-config-ing litter model
davidorme Oct 28, 2025
470d786
De-config-ing hydrology model
davidorme Oct 28, 2025
2381bd2
De-config-ing plants model
davidorme Oct 28, 2025
bc73771
De-config-ing animal model
davidorme Oct 28, 2025
177b76f
De-config-ing abiotic_simple model
davidorme Oct 28, 2025
62ba9de
De-config-ing testing model
davidorme Oct 28, 2025
c2ee96a
Stripping Config imports from core code
davidorme Oct 28, 2025
4deb724
Fixing up override params workflow, removing typed object in tests th…
davidorme Oct 28, 2025
e5b7dc1
Merge branch '1110-move-hydrology-over-to-the-new-configuration-syste…
davidorme Oct 28, 2025
43f93ee
Merge branch '1112-move-abiotic_simple-over-to-the-new-configuration-…
davidorme Oct 28, 2025
7be7ece
Merge branch '1113-move-animals-over-to-the-new-configuration-system'…
davidorme Oct 28, 2025
b61362e
Merge branch '1123-snagging-the-config-system-switch-over' into 1118-…
davidorme Nov 3, 2025
7ebe4ae
Merge branch '1110-move-hydrology-over-to-the-new-configuration-syste…
davidorme Nov 3, 2025
f8af9cc
Skipping tests of old configuration system
davidorme Nov 3, 2025
fb12560
Merge branch 'develop' into 1118-move-configuration-use-in-main-over-…
davidorme Nov 3, 2025
10bbeee
Merge branch 'develop' into 1118-move-configuration-use-in-main-over-…
davidorme Nov 3, 2025
206a786
Merge branch '1118-move-configuration-use-in-main-over-to-new-configu…
davidorme Nov 3, 2025
008d2e9
Shutting down constants_loader functionality - uses retired registry …
davidorme Nov 3, 2025
68b6b80
Fixed data loading notebook
davidorme Nov 3, 2025
5f81166
Fixing missing outdir in tests
davidorme Nov 3, 2025
f328f19
Forgot API docs for moconfig_builder
davidorme Nov 3, 2025
504c9e1
actually add the file
davidorme Nov 3, 2025
ec374c9
Merge branch 'develop' into 1118-move-configuration-use-in-main-over-…
davidorme Nov 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/source/_toc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ subtrees:
title: The base_model submodule
- file: api/core/config.md
title: The config submodule
- file: api/core/config_builder.md
title: The config_builder submodule
- file: api/core/configuration.md
title: The configuration submodule
- file: api/core/constants.md
Expand Down
33 changes: 33 additions & 0 deletions docs/source/api/core/config_builder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
jupytext:
cell_metadata_filter: -all
formats: md:myst
main_language: python
text_representation:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.18.1
kernelspec:
display_name: Python 3 (ipykernel)
language: python
name: python3
language_info:
codemirror_mode:
name: ipython
version: 3
file_extension: .py
mimetype: text/x-python
name: python
nbconvert_exporter: python
pygments_lexer: ipython3
version: 3.11.9
---

# API documentation for the {mod}`~virtual_ecosystem.core.config_builder` module

```{eval-rst}
.. automodule:: virtual_ecosystem.core.config_builder
:autosummary:
:members:
```
25 changes: 12 additions & 13 deletions docs/source/using_the_ve/data/data.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@ kernelspec:
display_name: Python 3 (ipykernel)
language: python
name: python3
language_info:
codemirror_mode:
name: ipython
version: 3
file_extension: .py
mimetype: text/x-python
name: python
nbconvert_exporter: python
pygments_lexer: ipython3
version: 3.10.14
---

# Adding and using data with the Virtual Ecosystem
Expand Down Expand Up @@ -83,8 +73,12 @@ from pathlib import Path
import numpy as np
from xarray import DataArray


from virtual_ecosystem.core.config_builder import (
ConfigurationLoader,
generate_configuration,
)
from virtual_ecosystem.core.grid import Grid
from virtual_ecosystem.core.config import Config
from virtual_ecosystem.core.data import Data
from virtual_ecosystem.core.axes import *
from virtual_ecosystem.core.readers import load_to_dataarray
Expand Down Expand Up @@ -234,13 +228,14 @@ file_path = "../../data/xy_dim.nc"
var_name = "temp"
"""

config = Config(cfg_strings=data_toml)
config_data = ConfigurationLoader(cfg_strings=data_toml)
config = generate_configuration(config_data.data)
```

The `Config` object can then be passed to the `load_data_config` method:

```{code-cell} ipython3
data.load_data_config(config)
data.load_data_config(config.core)
```

```{code-cell} ipython3
Expand All @@ -266,3 +261,7 @@ data.save_to_netcdf(
variables_to_save=variables_to_save
)
```

```{code-cell} ipython3

```
3 changes: 0 additions & 3 deletions docs/source/using_the_ve/virtual_ecosystem_in_static_mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ kernelspec:
display_name: Python 3 (ipykernel)
language: python
name: python3
mystnb:
execution_timeout: 60
execution_mode: 'off'
---

# Running the Virtual Ecosystem in Static Mode
Expand Down
141 changes: 1 addition & 140 deletions tests/core/test_base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""

from contextlib import nullcontext as does_not_raise
from logging import CRITICAL, DEBUG, ERROR
from logging import CRITICAL, ERROR
from typing import Any

import pytest
Expand Down Expand Up @@ -320,133 +320,6 @@ class InitVarModel(
assert str(err.value).startswith("Can't instantiate abstract class InitVarModel ")


@pytest.mark.skip(
"This functionality is going to be handed off to the variables system "
"so skipping for now but this will probably be deleted"
)
@pytest.mark.parametrize(
argnames="req_init_vars, raises, exp_err_msg, exp_log",
argvalues=[
pytest.param(
[("temperature", ("spatial",))],
does_not_raise(),
None,
((DEBUG, "init_var model: required var 'temperature' checked"),),
id="single var with axes ok",
),
pytest.param(
[("precipitation", tuple())],
does_not_raise(),
None,
((DEBUG, "init_var model: required var 'precipitation' checked"),),
id="single var without axes ok",
),
pytest.param(
[("temperature", ("spatial",)), ("precipitation", tuple())],
does_not_raise(),
None,
(
(DEBUG, "init_var model: required var 'temperature' checked"),
(DEBUG, "init_var model: required var 'precipitation' checked"),
),
id="multivar ok",
),
pytest.param(
[("precipitation", ("spatial",))],
pytest.raises(ValueError),
"init_var model: error checking vars_required_for_init, see log.",
(
(
ERROR,
"init_var model: required var 'precipitation' not on required "
"axes: spatial",
),
(
ERROR,
"init_var model: error checking vars_required_for_init, see log.",
),
),
id="missing axis",
),
],
)
def test_check_vars_required_for_init(
caplog,
fixture_data_instance_for_model_validation,
fixture_core_components,
req_init_vars,
raises,
exp_err_msg,
exp_log,
):
"""Tests the validation of the vars_required_for_init property on init."""

# This gets registered for each parameterisation but I can't figure out how to
# create the instance via a module-scope fixture and the alternative is just
# defining it at the top, which isn't encapsulated in a test.

from virtual_ecosystem.core.base_model import BaseModel
from virtual_ecosystem.core.config import Config
from virtual_ecosystem.core.configuration import CompiledConfiguration
from virtual_ecosystem.core.core_components import CoreComponents
from virtual_ecosystem.core.data import Data

class TestCaseModel(
BaseModel,
model_name="init_var",
model_update_bounds=("1 second", "1 year"),
vars_required_for_init=(),
vars_updated=[],
):
def spinup(self) -> None:
pass

def update(self, time_index: int, **kwargs: Any) -> None:
pass

def cleanup(self) -> None:
pass

@classmethod
def from_config(
cls,
data: Data,
configuration: CompiledConfiguration,
core_components: CoreComponents,
config: Config,
) -> Any:
return super().from_config(
data=data,
configuration=configuration,
core_components=core_components,
config=config,
)

# Registration of TestClassModel emits logging messages - discard.
caplog.clear()

# Override the vars_required_for_init for different test cases against the
# data_instance
TestCaseModel.vars_required_for_init = req_init_vars

# Create an instance to check the handling
with raises as err:
inst = TestCaseModel(
data=fixture_data_instance_for_model_validation,
core_components=fixture_core_components,
)

if err:
# Check any error message
assert str(err.value) == exp_err_msg
else:
# Check the special methods
assert repr(inst).startswith("TestCaseModel(")
assert str(inst) == "A init_var model instance"

log_check(caplog, exp_log)


@pytest.mark.parametrize(
argnames=["config_string", "raises", "expected_log"],
argvalues=[
Expand Down Expand Up @@ -510,7 +383,6 @@ def test_check_update_speed(
"""Tests check on update speed."""

from virtual_ecosystem.core.base_model import BaseModel
from virtual_ecosystem.core.config import Config
from virtual_ecosystem.core.config_builder import (
ConfigurationLoader,
generate_configuration,
Expand Down Expand Up @@ -547,13 +419,11 @@ def from_config(
data: Data,
configuration: CompiledConfiguration,
core_components: CoreComponents,
config: Config,
) -> Any:
return super().from_config(
data=data,
configuration=configuration,
core_components=core_components,
config=config,
)

# Process the configuration
Expand Down Expand Up @@ -645,7 +515,6 @@ def test_bypass_setup_due_to_static_configuration(
):
"""Test the _bypass_setup_due_to_static_configuration method."""
from virtual_ecosystem.core.base_model import BaseModel
from virtual_ecosystem.core.config import Config
from virtual_ecosystem.core.configuration import CompiledConfiguration
from virtual_ecosystem.core.core_components import (
CoreComponents,
Expand Down Expand Up @@ -680,13 +549,11 @@ def from_config(
data: Data,
configuration: CompiledConfiguration,
core_components: CoreComponents,
config: Config,
) -> BaseModel:
return super().from_config(
data=data,
configuration=configuration,
core_components=core_components,
config=config,
)

for var in data_vars.keys():
Expand Down Expand Up @@ -784,7 +651,6 @@ def test_run_update_due_to_static_configuration(
"""Test the _run_update_due_to_static_configuration method."""

from virtual_ecosystem.core.base_model import BaseModel
from virtual_ecosystem.core.config import Config
from virtual_ecosystem.core.configuration import CompiledConfiguration
from virtual_ecosystem.core.core_components import CoreComponents
from virtual_ecosystem.core.data import Data
Expand Down Expand Up @@ -817,13 +683,11 @@ def from_config(
data: Data,
configuration: CompiledConfiguration,
core_components: CoreComponents,
config: Config,
) -> BaseModel:
return super().from_config(
data=data,
configuration=configuration,
core_components=core_components,
config=config,
)

for var in data_vars.keys():
Expand Down Expand Up @@ -890,7 +754,6 @@ def test_bypass_setup_but_run_update_fails(
):
"""Test the _bypass_setup_due_to_static_configuration method."""
from virtual_ecosystem.core.base_model import BaseModel
from virtual_ecosystem.core.config import Config
from virtual_ecosystem.core.configuration import CompiledConfiguration
from virtual_ecosystem.core.core_components import (
CoreComponents,
Expand Down Expand Up @@ -925,13 +788,11 @@ def from_config(
data: Data,
configuration: CompiledConfiguration,
core_components: CoreComponents,
config: Config,
) -> BaseModel:
return super().from_config(
data=data,
configuration=configuration,
core_components=core_components,
config=config,
)

for var in data_vars.keys():
Expand Down
6 changes: 6 additions & 0 deletions tests/core/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
from virtual_ecosystem.core.exceptions import ConfigurationError


@pytest.fixture(autouse=True)
def skip_these_tests():
"""Do not run tests in this module."""
pytest.skip("These tests rely on the old configuration system and will be deleted.")


@pytest.mark.parametrize(
"dest,source,exp_result, exp_conflicts",
[
Expand Down
6 changes: 6 additions & 0 deletions tests/core/test_constants_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
from virtual_ecosystem.core.exceptions import ConfigurationError


@pytest.fixture(autouse=True)
def skip_these_tests():
"""Do not run tests in this module."""
pytest.skip("These tests rely on the old configuration system and will be deleted.")


@pytest.mark.parametrize(
"cfg_strings,model_name,class_name,raises,exp_val,exp_log",
[
Expand Down
Loading