-
Notifications
You must be signed in to change notification settings - Fork 4
Various bug fixes to allow vr_run to work with soil and abiotic_simple models
#236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
7be2a0d
ini soilmoisture changed to float
vgro 838c044
Removed soil mositure and temperature as required init variables for …
jacobcook1995 6c53e04
upper time bound changed to 1 month
vgro 15ccd7e
Removed outdating logging info from tests
jacobcook1995 5dec56c
Merge branch 'bugfix/vr_run_problems' of https://github.com/ImperialC…
vgro 1bcd22d
layers moves to core schema, not tested
vgro a3492da
schemer updated for layers in core
vgro 7da06b3
abiotic simple config updated layers from core
vgro 06484c4
layer roles function moved to utils
vgro 84c6fc7
Updated set_layer_roles docstring to include Raises
jacobcook1995 4ba300d
Switched the soil model to generate layer_roles itself rather than re…
jacobcook1995 791873f
time_index updated
vgro fe56e19
soil temperature added to setup
vgro 68bcb82
Changed default moisture value to be within acceptable range
jacobcook1995 bce650c
note on core.data.variables in docs
vgro 700f097
updated soil moisture unit in abiotic simple
vgro 3e5d7b1
corrected time coordinates
vgro 90f724b
Added description of the setup() step to main simulation docs
jacobcook1995 428a391
Removed example_config.toml as I do really see its purpose
jacobcook1995 9cd8139
Added details of how to access the example configuration and dummy da…
jacobcook1995 694e40b
More structure + mermaid diagram in main_simulation doc
davidorme 251cf3d
Text tweaks to main_simulation doc
davidorme 6ce98b8
Forgot to add sphinxcontrib-mermaid
davidorme File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,71 +1,159 @@ | ||
| # Virtual Rainforest simulation flow | ||
|
|
||
| This document describes the main simulation flow of the Virtual Rainforest model. This | ||
| flow will now be set out step by step. | ||
| This document describes the main simulation flow of the Virtual Rainforest model. The | ||
| main stages are: | ||
|
|
||
| * setup of the **simulation core** that provides shared resources and functions | ||
| * setup of the individual **science models** that simulate the behaviour of different | ||
| components of the Virtual Rainforest, and | ||
| * iteration of the simulation over the configured timescale. | ||
|
|
||
| ```{mermaid} | ||
| flowchart TD | ||
| A[vr_run] --> B | ||
| B --> F | ||
| C --> F | ||
| D --> F | ||
| D --> G | ||
| E --> F | ||
| H --> H2 | ||
| subgraph Core | ||
| direction LR | ||
| B[Load configuration] --> C[Create grid] | ||
| C --> D[Load data] | ||
| D --> E[Validate timescale] | ||
| end | ||
| subgraph Setup science models | ||
| direction LR | ||
| F[Model configuration] --> G[Model setup] | ||
| G --> H[Model spinup] | ||
| end | ||
| subgraph Simulation | ||
| H2[Save initial state] --> I[Start time] | ||
| I --> J[Update interval] | ||
| J --> K[Update science models] | ||
| K --> J | ||
| K --> L[End time] | ||
| L --> M[Save final state] | ||
| end | ||
| ``` | ||
|
|
||
| ## Core setup | ||
|
|
||
| The first stage in the simulation is the configuration and initialisation of the core | ||
| resources and functionality. | ||
|
|
||
| ### Loading configuration files | ||
|
|
||
| First, a set of user-provided configuration files in `TOML` format for a simulation are | ||
| loaded. These files are then validated to ensure: | ||
|
|
||
| * that they are valid `TOML`, | ||
| * and that all the required settings are present and not duplicated. | ||
|
|
||
| Some settings will be filled automatically from defaults settings and so can be omitted, | ||
| but validation will fail if mandatory settings are omitted. Further details can be found | ||
| in the [configuration documentation](./core/config.md). | ||
|
|
||
| ### Grid creation | ||
|
|
||
| Next, the spatial structure of the simulation is configured as a [`Grid` | ||
| object](./core/grid.md) that defines the area, coordinate system and geometry of the | ||
| individual cells that will be used in the simulation. | ||
|
|
||
| ### Loading and validation of input data | ||
|
|
||
| All of the data required to initialise and run the simulation is then loaded into an | ||
| internal [`Data` object](./core/data.md). The model configuration sets the locations of | ||
| files containing required variables and this configuration is passed into the | ||
| {meth}`~virtual_rainforest.core.data.Data.load_data_config` method, which ensures that: | ||
|
|
||
| * the input files are valid and can be read, and | ||
| * that the data in files is congruent with the rest of the configuration, such as | ||
| checking the dimensionality and shape of [core axes](./core/axes.md) like the spatial | ||
| grid. | ||
|
|
||
| ### Simulation timescale | ||
|
|
||
| The simulation runs between two dates with an update interval at which each science | ||
| model is recalculated. These values are defined in the `core` configuration and are | ||
| now validated to ensure that the start date, end date and update interval are sensible. | ||
|
|
||
| ```{note} | ||
| The simulation uses 12 equal length months (30.4375 days) and equal length years (365.25 | ||
| days), ignoring leap years. | ||
| ``` | ||
|
|
||
| ## Science models | ||
|
|
||
| ## Loading configuration files | ||
| The Virtual Rainforest is implemented as model objects, each of which is responsible for | ||
| simulating a particular aspect of the rainforest ecosystem. The models used for the | ||
| specific simulation run can be set in the configuration and will typically include the | ||
| four standard models: | ||
|
|
||
| As a first step, configuration files are loaded in and validated. These files are of | ||
| `toml` format and are found based on paths provided by the user. When these files are | ||
| loaded in they are validated to ensure that they are valid `toml`, and that all the | ||
| required settings are present and not duplicated. The Virtual Rainforest code provides | ||
| default settings for some configuration options and these will be used automatically if | ||
| that setting is not found in the configuration, but if no default is set then the | ||
| validation will fail. Further details can be found in the [configuration | ||
| documentation](./core/config.md). | ||
| * the [`AbioticModel`](../api/abiotic.md) or | ||
| [`AbioticSimpleModel`](../api/abiotic_simple.md), | ||
| * the `AnimalModel`, | ||
| * the `PlantModel` and the | ||
| * [`SoilModel`](../api/soil.md) | ||
|
|
||
| ## Grid creation | ||
| but this can be [extended to include new models](../development/defining_new_models.md) | ||
| or adopt different combinations of models. | ||
|
|
||
| The next step is creating a grid, which defines the spatial structure of the simulation: | ||
| the area, coordinate system and geometry of the individual cells that will be used in | ||
| the simulation. The [grid documentation](./core/grid.md) describes this object further. | ||
| This grid is then used to create an empty `Data` object of the correct size to describe | ||
| the simulation. | ||
| Once a list of models to configure has been extracted from the configuration, all | ||
| science models run through a set of steps to prepare for the simulation to start. Each | ||
| step is represented using a set of standard model methods that are run in the following | ||
| order. | ||
|
|
||
| ## Loading and validation of input data | ||
| ### Model configuration | ||
|
|
||
| This `Data` object now needs to be populated with data. The data used in the simulation | ||
| is stored in a set of data files which are specified in the configuration. This data is | ||
| then loaded using the `data.load_data_config` method, which has built in validation | ||
| procedures to ensure that the loaded data can be mapped onto the spatial grid and also | ||
| other core dimensions for the configured simulation. Further details can be found in the | ||
| [data system](./core/data.md) and [core axes](./core/axes.md) documentation. | ||
| The loaded configuration should include the configuration details for each individual | ||
| science model. These are now used to initialise each requested model using the | ||
| {meth}`~virtual_rainforest.core.base_model.BaseModel.from_config` method defined | ||
| for each model. This method checks that the configuration is valid for the science | ||
| model. | ||
|
|
||
| ## Configuration of specific models | ||
| ### Model setup | ||
|
|
||
| The Virtual Rainforest is implemented as model objects, each of which is responsible for | ||
| simulating a particular aspect of the rainforest ecosystem. The models used for the | ||
| specific simulation run can be set in the configuration. This will typically be the four | ||
| standard models ([`AbioticModel`](../api/abiotic.md), `AnimalModel`, `PlantModel` and | ||
| [`SoilModel`](../api/soil.md)), but this can be extended to include new models or | ||
| different combinations of models. For more information about implementing new models, | ||
| see [this page](../development/defining_new_models.md) about the required module | ||
| structure and the model API. Once a list of models to configure has been extracted from | ||
| the configuration, they are then all configured. | ||
| Some models require an additional setup step to calculate values for internal variables | ||
| from the initial loaded data or to set up further structures within the model, such as | ||
| representations of plant or animal communities. Each model will run the | ||
| {meth}`~virtual_rainforest.core.base_model.BaseModel.setup` method defined for the | ||
| specific model. In simple science models, this method may not actually need to do | ||
| anything. | ||
|
|
||
| ### Model spinup | ||
|
|
||
| Some models may then require a spin up step to allow initial variables to reach an | ||
| equilibrium before running the main simulation. Again, each model will run the | ||
| {meth}`~virtual_rainforest.core.base_model.BaseModel.spinup` method defined for the | ||
| specific model, and again this may not need to do anything for simple models. | ||
|
|
||
| ### Model update | ||
|
|
||
| At this point, the model instance is now ready for simulation. The | ||
| {meth}`~virtual_rainforest.core.base_model.BaseModel.update` method for each science | ||
| model is run as part of the simulation process described below. | ||
|
|
||
| ## Extracting simulation timing details | ||
| ## Simulation process | ||
|
|
||
| The configuration contains a start time, an end time and a time interval for the update | ||
| of all models. These details are extracted from configuration, with a check performed | ||
| to ensure that the simulation will update at least once between the start and end time | ||
| of the simulation. It is important to note that because months and years are of | ||
| inconsistent length they are currently averaged over. This means that 1 month becomes | ||
| 30.4375 days, and 1 year becomes 365.25 days. | ||
| Now that the simulation core and science models have been configure and initialised, | ||
| along with any setup or spinup steps, the simulation itself starts. | ||
|
|
||
| ## Saving the initial state | ||
| ### Saving the initial state | ||
|
|
||
| The `data` object has now been populated with all of the configured data required to run | ||
| the model. It can now optionally be saved to a file set in the configuration to generate | ||
| a single data file of the initial model state. | ||
| the model. The simulation configuration can optionally provide a filepath that will be | ||
| used to output a single data file of the initial simulation state. | ||
|
|
||
| ## Simulating over time | ||
| ### Simulation | ||
|
|
||
| The previously extracted timing details are used to setup a timing loop, which runs from | ||
| the start time to the end time with a time step set by the update interval. At each | ||
| The science models are now iterated over the configured simulation timescale, running | ||
| from the start time to the end time with a time step set by the update interval. At each | ||
| step all models are updated. | ||
|
|
||
| ## Saving the final state | ||
| ### Saving the final state | ||
|
|
||
| After the full simulation loop has been completed the final simulation state can be | ||
| saved. Whether to save this state and where to save it to are again configuration | ||
| options, but in this case the default is for the final state to be saved. | ||
| After the full simulation loop has been completed, the final simulation state held in | ||
| the `Data` object can be optionally be saved to a path provided in the configuration, | ||
| defaulting to saving the data. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is worth explicitly using warning admonitions here. Partly that is that they look nice and call more attention to the warning, but it is then also easier to search for and review these kinds of messages.
On another note - Myst has relatively recently gone to version 1.0.0 and there are some stabilised syntax things like using
colon-fencenotation. We should probably go through and update docs to use the recommended1.0.0syntax.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually it looks like we're currently pinned to
myst-parser <1.0.0by somemyst-nbandsphinxversion pins ( see executablebooks/MyST-NB#513). As and when that is resolved we should review our MyST content and syntax.