A shock wave: Burgers' equation and the second optimiser
A smooth start turns into a near-vertical jump. See why Adam alone gets stuck, how a second stage with L-BFGS fixes it, and how to grade an answer when the reference is a numerical integral and not a formula.
All the equations so far were linear. Doubling the solution doubled the answer, and the exact solution was a neat product of sines and exponentials. Burgers' equation is the first nonlinear problem in this series. Its solution starts as a gentle sine wave and steepens, until a nearly vertical jump appears in the middle: a shock.
It is the classic stress test for PINNs, and it teaches three lessons the earlier guides could not: what a nonlinear term does to the loss, why a second optimiser stage is often the difference between a poor answer and a good one, and how to build a reference solution when no simple formula exists.
Before you start
Finish Heat in a bar and A standing wave first. Open the Studio and choose an empty canvas, or take the quick route in Section 3.
1. The problem
Let $u(x,t)$ be a velocity along a line. Burgers' equation says that the velocity is carried along by itself, while a little friction smooths things out:
$$ \frac{\partial u}{\partial t} + u\,\frac{\partial u}{\partial x} = \nu\,\frac{\partial^2 u}{\partial x^2}, \qquad -1 < x < 1,\quad 0 < t \le 1, $$
with a small viscosity $\nu = 0.01/\pi \approx 0.0032$. The start is a sine wave, and the ends are held at zero:
$$ u(x,0) = -\sin(\pi x), \qquad u(-1,t) = 0, \qquad u(1,t) = 0 . $$
Why a shock appears
The term $u\,u_x$ says that every point on the profile moves at its own value of $u$. Where $u$ is positive, the profile moves right; where it is negative, left. The initial wave $-\sin(\pi x)$ is positive on the left half and negative on the right half, so the two sides rush towards the middle and pile up. Without friction they would form a true discontinuity in finite time. With friction $\nu$ they form a very thin steep layer instead, which is the shock. Smaller $\nu$ means a thinner shock and a harder problem. The value $0.01/\pi$ is a standard benchmark in the PINN literature.
The reference solution
There is a neat exact route even though no simple formula exists. The Cole–Hopf transform turns Burgers' equation into the plain heat equation, and the answer comes out as a ratio of two integrals:
$$ u(x,t) = -\,\frac{\displaystyle\int_{-\infty}^{\infty} \sin\bigl(\pi(x-\eta)\bigr)\, f(x-\eta)\, e^{-\eta^{2}/(4\nu t)}\, d\eta}{\displaystyle\int_{-\infty}^{\infty} f(x-\eta)\, e^{-\eta^{2}/(4\nu t)}\, d\eta}, \qquad f(y) = e^{-\cos(\pi y)/(2\pi\nu)} . $$
You do not need to follow the derivation. What matters is that this can be evaluated by numerical integration to high accuracy at any point, so it works as a trustworthy reference. The reference script does it with a fine trapezoid sum. As a sanity check, it was compared against an independent finite-difference solution at several times; the two agreed to about $10^{-3}$ at the sampled points, a gap that comes from the finite-difference grid and not from the reference.
Why this matters beyond Burgers
A PINN is only worth trusting when it has been compared against something independent. Sometimes that is an exact formula (earlier guides), sometimes a finite element or finite difference solution (the Poisson guide), and sometimes, as here, an integral that a computer can evaluate. The habit is the same every time.
2. How a PINN sees the problem
The network is $u_\theta(x,t)$ with two inputs. The residual now contains the unknown multiplied by its own derivative:
$$ r_\theta(x,t) = \frac{\partial u_\theta}{\partial t} + u_\theta\,\frac{\partial u_\theta}{\partial x} - \nu\,\frac{\partial^2 u_\theta}{\partial x^2}. $$
That product is what makes the problem nonlinear. In practice it changes very little in the Studio, because automatic differentiation does not care. What it changes is the difficulty of the optimisation: the loss surface is much more awkward, with long flat valleys that gradient-based training crawls along.
$$ \mathcal{L}(\theta) = \overline{r_\theta^{\,2}} + w_{\text{ic}}\,\overline{\bigl(u_\theta(x,0) + \sin\pi x\bigr)^2} + w_{\text{bc}}\,\overline{u_\theta^{\,2}}_{\text{ends}} . $$
3. The plan: one block per decision
| # | Block | The question it answers | Our choice |
|---|---|---|---|
| 1 | DOM Domain | Where does the problem live, and how is it sampled? | Line, $x\in[-1,1]$, Time dimension ticked, $t\in[0,1]$. 10000 interior points, 200 per boundary, 400 initial points |
| 2 | PDE | Which equation must hold inside? | Burgers, $u_t + u\,u_x = \nu\,u_{xx}$, with $\nu = 0.01/\pi \approx 0.0031831$ |
| 3 | BC × 2 | What is fixed at the ends? | Dirichlet, $u = 0$, on BC1 ($x=-1$) and BC2 ($x=1$) |
| 4 | IC | Where do we start? | $u(x, t_\text{init}) = -\sin(\pi x)$ |
| 5 | NET Network | What function family do we search in? | Eight hidden layers of 20, tanh |
| 6 | LOSS Loss | How are the errors weighted? | Mean square. PDE weight 1, BC weights [10, 10], IC weights [10] |
| 7 | OPT Optimiser | How do the weights change, and for how long? | Adam at $10^{-3}$ for 3000 epochs, then L-BFGS for 3000 iterations |
| 8 | RUN Train | How is the run carried out? | Defaults |
The network is deeper and narrower than before, and there are far more points. A shock is a sharp feature, and a small, shallow network struggles to bend steeply enough, so the extra depth and the ten thousand points are not a luxury here.
The quick route
The Burgers' shock formation starter has the domain, the viscosity, the eight-by-twenty network, the ten thousand points and a second L-BFGS stage already. From it, set Default boundary points to 200 and Initial points to 400 on the Domain, the Loss weights to [10, 10] and [10], and on the Optimiser Epochs 3000 (the starter has 10000) and the second stage's Iterations 3000 (the default is 500).
4. Step by step in the Studio
Step 1: Domain (DOM)
Add a Domain block: Line, x min -1, x max 1 (note the symmetric interval). Tick Time dimension, with $t$ from 0 to 1. Set Interior points to 10000, Default boundary points to 200 and Initial points to 400.
Step 2: Equation (PDE)
Add a PDE block, wire Domain Coords and Interior into it, and choose Equation Burgers. The Studio lists Burgers under Equation type Hyperbolic, because away from the shock it behaves like a wave that carries itself along. With any viscosity at all it is strictly parabolic; Section 4.3 explains the difference, and it does not change anything you enter here.
Set Viscosity v to 0.0031831. That is $0.01/\pi$. The field takes a number, not a formula, so type the decimal.
Check: the summary reads burgers. A common slip is to leave the default 0.01, which gives a viscosity three times too large and a visibly smoother, wrong shock.
Step 3: Boundary conditions (two BC blocks)
Add two Boundary condition blocks, wire Domain BC1 ($x=-1$) and BC2 ($x=1$) into them, and keep Dirichlet with u = 0.0 on both.
Step 4: Initial condition (IC)
Add an Initial condition block, wire Domain Initial → IC Initial, and set u(x, t_init) = to -sin(pi*x). Mind the minus sign. Without it the two halves of the wave move apart: a gentle fan opens at $x = 0$, and the steepening happens against the walls at $x = \pm1$ instead of in the middle. That is a different flow, not a mirror image of this one, and the comparison fails everywhere.
Step 5: Network (NET)
Add a Network block, wire Domain Coords → Network Coords, and set Hidden layers to 20, 20, 20, 20, 20, 20, 20, 20 (eight layers of 20) with tanh.
Step 6: Loss (LOSS)
Add a Loss block and wire the PDE residual, the Network, both BC outputs and the IC output into it. Keep Mean square and PDE weight 1; set BC weights to [10, 10] and IC weights to [10].
Step 7: Optimiser (OPT), two stages
This is the step that matters most in this guide. Add an Optimiser block with Adam, Learning rate 0.001, Epochs 3000. Then tick Second stage. Second optimiser is L-BFGS by default; set its Iterations to 3000 and leave its Learning rate at 1.0.
Why two stages? Adam is the reliable general-purpose choice. It takes cheap, noisy steps, copes with badly scaled problems and gets you into the right region quickly. L-BFGS is a quasi-Newton method: it uses curvature information to take far more careful steps, and it can walk down a long narrow valley that Adam crawls along. It is slow and fragile on its own, but excellent as a finishing stage. Chapter 9 explains both in detail.
The generated script records the whole second stage as one extra point at the end of its loss history, so loss.png shows a last point that is lower than the rest rather than the L-BFGS iterations themselves.
Fix the points for the second stage
The script the Studio generates today draws new boundary and initial points every time it evaluates the loss. L-BFGS needs the same loss at every evaluation, and on a problem in time it then stops after a few iterations, without an error message (Section 9.3). Until the generator changes, apply the patch in Section 9.3 to the downloaded script, adding sample_initial to the names it fixes, or set every boundary's Distribution and the Domain's Interior distribution to Regular grid.
Step 8: Train (RUN)
Add a Train block and wire Loss → Train Loss and Optimiser → Train Optimiser.
Check: Graph check: nothing to flag. A clean check means consistent, not accurate.
Step 9: Generate and run
Generate the Python code, download the script and run it on your own computer. The Studio builds and checks the configuration; training happens in your script. This is the most expensive run in the series: expect it to take on the order of ten to twenty minutes on a laptop CPU, most of it in the L-BFGS stage.
Step 10: Judge the result
The reference solution comes from the Cole–Hopf integral above, evaluated on a $201\times101$ grid in $(x,t)$ that was not used for training.

