arXiv:2610.37655cs.AIOct 2026

Manuscript Offprint

arXiv:2610.37655

KPPax: preprocess differentiable kinetic ODE for machine learning in atmospheric chemistry

Wenqing Peng, Michael Boy, Zhi-Song Liu

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Atmospheric chemical mechanisms are commonly distributed in the language of the Kinetic Pre-Processor (KPP), which generates efficient Fortran or C code but does not fit into the differentiable programming frameworks in which machine-learning models are developed. We present KPPax, a kinetic preprocessor that generates differentiable, just-in-time compiled, and vectorisable chemistry code in JAX from mechanisms written in the KPP language. KPPax evaluates the rate law with sparse operations in log space, which keeps it differentiable, and integrates the stiff system with the implicit solvers and the forward- and reverse-mode adjoints of the diffrax library, so that exact sensitivities are obtained without hand-derived adjoint code. We demonstrate two applications with the POLLU benchmark mechanism. In the first, the Fisher information matrix computed from an automatically differentiated Jacobian predicts, before any fit, which of the 25 rate coefficients a flow-tube-like design can identify, and noisy synthetic estimation confirms the predicted uncertainties of the nine identifiable rate coefficients to within about 30% while revealing clusters of fast reactions of which only ratios are constrained. In the second, a neural-network correction of an emission inventory is trained offline on per-scenario 4D-Var retrievals and then fine-tuned online through the chemical model, which reduces the error of the biogenic correction by a factor of 2.4–5 and recovers information on low-temperature emissions that the individual retrievals lose. KPPax makes KPP mechanisms directly usable for parameter estimation and hybrid physics–machine-learning modelling.

1 Introduction

Chemicals and aerosols in the ambient air affect human health, weather, and climate (Seinfeld and Pandis, 2016). Their atmospheric concentrations vary strongly in space and time, governed by emission, chemical transformation, aerosol formation, transport by meteorological conditions, and eventual removal by deposition (Brasseur and Jacob, 2017). Comprehensive atmospheric chemical mechanisms, such as the near-explicit Master Chemical Mechanism (Jenkin et al., 1997; Saunders et al., 2003), contain thousands of species coupled through more than ten thousand reactions, and hand-coding the resulting stiff ODE system and its Jacobian is tedious and error-prone.

The Kinetic PreProcessor (KPP) automates this process (Damian et al., 2002). Given a chemical mechanism specified in a dedicated description syntax, the KPP language, KPP parses the reaction list with a Flex/Yacc scanner–parser and generates Fortran or C code that evaluates the time derivative of the concentrations and its Jacobian. The generated code exploits the sparsity of the Jacobian through species reordering and sparse linear algebra routines, which keeps the implicit time stepping required by stiff chemistry efficient, and it is paired with a suite of stiff numerical integrators, including Rosenbrock, BDF, and Runge–Kutta methods. KPP also generates direct-decoupled and adjoint sensitivity code, which efficiently computes derivatives of the model solution with respect to rate coefficients, initial concentrations, and other parameters. These sensitivities support applications such as parameter estimation, uncertainty analysis, and variational data assimilation (Sandu et al., 2003). This tight coupling between mechanism parsing, sparse Jacobian generation, and forward and adjoint sensitivity code generation has made KPP a standard tool in atmospheric chemistry modelling, but it also means that the resulting code

*Corresponding author: wenqing.peng@helsinki.fi inherits the constraints of the Fortran and C environments and of the CPU hardware for which it was designed.

