You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/workflow1_framework.rst
+14-5Lines changed: 14 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,17 +3,26 @@ Introduction to the framework
3
3
4
4
The Xarray-simlab-ODE (``xso``) is a Python framework that allows users to construct and customize, in a modular fashion, models based on ordinary differential equations (ODEs). It is technically a wrapper around the modeling framework `xarray-simlab <https://xarray-simlab.readthedocs.io/en/latest/>`__, additionally providing a functional set of variables, processes and a solver backend for ODE-based models.
5
5
6
-
It is a non-opinionated framework, i.e., it does not provide a fixed notion of how the model should be implemented, instead it attempts to remove the redundant boilerplate code, allowing a user to construct and work with ODE-based models.
6
+
It is a non-opinionated framework, i.e., it does not provide a fixed notion of how the model should be structured, instead it attempts to remove the redundant boilerplate code, allowing a user to construct and work with ODE-based models.
7
7
8
-
XSO was developed as the technical foundation of the `Phydra library <https://github.com/ben1post/phydra>`__, but is not limited to any particular domain and can be used to create ODE-based models of any type.
8
+
XSO was developed as the technical foundation of the `Phydra library <https://github.com/ben1post/phydra>`__ for marine ecosystem modeling, but is not limited to any particular domain and can be used to create ODE-based models of any type.
9
9
10
10
11
11
Building blocks
12
12
===============
13
13
14
-
The XSO framework provides several *variable types*, which directly correspond to the basic mathematical components of models based on ordinary differential equations (e.g., state variables, parameters, forcing, and partial equations).
14
+
The XSO framework is built around these concepts:
15
15
16
-
Every aspect of the model needs to be defined at the level of *variable types*. Model *components* can be flexibly constructed from the provided set of *variable types* and wrap a logical component of the model as users see fit.
16
+
* Model data (setup and output)
17
+
* Model objects
18
+
* Components
19
+
* Variable types
20
+
21
+
The XSO framework provides several *variable types*, which directly correspond to the basic terms of models based on ordinary differential equations, e.g., state variables, parameters, forcing, and mathematical terms (here called *fluxes*) building the system of equations.
22
+
23
+
Every aspect of the model needs to be defined at the level of *variable types*. Model *components* can be flexibly constructed from the provided set of *variable types* and wrap a logical component of the model as users see fit. These components can then be modularly assembled to a *model object*, which defines the model structure.
24
+
25
+
The *model object* is then used to create a *model setup* dataset, which contains all relevant information needed at runtime, such as the solver algorithm to be used, as well as time steps and model parameterization. With both the *model object* and the corresponding *model setup*, the model can be exectued. Output is returned as an Xarray dataset with all metadata, which can be easily stored and shared.
17
26
18
27
State variables, forcing and parameters need to be initialized in one *component*, but can be referenced across the model (using the :code:`foreign=True` argument). The system of differential equations is constructed from the *fluxes* contained in the model *components* via the supplied labels at model setup.
19
28
@@ -37,7 +46,7 @@ These can be used to define variables in compact Python classes, to construct fu
37
46
Components
38
47
__________
39
48
40
-
*Components* are the general building-blocks of a model that declare a subset of variables and define a specific set of mathematical functions computed for these variables during model runtime. More specifically, a *component* refers to a Python class containing *variable types* that is decorated with :deco:`xso.component`.
49
+
*Components* are the general building-blocks of a model that declare a subset of variables and define a specific set of mathematical functions computed for these variables during model runtime. More specifically, a *component* refers to a Python class containing XSO *variable types* that is decorated with :deco:`xso.component`.
41
50
42
51
For example, a *component* could define a specific nutrient uptake function, e.g. Monod-type phytoplankton growth on a single nutrient. The decorating function registers the *variable types* within the framework, reducing boilerplate code and creating fully functional model building blocks. *Components* can be reused within a model.
Copy file name to clipboardExpand all lines: docs/workflow2_variables_components.rst
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,7 +41,7 @@ The XSO framework allows structuring a model into modular components. The specif
41
41
Anatomy of a component
42
42
======================
43
43
44
-
A :class:`xso.component` is essentially a wrapper around a :class:`xsimlab:xsimlab.process` class, the main building block of the Xarray-simlab framework. There is a lot of additional functionality provided by ``xso`` through the *variable types* and the :deco:`xso.component` decorator. The following sections will explain the anatomy of a component via examples.
44
+
A :class:`xso.component` is essentially a wrapper around the :deco:`xsimlab:xsimlab.process` class decorator, represents a logical unit in a computational model. There is a lot of additional functionality provided by ``xso`` through the *variable types* and the :deco:`xso.component` decorator. The following sections will explain the anatomy of an XSO component via examples.
45
45
46
46
Component defining a variable
47
47
-----------------------------
@@ -126,7 +126,7 @@ One of the more powerful features is the dimensionality and vectorization functi
126
126
return var_list * rate
127
127
128
128
129
-
In this component, we define a single flux for multiple variables that are flowing out of the system. The ``list_input=True`` argument indicates that the variable labels can be supplied at *model setup* as a list. The XSO backend aggregates all labeled variables into an array, with the dimension label supplied via ``dims='flow_list'``. We need to make sure, that this dimension is also present in the ``dims`` argument of the :func:`xso.flux` decorator, so that the flux function knows how to handle the aggregated variables. The backend automatically routes the flux values to the appropriate variables, here as a negative function.
129
+
In this component, we define a single flux for multiple variables that are flowing out of the system. The ``list_input=True`` argument indicates that the variable labels can be supplied at *model setup* as a list. The XSO backend aggregates all labeled variables into an array, with the dimension label supplied via ``dims='flow_list'``. We need to make sure, that this dimension is also present in the ``dims`` argument of the :deco:`xso.flux` decorator, so that the flux function knows how to handle the aggregated variables. The backend automatically routes the flux values to the appropriate variables, here as a negative function.
130
130
131
131
This allows for highly flexible complex model setups, as we can easily remove and add state variables, without overcomplicating our model structure.
Copy file name to clipboardExpand all lines: docs/workflow3_models.rst
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -65,7 +65,7 @@ As can be seen from the ``__repr__`` of the model object, there are two perhaps
65
65
#. The number of variables does not exactly correspond to the number of variable types in the model. Each :func:`xso.variable` initialized within a *component* requires two input arguments. E.g., for the ``value`` variable, it is ``value_label`` and ``value_init``. The ``value_label`` is the label of the variable, and the ``value_init`` is the initial value of the variable. The label supplied here can be used to reference the variable in another component within the same model (where the input parameter is a ``label reference``).
66
66
#. There are three model processes automatically added to the model object. These are the ``Solver``, ``Core`` and ``Time`` components provided by :mod:`xso.backendcomps`, that allow the model system to be setup and solved.
67
67
68
-
In order to setup the model with a custom unit for time (e.g. per month, per year) this can be supplied to the :func:`xso.create` function as the ``time_unit`` argument. The ``time_unit`` argument is a string that can be parsed by the :func:`pint:pint.Unit` function. The default unit for time is ``'d'`` for days.
68
+
In order to setup the model with a custom unit for time (e.g. per month, per year) this can be supplied to the :func:`xso.create` function as the ``time_unit`` argument. The default unit for time is ``'d'`` for days.
69
69
70
70
Setup a model
71
71
=============
@@ -98,7 +98,7 @@ A model is setup by calling the :func:`xso.setup` function. The :func:`xso.setup
98
98
})
99
99
100
100
101
-
The :func:`xso.setup` function returns an :class:`xarray:Dataset` with the input variables and model components as data variables.
101
+
The :func:`xso.setup` function returns an :class:`xarray:xarray.Dataset` with the input variables and model components as data variables.
0 commit comments