kinn fits neural-network trajectories to kinetic models and measurements using JAX. It supports forward problems with known rate constants and inverse problems that estimate rates from measurements. Both modes support fixed residual weighting or MLE adaptive covariance weighting. The MLE formulation includes SVD conservation constraints and, for inverse problems, automatic variance propagation.
Python 3.11 or newer is required. Install kinnlib from PyPI; the Python import and command are both kinn.
python -m venv .venv
source .venv/bin/activate
python -m pip install kinnlibOn Windows PowerShell, activate with .venv\Scripts\Activate.ps1 instead. Installation provides the kinn Python package and the kinn command. python -m kinn is an equivalent entry point. Training runs locally on the machine where you invoke it.
The GitHub release also provides a wheel and source archive. To install from a source checkout:
git clone https://github.com/gusmaogabriels/kinn.git
cd kinn
python -m pip install .Generate an adsorption example, check its inputs, and solve the inverse problem:
kinn example --method mle --mode inverse --kind adsorption --output inverse.json
kinn validate inverse.json
kinn run inverse.json --output inverse-result.jsonThe example describes A + * ⇌ A*, observes the bulk species A, and supplies a known initial state. Its synthetic measurements use rates [2, 1]; inference starts from [1.5, 0.7]. Replace the measurements and mechanism with your own, or provide a CSV through data_file as described in the input guide.
kinn example --method mle --mode forward --kind homogeneous --output forward.json
kinn validate forward.json
kinn run forward.json --output forward-result.jsonThis example fits a neural trajectory for A ⇌ B with known rates [2, 1] and initial state [1, 0]. Forward training matches the network's time derivative to the kinetic model while enforcing the supplied initial state. Rates remain unchanged under either training method; forward inputs contain no measured values.
mode selects what is fitted; method selects the residual weighting and its associated original surrogate parameterization. These are independent choices in one package, kinn. When method is omitted, it defaults to mle.
mode |
method |
Fitted quantities | Objective |
|---|---|---|---|
forward |
fixed |
Neural trajectory; supplied rates stay fixed | Physics MSE |
forward |
mle |
Neural trajectory; supplied rates stay fixed | Physics residual with adaptive covariance weighting |
inverse |
fixed |
Neural trajectory and rate constants | Physics MSE + alpha × data MSE |
inverse |
mle |
Neural trajectory and rate constants | Data and physics residuals with adaptive covariance weighting and local variance propagation |
To generate inputs for the original fixed-weight formulation:
kinn example --method fixed --mode forward --kind homogeneous --output fixed-forward.json
kinn example --method fixed --mode inverse --kind adsorption --output fixed-inverse.json
kinn validate fixed-inverse.json
kinn run fixed-inverse.json --output fixed-inverse-result.jsonFor inverse fixed problems, training.alpha is a positive scalar held constant throughout one kinn run. It defaults to 1; the generated fixed inverse examples explicitly choose 100. Repeat the same problem with different alpha values to study the data/physics tradeoff. Forward fixed problems have no data term, so alpha has no effect.
MLE updates covariance matrices during training, rather than tuning a scalar alpha. Omit training.alpha for mle; validation rejects it. Architecture, learning rate and training budget remain configurable for both methods.
--method and --mode are flags for kinn example. To solve your own input, set method and mode inside the JSON; kinn run reads them from that file.
The CLI includes the original four mechanisms, both initial conditions, and 21 saved fixed-weight training archives. Re-evaluate a reference experiment with its trajectories, derivatives, parameters, calibration scales and Pareto history:
python -m pip install "kinnlib[reproduce]"
kinn reproduce list
kinn reproduce run trainer_invvwn_3_alpha13 --output paper-example --plotsFresh fixed-weight training is also available with the saved architectures and stage schedules:
kinn reproduce plan trainer_fwd_0_alpha13 --output training-plan.json
kinn reproduce train trainer_fwd_0_alpha13 --output fresh-forward --plotsEvaluating a saved archive and training afresh are separate operations. These reference commands currently cover the fixed-weight paper experiments; full reproduction of both papers remains incomplete. The reproduction guide describes the available experiments, checkpoint selection and exported files. General forward and inverse problems with MLE weighting use kinn run as shown above.
Inputs describe the mechanism, datasets and surrogate architecture. A complete forward input for A ⇌ B with MLE covariance weighting is:
{
"schema_version": 1,
"method": "mle",
"mode": "forward",
"species": ["A", "B"],
"stoichiometry": [[-1, 1], [1, -1]],
"rate_constants": [2, 1],
"datasets": [{
"times": [0, 0.1, 0.2, 0.4, 0.7, 1],
"initial_state": [1, 0]
}],
"surrogate": {
"layers": [16, 16],
"activations": "tanh"
},
"units": {"time": "s", "bulk": "normalized concentration"}
}The stoichiometric matrix has species rows and directed reaction columns. Negative entries are reactants and positive entries are products. Each reversible reaction needs two columns and two rate constants, in matching order. Reaction orders follow the negative entries of the matrix.
For surface mechanisms, include adsorbates and vacant sites in species and identify them in surface_species. The current CLI supports one conserved site balance with equal site occupancy: the surface rows must sum to zero in every reaction column, and initial surface fractions must sum to one. Bulk concentrations and surface fractions must use compatible normalization for the supplied matrix.
Forward inputs supply rate_constants and a full initial_state for every dataset. Inverse inputs instead supply initial_rate_constants, observed_species, and values or a CSV data_file for each dataset. Observations may cover all bulk species or all species. Multiple datasets can have different time grids and separate neural trajectories while sharing kinetic parameters. A supplied initial_state is enforced exactly; it is required for forward problems and optional for inverse problems.
Set hidden-layer widths with surrogate.layers. Activations may be one name for all layers or a list with one name per layer: tanh, sigmoid, swish, softplus, sin or gaussian. Training settings include epochs, optimizer steps per epoch, learning rate, seed and residual tolerances. training.warmup_steps initializes the data fit in inverse mode. Forward convergence uses physics_tolerance; inverse convergence also requires data_tolerance.
The input contract currently covers closed, isothermal, well-mixed mass-action systems. Arbitrary rate laws, multiple surface site types and partial observations of bulk species need extensions to that contract. See the CLI and input guide for the full settings, units and constraints; the examples contain complete inputs.
The Python API accepts the same JSON file or an equivalent dictionary:
from kinn import solve
result = solve("inverse.json")
print(result["status"])
print(result["rate_constants"])
print(result["uncertainty"])| Result field | Contents |
|---|---|
mode, method |
The problem mode and training method used |
status |
Whether residual tolerances and sampled physical checks passed |
rate_constants, log_rate_constants |
Supplied rates in forward mode, fitted rates in inverse mode; reaction-column order |
predictions |
Times and predicted states for each dataset, in input species order |
history |
Epoch, data RMSE and physics RMSE throughout training |
uncertainty |
Final empirical covariance estimates for MLE; method: "not_estimated" for fixed weighting |
physical_checks |
Sampled nonnegativity and surface-site balance checks |
timing |
Setup, first-epoch, warm execution and total solve timings |
Inverse MLE results include state-residual, log-rate, rate and time-dependent kinetic-RHS error covariance. Rank-deficient kinetic sensitivities produce null rate-error covariances with a diagnostic. Forward MLE results report physics_defect_covariance; they do not estimate uncertainty in the supplied rates. Fixed weighting does not estimate covariance in either mode.
For general problems, kinn run stores final results and RMSE history, but does not yet export neural weights, reloadable checkpoints or parameter/covariance histories. The separate kinn reproduce commands export the fixed-weight reference experiment parameters and saved stages; see the reproduction guide. These paper-specific exports have a different scope from a general solve.
For programs and agents, kinn capabilities describes supported operations and kinn schema prints the JSON Schema. kinn validate checks the input without importing JAX or training. A run exits with code 0 on convergence with sampled physical checks, 1 on nonconvergence or numerical failure, and 2 on an input or file error. Inspect status before using a result.
The original ten-species, fourteen-rate DCS example is a more demanding benchmark. Its current default budget reaches max_epochs; it is useful for evaluating architectures and convergence, and is not a demonstrated converged CLI example.
Neural evaluations, time derivatives, kinetic Jacobians and optimizer steps use JAX. Compiled blocks of optimizer steps reuse their compiled program during a solve. Validation, convergence decisions and file handling run in Python.
The first-epoch timing includes compilation on first use. Warm epoch timings include covariance refresh and diagnostics; warm optimizer-kernel timings isolate the optimizer steps. JAX results are synchronized before timings are recorded. wall_seconds includes setup and uncertainty reporting but excludes Python/import startup; the timing benchmark also measures fresh-process wall time. See the timing guide for details.
CI covers Linux, macOS and Windows, supported dependency combinations, numerical examples, covariance propagation and installation of the built wheel.
For research using KINN, cite the software version or source revision used and the applicable methods papers. CITATION.cff contains software and paper citation metadata.
- Gabriel S. Gusmão, Adhika P. Retnanto, Shashwati C. da Cunha and Andrew J. Medford. Kinetics-informed neural networks. Catalysis Today (2023).
- Gabriel S. Gusmão and Andrew J. Medford. Maximum-likelihood estimators in physics-informed neural networks for high-dimensional inverse problems. Computers & Chemical Engineering (2024).
During MLE training, KINNs estimates covariance from sampled residuals and propagates state and parameter uncertainty through the kinetic model. The resulting inverse covariance matrices weight the data and physics residuals. They are refreshed between training cycles and held fixed within each block of parameter updates, as described in the MLE paper.
The mathematical formulation below explains the residuals, SVD projection and covariance updates.
The comparison below shows this adaptive trajectory alongside the regularization sweep from the original fixed-alpha formulation, evaluated in the same likelihood coordinates.
Animated redraw of Figure 2c of the MLE paper. Fixed-alpha and MLE paths share the paper's likelihood coordinates. Arrows mark increasing alpha on the tightening branch and decreasing alpha on the relaxation branch. The black circle marks the paper's final MLE estimate, enlarged in the inset. Frames reveal every published point, with faster playback near convergence; playback does not represent training time.
The MLE paper extends KINNs with adaptive covariance weighting, SVD coordinates and automatic variance propagation. The animation below illustrates inverse fitting for the DCS mechanism.
Try it live: an interactive, in-browser version of the KINNs inverse-kinetics solver runs at gabrielgusmao.com/blog/kinns-playground: recover rate constants from noisy transient data with JAX-style autodiff and MLE uncertainty, no install. See also the Lotka-Volterra Neural ODE and pharmacokinetics Neural ODE playgrounds.
KINNs with MLE adaptive covariance for the dcs reaction type
The kinetic model represents the following fully reversible chemical reactions. Type d involves adsorption/desorption steps. Type c introduces surface intermediates, such as
Here
The JAX-based kinetic models, neural networks and trainers are under kinn.
The original fixed-alpha Pareto studies are retained in:
The corresponding Python sources are kinn_datagen_reg.py and kinn_plotsgen_reg.py. The original kinetic model, neural network, and training loop live in kinn/basis; the paper-specific constraints, loss, and benchmark systems are in trainer_source.py.
This section follows the MLE paper, which also states the original fixed-alpha KINNs objective. Equation references below identify the source of each part of the formulation. The paper denotes physical concentrations by
The kinetic model in Eq. 2.1.1 is
Eqs. 2.1.2–2.1.4 define the interpolation and model residuals and the fixed-alpha objective over
Inverse fitting optimizes the neural weights and kinetic parameters at fixed
For real-valued matrices, the SVD in Eqs. 2.3.1–2.3.2 can be written
The columns of
Time dependence is represented in the range coordinates; the nullspace coordinates encode conserved quantities. For heterogeneous systems, the paper partitions these bases into bulk and surface rows and uses the normalization operator
Eq. 4.1.5 estimates the state-error covariance from centered residuals:
The paper obtains local parameter-error samples by the least-squares relation in Eq. 4.1.4, then estimates
The first-order expansion in Eq. 2.2.2 includes both the surrogate representation and kinetic-model contributions:
The paper neglects
Project residuals into the range using
The precision matrices in Eq. 4.7.3 are the inverses of the projected covariances:
With
The paper holds precision matrices fixed during parameter updates, then recomputes residual covariances, kinetic sensitivities and projected precision matrices between epochs (Algorithm 1). Gaussian normalization terms are constant within that parameter-update problem. The covariance stabilization in Eq. 4.2.1 adds a diagonal term based on the absolute residual mean. This is the paper's mechanism for adapting residual weights as training proceeds.
mode selects forward or inverse fitting; method selects fixed or mle. The general CLI's observed-species handling, separate time grids, OAS shrinkage, eigenvalue floor and uncentered state-residual second moments are implementation choices documented in the CLI guide. They are not the paper's equations above. The package uses
The paper's parameter intervals additionally use likelihood-Hessian/Fisher-information analysis. General kinn run returns empirical error covariances and does not export those intervals. The original notebook, Python source, and MLE routines retain the research formulation.

