|
| 1 | +PINN playground with DeepXDE |
| 2 | +============================ |
| 3 | + |
| 4 | +This playground starts a minimal setup for experiments that combine |
| 5 | +`DeepXDE <https://github.com/lululxvi/deepxde>`_ with pySDC ideas. |
| 6 | + |
| 7 | +Current toy example |
| 8 | +------------------- |
| 9 | + |
| 10 | +The script ``deepxde_toy_ode.py`` trains a PINN for |
| 11 | + |
| 12 | +.. math:: |
| 13 | +
|
| 14 | + y'(t) - y(t) = 0, \quad t \in [0, 1], \quad y(0)=1, |
| 15 | +
|
| 16 | +whose exact solution is :math:`y(t)=\exp(t)`. |
| 17 | + |
| 18 | +It is intentionally small and fast, so it can serve as a starting point |
| 19 | +for later SDC-coupled prototypes. |
| 20 | + |
| 21 | +Setup with micromamba |
| 22 | +--------------------- |
| 23 | + |
| 24 | +From this directory: |
| 25 | + |
| 26 | +.. code-block:: bash |
| 27 | +
|
| 28 | + micromamba env create -f environment.yml |
| 29 | + micromamba activate pySDC_pinn |
| 30 | +
|
| 31 | +The environment installs: |
| 32 | + |
| 33 | +- pySDC in editable mode from the repository root, |
| 34 | +- DeepXDE with a PyTorch backend, |
| 35 | +- basic numerical and plotting dependencies. |
| 36 | + |
| 37 | +Run the toy problem |
| 38 | +------------------- |
| 39 | + |
| 40 | +.. code-block:: bash |
| 41 | +
|
| 42 | + python deepxde_toy_ode.py |
| 43 | +
|
| 44 | +Expected output: |
| 45 | + |
| 46 | +- training progress from DeepXDE, |
| 47 | +- relative L2 error against the exact solution, |
| 48 | +- a plot at ``data/deepxde_toy_ode_solution.png``. |
| 49 | + |
| 50 | +Second case: ROBER without QSSA |
| 51 | +------------------------------- |
| 52 | + |
| 53 | +The script ``deepxde_rober_no_qssa.py`` solves the full stiff ROBER system |
| 54 | +with three species and no quasi-steady-state reduction. |
| 55 | + |
| 56 | +The collocation points are sampled logarithmically in time to capture both |
| 57 | +fast initial transients and slower long-time behavior (default |
| 58 | +``t in [1e-5, 1e5]``). |
| 59 | + |
| 60 | +.. code-block:: bash |
| 61 | +
|
| 62 | + python deepxde_rober_no_qssa.py |
| 63 | +
|
| 64 | +You can reduce runtime while testing by lowering the number of epochs, e.g. |
| 65 | + |
| 66 | +.. code-block:: bash |
| 67 | +
|
| 68 | + python deepxde_rober_no_qssa.py --epochs 500 |
| 69 | +
|
| 70 | +For a very quick smoke test, reduce both epochs and time horizon: |
| 71 | + |
| 72 | +.. code-block:: bash |
| 73 | +
|
| 74 | + python deepxde_rober_no_qssa.py --epochs 50 --t-max 1e2 --num-collocation 256 --num-eval 200 |
| 75 | +
|
| 76 | +Expected artifacts: |
| 77 | + |
| 78 | +- ``data/deepxde_rober_no_qssa_solution.png`` |
| 79 | +- ``data/deepxde_rober_no_qssa_metrics.txt`` |
| 80 | + |
| 81 | +Third case: Figure-4-style regular PINN for ROBER |
| 82 | +------------------------------------------------- |
| 83 | + |
| 84 | +The script ``deepxde_rober_regular_fig4.py`` follows the regular PINN |
| 85 | +configuration described around Figure 4 in the stiff-PINN paper: |
| 86 | + |
| 87 | +- full ROBER system (no QSSA in the equations), |
| 88 | +- hard-coded IC architecture ``y(t)=y0+(t/t_scale)SNN(log(t/t_scale))``, |
| 89 | +- 2500 residual points in ``t in [1e-5, 1e5]`` sampled uniformly in log scale, |
| 90 | +- 3 hidden layers with 128 neurons, GELU activation, Adam with ``lr=1e-3`` and batch size ``128``, |
| 91 | +- defaults that are closer to the paper/authors' code: log-time NN input, hard ICs, minibatching, and normalized time scaling inside the ansatz. |
| 92 | + |
| 93 | +Run a paper-style training: |
| 94 | + |
| 95 | +.. code-block:: bash |
| 96 | +
|
| 97 | + python deepxde_rober_regular_fig4.py |
| 98 | +
|
| 99 | +Run a quick smoke test: |
| 100 | + |
| 101 | +.. code-block:: bash |
| 102 | +
|
| 103 | + python deepxde_rober_regular_fig4.py --iterations 200 --num-points 512 --num-eval 300 |
| 104 | +
|
| 105 | +Enable guarded/minibatch training (useful for sweeps/debugging, not paper baseline): |
| 106 | + |
| 107 | +.. code-block:: bash |
| 108 | +
|
| 109 | + python deepxde_rober_regular_fig4.py --batch-size 128 --max-loss-stop 1e4 --max-divergence-loss 1e12 |
| 110 | +
|
| 111 | +Compare paper ingredients directly: |
| 112 | + |
| 113 | +.. code-block:: bash |
| 114 | +
|
| 115 | + python deepxde_rober_regular_fig4.py --run-tag paper_like |
| 116 | + python deepxde_rober_regular_fig4.py --no-hard-ic --run-tag no_hard_ic |
| 117 | + python deepxde_rober_regular_fig4.py --no-use-log-input --run-tag no_log_input |
| 118 | +
|
| 119 | +Run a broader parameter sweep with automatic ranking: |
| 120 | + |
| 121 | +.. code-block:: bash |
| 122 | +
|
| 123 | + python deepxde_rober_regular_fig4_sweep.py --iterations 4000 --max-loss-stop 1e4 --sweep-tag fig4_scan |
| 124 | +
|
| 125 | +Sweep outputs are written to ``data/`` as tagged logs, metrics, and summary files. |
| 126 | + |
| 127 | +Expected artifacts: |
| 128 | + |
| 129 | +- ``data/deepxde_rober_regular_fig4_solution.png`` |
| 130 | +- ``data/deepxde_rober_regular_fig4_loss.png`` |
| 131 | +- ``data/deepxde_rober_regular_fig4_metrics.txt`` |
| 132 | + |
| 133 | +Fourth case: upstream-style Stiff-PINN Robertson with QSSA |
| 134 | +---------------------------------------------------------- |
| 135 | + |
| 136 | +The script ``stiff_pinn_robertson_qssa.py`` ports the Robertson QSSA example |
| 137 | +from the upstream `DENG-MIT/Stiff-PINN <https://github.com/DENG-MIT/Stiff-PINN>`_ |
| 138 | +repository into a portable playground runner: |
| 139 | + |
| 140 | +- keeps the PyTorch hard-IC ansatz used by the upstream QSSA model, |
| 141 | +- reconstructs the eliminated intermediate species through the QSSA formula, |
| 142 | +- uses SciPy BDF for the reference solution instead of the upstream ``assimulo`` dependency, |
| 143 | +- writes plots, model weights, and metrics into ``data/``. |
| 144 | + |
| 145 | +Run a quick Robertson QSSA training: |
| 146 | + |
| 147 | +.. code-block:: bash |
| 148 | +
|
| 149 | + python stiff_pinn_robertson_qssa.py --epochs 400 --run-tag smoke |
| 150 | +
|
| 151 | +Run a longer training closer to the upstream setup: |
| 152 | + |
| 153 | +.. code-block:: bash |
| 154 | +
|
| 155 | + python stiff_pinn_robertson_qssa.py --epochs 2000 --batch-size 512 --run-tag long |
| 156 | +
|
| 157 | +Expected artifacts: |
| 158 | + |
| 159 | +- ``data/stiff_pinn_robertson_qssa_solution.png`` |
| 160 | +- ``data/stiff_pinn_robertson_qssa_model.pt`` |
| 161 | +- ``data/stiff_pinn_robertson_qssa_metrics.txt`` |
| 162 | + |
| 163 | +Fifth case: simple DeepXDE regular PINN matching paper setup |
| 164 | +------------------------------------------------------------ |
| 165 | + |
| 166 | +The script ``deepxde_rober_paper_simple.py`` is a compact DeepXDE-only |
| 167 | +reproduction of the regular (non-QSSA) ROBER setup described in the paper: |
| 168 | + |
| 169 | +- full ROBER equations with ``k1=0.04, k2=3e7, k3=1e4``, |
| 170 | +- logarithmic time domain ``t in [1e-5, 1e5]``, |
| 171 | +- 2500 residual points sampled uniformly in logarithmic scale, |
| 172 | +- hard-IC ansatz ``y=y0+(t/t_scale)SNN(log(t/t_scale))``, |
| 173 | +- 3 hidden layers with 128 neurons (GELU), |
| 174 | +- Adam with ``lr=1e-3`` and minibatch size ``128``. |
| 175 | + |
| 176 | +It now supports two approaches: |
| 177 | + |
| 178 | +- ``--approach global``: original single-network baseline over the full time window, |
| 179 | +- ``--approach slab_irk``: sequential local slabs, each with a local PINN and implicit RK guide points. |
| 180 | + |
| 181 | +For slab mode, implicit one-step guide methods are available via ``--irk-order``: |
| 182 | + |
| 183 | +- ``--irk-order 2``: implicit midpoint (order 2), |
| 184 | +- ``--irk-order 4``: 2-stage Gauss-Legendre IRK (order 4). |
| 185 | + |
| 186 | +Quick smoke run: |
| 187 | + |
| 188 | +.. code-block:: bash |
| 189 | +
|
| 190 | + python run_deepxde_rober_paper_simple.py --mode smoke --approach global |
| 191 | +
|
| 192 | +Quick slab+IRK2 smoke run: |
| 193 | + |
| 194 | +.. code-block:: bash |
| 195 | +
|
| 196 | + python run_deepxde_rober_paper_simple.py --mode smoke --approach slab_irk --irk-order 2 --num-slabs 8 |
| 197 | +
|
| 198 | +Quick slab+IRK4 smoke run: |
| 199 | + |
| 200 | +.. code-block:: bash |
| 201 | +
|
| 202 | + python run_deepxde_rober_paper_simple.py --mode smoke --approach slab_irk --irk-order 4 --num-slabs 8 |
| 203 | +
|
| 204 | +Compare IRK orders directly (runs both and prints RMSE lines): |
| 205 | + |
| 206 | +.. code-block:: bash |
| 207 | +
|
| 208 | + python run_deepxde_rober_paper_simple.py --mode smoke --approach slab_irk --num-slabs 8 --compare-irk-orders |
| 209 | +
|
| 210 | +Run a small IRK sweep over order/slabs/steps and rank by mean RMSE: |
| 211 | + |
| 212 | +.. code-block:: bash |
| 213 | +
|
| 214 | + python run_deepxde_rober_paper_simple_irk_sweep.py --mode smoke --num-slabs-list 4,8 --steps-per-slab-list 20,40 --irk-weight-list 1.0 --seed-list 42 |
| 215 | +
|
| 216 | +Paper-style run: |
| 217 | + |
| 218 | +.. code-block:: bash |
| 219 | +
|
| 220 | + python run_deepxde_rober_paper_simple.py --mode paper --approach global |
| 221 | +
|
| 222 | +Paper-style slab+IRK4 run: |
| 223 | + |
| 224 | +.. code-block:: bash |
| 225 | +
|
| 226 | + python run_deepxde_rober_paper_simple.py --mode paper --approach slab_irk --irk-order 4 --num-slabs 8 |
| 227 | +
|
| 228 | +Expected artifacts: |
| 229 | + |
| 230 | +- ``data/deepxde_rober_paper_simple_solution.png`` |
| 231 | +- ``data/deepxde_rober_paper_simple_loss.png`` |
| 232 | +- ``data/deepxde_rober_paper_simple_metrics.txt`` |
| 233 | + |
| 234 | +Per run (for tagged runs), additional variable-wise plots are written: |
| 235 | + |
| 236 | +- ``data/deepxde_rober_paper_simple_<tag>_y1.png`` |
| 237 | +- ``data/deepxde_rober_paper_simple_<tag>_y2.png`` |
| 238 | +- ``data/deepxde_rober_paper_simple_<tag>_y3.png`` |
| 239 | + |
0 commit comments