Optimization with diffWOFOST
We provide an example notebook showing optimization of models' parameters with
diffWOFOST. To get familiar with the concepts and implementation, check out
Introduction in the documentation.
| Model | Open the notebook | Access the source | View the notebook |
|---|---|---|---|
| Phenology | |||
| Root dynamics | |||
| Leaf dynamics |
Note
When calculating gradients, it is important to ensure that the predicted physical parameters are within realistic bounds regarding the crop and environmental conditions.
Also, when calculating gradients of an output w.r.t. parameters, it would be good to know in advance how the parameters in a model influence the outputs. If a parameter has little to no influence on an output, the gradient of the output w.r.t the parameter will be close to zero, which may not provide useful information for optimization.
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.
Default Behavior:
- Device: Automatically defaults to 'cuda' if available, otherwise 'cpu'
- Dtype: Defaults to torch.float64
Basic Usage:
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 for more details.