The first two panels are the same picture: a wave that steepens into a sharp line down the middle by about $t=0.5$. The error panel shows exactly what you would predict. It is tiny everywhere except along the shock. In the reference run the largest error inside $|x|<0.1$ was about $2.6\times10^{-2}$, while everywhere else it was $2.3\times10^{-3}$ or less.
Snapshots show it more directly. The solid line is the reference and the dashed line the PINN:

At $t=0.25$ the profile is still smooth. By $t=0.5$ the jump is almost vertical, and at $t=1$ the two halves have become straight ramps that meet at a small jump. The PINN follows all three closely. A sharper test: on the 201-point grid used for the comparison, the steepest slope in the profile at $t=1$ is $-59.4$ in the reference and $-59.5$ in the PINN. Read that with care. A grid spacing of 0.01 is too coarse to resolve this shock, whose true steepest slope at $t=1$ is about $-84$, so the two numbers say the network and the reference agree at that resolution, not that the network has resolved the shock exactly.
The summary measure is the relative $L^2$ error over the whole grid,
$$ \varepsilon = \frac{\lVert u_\theta - u_{\text{ref}} \rVert_2}{\lVert u_{\text{ref}} \rVert_2}. $$
What to expect
These figures come from a hand-written reference implementation with exactly the settings above (random seed 0). The Studio's script may initialise and sample slightly differently, so your numbers will differ, but you should land in the same neighbourhood.
| Stage | Epoch / iteration | Total loss | Relative $L^2$ error |
|---|---|---|---|
| Adam | 0 | $4.5$ | $0.96$ |
| Adam | 500 | $3 \times 10^{-1}$ | $0.44$ |
| Adam | 1000 | $2 \times 10^{-1}$ | $0.33$ |
| Adam | 2000 | $4 \times 10^{-2}$ | $0.18$ |
| Adam | 3000 | $9 \times 10^{-3}$ | $0.17$ |
| then L-BFGS | 3000 more | $3 \times 10^{-5}$ | $\mathbf{2.0 \times 10^{-3}}$ |
Read the last two rows twice. After 3000 epochs of Adam the loss had fallen by a factor of 500 from where it started, yet the answer was still 17% wrong: the largest pointwise error was about 1.6 on a solution whose largest value is 1. The next 3000 iterations of L-BFGS took the error from 17% to 0.2%, a factor of about 85, and the largest pointwise error fell to $2.6\times10^{-2}$.

