Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 6 additions & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ authors:
email: f.nattino@esciencecenter.nl
affiliation: Netherlands eScience Center
orcid: 'https://orcid.org/0000-0003-3286-0139'
- given-names: Simone
family-names: Ciarella
email: s.ciarella@esciencecenter.nl
affiliation: Netherlands eScience Center
orcid: 'https://orcid.org/0000-0002-9247-139X'
Comment thread
SarahAlidoost marked this conversation as resolved.
- given-names: Michiel
family-names: Kallenberg
email: michiel.kallenberg@wur.nl
Expand All @@ -35,7 +40,7 @@ authors:
affiliation: Wageningen University & Research
orcid: 'https://orcid.org/0000-0002-5517-6404'
date-released: 2025-10-29
version: "0.2.0"
version: "0.3.0"
repository-code: "https://github.com/WUR-AI/diffwofost"
keywords:
- "wofost"
Expand Down
11 changes: 6 additions & 5 deletions docs/api_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ hide:

## **Crop modules**

::: diffwofost.physical_models.crop.leaf_dynamics.WOFOST_Leaf_Dynamics

::: diffwofost.physical_models.crop.root_dynamics.WOFOST_Root_Dynamics

::: diffwofost.physical_models.crop.phenology.DVS_Phenology

::: diffwofost.physical_models.crop.partitioning.DVS_Partitioning

::: diffwofost.physical_models.crop.assimilation.WOFOST72_Assimilation

::: diffwofost.physical_models.crop.partitioning.DVS_Partitioning
::: diffwofost.physical_models.crop.leaf_dynamics.WOFOST_Leaf_Dynamics

::: diffwofost.physical_models.crop.root_dynamics.WOFOST_Root_Dynamics


## **Utility (under development)**

Expand Down
49 changes: 46 additions & 3 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ We provide an example notebook showing optimization of models' parameters with

