Skip to content

Add live training monitor - #2103

Open
fvalle1 wants to merge 7 commits into
lululxvi:masterfrom
fvalle1:feature/live-training-monitor
Open

fvalle1 wants to merge 7 commits into
lululxvi:masterfrom
fvalle1:feature/live-training-monitor

Conversation

@fvalle1

@fvalle1 fvalle1 commented Aug 12, 2026 •

Copy link
Copy Markdown

What's missing

DeepXDE has no way to watch live a PINN train. The closest existing tools are:

  • MovieDumper — accumulates frames but only writes the GIF in
    on_train_end, after training has already finished.
  • dde.saveplot() — plots the solution and loss history, but only once,
    after training completes.

Neither gives feedback while the model is still training. Other PINN
libraries (e.g. neurodiffeq's Monitor1D/Monitor2D)
support this: a periodically-refreshed plot of the current
prediction and loss history during training, which is very useful for
spotting divergence, bad loss weighting, or stalled optimization early instead of after a long run.

This feature can be helpful for issues (#2014, #1116).

What this PR adds

  • dde.callbacks.TrainingMonitor: a new Callback that, every period
    epochs, redraws subplots — the current predicted solution
    (optionally against a reference/analytical solution via y_reference)
    and the train/test loss history on a log scale.
  • Designed to be safe in headless/CI environments: it detects when there
    is no usable interactive Matplotlib backend/display and disables itself
    gracefully.
  • New example: examples/pinn_forward/ode_2nd_with_monitor.py, a damped
    harmonic oscillator solved with a PINN, using TrainingMonitor against
    the closed-form analytical solution.
  • New example: examples/pinn_forward/diffusion_1d_with_monitor.py, a monitor added to an already existing example.
  • New test: tests/test_callbacks.py, covering periodic triggering logic
    and headless-safety under the Agg backend.

Usage

monitor = dde.callbacks.TrainingMonitor(
    period=200,
    x_plot=x_plot,
    y_reference=analytical_solution,
)
model.train(iterations=10000, callbacks=[monitor])

Test plan

  • pytest tests/test_callbacks.py passes (4/4) under MPLBACKEND=Agg
  • examples/pinn_forward/ode_2nd_with_monitor.py runs end-to-end
  • import deepxde unaffected across the change
  • pylint deepxde/callbacks.py shows no new warnings beyond the
    file's existing baseline

Still in progress

  • Update .rst files with documentation for ode example
  • Test monitor against all existing examples

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