Ingestion Dose Sensitivity With JAX
How much does one year of ingestion dose change when a deposition input or a group of model parameters changes slightly? ECOSYS can answer this for a restricted Cs-137 scenario by automatic differentiation (AD) through the complete ingestion food chain, using the optional JAX backend.
The result is a set of local partial sensitivities at the baseline parameter values. They are not uncertainty estimates, confidence intervals or Fisher information (see what this is not).
Experimental, narrow scope
This capability covers one-year ingestion dose for one Cs-137 event in the
valley parameter set. Other nuclides, pathways, horizons and parameter
sets raise an explicit ValueError; they are not silently approximated.
Installation
JAX is an optional extra. The reproducible Python 3.9 CPU environment is pinned
in constraints/jax-py39.txt (JAX and jaxlib 0.4.30, NumPy 1.26.4):
python -m pip install -c constraints/jax-py39.txt -e ".[dev,jax]"
python -m pip check
Importing ecosys or ecosys.sensitivity never imports JAX, and ordinary
simulations do not need it. Without JAX, the sensitivity functions raise an
ImportError naming the extra to install. Double precision is required:
call configure_jax() explicitly, before creating any JAX arrays. It enables
JAX's process-wide jax_enable_x64 setting; ECOSYS never changes it on import.
Command-line example
python scripts/ingestion_sensitivity.py
The default reproduces the README quick-start scenario: 1 Bq s/m³ integrated air activity, 1 Bq/m² wet deposition and 1 mm rain on 1 January 2001, one adult of age 30, the event-anchored default integration grid, and no landscape (so no soil-to-plant transfer). Output from the Python 3.9 / JAX 0.4.30 CPU environment:
Cs-137 / valley / adult age 30: 2001-01-01 through 2002-01-01
Cumulative per-capita ingestion dose: 3.29363635919e-09 Sv (3.293636 nSv)
Integration support: 199 nodes; float64 JAX
Soil transfer: disabled (README-compatible no-landscape scenario)
Signed partial sensitivities ranked by absolute elasticity:
Parameter / shared group multiplier dD/dz (Sv) Elasticity
model.cs.food_processing_factor_scale +3.29363636e-09 +1.00000000
model.cs.ingestion_dose_factor_scale +3.29363636e-09 +1.00000000
model.consumption_rate_scale +3.29363636e-09 +1.00000000
event.wet_ground_deposition +3.28734580e-09 +0.99809009
model.cs.animal_transfer_scale +2.50063371e-09 +0.75923187
event.rainfall -1.39913397e-09 -0.42479916
model.cs.water_film_scale +1.39913397e-09 +0.42479916
model.plant.weathering_half_life_scale +1.31217948e-09 +0.39839841
model.cs.animal_retention_half_life_scale -2.20759211e-10 -0.06702598
event.integrated_air_activity +6.29056029e-12 +0.00190991
model.cs.deposition_velocity_scale +6.12475669e-12 +0.00185957
model.cs.soil_plant_transfer_scale +0.00000000e+00 +0.00000000
Largest food contributions:
drinking_milk 1.188202 nSv 36.08%
leafy_vegetables 1.072892 nSv 32.57%
veal 0.279900 nSv 8.50%
lamb_meat 0.200263 nSv 6.08%
cow_beef 0.179916 nSv 5.46%
Options:
| Option | Effect |
|---|---|
--event-date YYYY-MM-DD |
Deposition date and output origin (default 2001-01-01). |
--soil arable, extensive_pasture or intensive_pasture |
Use a scalar Landscape with this soil type, enabling soil-to-plant transfer. |
--output PATH |
Write the complete labeled result as strict JSON. |
--check-finite-difference |
Check every AD derivative against the original engine (below). |
--top-foods N |
Number of food contributions to print (default 5). |
The first evaluation includes JIT compilation and takes of the order of
10–30 s on a desktop CPU; --check-finite-difference adds 72 perturbed
original-engine runs (12 coordinates, 3 step sizes, ±). A summer event with soil transfer:
python scripts/ingestion_sensitivity.py --event-date 2001-06-01 --soil arable
gives 87.18 nSv, with a small nonzero soil-transfer elasticity (+0.0067); drinking milk, lamb and leafy vegetables are then the largest contributions.
Any landscape soil type switches soil transfer on, but root uptake follows each
plant's own canonical soil type (arable crops, pasture grasses). The landscape's
soil type only changes resuspension, which is not an ingestion pathway, so all
three --soil choices currently give the same ingestion dose.
Python API
from datetime import date
import json
import numpy as np
from ecosys.data import load_model_data
from ecosys.sensitivity import (
configure_jax, evaluate_sensitivity, prepare_ingestion_problem,
)
from ecosys.sensitivity.reference import reference_request
configure_jax() # float64, before any JAX arrays are created
model = load_model_data(parameter_set="valley")
request = reference_request(date(2001, 1, 1)) # README scenario, no landscape
problem = prepare_ingestion_problem(model, request)
result = evaluate_sensitivity(problem)
print(f"Dose: {result.total_sv:.6e} Sv")
for index in result.ranked_parameters():
spec = result.parameter_specs[index]
print(f"{spec.id:<45} elasticity {result.elasticities[0, index]:+.5f}")
# Row 0 is total dose; rows 1: are foods. Columns follow parameter_specs.
assert np.isclose(result.total_sv, 3.2936363591862e-09, rtol=1e-9)
assert np.allclose(result.per_food_jacobian_sv.sum(axis=0), result.gradient_sv)
manifest = json.loads(result.to_json()) # strict JSON: no NaN, no JAX objects
assert manifest["schema_version"] == "1.0"
assert manifest["provenance"]["runtime"]["jax_enable_x64"] is True
prepare_ingestion_problem is host-only NumPy code and does not import JAX.
To evaluate a different scenario, build another SimulationRequest within the
supported contract and prepare it again. reference_request(event_date,
landscape=Landscape("arable")) gives the soil-enabled variant. For repeated
evaluation at other coordinates, make_ingestion_functions(problem) returns
compiled total, per_food, value_and_grad and food_jacobian callables;
keep and reuse them, as compilation dominates the first call.
Supported scenario contract
prepare_ingestion_problem validates the request before any expensive work:
- the
valleyparameter set (or overrides derived from it viaModelData.with_overrides); - exactly one
cs_137DepositionEvent, without iodine fractions, whose date equalsoutput_start_date; - strictly positive, finite scalar air activity, wet deposition and rainfall (the coordinates are logarithmic);
- one unbatched cohort aged at least 18 years, with no activity override;
- no
pathway_ids(ingestion is selected internally); - no landscape, or one valid scalar landscape;
- support ending exactly at the first calendar anniversary of the event, and containing every node of the default grid (a refinement is allowed).
Output: the one-year selector
The differentiated outputs are cumulative per-capita ingestion effective
dose in Sv at the final support node, the first Gregorian anniversary of the
event (for example 2001-01-01 through 2002-01-01). Other pathways are not
included. The output axis is ingestion.cumulative.total followed by one row
per consumed food (ingestion.cumulative.food.<food_id>, 33 in valley).
Food rows sum to the total, and so do their Jacobian rows.
The twelve coordinates
Each coordinate z multiplies its members by exp(z); the baseline is
z = 0. The first three are the event inputs. The remaining nine are shared
group multipliers: one coordinate scales every member of the group together.
Its sensitivity is not the sensitivity to any single member (for example, cow
milk transfer alone), and it is not an estimate of that group's uncertainty.
| Coordinate | Members scaled together (valley, Cs) |
|---|---|
event.integrated_air_activity |
Event time-integrated air activity (Bq s/m³) |
event.wet_ground_deposition |
Event wet ground deposition (Bq/m²) |
event.rainfall |
Event rainfall depth (mm) |
model.cs.deposition_velocity_scale |
20 particulate dry-deposition velocities (ground and 19 plant targets) |
model.cs.water_film_scale |
19 plant water-film thicknesses (wet interception) |
model.cs.soil_plant_transfer_scale |
18 soil-to-plant transfer factors |
model.plant.weathering_half_life_scale |
19 plant weathering half-lives (all elements) |
model.cs.animal_retention_half_life_scale |
14 animal-product retention-component half-lives |
model.cs.animal_transfer_scale |
11 feed-to-animal-product transfer factors |
model.cs.food_processing_factor_scale |
33 food-domain processing factors |
model.consumption_rate_scale |
165 age-indexed food consumption rates |
model.cs.ingestion_dose_factor_scale |
5 age-indexed Cs-137 ingestion dose coefficients |
The complete member list, with canonical source keys, source and numeric units,
and values, is part of every result (parameter_specs, and parameters in
JSON). Age-indexed groups include every age row; only rows used by the adult
cohort can contribute.
Derivative units and elasticities
Three equivalent forms are reported for every output row and coordinate:
| Quantity | Definition | Unit |
|---|---|---|
jacobian_sv (derivative_wrt_z_sv) |
∂D/∂z | Sv per unit z |
raw_derivatives (raw_derivative) |
∂D/∂z ÷ baseline | event: Sv per report unit (e.g. Sv / (mm)); group: Sv per unit multiplier |
elasticities (elasticity) |
∂ ln D / ∂ ln x = ∂D/∂z ÷ D | dimensionless |
An elasticity of 0.4 means that a 1 % increase in the input increases the dose
by approximately 0.4 %, locally. Signs are retained. The elasticity of a zero
output is undefined: it is NaN in the Python result and JSON null with
elasticity_status: "undefined_zero_output".
Reading the example
- Consumption, dose coefficient and food-processing multipliers have elasticity one. Dose is linear in each: every consumed food is produced by one food-domain processing edge. These checks are structural, not findings.
- Air and wet elasticities sum to one. Dose is proportional to the joint source. In the default, the 1 Bq s/m³ air input is a much smaller source than 1 Bq/m² wet deposition, which dominates.
- Rainfall and water film are equal and opposite. Wet interception depends on rainfall only through its ratio to the water-film thickness. Here more rain at fixed wet deposition means less intercepted by plants, not more deposition. Atmospheric washout is outside ECOSYS.
- Retention half-lives have a negative elasticity over this one-year window. Transfer factors set the equilibrium product level; longer retention slows the approach to it, so less activity is consumed before the anniversary.
- Soil transfer is zero without a landscape because the soil pathway is
disabled; it is not evidence that soil transfer is unimportant. Use
--soil arable, and note that one-year soil contributions remain small.
Local elasticities describe small changes around the baseline. Model switches (harvest dates, interception clipping at one, the rain-free convention, soil thresholds) are piecewise, so large changes need a new evaluation.
Fixed within a prepared problem
Preparation resolves on the host, and does not differentiate:
- event, harvest, grazing and feeding dates and the calendar (phenology, LAI);
- storage and processing delays, and support nodes;
- soil rate constants and landscape/soil type;
- the parameter set, nuclide, cohort, and food/product identities.
Changing any of these requires a new prepare_ingestion_problem call. Plant
concentrations are linear in the deposited and soil sources; weathering, source
activity and all twelve coordinates remain traced through the complete chain.
JSON schema and provenance
result.to_json() (or --output) writes schema 1.0, kind
one_year_ingestion_sensitivity, containing ordinary JSON numbers only:
| Key | Content |
|---|---|
parameters |
Coordinate IDs, kinds, all members with source keys, units and values, baseline and raw-derivative unit |
coordinates |
The evaluation point (z = 0 for every coordinate) |
outputs |
For each output: ID, food, cohort, target date, unit, value and one entry per parameter |
support |
Integration support in elapsed days |
provenance |
Input, dataset, scientific-model, numeric-baseline, support and problem digests; engine run provenance; request summary; origin/target dates; plant/product/food IDs; Python/JAX/jaxlib/NumPy/Astropy versions, backend and x64 flag |
verification |
null, or finite-difference check details |
The scientific_model_digest covers in-memory with_overrides changes, and
sensitivity_problem_digest identifies the complete problem: provenance,
coordinates, transforms and outputs.
Verifying derivatives
--check-finite-difference, or result.with_reference_check(reference) with
ecosys.sensitivity.reference.finite_difference_reference, recomputes every
total and per-food derivative by central differences of the original,
unit-aware engine at h = 1e-3, 1e-4, 1e-5. The check fails with a
ValueError if any exceeds rtol = 1e-4 plus a dose-scaled absolute
tolerance; otherwise the details travel with the JSON result.
The test suite also compares AD against finite differences for winter, summer and soil-enabled summer events, at non-baseline points, and on refined grids.
What these numbers are not
- Not uncertainty. A sensitivity does not include a parameter's plausible range. Propagating uncertainty needs a parameter distribution or covariance.
- Not Fisher information. Fisher information needs observed quantities, a noise/likelihood model and the Jacobian of those observables. Dose is not an observation, so it has no Fisher information here.
- Not an output Hessian. Second derivatives of dose (curvature) are a different quantity from Fisher information. Hessian-vector products are tested at interior points, but no Hessian API is supported yet.
Both are planned follow-up work. The model also ignores daughter ingrowth, and these doses are specific to the model's food-supply assumptions.