# pratikrathore8/opt_for_pinns architecture

> Architecture diagram of the GitHub repository pratikrathore8/opt_for_pinns, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pratikrathore8/opt_for_pinns
- Repository: https://github.com/pratikrathore8/opt_for_pinns

## Overview

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: [`src/train_utils.py`](https://github.com/pratikrathore8/opt_for_pinns/blob/main/src/train_utils.py) (Train utils), [`run_experiment.py`](https://github.com/pratikrathore8/opt_for_pinns/blob/main/run_experiment.py) (Experiment runner), [`src/pyhessian.py`](https://github.com/pratikrathore8/opt_for_pinns/blob/main/src/pyhessian.py) (Hessian tools), [`src/models.py`](https://github.com/pratikrathore8/opt_for_pinns/blob/main/src/models.py) (PINN model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g1["Experiment execution"]
  node_n1["Experiment runner<br/>entrypoint<br/>[run_experiment.py]"]
  node_n2(("PDE setup<br/>problem family<br/>[run_experiment.py]"))
end

subgraph group_g2["Training core"]
  node_n3["PINN model<br/>network<br/>[models.py]"]
  node_n4["Train utils<br/>loss/training<br/>[train_utils.py]"]
end

subgraph group_g3["Optimization"]
  node_n5["GD<br/>optimizer<br/>[gd.py]"]
  node_n6["Adam+L-BFGS<br/>hybrid optimizer<br/>[adam_lbfgs.py]"]
  node_n7["Adam+L-BFGS+GD<br/>hybrid optimizer<br/>[adam_lbfgs_gd.py]"]
  node_n8["Adam+L-BFGS+NNCG<br/>hybrid optimizer<br/>[adam_lbfgs_nncg.py]"]
  node_n9["Nystrom CG<br/>second-order optimizer<br/>[nys_newton_cg.py]"]
  node_n10["Polyak L-BFGS<br/>specialized optimizer<br/>[polyak_lbfgs.py]"]
end

subgraph group_g4["Curvature analysis"]
  node_n11[("Hessian tools<br/>analysis util<br/>[pyhessian.py]")]
  node_n12[("Precond Hessian<br/>analysis util<br/>[precond_hessian.py]")]
end

subgraph group_g5["Reproducibility"]
  node_n13["Config recipes<br/>run scripts"]
end

subgraph group_g6["Post-processing"]
  node_n14["Plot notebooks<br/>analysis notebooks"]
end

node_n13 -->|"launches"| node_n1
node_n1 -->|"selects"| node_n2
node_n1 -->|"builds"| node_n3
node_n1 -->|"trains via"| node_n4
node_n4 -->|"optimizes"| node_n3
node_n4 -->|"can use"| node_n5
node_n4 -->|"can use"| node_n6
node_n4 -->|"can use"| node_n7
node_n4 -->|"can use"| node_n8
node_n4 -->|"can use"| node_n9
node_n4 -->|"can use"| node_n10
node_n4 -->|"analyzes curvature"| node_n11
node_n11 -->|"supports"| node_n12
node_n1 -->|"records diagnostics"| node_n11
node_n1 -->|"logs for"| node_n14

click node_n1 "https://github.com/pratikrathore8/opt_for_pinns/blob/main/run_experiment.py"
click node_n2 "https://github.com/pratikrathore8/opt_for_pinns/blob/main/run_experiment.py"
click node_n3 "https://github.com/pratikrathore8/opt_for_pinns/blob/main/src/models.py"
click node_n4 "https://github.com/pratikrathore8/opt_for_pinns/blob/main/src/train_utils.py"
click node_n5 "https://github.com/pratikrathore8/opt_for_pinns/blob/main/src/opts/gd.py"
click node_n6 "https://github.com/pratikrathore8/opt_for_pinns/blob/main/src/opts/adam_lbfgs.py"
click node_n7 "https://github.com/pratikrathore8/opt_for_pinns/blob/main/src/opts/adam_lbfgs_gd.py"
click node_n8 "https://github.com/pratikrathore8/opt_for_pinns/blob/main/src/opts/adam_lbfgs_nncg.py"
click node_n9 "https://github.com/pratikrathore8/opt_for_pinns/blob/main/src/opts/nys_newton_cg.py"
click node_n10 "https://github.com/pratikrathore8/opt_for_pinns/blob/main/src/opts/polyak_lbfgs.py"
click node_n11 "https://github.com/pratikrathore8/opt_for_pinns/blob/main/src/pyhessian.py"
click node_n12 "https://github.com/pratikrathore8/opt_for_pinns/blob/main/src/precond_hessian.py"
click node_n13 "https://github.com/pratikrathore8/opt_for_pinns/tree/main/config"
click node_n14 "https://github.com/pratikrathore8/opt_for_pinns/tree/main/plotting"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_n1,node_n2 toneBlue
class node_n3,node_n4 toneAmber
class node_n5,node_n6,node_n7,node_n8,node_n9,node_n10 toneMint
class node_n11,node_n12 toneRose
class node_n13 toneIndigo
class node_n14 toneTeal
```

## Components

### Experiment execution

Top-level training entrypoint and problem setup.

- [Experiment runner](https://github.com/pratikrathore8/opt_for_pinns/blob/main/run_experiment.py): entrypoint · Top-level script that wires PDE choice, model, optimizer, logging, and device selection. · `run_experiment.py`
- [PDE setup](https://github.com/pratikrathore8/opt_for_pinns/blob/main/run_experiment.py): problem family · Convection, reaction, and wave problem configuration driven by CLI arguments. · `run_experiment.py`

### Training core

PINN model and loss/training utilities.

- [PINN model](https://github.com/pratikrathore8/opt_for_pinns/blob/main/src/models.py): network · Learnable neural approximation used to represent the PDE solution. · `src/models.py`
- [Train utils](https://github.com/pratikrathore8/opt_for_pinns/blob/main/src/train_utils.py): loss/training · Training loop, residual evaluation, boundary conditions, and loss assembly. · `src/train_utils.py`

### Optimization

Optimizer implementations and composition strategies.

- [GD](https://github.com/pratikrathore8/opt_for_pinns/blob/main/src/opts/gd.py): optimizer · Baseline gradient descent implementation. · `src/opts/gd.py`
- [Adam+L-BFGS](https://github.com/pratikrathore8/opt_for_pinns/blob/main/src/opts/adam_lbfgs.py): hybrid optimizer · Common staged optimizer combining adaptive and quasi-Newton updates. · `src/opts/adam_lbfgs.py`
- [Adam+L-BFGS+GD](https://github.com/pratikrathore8/opt_for_pinns/blob/main/src/opts/adam_lbfgs_gd.py): hybrid optimizer · Extended hybrid schedule that adds a gradient-descent phase. · `src/opts/adam_lbfgs_gd.py`
- [Adam+L-BFGS+NNCG](https://github.com/pratikrathore8/opt_for_pinns/blob/main/src/opts/adam_lbfgs_nncg.py): hybrid optimizer · Hybrid optimizer that incorporates Newton-CG style refinement. · `src/opts/adam_lbfgs_nncg.py`
- [Nystrom CG](https://github.com/pratikrathore8/opt_for_pinns/blob/main/src/opts/nys_newton_cg.py): second-order optimizer · Curvature-aware Newton-CG variant using low-rank structure. · `src/opts/nys_newton_cg.py`
- [Polyak L-BFGS](https://github.com/pratikrathore8/opt_for_pinns/blob/main/src/opts/polyak_lbfgs.py): specialized optimizer · Specialized optimizer variant in the Polyak / quasi-Newton family. · `src/opts/polyak_lbfgs.py`

### Curvature analysis

Hessian and preconditioning utilities.

- [Hessian tools](https://github.com/pratikrathore8/opt_for_pinns/blob/main/src/pyhessian.py): analysis util · Hessian computation utilities for loss landscape diagnostics. · `src/pyhessian.py`
- [Precond Hessian](https://github.com/pratikrathore8/opt_for_pinns/blob/main/src/precond_hessian.py): analysis util · Hessian preconditioning support for curvature analysis. · `src/precond_hessian.py`

### Reproducibility

Shell launchers for fixed experiment recipes.

- [Config recipes](https://github.com/pratikrathore8/opt_for_pinns/tree/main/config): run scripts · Shell launchers that fix PDE and optimizer combinations for reproducible experiments. · `config`

### Post-processing

Notebooks for plots and analysis.

- [Plot notebooks](https://github.com/pratikrathore8/opt_for_pinns/tree/main/plotting): analysis notebooks · Jupyter notebooks for figures, metrics, and post-processing. · `plotting`

## Connections

- 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.