Other tools to preprocess and solve chemical kinetics have been developed for other software and hardware environments. pykpp (Henderson) is a preprocessor written in Python, which parses mechanisms written in the KPP language and solves the kinetic ODE with SciPy solvers. PyBox generates 0-dimensional box models that include both atmospheric chemistry and aerosol processes, in which the chemistry is solved by the Assimulo ODE solver (Topping et al., 2018), and PyCHAM reuses the mechanism parsing of PyBox but solves the ODE with SciPy (O'Meara et al., 2021). The Multi-Scale Infrastructure for Chemistry and Aerosols (MUSICA) is implemented in C++ and provides an option to run on accelerators such as GPUs (Pfister et al., 2020). For the EMAC model, a source-to-source tool translates the KPP-generated Fortran code into CUDA kernels to solve the chemical kinetics on GPUs (Alvanos and Christoudias, 2017). TChem-atm couples gas-phase and aerosol chemistry and runs on CPUs and GPUs through the Kokkos performance-portability library, constructing the Jacobian automatically for a range of stiff ODE solvers (Díaz-Ibarra et al., 2026). These developments target the efficient forward simulation of process-based atmospheric models, which are built on explicit physical and chemical processes and are therefore interpretable, since the driving forces in the model can be perturbed to test their influence on the output. However, process-based models are limited by the processes that they do not resolve, and amending the model structure or tuning its parameters against observations remains laborious and computationally expensive.

Data-driven approaches, for example neural networks trained on historical atmospheric observations, offer flexible and fast emulation of atmospheric processes with comparable accuracy. ChemNNE is a neural-network emulator of the atmospheric chemical ODE that is considerably faster than the numerical solver (Liu et al., 2025), and TopoFlow is a topography-aware neural network for high-resolution air-quality prediction (Kheder et al., 2026). Neural networks can also partially solve the estimation of rate coefficients in chemical ODEs (Peng et al., 2025; Liu et al., 2026). However, purely data-driven models often lack interpretability and the ability to predict anomalies or extreme events, and their training is data-intensive and becomes infeasible when observations are sparse. Neural networks are trained by gradient descent, which relies on automatic differentiation, and although this is possible in Fortran, the majority of neural-network models are developed in Julia or in Python frameworks such as PyTorch and JAX.

Hybrid models that combine physically based process models with data-driven neural networks are expected to unite the flexibility of neural networks with the interpretability and physical constraints of process-based models, enabling both fast emulation and learning from data and an understanding of the underlying processes (Shen et al., 2023; Innes et al., 2019; Gelbrecht et al., 2023). For example, the hybrid weather and climate model NeuralGCM, which combines a differentiable dynamical core with neural networks, both implemented in JAX, achieves a performance comparable to the best machine-learning and process-based models (Kochkov et al., 2024). In ecohydrology, JAX-CanVeg integrates a land-surface model with neural-network components and improves the simulation (Jiang et al., 2025). Such hybrid models require the process model itself to be differentiable, so that gradients can be propagated through it to the network parameters. General-purpose differentiable modelling tools for reaction networks exist, such as Catalyst.jl in Julia (Loman et al., 2023), but to the best of our knowledge no tool generates differentiable code from mechanisms written in the KPP language, in which atmospheric mechanisms such as the MCM are distributed and used.

Differentiability matters most for inverse problems, in which model parameters or inputs are inferred from observations of the model output. Estimating rate coefficients from chamber or flow-tube observations is such a problem, and it is often ill-posed because the observations constrain only some combinations of the rate coefficients, so that the identifiability of the parameters should be analysed before they are estimated (Guillaume et al., 2019). Another example is the inversion of emissions from concentration observations, which has traditionally relied on variational data assimilation with hand-derived adjoint models (Elbern et al., 2007; Henze et al., 2007). To learn how emissions depend on environmental drivers, the retrieved emission fields can be used to train a neural network offline, in the same way as data assimilation has been combined with machine learning to learn model dynamics from sparse and noisy observations (Brajard et al., 2020). Such a two-step approach, however, discards the information that the individual retrievals cannot resolve, whereas online training, in which the network is fitted to the observations through the chemical model, requires the gradient of the model output with respect to the network parameters.

To address this, we present KPPax, a kinetic preprocessor implemented in the JAX framework that generates differentiable, just-in-time compiled, and vectorisable chemistry code from mechanisms written in the KPP language, which is directly usable within the data-driven modelling ecosystem. KPPax evaluates the rate law with sparse operations in log space, which keeps it differentiable, and integrates the stiff system with the implicit solvers and the forward- and reverse-mode adjoints of the diffrax library (Kidger, 2022), which enables inverse modelling, parameter estimation, and hybrid modelling of physical and neural models. Section 2 describes the implementation. Section 3 uses the sensitivities from KPPax to analyse the identifiability of the rate coefficients of a benchmark mechanism before estimating them from noisy synthetic observations. Section 4 trains a neural-network correction of an emission inventory and shows that online fine-tuning through the chemical model improves on the offline two-step approach. Section 5 discusses the limitations, and Sect. 6 concludes.

References (31)