5. What it takes: a failed first attempt
The set-up above was reached by trying something smaller first. A first run used 4 hidden layers of 32 neurons, 6000 interior points, 6000 Adam epochs and only 500 L-BFGS iterations. It ended at a relative error of $7.6\times10^{-2}$, with the shock in about the right place but visibly smeared. Compared with that, the working set-up changed three things at once: a deeper network, more points, and many more L-BFGS iterations, so this experiment does not say which one mattered most. Treat the three as a package. If you want to find out which matters, vary them one at a time. That is a good exercise (see Section 7).
Lessons from the failure
(1) A loss that has dropped by orders of magnitude is not evidence of success, so always compare against a reference. (2) With a sharp feature, change the optimiser and the capacity before changing the loss weights. (3) Be ready to run longer: a shock takes patience.
6. If something goes wrong
| What you see | Likely cause | What to try |
|---|---|---|
| The loss falls but the answer is poor, with a smeared shock | Adam stalled; no second stage | Switch on L-BFGS as in Step 7, with fixed points |
| The shock is smoother than the reference | Viscosity too large (0.01 instead of 0.0031831), or a network that is too small |
Recheck the viscosity; try 8 × 20 |
| The profile flattens in the middle and steepens at the walls | Missing minus sign in the initial condition | Re-enter -sin(pi*x) |
| The shock is in the wrong place | A mistake in the initial condition or the domain | Check $x\in[-1,1]$ and the initial condition |
L-BFGS ends immediately or the loss goes nan |
Starting L-BFGS from a poor point, or too large a step | Run more Adam epochs first, then L-BFGS |
| Error spread over the whole domain | Too few interior points | Raise to 10000 or more |
| Training takes far too long | L-BFGS with many points is slow | Use fewer L-BFGS iterations first, then add more |
7. Try it yourself
- Vary one thing at a time. Starting from the working set-up, change only the network (4 × 32), or only the point count (3000), or only the L-BFGS iterations (500). Which matters most? Record the error each time.
- Adam only. Skip L-BFGS and run Adam for 20000 epochs instead. How far does the error get?
- A larger viscosity. Set $\nu = 0.05$. The shock is much milder, so the problem is easier. How much smaller is the error, and does Adam alone now succeed?
- A smaller viscosity. Set $\nu = 0.001$. The shock is much sharper and the problem much harder. What happens to the error, and does the fix still work?
- Check the shock position. For this problem the shock stays at $x = 0$ for all time, by symmetry. Find, in your result, the $x$ at which the PINN crosses zero at $t=1$.
8. Recap
- Burgers' equation is nonlinear: the term $u\,u_x$ makes a smooth start develop a shock, and makes training much harder.
- When there is no formula, evaluate a reference numerically. Here, the Cole–Hopf transform gives an integral that a computer can compute. Check it against a second, independent method.
- A low loss is not a good answer. In the reference run Adam took the loss down by a factor of 500 and the answer was still 17% wrong.
- Use a two-stage optimiser: Adam to reach the right region, then L-BFGS to finish. Here it cut the error from 17% to 0.2%.
- Sharp features need capacity and points: a deeper network and many more collocation points than a smooth problem.
Next: back to a gentle problem on a curved domain, in Laplace's equation on a disc.
Reference script for the numbers quoted above: burgers_1d_reference.py, run as python burgers_1d_reference.py 3000 3000 8 20 10000. It contains the Cole–Hopf reference solution, is written by hand for checking this guide, and is not the Studio's generated output.