Skip to content

Add solver-in-the-loop active learning example with neojax - #113

Open
paulgekeler wants to merge 1 commit into
Ceyron:mainfrom
paulgekeler:add-neojax-example
Open

paulgekeler wants to merge 1 commit into
Ceyron:mainfrom
paulgekeler:add-neojax-example

Conversation

@paulgekeler

Copy link
Copy Markdown

Summary

Adds a new example in the Advanced section as discussed in #65. The example experiments with a solver-in-the-loop active learning approach based on exponax and neojax. This is something I wanted to try for a while and exponax speed makes it possible because the solver overhead is negligible compared to training time.
The underlying PDEs are the 2D Navier-Stokes equations on a periodic, unit-square domain. We try to learn a surrogate for the solution operator

$$ \begin{align} \mathcal{G}: (s, \text{log}_{10}\nu, A) \mapsto \omega(\cdot, T) / A, \end{align} $$

where $\omega$ is the vorticity, $A \in [0.5, 10.0]$ the amplitude of the initial vorticity $\omega(\cdot,0) = As$, where $s$ is a random smooth field and $\nu$ with $\text{log}_{10}(\nu) \in [-4.0, -2.5]$ the viscosity. The operator thus maps the shape of the initial condition and the parameters to the vorticity at the final time $T$.
The parameters are chosen such that a small learnable part of the parameter space has a high Reynolds number and is therefore harder to learn but still learnable. Ideally, uncertainty-based sample acquisition queries more in this subspace than random acquisition.

We create an ensemble of 5 CNOs (leveraging vmap over constructor) in neojax and pretrain it on 128 simulations created with exponax for WARMUP_EPOCHS (default 60). Then for N_ROUNDS (default 6) refinement rounds, we draw candidate initial conditions and parameters (either random or uncertainty-based), query the exponax solver to solve for these ics and params (N_QUERY samples) and fine-tune the ensemble using the created (input, solution) pairs. We then compare how uncertainty-based acquisition compares to random acquisition w.r.t. relative $L^2$ error and the number of seen simulations.
Because exponax is so fast, the solver-in-the-loop has little overhead over pure ensemble training. The example highlights this by logging solver and training timings at intervals.

The runs are repeated across 3 seeds to check for repeatability.

Notes

I didn't want to edit the dependencies without checking first and there are no example dependencies so the first cell pip installs "neojax-operators[ex]" and exponax.

Checks

mkdocs build succeeded (raised warnings unrelated to this PR: traitlets dependency, unused other notebooks)

Additions

  • Adds example notebook active_learning.ipynb under docs/examples/active_learning.ipynb
  • Reference notebook in mkdocs navigation yaml

@paulgekeler

Copy link
Copy Markdown
Author

Please make any changes you'd like. We can also change the example to something completely different if need be.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant