Heat in a bar: adding time to a PINN
Cool a heated metal bar over time. Time becomes one more input to the network, the starting temperature becomes a new loss term, and the exact solution lets you grade the answer.
The two Poisson guides were steady problems: nothing changed with time, so the answer was a single picture. This guide adds the clock. You will solve the heat equation in a thin bar, a problem where the temperature starts in one shape and slowly relaxes towards another.
Almost everything you already know carries over. What is new is small but important: time is just another input to the network, and the starting condition is a loss term of its own.
Before you start. Finish Your first PINN in the Studio. This guide assumes you know what each of the seven blocks is for. Open the Studio and choose an empty canvas.
1. The problem
A thin bar of unit length is hot in the middle and held at zero degrees at both ends. Let $u(x,t)$ be its temperature at position $x$ and time $t$. Heat spreads according to
$$ \frac{\partial u}{\partial t} = a\,\frac{\partial^2 u}{\partial x^2}, \qquad 0 < x < 1,\quad 0 < t \le 1, $$
where $a$ is the diffusivity, how quickly the material conducts heat. We use $a = 0.1$, which is also the Studio's default. The bar starts with a smooth hump of heat,
$$ u(x, 0) = \sin(\pi x) \qquad \text{(initial condition)}, $$
and both ends are kept cold for all time,
$$ u(0, t) = 0, \qquad u(1, t) = 0 \qquad \text{(boundary conditions)}. $$
Three kinds of information now pin down the answer: what the equation says inside, what happens at the ends, and where we start. Remove any of the three and many different solutions would fit.
The exact answer (so we can check ourselves)
Try $u(x,t) = e^{-a\pi^2 t}\sin(\pi x)$. The shape never changes, only its height, which decays with time. Differentiating gives
$$ u_t = -a\pi^2\, e^{-a\pi^2 t}\sin(\pi x), \qquad u_{xx} = -\pi^2\, e^{-a\pi^2 t}\sin(\pi x), $$
so $u_t = a\,u_{xx}$ holds. At $t = 0$ the factor is 1, which gives $\sin(\pi x)$. At $x = 0$ and $x = 1$ the sine is zero. So
$$ u_{\text{exact}}(x,t) = e^{-a\pi^2 t}\,\sin(\pi x). $$
With $a = 0.1$ the hump decays by a factor $e^{-0.1\pi^2} \approx 0.373$ by $t = 1$. The network never sees this formula while it trains. We keep it only to grade the result.
2. How a PINN sees the problem
The unknown is now a function of two inputs, so the network is $u_\theta(x, t)$. Time is not special to the network. It is just a second coordinate, and the equation relates how the output changes along one axis to how it curves along the other.
The equation error. At many points $(x_i, t_i)$ inside the bar, over the whole time range, the network is differentiated by automatic differentiation, once in time and twice in space:
$$ r_\theta(x,t) = \frac{\partial u_\theta}{\partial t} - a\,\frac{\partial^2 u_\theta}{\partial x^2}. $$
The boundary error. The ends should stay at zero for all times: $u_\theta(0,t) = 0$ and $u_\theta(1,t) = 0$.
The initial error. At $t = 0$ the network should reproduce the starting profile: $u_\theta(x, 0) = \sin(\pi x)$.
The loss adds all three, each with a weight:
$$ \mathcal{L}(\theta) = \underbrace{\frac{1}{N_r}\sum_i r_\theta(x_i,t_i)^2}_{\text{PDE loss}} + w_{\text{bc}}\underbrace{\frac{1}{N_b}\sum_j u_\theta(x^b_j, t^b_j)^2}_{\text{boundary loss}} + w_{\text{ic}}\underbrace{\frac{1}{N_i}\sum_k \bigl(u_\theta(x_k, 0) - \sin(\pi x_k)\bigr)^2}_{\text{initial-condition loss}} . $$
Space and time together. The picture to hold in your head is a rectangle with $x$ across and $t$ up. The ends of the bar are the left and right sides, the starting condition is the bottom edge, and the equation must hold everywhere inside. The top edge, $t = 1$, is free: nothing is imposed there, the network simply inherits what the equation and the starting profile force on it.
3. The plan: one block per decision
| # | Block | The question it answers | Our choice |
|---|---|---|---|
| 1 | DOM Domain | Where does the problem live? | One space dimension, $x\in[0,1]$, time on, $t\in[0,1]$ |
| 2 | PDE Equation | Which equation must hold inside? | Heat, $u_t = a\,u_{xx}$, with $a = 0.1$ |
| 3 | BC Boundary | What is fixed at the ends, and at the start? | $u(0,t)=0$, $u(1,t)=0$, and the initial profile $u(x,0)=\sin(\pi x)$ |
| 4 | NET Network | What function family do we search in? | 2 inputs ($x$, $t$), 3 hidden layers of 32 neurons, $\tanh$, 1 output |
| 5 | LOSS Loss | How do we score the errors? | Mean squared error, weight 1 on the PDE and 10 on the boundary and initial terms |
| 6 | OPT Optimiser | How do the weights change? | Adam, learning rate $10^{-3}$ |
| 7 | RUN Train | How long and with how many points? | 5000 epochs, about 2000 interior points, 100 on each boundary, 100 at $t=0$ |
A note on labels. The Studio's wording can differ slightly between versions. The quantity to set is what matters; if a field name does not match this page exactly, pick the nearest one. If a value is not offered, keep the Studio's default and carry on.
4. Step by step in the Studio
Step 1: Domain (DOM)
Add a Domain block. Make it one-dimensional with $x$ from 0 to 1, and this time switch time on, with $t$ from 0 to 1.
Check: the block shows one space coordinate and a time axis. Forgetting to switch time on is the most common mistake in this guide, and it will show up later as a warning that the Equation needs time.
Step 2: Equation (PDE)
Add an Equation block, connect the Domain to it, and choose the Heat equation. Set the diffusivity $a$ to 0.1, the default.
Check: the summary reads $u_t = a\,u_{xx}$ with $a = 0.1$.
Step 3: Boundary and initial conditions (BC)
Add a Boundary block and connect the Domain to it. You need three conditions:
| Where | Type | Value |
|---|---|---|
| $x = 0$ (for all $t$) | Fixed value (Dirichlet) | $u = 0$ |
| $x = 1$ (for all $t$) | Fixed value (Dirichlet) | $u = 0$ |
| $t = 0$ (for all $x$) | Initial condition | $u = \sin(\pi x)$, entered as sin(pi*x) |
Expressions use ** for powers and pi for $\pi$.
Check: the Studio counts three conditions. A time-dependent equation of this kind needs the initial condition as well as the two ends, and the Studio warns you if the initial condition is missing.
Step 4: Network (NET)
Add a Network block and connect the Domain to it. It now has 2 inputs ($x$ and $t$), 3 hidden layers of 32 neurons with tanh, and 1 output.
Check: the Studio fills in the input size of 2 from the Domain. If it says 1, time is off in the Domain.
Step 5: Loss (LOSS)
Add a Loss block and connect the Equation, Boundary and Network to it. Use mean squared error. Set the PDE weight to 1. For the boundary and initial conditions use a weight of 10. The Studio takes boundary weights as a list in the same order as the conditions, so enter [10, 10, 10] for the three conditions above.
Section 5 shows what a weight of 1 and of 100 would have done. Heat is more forgiving about weights than the 2D Poisson problem was, but too large a value is not free.
Step 6: Optimiser (OPT)
Add an Optimiser block: Adam, learning rate 0.001.
Step 7: Train (RUN)
Add the Train block and connect the Loss and Optimiser to it. Set 5000 epochs and about 2000 interior points. The Studio places the boundary and initial points for you; a hundred on each is plenty here.
Check: no warnings. A clean check means the configuration is consistent, not that the answer is accurate.
Step 8: Generate and run
Generate the Python code, download the script, and run it on your own computer (pip install torch, then python your_script.py). The Studio builds and checks the configuration, but it does not train the model. Training runs in the script you downloaded. On a laptop-class CPU this problem takes about a minute.
Step 9: Judge the result
Compare the prediction against the exact solution on a grid that was not used for training: here a $101\times101$ grid in $(x,t)$.

