Welcome to TorchCrop¶
Introduction¶
torchcrop is a fully differentiable reimplementation of the
LINTUL-5 crop growth model (Wolf, 2012).
Every step of the simulation — from sowing to harvest — produces valid
torch.autograd gradients, so mechanistic crop processes can be combined
seamlessly with learnable components (neural residuals, learned stress
responses, parameter networks) and calibrated end-to-end with standard
torch.optim optimizers.
Features¶
- Differentiable Lintul5 — daily forward-Euler simulation of phenology,
radiation interception, photosynthesis, partitioning, leaf/stem/root
dynamics, water balance, and NPK demand, uptake, and soil availability,
all as
torch.nn.Modules. Supports potential (IOPT=1), water-limited (IOPT=2), and water-and-NPK-limited (IOPT=3/4) production modes, with optional automatic irrigation. - Batch-first — every state, parameter and driver carries a leading
batch dimension
[B, ...]so that many sites, years, or parameter sets can be simulated in parallel on GPU. - 23 bundled crop presets —
torchcrop.available_crops()lists species (wheat, maize, rice, soybean, potato, sugar beet, …); load one viaCropParameters(crop_name="wheat"). - Gradient-based calibration —
torchcrop.calibrationprovides a constraint-aware (bounds, dtype, table-ordinate, ordering), transform-basedCalibrationManagerfor fitting crop parameters to observations. - Hybrid modeling hooks — a
HybridManagerwiring layer accepts declarativeResidualSpecs (seedefault_slots()) to injectNeuralResidualcorrections at named points in the pipeline, plus drop-inLearnedStressFactorandParameterNetmodules. - External irrigation/fertiliser — pass explicit
irrigation: [B, T]andfertilizer: [B, T, 3]schedules tomodel(...), overriding the internal table-driven application on a per-day basis. - Smooth options — stage-based branching (
DVS < 1, maturity, etc.) can be switched between hardtorch.whereand sigmoid blends for second-order smoothness. - Gradient-checked primitives — differentiable AFGEN-style interpolation
and soft FST helpers (
LIMIT,INSW,NOTNUL) passtorch.autograd.gradcheck.
Installation¶
1 | |
Quickstart¶
1 2 3 4 5 6 7 8 9 10 11 | |
Gradient-based parameter calibration¶
torchcrop.calibration turns bounded crop/soil/site parameters into
optimizable latents, keeping them inside their physical range by
construction:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | |
See docs/examples/04_calibration/ for a full worked example.
Hybrid modeling¶
Inject a neural residual on top of a named point in the mechanistic pipeline
via a declarative ResidualSpec:
1 2 3 4 5 6 7 8 9 10 11 12 | |
torchcrop.nn.default_slots() returns the recommended catalogue of
observable-tied slots (photosynthesis, water stress, partitioning, leaf
senescence); pass a hand-picked subset rather than the whole list unless
every pathway is observable. All parameters — mechanistic and neural — are
surfaced by model.parameters() and can be optimized jointly.
Package layout¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | |
Examples¶
Worked notebooks under docs/examples/ (rendered into the docs site):
01_potential/— potential production (winter wheat)02_water_limited/— water-limited production (winter wheat)03_water_and_nutrient_limited/— water + N and water + NPK limited production04_calibration/— gradient-based parameter calibration05_hybrid/— hybrid ML residual corrections (reserved, notebook in progress)06_daily_timestep/— low-level, day-by-day API usageothers/data_prep.ipynb— preparing the Brandenburg example dataset
Development¶
1 2 3 4 | |
References¶
- Wolf, J. (2012). User guide for LINTUL5. Wageningen UR. https://models.pps.wur.nl/lintul-5-crop-growth-simulation-model-potential-water-limited-n-limited-and-npk-limited-conditions
- WUR-AI. diffWOFOST — Differentiable WOFOST crop model. https://github.com/WUR-AI/diffWOFOST