Configuration¤
NNFE uses a hierarchy of frozen dataclasses to represent the full run
configuration. All classes can be constructed programmatically or loaded
from YAML via the top-level NNFEConfig.from_yaml
class method.
NNFEConfig¤
nnfe.nnfe_config.NNFEConfig
¤
Top-level configuration for the full NNFE solver.
Aggregates all sub-configs required to instantiate
:class:~nnfe.nnfe_object.NNFE via :meth:NNFE.from_config.
Attributes:
| Name | Type | Description |
|---|---|---|
project |
Filesystem and run-management settings. |
|
plotter |
Diagnostic plot settings. |
|
sampler |
Training/testing point sampler settings. |
|
FE |
Finite element problem configuration (from |
|
ML |
Neural network and optimizer configuration. |
|
NNFE |
NNFE-specific parameter mapping configuration. |
from_yaml(path: Path) -> NNFEConfig
classmethod
¤
Load a complete :class:NNFEConfig from a YAML file.
The FE and ML sections may either be inlined in the main YAML
or provided as paths to separate .yaml files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to the top-level NNFE config YAML file. |
required |
Returns:
| Type | Description |
|---|---|
NNFEConfig
|
A fully populated :class: |
ProjectConfig¤
nnfe.nnfe_config.ProjectConfig
¤
Filesystem and run-management settings.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
Human-readable project name; used as a directory prefix. |
|
parent_dir |
Root directory under which the run folder is created. |
|
save |
Whether to persist model weights and configuration to disk. |
|
print_progress |
Print loss to stdout every N epochs. |
|
save_progress |
Save model weights every N epochs during training.
|
|
extra_dirs |
Mapping of logical names (e.g. |
|
trained_weights_path |
Optional path to pre-trained model weights loaded at startup (before training). |
name = 'Project'
class-attribute
¤
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to 'utf-8'. errors defaults to 'strict'.
parent_dir = PosixPath('.')
class-attribute
¤
Path subclass for non-Windows systems.
On a POSIX system, instantiating a Path should return this object.
save = True
class-attribute
¤
Returns True when the argument is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.
from_dict(params: dict) -> ProjectConfig
classmethod
¤
Construct a :class:ProjectConfig from a raw config dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Dict with keys |
required |
Returns:
| Type | Description |
|---|---|
ProjectConfig
|
A new :class: |
PlotterConfig¤
nnfe.nnfe_config.PlotterConfig
¤
Settings controlling which diagnostic plots are generated.
Attributes:
| Name | Type | Description |
|---|---|---|
plot_loss |
Whether to plot the training loss curve. |
|
plot_lr |
Whether to plot the learning-rate schedule. |
|
plot_sample |
Whether to plot the sampling distribution (currently unused but reserved for future use). |
plot_loss = True
class-attribute
¤
Returns True when the argument is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.
plot_lr = True
class-attribute
¤
Returns True when the argument is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.
plot_sample = True
class-attribute
¤
Returns True when the argument is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.
from_dict(params: dict) -> PlotterConfig
classmethod
¤
Construct a :class:PlotterConfig from a raw config dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Dict with keys |
required |
Returns:
| Type | Description |
|---|---|
PlotterConfig
|
A new :class: |
SamplerConfig¤
nnfe.nnfe_config.SamplerConfig
¤
Configuration for the training and testing point samplers.
Stores what to sample (sampler type and bounds); the actual sampling is
performed by :class:~nnfe.sampling.Sampler.
Attributes:
| Name | Type | Description |
|---|---|---|
training_sampler |
Name of the sampler used for training points.
Currently only |
|
training_kwargs |
Keyword arguments forwarded to the training sampler
(e.g. |
|
testing_sampler |
Name of the sampler used for test points. |
|
testing_kwargs |
Keyword arguments forwarded to the testing sampler. |
testing_sampler = 'uniform'
class-attribute
¤
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to 'utf-8'. errors defaults to 'strict'.
training_sampler = 'uniform'
class-attribute
¤
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to 'utf-8'. errors defaults to 'strict'.
from_dict(params: dict) -> SamplerConfig
classmethod
¤
Construct a :class:SamplerConfig from a raw config dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Dict with keys |
required |
Returns:
| Type | Description |
|---|---|
SamplerConfig
|
A new :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If either sampler name is not recognised. |
NNFEParamsConfig¤
nnfe.nnfe_config.NNFEParamsConfig
¤
NNFE-specific parameter configuration describing which FE quantities the network controls.
The NNFE method parameterises FE internal variables and/or Dirichlet boundary conditions with the neural network output. This config specifies which variables are parameterised and in what order they appear in the network output vector.
Attributes:
| Name | Type | Description |
|---|---|---|
natural |
Nested dict mapping FE keys to the internal variables (volumetric or surface) that are controlled by the natural (Neumann-type) outputs of the network. Structure:: |
|
essential |
Nested dict for Dirichlet (essential) boundary condition outputs (currently unused in the gradient computation but reserved). |
|
natural_order |
Ordered list of variable names that maps network output indices to natural variables (used for slicing the output vector). |
|
essential_order |
Ordered list of variable names for essential (Dirichlet) outputs. An empty list disables Dirichlet training. |
from_dict(params: dict) -> NNFEParamsConfig
classmethod
¤
Construct an :class:NNFEParamsConfig from a raw config dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Dict with keys |
required |
Returns:
| Type | Description |
|---|---|
NNFEParamsConfig
|
A new :class: |
MLConfig¤
nnfe.ml_config.MLConfig
¤
Top-level machine-learning configuration consumed by
:class:~nnfe.ml.MLManager.
Attributes:
| Name | Type | Description |
|---|---|---|
networks |
Ordered mapping of network names to their
:class: |
|
optimizer |
Optimizer and learning-rate schedule configuration. |
|
epochs |
Total number of training iterations. |
|
batch_size |
Fraction of the training set to sample per step
(value in |
|
rng_key |
Integer seed for JAX PRNG initialisation. Defaults to
|
rng_key = 0
class-attribute
¤
int([x]) -> integer int(x, base=10) -> integer
Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.int(). For floating-point numbers, this truncates towards zero.
If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by '+' or '-' and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal.
int('0b100', base=0) 4
from_dict(params: dict) -> MLConfig
classmethod
¤
Construct an :class:MLConfig from a raw config dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Dict with keys |
required |
Returns:
| Type | Description |
|---|---|
MLConfig
|
A new :class: |
NetworkConfig¤
nnfe.ml_config.NetworkConfig
¤
Configuration for a single neural network.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
Name of the network class in :mod: |
|
kwargs |
Keyword arguments forwarded to the network constructor.
The special value |
|
load_model |
Optional path to a serialised Equinox model file
( |
|
static |
If |
static = False
class-attribute
¤
Returns True when the argument is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.
from_dict(params: dict) -> NetworkConfig
classmethod
¤
Construct a :class:NetworkConfig from a raw config dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Dict with keys |
required |
Returns:
| Type | Description |
|---|---|
NetworkConfig
|
A new :class: |
OptimizerConfig¤
nnfe.ml_config.OptimizerConfig
¤
Configuration for the Optax optimizer and its learning-rate schedule.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
Name of the Optax optimizer (e.g. |
|
lr_scheduler |
Whether to use a learning-rate schedule. When
|
|
optimizer_kwargs |
Extra keyword arguments forwarded to the Optax
optimizer (excluding |
|
scheduler |
Nested dict describing a
:func: |
lr_scheduler = True
class-attribute
¤
Returns True when the argument is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.
from_dict(params: dict) -> OptimizerConfig
classmethod
¤
Construct an :class:OptimizerConfig from a raw config dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Dict with keys |
required |
Returns:
| Type | Description |
|---|---|
OptimizerConfig
|
A new :class: |