The first two panels are the same picture: a hump that fades as time goes up. The third panel shows where the error lives. It is largest along the bottom edge, where the starting profile is imposed and the network has to match the initial condition against the equation, and in a few soft patches in the interior. It is smallest at the cold ends.
A second view makes the decay concrete. Four snapshots in time, with the PINN dashed over the exact curve:

The measure we use is the relative $L^2$ error over the whole $(x,t)$ grid,
$$ \varepsilon = \frac{\lVert u_\theta - u_{\text{exact}} \rVert_2}{\lVert u_{\text{exact}} \rVert_2} . $$
A very physical extra check: the peak temperature at the middle of the bar at $t = 1$ should be $e^{-a\pi^2} = 0.3727$. The reference run gave 0.3725.
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.
| Epoch | Total loss | Relative $L^2$ error |
|---|---|---|
| 0 | $1 \times 10^{1}$ | $1.7$ |
| 500 | $5 \times 10^{-2}$ | $5.0 \times 10^{-2}$ |
| 1000 | $6 \times 10^{-3}$ | $1.1 \times 10^{-2}$ |
| 2000 | $2.5 \times 10^{-3}$ | $8.3 \times 10^{-3}$ |
| 3000 | $7 \times 10^{-4}$ | $3.9 \times 10^{-3}$ |
| 5000 | $2 \times 10^{-4}$ | $1.3 \times 10^{-3}$ |
The largest pointwise error at the end was about $3 \times 10^{-3}$, on a solution whose largest value is 1.

