neural-pde
Skill0 starsChanged 4 days agoMITView on GitHub
Solve PDEs with neural networks in NeuralPDE.jl: physics-informed losses, method-of-lines discretisation, adaptive sampling, and when a PINN beats a classical solver. Use when a PDE has no friendly solver.
In this repository55 other files it gives its agents.
- advanced-optimizationSkill
- bayesian-inferenceSkill
- bayesian-pinnSkill
- bayesian-ude-workflowSkill
- catalyst-reactionsSkill
- continuum-mechanics-and-rheologySkill
- control-theorySkill
- creating-julia-appSkill
- debugging-toolkitSkill
- differential-equationsSkill
- differentiationSkill
- equation-discoverySkill
- experiment-trackingSkill
- fem-feaSkill
- julia-graph-neural-networksSkill
- julia-languageSkill
- julia-ml-and-dlSkill
- julia-model-deploymentSkill
- julia-paper-implementationSkill
- julia-pro-helpSkill
- julia-pro-modeSkill
- julia-reinforcement-learningSkill
- modeling-toolkitSkill
- nonlinear-dynamicsSkill
- numerical-methods-implementationSkill
- package-development-workflowSkill
- performance-tuningSkill
- physical-learning-systemsSkill
- playbook-debugSkill
- playbook-model-validateSkill
- playbook-package-releaseSkill
- playbook-paper-implementSkill
- playbook-perfSkill
- playbook-test-specSkill
- principle-both-sidesSkill
- principle-breakingSkill
- principle-file-is-truthSkill
- principle-gateSkill
- principle-limitsSkill
- principle-loud-failureSkill
- principle-one-stepSkill
- principle-proof-listSkill
- principle-rebuttalSkill
- principle-runtime-surfaceSkill
- principle-three-boundsSkill
- principle-three-clocksSkill
- scientific-visualizationSkill
- sciml-and-diffeqSkill
- setup-julia-proSkill
- signal-processingSkill
- simulation-and-hpcSkill
- statistical-physicsSkill
- symbolic-mathSkill
- web-development-juliaSkill
- zarr-cloud-arraysSkill
The file
Files
NeuralPDE.jl — PINNs (deterministic)
When a PINN beats a mesh
| Situation | Use |
| regular domain, ≤3 spatial dims, smooth solution | MethodOfLines — symbolic PDE to an ODE system, any DiffEq solver, faster and more accurate |
| ≥4 spatial dims, or a domain you cannot mesh | PINN — collocation points, no mesh |
| unknown coefficient to be fit from data | PINN with param_estim |
| uncertainty on the solution or on a coefficient | bayesian-pinn |
| advection-dominated, shocks | MethodOfLines with WENOScheme(); a PINN smears the front |
A PINN is a mesh workaround, not an accuracy win. On a problem where MOL works, MOL wins on both counts, and the PINN's answer is only as good as the comparison against it.
Symbolic problem
using NeuralPDE, Lux, ModelingToolkit, DomainSets, IntervalSets, Random
import ModelingToolkit: Interval
@parameters t x
@variables u(..)
Dt, Dxx = Differential(t), Differential(x)^2
eq = Dt(u(t, x)) ~ Dxx(u(t, x))
bcs = [u(0, x) ~ cos(π * x), u(t, 0) ~ 0, u(t, 1) ~ 0]
domains = [t ∈ Interval(0.0, 1.0), x ∈ Interval(0.0, 1.0)]
@named pde_system = PDESystem(eq, bcs, domains, [t, x], [u(t, x)])@parameters, @variables, and Differential come from ModelingToolkit; modeling-toolkit carries the symbolic-numeric pipeline behind them. Every boundary and initial condition must be written as a symbolic equation — a condition left in prose is a condition the loss never sees.
Ansatz and training
Lux's explicit parameters, because the discretizer needs (ps, st) separated from the model:
chain = Chain(Dense(2, 16, σ), Dense(16, 16, σ), Dense(16, 1))
ps_init, st = Lux.setup(Random.default_rng(), chain)
using QuasiMonteCarlo, Optimization, OptimizationOptimisers
strategy = QuasiRandomTraining(256; sampling_alg = SobolSample())
discretization = PhysicsInformedNN(chain, strategy)
prob = discretize(pde_system, discretization)
result = solve(prob, OptimizationOptimisers.Adam(0.01); maxiters = 5000)| Strategy | When |
QuasiRandomTraining(n; sampling_alg = SobolSample()) | default; low-discrepancy points converge faster than uniform random |
GridTraining(dx) | low dimension, and you want the mesh behaviour anyway |
StochasticTraining(n) | irregular domains, where a grid is meaningless |
QuadratureTraining() | smooth solution, residual wanted in integral form |
For a system, pass a Vector of chains — one per dependent variable.
Inverse problems
@parameters α
eq = Dt(u(t, x)) ~ α * Dxx(u(t, x))
discretization = PhysicsInformedNN(chain, strategy;
additional_loss = (phi, θ, p) -> sum(abs2, phi(t_obs, θ) .- u_obs),
param_estim = true,
init_params = ComponentArray(α = 0.1))additional_loss is the data term and param_estim = true makes the symbolic parameter trainable. Identifiability is the trap: several (α, weights) pairs reproduce the observations, so the fitted α is one member of a set unless the data pins it down.
Method of lines
using MethodOfLines, OrdinaryDiffEq
discretization = MOLFiniteDifference([x => 0.05], t;
approx_order = 2, advection_scheme = UpwindScheme(), grid_align = CenterAlignedGrid())
prob = discretize(pde_system, discretization)
sol = solve(prob, Tsit5(), saveat = 0.1)Central differences oscillate near a sharp front; switch advection_scheme to WENOScheme() for hyperbolic problems before blaming the solver.
Traps
- Collocation points that never touch the boundary. Sobol points in the interior leave the boundary conditions to the initial guess; sample the boundary explicitly.
- Loss terms on different scales. The physics residual and the data misfit differ by orders of magnitude and one of them stops training; weight them, and log both.
- No MOL baseline. A PINN's error is unknown without a reference solve on a simplified version of the same problem.
- Training loss read as accuracy. A small residual at the collocation points says nothing between them; evaluate on a held-out grid.
maxitersas convergence. Adam at 5000 iterations is a budget, not a criterion; check the residual curve and the L-BFGS refinement.
Done when
The PINN is justified against a MOL solve, every boundary and initial condition is a symbolic equation, the residual is evaluated on a held-out grid and compared to that reference, and both loss terms are logged with their weights.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