| Model | Open the notebook | Access the source | View the notebook |
|---|----|------------|---------------|
| Leaf and Root dynamics| [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)][leaf_colab_link] | [![Access the source code](https://img.shields.io/badge/GitHub_Repository-000.svg?logo=github&labelColor=gray&color=blue)][leaf_source_link] | [![here](https://img.shields.io/badge/View_Notebook-orange.svg?logo=jupyter&labelColor=gray)](./notebooks/optimization.ipynb) |
| Phenology | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)][pheno_colab_link] | [![Access the source code](https://img.shields.io/badge/GitHub_Repository-000.svg?logo=github&labelColor=gray&color=blue)][pheno_source_link] | [![here](https://img.shields.io/badge/View_Notebook-orange.svg?logo=jupyter&labelColor=gray)](./notebooks/optimization_phenology.ipynb) |
| Root dynamics| [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)][root_colab_link] | [![Access the source code](https://img.shields.io/badge/GitHub_Repository-000.svg?logo=github&labelColor=gray&color=blue)][root_source_link] | [![here](https://img.shields.io/badge/View_Notebook-orange.svg?logo=jupyter&labelColor=gray)](./notebooks/optimization_root_dynamics.ipynb) |
| Leaf dynamics| [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)][leaf_colab_link] | [![Access the source code](https://img.shields.io/badge/GitHub_Repository-000.svg?logo=github&labelColor=gray&color=blue)][leaf_source_link] | [![here](https://img.shields.io/badge/View_Notebook-orange.svg?logo=jupyter&labelColor=gray)](./notebooks/optimization_leaf_dynamics.ipynb) |


!!! note

When calculating gradients, it is important to ensure that the predicted
physical parameters are within realistic bounds regarding the crop and
environmental conditions.
Expand All @@ -22,7 +25,47 @@ We provide an example notebook showing optimization of models' parameters with
output w.r.t the parameter will be close to zero, which may not provide
useful information for optimization.

[leaf_colab_link]: https://colab.research.google.com/github/WUR-AI/diffWOFOST/blob/main/docs/notebooks/optimization.ipynb
[leaf_source_link]: https://github.com/WUR-AI/diffWOFOST/blob/main/docs/notebooks/optimization.ipynb

## Computing configuration

The object `ComputeConfig` provides a central configuration for PyTorch device
and dtype settings across all simulation objects in diffWOFOST. Instead of
setting device and dtype individually for each class, use this central
configuration to apply settings globally.
Comment thread
SarahAlidoost marked this conversation as resolved.

**Default Behavior:**

- **Device**: Automatically defaults to 'cuda' if available, otherwise 'cpu'
- **Dtype**: Defaults to torch.float64

**Basic Usage:**

```python
from diffwofost.physical_models.config import ComputeConfig
import torch
# Set device to CPU
ComputeConfig.set_device('cpu')

# Or use a torch.device object
ComputeConfig.set_device(torch.device('cuda'))

# Set dtype to float32
ComputeConfig.set_dtype(torch.float32)

# Get current settings
device = ComputeConfig.get_device() # Returns: torch.device('cpu')
dtype = ComputeConfig.get_dtype() # Returns: torch.float32
```

**More info:**

See the [ComputeConfig API
reference](./api_reference.md#diffwofost.physical_models.config.ComputeConfig)
for more details.

[leaf_colab_link]: https://colab.research.google.com/github/WUR-AI/diffWOFOST/blob/main/docs/notebooks/optimization_leaf_dynamics.ipynb
[leaf_source_link]: https://github.com/WUR-AI/diffWOFOST/blob/main/docs/notebooks/optimization_leaf_dynamics.ipynb
[root_colab_link]: https://colab.research.google.com/github/WUR-AI/diffWOFOST/blob/main/docs/notebooks/optimization_root_dynamics.ipynb
[root_source_link]: https://github.com/WUR-AI/diffWOFOST/blob/main/docs/notebooks/optimization_root_dynamics.ipynb
[pheno_colab_link]: https://colab.research.google.com/github/WUR-AI/diffWOFOST/blob/main/docs/notebooks/optimization_phenology.ipynb
[pheno_source_link]: https://github.com/WUR-AI/diffWOFOST/blob/main/docs/notebooks/optimization_phenology.ipynb
5 changes: 2 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,5 @@ The package is structured as follows:
```

!!! note
At the moment only two modules of `leaf_dynamics` and `root_dynamics` are
differentiable w.r.t two parameters of `SPAN` and `TDWI`. But the package is under
continuous development. So make sure that you install the latest version.
At the moment the package is under continuous development. So make sure that
you install the latest version.
12 changes: 12 additions & 0 deletions docs/notebooks/optimization_leaf_dynamics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@
"from diffwofost.physical_models.utils import get_test_data"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9c2ca761-22b0-4707-9f55-619f62617d12",
"metadata": {},
"outputs": [],
"source": [
"# --- run on CPU ------\n",
"from diffwofost.physical_models.config import ComputeConfig\n",
"ComputeConfig.set_device('cpu')"
]
},
{
"cell_type": "code",
"execution_count": 2,
Expand Down
12 changes: 12 additions & 0 deletions docs/notebooks/optimization_phenology.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@
"from diffwofost.physical_models.utils import get_test_data"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8a06565c-139a-4039-92d5-bcfd7bcf8344",
"metadata": {},
"outputs": [],
"source": [
"# --- run on CPU ------\n",
"from diffwofost.physical_models.config import ComputeConfig\n",
"ComputeConfig.set_device('cpu')"
]
},
{
"cell_type": "code",
"execution_count": 2,
Expand Down
12 changes: 12 additions & 0 deletions docs/notebooks/optimization_root_dynamics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@
"from diffwofost.physical_models.utils import get_test_data"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "10c6361e-ad31-455f-aed1-b7a282cb793c",
"metadata": {},
"outputs": [],
"source": [
"# --- run on CPU ------\n",
"from diffwofost.physical_models.config import ComputeConfig\n",
"ComputeConfig.set_device('cpu')"
]
},
{
"cell_type": "code",
"execution_count": 3,
Expand Down
10 changes: 9 additions & 1 deletion docs/run_model.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,21 @@ In a nutshell, we can run a model, for example, `leaf_dynamics` using diffWOFOST

```python
from diffwofost.physical_models.utils import EngineTestHelper
from diffwofost.physical_models.config import Configuration
from diffwofost.physical_models.crop.leaf_dynamics import WOFOST_Leaf_Dynamics

# create config
leaf_dynamics_config = Configuration(
CROP=WOFOST_Leaf_Dynamics,
OUTPUT_VARS=["LAI", "TWLV"],
)

# create the model
model = EngineTestHelper(
crop_parameters_provider, # this provides the crop parameters
weather_data_provider,
agromanagement_provider,
leaf_dynamics_config_file, # this where the differentiable model is specified
leaf_dynamics_config, # this where the differentiable model is specified
external_states, # any external states if needed
)

Expand Down
7 changes: 2 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ license = {file = "LICENSE"}
name = "diffwofost"
readme = {file = "README.md", content-type = "text/markdown"}
requires-python = ">=3.11"
version = "0.2.0"
version = "0.3.0"

[project.optional-dependencies]
dev = [
Expand Down Expand Up @@ -131,7 +131,7 @@ force-single-line = true
no-lines-before = ["future","standard-library","third-party","first-party","local-folder"]

[tool.bumpversion]
current_version = "0.2.0"
current_version = "0.3.0"

[[tool.bumpversion.files]]
filename = "src/diffwofost/__init__.py"
Expand All @@ -141,6 +141,3 @@ filename = "pyproject.toml"

[[tool.bumpversion.files]]
filename = "CITATION.cff"

[[tool.bumpversion.files]]
filename = "docs/conf.py"
6 changes: 5 additions & 1 deletion src/diffwofost/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@

import logging
from diffwofost.physical_models import utils
from diffwofost.physical_models.crop import assimilation
from diffwofost.physical_models.crop import leaf_dynamics
from diffwofost.physical_models.crop import partitioning
from diffwofost.physical_models.crop import phenology
from diffwofost.physical_models.crop import root_dynamics

logging.getLogger(__name__).addHandler(logging.NullHandler())

__author__ = ""
__email__ = ""
__version__ = "0.2.0"
__version__ = "0.3.0"

__all__ = [
"leaf_dynamics",
"root_dynamics",
"phenology",
"assimilation",
"partitioning",
"utils",
]