Benchmarks¶
ReferenceSolution
dataclass
¶
A solution sampled on a tensor-product (x, t) grid.
Attributes:
| Name | Type | Description |
|---|---|---|
x |
ndarray
|
Spatial grid, shape |
t |
ndarray
|
Temporal grid, shape |
u |
ndarray
|
Solution values, shape |
burgers_reference ¶
Burgers u_t + u u_x = nu u_xx on [-1, 1] with u0 = -sin(pi x).
Cole-Hopf gives
u(x, t) = -∫ sin(pi (x - η)) f(x - η) G(η, t) dη / ∫ f(x - η) G(η, t) dη
with f(y) = exp(-cos(pi y) / (2 pi nu)) and the heat kernel G.
Substituting η = sqrt(4 nu t) z turns G into exp(-z²); the
integrand is periodic times Gaussian, so the trapezoid rule converges
spectrally. z_max = 15 keeps the far peaks of f (which dominate
near x = 0 once the shock forms) inside the window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nu
|
float
|
Viscosity. The default is the classic |
0.01 / pi
|
nx
|
int
|
Number of spatial grid points on |
256
|
nt
|
int
|
Number of time grid points on |
101
|
t_max
|
float
|
Final time. |
1.0
|
n_quad
|
int
|
Trapezoid nodes on |
6001
|
z_max
|
float
|
Half-width of the quadrature window in |
15.0
|
Returns:
| Type | Description |
|---|---|
ReferenceSolution
|
The reference field on the |
Source code in pinnrl/benchmarks/reference.py
allen_cahn_reference ¶
allen_cahn_reference(
epsilon=np.sqrt(0.0002),
t_max=5.0,
nx=257,
nt=101,
refine=8,
boundary_value=-1.0,
)
Allen-Cahn u_t = eps² u_xx + u - u³ on [-1, 1], u0 = x² cos(pi x).
Dirichlet u(±1, t) = boundary_value. The defaults are the
u_t = 0.001 u_xx + 5 (u - u³) benchmark on t ∈ [0, 1] rewritten
in the time variable τ = 5 t, which matches the reaction coefficient
of :class:pinnrl.pdes.allen_cahn.AllenCahnEquation.
The solver grid is refine times finer than the output grid and the
output points are a subset of it, so no interpolation error enters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
epsilon
|
float
|
Interface parameter in the residual |
sqrt(0.0002)
|
t_max
|
float
|
Final time. |
5.0
|
nx
|
int
|
Output spatial points on |
257
|
nt
|
int
|
Output time points on |
101
|
refine
|
int
|
Solver-grid refinement factor relative to the output grid. |
8
|
boundary_value
|
float
|
Dirichlet value at both ends. |
-1.0
|
Returns:
| Type | Description |
|---|---|
ReferenceSolution
|
The reference field on the |
Source code in pinnrl/benchmarks/reference.py
StudySettings
dataclass
¶
StudySettings(
num_steps=15000,
n_collocation=1000,
resample_every=100,
learning_rate=0.001,
hidden_dims=(64, 64, 64, 64),
n_checkpoints=50,
rad_k=1.0,
rad_c=1.0,
rad_pool_factor=20,
)
Shared knobs for every run in a study.
Attributes:
| Name | Type | Description |
|---|---|---|
num_steps |
int
|
Optimizer steps per run (the equal training budget). |
n_collocation |
int
|
Collocation points per step. |
resample_every |
int
|
Steps between resampling for |
learning_rate |
float
|
Adam learning rate (constant). |
hidden_dims |
tuple[int, ...]
|
Widths of the tanh MLP. |
n_checkpoints |
int
|
Evaluations along the run; |
rad_k |
float
|
RAD exponent |
rad_c |
float
|
RAD uniform floor |
rad_pool_factor |
int
|
RAD candidate pool size as a multiple of |
run_sampling_study ¶
run_sampling_study(
pdes=STUDY_PDES,
strategies=STUDY_STRATEGIES,
seeds=tuple(range(10)),
settings=None,
workers=1,
on_result=None,
)
Run every (pde, strategy, seed) combination.
Tasks are ordered by PDE, then seed, then strategy, so the strategies for
one seed run side by side under similar machine load. workers > 1 uses a spawn-based
process pool; workers = 1 runs inline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pdes
|
Sequence[str]
|
Subset of :data: |
STUDY_PDES
|
strategies
|
Sequence[str]
|
Subset of :data: |
STUDY_STRATEGIES
|
seeds
|
Sequence[int]
|
Seeds to run; each fixes the initial weights. |
tuple(range(10))
|
settings
|
StudySettings | None
|
Shared study settings. |
None
|
workers
|
int
|
Parallel worker processes. |
1
|
on_result
|
Callable[[StudyRun], None] | None
|
Optional callback invoked as each run finishes. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
One |
list[StudyRun]
|
class: |
Source code in pinnrl/benchmarks/sampling_study.py
run_study_case ¶
Train one PINN for settings.num_steps steps under one sampler.
Source code in pinnrl/benchmarks/sampling_study.py
summarize ¶
Median/IQR per (pde, strategy) plus a paired comparison against uniform.
budget="steps" compares final errors (equal training points).
budget="evals" compares each run at the last checkpoint whose residual
evaluations (training plus sampler overhead) do not exceed the smallest
total spent by any run on that PDE.
Source code in pinnrl/benchmarks/sampling_study.py
solve_heat_1d ¶
Explicit-Euler FDM solver for the 1-D heat equation on a periodic domain.
Solves u_t = α·u_xx with initial condition sin(2π·f·x) and
periodic boundaries. The defaults give a diffusion number
r = α·dt/dx² ≈ 0.26, about half the explicit-stability cap of 0.5.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alpha
|
float
|
Thermal diffusivity. |
0.1
|
frequency
|
float
|
Spatial frequency of the sinusoidal initial condition. |
1.0
|
domain
|
tuple[float, float]
|
Spatial domain |
(0.0, 1.0)
|
t_max
|
float
|
Final time. |
1.0
|
nx
|
int
|
Number of distinct points on the periodic grid ( |
101
|
nt
|
int
|
Number of time levels including |
4001
|
Returns:
| Type | Description |
|---|---|
FDMResult
|
class: |
FDMResult
|
solution at |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the explicit-Euler scheme would be unstable for the
chosen |
Source code in pinnrl/benchmarks/fdm.py
solve_wave_1d ¶
Leap-frog FDM solver for the 1-D wave equation on a periodic domain.
Solves u_tt = c²·u_xx with the travelling-wave initial condition
u(x, 0) = sin(2πx), u_t(x, 0) = -2π·c·cos(2πx) so that the
closed-form solution is the right-moving wave sin(2π(x − c·t)). This
is not :class:pinnrl.pdes.wave_equation.WaveEquation's standing-wave
exact solution, which starts at rest.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
c
|
float
|
Wave speed. |
1.0
|
domain
|
tuple[float, float]
|
Spatial domain |
(0.0, 1.0)
|
t_max
|
float
|
Final time. |
1.0
|
nx
|
int
|
Number of distinct points on the periodic grid ( |
201
|
nt
|
int
|
Number of time levels including |
4001
|
Returns:
| Type | Description |
|---|---|
FDMResult
|
class: |
FDMResult
|
solution at |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the leap-frog CFL condition |