How pratikrathore8/opt_for_pinns works
This repository is an experiment harness for training Physics-Informed Neural Networks (PINNs) and analyzing their loss landscape. The architecture is centered on a single training entrypoint, a set of optimizer implementations, and a separate plotting/analysis layer that consumes logged experiment results.
1. Main orchestration path
run_experiment.py is the top-level driver. It accepts PDE choice, PDE parameters, optimizer choice, network size, sampling sizes, epoch count, logging project, and device. In practice, the whole repo flows through this script for experiment execution.
2. Problem setup boundary
The experiments are organized around three PDE families: convection, reaction, and wave. The --pde and --pde_params arguments determine which physics problem is instantiated, while num_x, num_t, and num_res control the discretization / sampling of the training domain and residual points.
3. PINN model subsystem
src/models.py contains the neural network model used for the PINN. It is the learnable approximation component that maps inputs in the PDE domain to solution values, and is the primary object optimized during training.
4. Training and loss computation
src/train_utils.py likely contains the training loop, PDE residual evaluation, boundary/initial condition handling, loss assembly, and evaluation utilities. This is the boundary between the PDE formulation and the optimizer layer.
5. Optimizer subsystem
src/opts/ contains multiple optimizer implementations and optimizer-composition strategies:
• standard methods like gd.py
• hybrid schedules like adam_lbfgs.py, adam_lbfgs_gd.py, adam_lbfgs_nncg.py
• curvature-aware / second-order methods like nys_newton_cg.py
• specialized variants like polyak_gd.py, polyak_lbfgs.py, sketchygn.py, sketchysgd.py, and alr_mag.py
This directory is a major architectural boundary: it encapsulates optimization logic separately from the PINN model and PDE code.
6. Curvature / Hessian analysis utilities
src/pyhessian.py and src/precond_hessian.py provide Hessian-related computation and preconditioning support. These are important for the repo’s central theme: diagnosing ill-conditioning and loss landscape structure, not just training accuracy.
7. Experiment configuration layer
The config/ directory contains shell scripts for reproducible runs. They encode the experimental matrix by PDE type and optimizer recipe, such as:
• convection_*
• reaction_*
• wave_*
These scripts are the reproducibility boundary: they wrap run_experiment.py with fixed hyperparameter choices for the paper’s figures.
8. Logging and experiment tracking
The README indicates Weights & Biases is used for monitoring and aggregation. The wandb_project argument and notebook references to entity_name show that experiment results are expected to be logged externally, then queried later for analysis and plotting.
9. Analysis / figure-generation layer
The plotting/ directory contains Jupyter notebooks for post-processing and paper figures:
• l2re_loss_scatter.ipynb
• spectral_densities.ipynb
• opt_comparison.ipynb
• under_optimization.ipynb
• line_search.ipynb
• solution_visualizations.ipynb
• condition_number.ipynb
These notebooks do not train models; they consume logged runs and derived statistics to produce the paper’s plots.
10. Data flow across the repo
Typical flow is:
config/*.sh → run_experiment.py → src/models.py + src/train_utils.py + one of src/opts/* → logging to Weights & Biases → plotting/*.ipynb for figures.
A second flow is curvature analysis: training outputs feed pyhessian.py / precond_hessian.py, then notebook-based analysis.
11. Technologies and runtime
This is a Python research codebase with shell-script launchers and Jupyter notebooks. It is intended to run on GPU when available via the --device option. External dependency management is via requirements.txt.
12. Architectural emphasis
The repository is not a general-purpose library; it is a reproducible research pipeline. The key architectural concerns are experiment orchestration, optimizer experimentation, curvature diagnostics, and notebook-based figure reproduction rather than deployment or serving.
Main entry points: train_utils.py Train utils · run_experiment.py Experiment runner · pyhessian.py Hessian tools · models.py PINN model
Components 14
Experiment execution
Top-level training entrypoint and problem setup.
- Experiment runner · Top-level script that wires PDE choice, model, optimizer, logging, and device selection.
run_experiment.py - PDE setup · Convection, reaction, and wave problem configuration driven by CLI arguments.
run_experiment.py
Training core
PINN model and loss/training utilities.
- PINN model · Learnable neural approximation used to represent the PDE solution.
src/models.py - Train utils · Training loop, residual evaluation, boundary conditions, and loss assembly.
src/train_utils.py
Optimization
Optimizer implementations and composition strategies.
- GD · Baseline gradient descent implementation.
src/opts/gd.py - Adam+L-BFGS · Common staged optimizer combining adaptive and quasi-Newton updates.
src/opts/adam_lbfgs.py - Adam+L-BFGS+GD · Extended hybrid schedule that adds a gradient-descent phase.
src/opts/adam_lbfgs_gd.py - Adam+L-BFGS+NNCG · Hybrid optimizer that incorporates Newton-CG style refinement.
src/opts/adam_lbfgs_nncg.py - Nystrom CG · Curvature-aware Newton-CG variant using low-rank structure.
src/opts/nys_newton_cg.py - Polyak L-BFGS · Specialized optimizer variant in the Polyak / quasi-Newton family.
src/opts/polyak_lbfgs.py
Curvature analysis
Hessian and preconditioning utilities.
- Hessian tools · Hessian computation utilities for loss landscape diagnostics.
src/pyhessian.py - Precond Hessian · Hessian preconditioning support for curvature analysis.
src/precond_hessian.py
Reproducibility
Shell launchers for fixed experiment recipes.
- Config recipes · Shell launchers that fix PDE and optimizer combinations for reproducible experiments.
config
Post-processing
Notebooks for plots and analysis.
- Plot notebooks · Jupyter notebooks for figures, metrics, and post-processing.
plotting
Connections 15
- Config recipes → Experiment runner: launches · Fixed experiment scripts call the main runner.
- Experiment runner → PDE setup: selects · CLI arguments choose the PDE family and sampling setup.
- Experiment runner → PINN model: builds · Runner instantiates the PINN model.
- Experiment runner → Train utils: trains via · Runner hands control to training and loss computation utilities.
- Train utils → PINN model: optimizes · Training updates the model parameters.
- Train utils → GD: can use · Training can be coupled to baseline GD.
- Train utils → Adam+L-BFGS: can use · Training can use the Adam + L-BFGS hybrid.
- Train utils → Adam+L-BFGS+GD: can use · Training can use the Adam + L-BFGS + GD schedule.
- Train utils → Adam+L-BFGS+NNCG: can use · Training can use the Adam + L-BFGS + NNCG schedule.
- Train utils → Nystrom CG: can use · Training can use curvature-aware second-order optimization.
- Train utils → Polyak L-BFGS: can use · Training can use specialized Polyak / L-BFGS variants.
- Train utils → Hessian tools: analyzes curvature · Training outputs feed Hessian diagnostics.
- Hessian tools → Precond Hessian: supports · Preconditioning augments Hessian-based analysis.
- Experiment runner → Hessian tools: records diagnostics · Experiment runs can emit data used by curvature analysis.
- Experiment runner → Plot notebooks: logs for · Logged runs are later consumed by notebooks for figures.