Configuration¶
config.yaml is turned into these dataclasses by TrainingConfig.from_dict and
ModelConfig.from_architecture. The same path is used by Config() and pinnrl-train.
Config ¶
Configuration for the PINNs-RL-PDE framework.
Loads device, model, training and rl from config.yaml.
The model block is taken from the architecture configured for
pde_type (falling back to the top-level model: block).
Source code in pinnrl/config/__init__.py
get ¶
Get the value for a given key or return the default value if the key doesn't exist.
TrainingConfig
dataclass
¶
TrainingConfig(
num_epochs,
batch_size,
num_collocation_points,
num_boundary_points,
num_initial_points,
learning_rate,
weight_decay,
gradient_clipping,
early_stopping,
learning_rate_scheduler,
collocation_distribution="uniform",
adaptive_weights=None,
loss_weights=None,
optimizer="adam",
adam_lbfgs_switch_ratio=0.7,
lbfgs=None,
mode="forward",
loss_function="mse",
huber_delta=1.0,
validation_frequency=10,
)
Training hyper-parameters and sub-configurations.
Attributes:
| Name | Type | Description |
|---|---|---|
num_epochs |
int
|
Total training epochs. |
batch_size |
int
|
Mini-batch size. |
num_collocation_points |
int
|
Number of interior collocation points. |
num_boundary_points |
int
|
Number of boundary condition points. |
num_initial_points |
int
|
Number of initial condition points. |
learning_rate |
float
|
Optimizer learning rate. |
weight_decay |
float
|
L2 regularisation coefficient. |
gradient_clipping |
float
|
Max gradient norm for clipping ( |
early_stopping |
EarlyStoppingConfig
|
Early-stopping configuration. |
learning_rate_scheduler |
LearningRateSchedulerConfig
|
LR scheduler configuration. |
collocation_distribution |
str
|
Collocation sampling strategy ( |
adaptive_weights |
AdaptiveWeightsConfig
|
Adaptive loss weighting configuration. |
loss_weights |
dict[str, float]
|
Static weights for |
optimizer |
str
|
|
adam_lbfgs_switch_ratio |
float
|
Fraction of |
lbfgs |
LBFGSConfig | None
|
L-BFGS settings. |
mode |
str
|
|
loss_function |
str
|
Reduction of each loss term ( |
huber_delta |
float
|
Delta of the Huber loss. |
validation_frequency |
int
|
Epochs between validation, logging and run checkpoints. |
optimizer_config
property
¶
Learning rate and weight decay, shaped like the optimizer_config YAML block.
__getitem__ ¶
Get the value for a given key, also to make it subscriptible.
get ¶
Get the value for a given key or return the default value if the key doesn't exist.
from_dict
classmethod
¶
Build from the training: block of config.yaml.
This is the one place the YAML layout is translated into a
TrainingConfig; both :class:Config and pinnrl-train use it.
learning_rate and weight_decay come from optimizer_config
(or the top level); the scheduler from scheduler_type,
warmup_epochs and reduce_lr_params; a legacy pde key in
loss_weights is renamed to residual. Missing keys fall back to
defaults. Float fields are coerced with float() because YAML 1.1
reads 1e-7 (no decimal point) as a string.
Source code in pinnrl/config/__init__.py
ModelConfig
dataclass
¶
ModelConfig(
input_dim,
hidden_dim,
output_dim,
num_layers,
activation,
fourier_features=0,
fourier_scale=1.0,
dropout=0.0,
layer_norm=False,
architecture="feedforward",
)
Configuration for neural network models.
Attributes:
| Name | Type | Description |
|---|---|---|
input_dim |
int
|
Number of input features (e.g. 2 for (x, t)). |
hidden_dim |
int
|
Width of hidden layers. |
output_dim |
int
|
Number of output features. |
num_layers |
int
|
Depth: linear layers after the feature map for Fourier
(the last is the output layer), attention blocks, and the block
count for ResNet / FNO when |
activation |
str
|
Activation function name. |
fourier_features |
bool
|
|
fourier_scale |
float | None
|
Copy of |
dropout |
float
|
Dropout rate (0.0 disables). |
layer_norm |
bool
|
Whether to apply layer normalisation. |
architecture |
str
|
Architecture backend name. |
hidden_dims |
list[int] | None
|
Hidden-layer widths for feedforward, SIREN and the
autoencoder encoder; defaults to |
omega_0 |
float | None
|
Frequency factor for SIREN networks. |
num_blocks |
int | None
|
Number of residual / FNO blocks. |
num_heads |
int | None
|
Number of attention heads. |
latent_dim |
int | None
|
Latent dimension for the AutoEncoder. |
mapping_size |
int
|
Size of the Fourier feature mapping. |
scale |
float
|
Scale for Fourier feature mapping. |
modes |
int | None
|
Number of Fourier modes for FNO. |
Source code in pinnrl/config/__init__.py
get ¶
Return the attribute key, or default when it is missing or None.
Optional fields (omega_0, num_heads, latent_dim, modes) default
to None; treating None as unset lets each network apply its own default.
Source code in pinnrl/config/__init__.py
__getitem__ ¶
from_architecture
classmethod
¶
Build from one entry of the architectures: block of config.yaml.
hidden_dim and num_layers default to the first width and the
length of hidden_dims when only the list is given (else 128 and 4);
activation defaults to tanh. Architecture extras
(omega_0, modes, ...) are copied when present.
Source code in pinnrl/config/__init__.py
LearningRateSchedulerConfig
dataclass
¶
Learning rate scheduler settings.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
str
|
Scheduler type ( |
warmup_epochs |
int
|
Epochs of linear LR warm-up before the scheduler starts;
cosine then anneals over |
min_lr |
float
|
Minimum learning rate (cosine |
factor |
float
|
Multiplicative factor for |
patience |
int
|
Epochs without improvement before |
EarlyStoppingConfig
dataclass
¶
Early-stopping criteria for training.
Attributes:
| Name | Type | Description |
|---|---|---|
enabled |
bool
|
Whether early stopping is active. |
patience |
int
|
Epochs without validation-loss improvement before stopping
(checked every |
min_delta |
float
|
Minimum validation-loss decrease to count as improvement. |
LBFGSConfig
dataclass
¶
LBFGSConfig(
history_size=50,
max_iter=20,
line_search_fn="strong_wolfe",
tolerance_grad=1e-07,
tolerance_change=1e-09,
)
L-BFGS optimizer settings.
Attributes:
| Name | Type | Description |
|---|---|---|
history_size |
int
|
Number of past gradients/updates retained for the inverse-Hessian approximation. |
max_iter |
int
|
Max L-BFGS iterations per |
line_search_fn |
str | None
|
Line-search strategy passed to |
tolerance_grad |
float
|
First-order optimality tolerance. |
tolerance_change |
float
|
Loss-change tolerance for early termination. |
AdaptiveWeightsConfig
dataclass
¶
Configuration for adaptive loss weighting.
Attributes:
| Name | Type | Description |
|---|---|---|
enabled |
bool
|
Whether adaptive weighting is active. |
strategy |
str
|
Weight adaptation strategy ( |
alpha |
float
|
EMA retention factor (0–1); higher adapts more slowly. |
eps |
float
|
Small constant for numerical stability. |
initial_weights |
list[float]
|
Weights for [residual, boundary, initial] returned by the first update. |
RLConfig
dataclass
¶
RLConfig(
enabled=False,
n_x_cells=None,
n_t_cells=None,
policy_fraction=None,
temperature=None,
probe_cells=None,
probe_points=None,
probe_every=None,
)
The rl: block: the experimental residual-bandit sampler (--rl).
Sampler fields left as None fall back to the defaults of
:class:~pinnrl.rl.bandit_sampler.ResidualBanditSampler, so those
defaults live in one place.
from_dict
classmethod
¶
Build from the rl: block of config.yaml; unknown keys are ignored.
build_sampler ¶
Create the :class:ResidualBanditSampler these settings describe for pde.
Source code in pinnrl/config/__init__.py
resolve_device ¶
Return torch.device(name) if that backend is available, else CPU.
Only "cuda" and "mps" are probed; any other name resolves to CPU,
so a config written on one machine still runs on another.