Trusty Neurocoder¶
Structured Surrogates for Scientific Simulation Kernels¶
Christopher J. Mungall Lawrence Berkeley National Laboratory
The Core Problem¶
Many DOE science programs depend on large simulation codes that are:
- scientifically valuable
- expensive to run
- hard to calibrate against real data
- full of local submodels that are partly known and partly uncertain
Common fallback: - fit a black-box neural surrogate
Common failure: - it may reproduce outputs, but loses scientific structure and meaning
What Is a "Kernel" Here?¶
A kernel here is a small, repeated scientific computation, not the whole simulator.
Typical shape:
or:
It is the local rule that says:
given the current scientific state, how does it change?
Full Simulator vs Kernel¶
The full code usually looks like:
The simulator includes: - timestepping - I/O - parallelization - diagnostics - checkpointing
The kernel is the step(...) or rhs(...) update rule.
Example Kernel¶
def update_pools(state, moisture, temp, params):
decay_fast = k_fast * moisture_response(moisture) * state.fast
decay_slow = k_slow * temp_response(temp) * state.slow
return {
"fast": state.fast - decay_fast,
"slow": state.slow + decay_fast - decay_slow,
"atm": state.atm + decay_slow,
}
This is a good kernel because it is:
- scientifically meaningful
- called repeatedly
- small enough to isolate
- a plausible place to learn uncertain pieces
Why Not Learn the Whole Simulator?¶
Replacing the entire simulation with one neural net is usually a bad abstraction.
You lose:
- variable roles
- conservation structure
- module boundaries
- known physics vs unknown physics
- interpretability
For large models such as ecosystem simulators with many interacting variables, that loss of structure becomes a real scientific risk, not just an aesthetic problem.
What This Project Tries to Do¶
Extract a small scientific kernel from a larger codebase, then:
- represent the known structure symbolically
- compile that structure into a differentiable neural module
- keep trusted physics fixed
- make only uncertain parts learnable
- fit those parts from data
Goal:
structured surrogate modeling, not unrestricted black-box replacement
The Pipeline¶
Scientific code
↓
Extract kernel / mini-module
↓
Encode known program structure
↓
Compile to NSAM / differentiable module
↓
Learn unknown parameters or subfunctions
↓
Use as calibrated module or fast surrogate
This repo is currently a proof of concept for that pipeline.
Architecture: From Simulator to Structured Surrogate¶
Large scientific codebase
↓
Extract one kernel / mini-module
↓
step(state, params, forcing)
↓
Represent the known scaffold symbolically
├─ variable roles stay explicit
├─ known physics stays fixed
└─ unknown pieces become learnable "holes"
↓
Compile to NSAM / differentiable module
↓
Train on simulator traces, observations, or both
↓
Fast, calibrated, more interpretable local module
This is the intended architecture boundary:
learn the uncertain part inside a known scientific scaffold
What Gets Learned?¶
Three realistic modes:
- Parameter fitting
- known equation form
-
unknown constants
-
Small unknown function fitting
- known scaffold
-
unknown response curve or sub-expression
-
Local surrogate fitting
- preserve module boundary
- replace an expensive local update with a cheaper learned approximation
The key constraint is that learning happens inside a known scientific scaffold.
Worked Example: EcoSIM-Style Soil Carbon Kernel¶
decay_fast = k_fast * f_theta(moisture) * state.fast
decay_slow = k_slow * temp_response(temp) * state.slow
Interpretation:
state.fast,state.slow,state.atmare carbon poolstemp_response(temp)is known or trustedf_theta(moisture)is uncertain and learnable- pool-to-pool transfers and mass balance stay fixed
Training options:
- fit
f_thetafrom expensive simulator traces - fit
f_thetaork_fastfrom field observations - do both: simulator as prior, observations as correction
What is preserved:
- variable meanings
- conservation structure
- the module boundary
Today the repo demonstrates the mechanics on toy update loops; this is the kind of real kernel it is aiming at.
Where Does the Training Signal Come From?¶
Potential sources:
- simulation outputs
- emulate an expensive code path
- real observations
- calibrate model components to the world
- hybrid workflows
- use both simulation traces and experimental or field data
So this can support:
- surrogate modeling
- parameter calibration
- partial system identification
Why Not Just Use PINNs?¶
PINNs are useful, but they solve a different problem.
Roughly:
- PINNs
- learn solutions or latent functions while enforcing physics in training
- This approach
- keeps an explicit program/module structure and learns only selected unknown parts
The point is not "better than PINNs at everything."
The point is:
more modular, more interpretable, and closer to the original scientific code structure
Comparison¶
| Approach | What it learns | What it keeps | Strength | Weakness |
|---|---|---|---|---|
| Black-box surrogate | whole input-output map | very little | flexible, fast inference | hard to interpret or verify |
| PINN | solution or latent function under physics constraints | some physics in loss | physics-aware training | hard training, often not modular |
| NSAM kernel approach | parameters or subfunctions inside a known scaffold | program structure, variable roles, invariants | structured, interpretable, learnable | requires kernel extraction; still early-stage |
The Value Proposition¶
Take a small scientific kernel from a larger simulation.
Then:
- preserve the known scientific structure
- compile it into a differentiable module
- learn only the uncertain pieces
- keep more semantics than a black-box surrogate
- potentially get a cheaper module for repeated use
Short version:
Faster and learnable local scientific modules without throwing away the scientific story.
What Gets Extracted¶
Not the whole land model.
Usually a scientist-meaningful local update kernel such as:
- decomposition for one timestep
- temperature or moisture response within a module
- a reaction-rate law
- a transfer rule between a few state variables
The agent can help locate and reimplement these kernels, but the decomposition into "known scaffold" and "unknown part" still needs scientist validation.
Why "Semantics" Matters¶
Semantics here means more than names.
It includes facts like:
- this variable is carbon in pool A
- this term is a branching ratio and should stay in
[0, 1] - this update should conserve total mass
- this sub-expression is known physics
- only this response function is uncertain
A black-box vector-to-vector model can hide all of that.
This approach tries to preserve it.
Why This Fits DOE-Style Simulation Work¶
DOE simulations often contain:
- expensive local update rules
- partial knowledge, not complete ignorance
- strong scientific constraints
- a need for calibration and surrogate modeling
That makes them a good match for:
- extracting a kernel
- preserving the scaffold
- learning the uncertain part
This is especially attractive where full black-box replacement would be scientifically or operationally unacceptable.
What the Repo Demonstrates Today¶
Eight working examples across DOE science domains:
| Model | Domain | What's learned | Key result |
|---|---|---|---|
| Exponential decay | Foundation | rate k | recovered exactly |
| Coupled pools | Earth science | transfer α | recovered exactly |
| Unknown function | Earth science | Hill equation | decompiled from MLP |
| CENTURY-Lite | Earth science | Q10 + Hill | both forms recovered |
| Decay chain | Nuclear | branching ratios | exact (10⁻⁶) |
| Battery fade | Energy storage | SEI growth law | parabolic law recovered |
| Chemical kinetics | Combustion | Arrhenius rate | A=2.01, E=4.99 |
| EcoSIM decomp | Earth science | T + water response | extracted from Fortran |
Controlled Comparison: Cajal vs PINN vs Black-Box¶
Identical data, identical task (reversible reaction A⇌B):
| Black-box | PINN (λ=10) | Cajal | |
|---|---|---|---|
| Interpolation MSE | 6.2×10⁻³ | 7.7×10⁻³ | 9.3×10⁻⁷ |
| Conservation error | 5.4×10⁻³ | 6.5×10⁻³ | 1.6×10⁻⁷ |
| Extrapolation MSE | 3.1×10⁻² | 5.0×10⁻² | 1.3×10⁻² |
| Sample efficiency (2 traj) | 8.6×10⁻² | — | 1.2×10⁻³ |
| Interpretable? | No | No | k=1.97·exp(-4.86/T) |
PINN conservation penalty hurts extrapolation (worse than black-box).
2-Paragraph Pitch¶
DOE science depends on large simulation codes that are expensive to run and difficult to calibrate, while many important submodels are only partially known. Black-box neural surrogates can reduce cost, but they often discard the scientific structure that tells us what variables mean, what should be conserved, and which parts of the model are trusted versus uncertain.
Trusty Neurocoder targets that gap by extracting small scientific kernels, preserving their known symbolic structure, and compiling them into differentiable neural modules. This makes it possible to extract, compress, and reinterpret uncertain simulator kernels from legacy code and simulation traces, and to recalibrate them against observations while keeping more semantics, interpretability, and verifiability than a generic neural surrogate. In the current repo, most training data is synthetic or comes from Python reimplementations of extracted equations; training directly on full simulator traces is the next step.
One-Slide Executive Summary¶
- Problem: DOE simulations are expensive, and their uncertain submodels are hard to calibrate.
- Risk with black-box surrogates: they lose scientific meaning and constraints.
- Approach: extract a kernel from a larger simulator, keep known structure, compile to differentiable module, learn only uncertain parts.
- Results: 8 working models, 6,700× better than black-box, exact conservation, decompiles to interpretable math.
- End-to-end: agent reads EcoSIM Fortran → proposes kernel structure → scientist validates decomposition → builds Cajal surrogate → trains → decompiles → verifies.
- Status: working prototype on synthetic and reimplemented trajectories; training on full EcoSIM traces next.
Key Insight¶
Do not replace the whole simulator.
Replace or calibrate the right small kernel.
Keep the scientific scaffold. Learn the uncertain parts.
Trusty Neurocoder aims at structured surrogate modeling for scientific code.