Do not worry about spikes. Around epoch 4500 the error briefly jumped to about $2\times10^{-2}$ and then recovered by epoch 5000. That is ordinary Adam behaviour on a PINN loss. Judge a run by where it settles, and keep the best result, not simply the last.
5. How much do the weights matter?
The same problem was run three times with only the boundary-and-initial weight changed.
| Weight on boundary and initial terms | Relative $L^2$ error after 5000 epochs |
|---|---|
| 1 | $2.0 \times 10^{-3}$ |
| 10 | $1.3 \times 10^{-3}$ |
| 100 | $9.0 \times 10^{-3}$ |
Read this carefully. These are single runs with one random seed, so the gap between 1 and 10 is within the run-to-run scatter. The only clear message is that a weight of 100 was worse here: when the constraint terms dominate, the equation term barely matters to the optimiser and the interior is learned slowly. In the 2D Poisson guide a large boundary weight helped enormously; here a modest one is enough. There is no universal best weight. Start at 10, look at the three loss terms, and adjust only if one of them lags far behind the others.
6. If something goes wrong
| What you see | Likely cause | What to try |
|---|---|---|
| A warning that the Equation needs time | Time is off in the Domain | Switch time on in Step 1 |
| A warning about the number of conditions | The initial condition is missing | Add it as in Step 3 |
| The solution does not decay, or decays too fast or too slowly | Wrong diffusivity $a$ | Check $a = 0.1$ in Step 2. The decay rate is $a\pi^2$ |
| The profile at $t=0$ is the wrong shape | Typo in the initial-condition expression | Re-enter sin(pi*x). Remember pi, not 3.14 |
| Error is worst along the bottom edge | The initial condition is under-weighted | Raise its weight, for example to 10 or 30 |
Loss is nan |
Learning rate too high | Lower to $10^{-4}$ and recheck the expressions |
| Right shape at early times, drifting later | Too few interior points in time | Raise the interior points to 4000 |
7. Try it yourself
- A different diffusivity. Set $a = 0.5$. The exact solution is $e^{-0.5\pi^2 t}\sin(\pi x)$, which decays about five times faster. Only the Equation block changes. By $t = 1$ the bar is almost cold, so the relative error will look worse even if the absolute error is small. Why?
- A different mode. Start from $\sin(2\pi x)$. The exact solution is $e^{-4a\pi^2 t}\sin(2\pi x)$. Higher modes decay faster, by a factor of $n^2$ for mode $n$. Change only the initial condition.
- A hotter end. Hold $u(1,t)=1$ and start from $u(x,0)=\sin(\pi x)+x$ (the two ends are then consistent with the start). The exact solution is $e^{-a\pi^2 t}\sin(\pi x) + x$: the hump fades and the bar settles towards the straight line $u = x$. Change the initial condition and one boundary condition.
- Fewer points in time. Cut the interior points to 500. Does the error grow more at late times or early times?
8. Recap
- A time-dependent PINN is the same machine with time as an extra input: the network is $u_\theta(x,t)$.
- The initial condition is a constraint on the line $t=0$. It is a loss term of its own, with its own weight.
- The Domain must have time switched on, and the Network must have 2 inputs. The Studio warns when either is wrong.
- Check the answer against the exact solution on a fresh grid, and look at where the error lives. In this run it was largest at the start.
- Weights matter, but unevenly. Heat tolerated a wide range; a very large weight was the one setting that hurt.
Next: a problem with no tidy formula, where you invent the answer first and build the problem around it, in Manufactured solutions.
Reference script for the numbers quoted above: heat_1d_reference.py. It is written by hand for checking this guide and is not the Studio's generated output.