neural_lam.train_model#
CLI entry point for training Neural-LAM models.
Classes#
|
|
Handle containing output paths for a Neural-LAM run. |
Functions#
|
Select the forecaster and Lightning module for a predictor. |
|
Instantiate a Graph-EFM predictor from CLI architecture options. |
|
Build the argument parser for training and evaluating models. |
|
Instantiate a step predictor with the GNN kwargs its family accepts. |
|
Run training or evaluation using strongly-typed configuration dataclasses. |
Reconstruct a forecasting module from a checkpoint without |
|
|
Main function for training and evaluating models. |
|
Run the training or evaluation loop from parsed CLI arguments. |
Module Contents#
- class neural_lam.train_model.AdaptiveHelpFormatter(prog: str)[source]#
Bases:
argparse.ArgumentDefaultsHelpFormatter--helpformatter that scales the column width to the terminal.Pick a help-column width based on the current terminal size.
- class neural_lam.train_model.Run[source]#
Handle containing output paths for a Neural-LAM run.
- example_plots(example_i: int) pathlib.Path[source]#
Frames and GIF of example
example_i(1-based, create_gif).
- property checkpoint_dir: pathlib.Path#
Directory holding
min_val_loss.ckptandlast.ckpt.
- checkpoint_path: pathlib.Path | None = None#
- property plot_dir: pathlib.Path#
Directory evaluation plots are written to (logger
save_dir).
- property rmse_plot: pathlib.Path#
Lead time x variable RMSE heatmap written by test evaluation.
- run_dir: pathlib.Path#
- neural_lam.train_model.build_forecaster(args: argparse.Namespace, config: neural_lam.config.NeuralLAMConfig, datastore: neural_lam.datastore.base.BaseDatastore, predictor: Any) tuple[neural_lam.models.BaseForecaster, type[neural_lam.models.modules.base.BaseForecastingModule], dict[str, Any]][source]#
Select the forecaster and Lightning module for a predictor.
- Parameters:
args (Namespace) – Run arguments, including the deterministic loss selection.
config (NeuralLAMConfig) – Architecture and training objective settings.
datastore (BaseDatastore) – Grid metadata and standardization statistics.
predictor (StepPredictor) – Predictor created by
build_predictor.
- Returns:
forecaster (BaseForecaster) – Deterministic rollout or Graph-EFM variational forecaster.
module_class (type) – Lightning module matching the forecast family.
module_kwargs (dict[str, Any]) – Additional module settings, including evaluation ensemble size.
- neural_lam.train_model.build_graph_efm_predictor(predictor_class: type, args: argparse.Namespace, config: neural_lam.config.NeuralLAMConfig, datastore: neural_lam.datastore.base.BaseDatastore) Any[source]#
Instantiate a Graph-EFM predictor from CLI architecture options.
- Parameters:
predictor_class (type) – Hierarchical or multiscale Graph-EFM predictor class.
args (Namespace) – Architecture and forcing-window options.
config (NeuralLAMConfig) – Output clamping configuration.
datastore (BaseDatastore) – Graph features and standardization statistics.
- Returns:
Configured Graph-EFM predictor.
- Return type:
- Raises:
ValueError – If the predictor class is not a supported Graph-EFM variant.
- neural_lam.train_model.build_parser() argparse.ArgumentParser[source]#
Build the argument parser for training and evaluating models.
- Returns:
The parser.
- Return type:
ArgumentParser
- neural_lam.train_model.build_predictor(predictor_class: type, args: argparse.Namespace, config: neural_lam.config.NeuralLAMConfig, datastore: neural_lam.datastore.base.BaseDatastore) Any[source]#
Instantiate a step predictor with the GNN kwargs its family accepts.
Hierarchical GNN kwargs are only passed to
BaseHiGraphModelsubclasses, gating on the class hierarchy so that future hierarchical models are covered without maintaining a model-name list. GNN type arguments fall back toInteractionNetfor checkpoints saved before those CLI flags existed. Graph-EFM delegates to its own builder.- Parameters:
predictor_class (type) – Step predictor class selected from
MODELS.args (Namespace) – Architecture and forcing-window arguments.
config (NeuralLAMConfig) – Output clamping settings.
datastore (BaseDatastore) – Grid features, graph location and standardization statistics.
- Returns:
Predictor configured for its graph family.
- Return type:
- neural_lam.train_model.fit(model_config: neural_lam.config.ModelConfig, train_config: neural_lam.config.TrainRunConfig, data_config: neural_lam.config.DataConfig, compute_config: neural_lam.config.ComputeConfig, logging_config: neural_lam.config.LoggingConfig, *, config: neural_lam.config.NeuralLAMConfig | None = None, datastore: neural_lam.datastore.base.BaseDatastore | None = None, datastore_boundary: neural_lam.datastore.base.BaseDatastore | None = None, config_path: str | None = None) Run[source]#
Run training or evaluation using strongly-typed configuration dataclasses.
Training and evaluation use the current run configuration. When loading a checkpoint, use architecture settings that match its saved weights.
- Parameters:
model_config (ModelConfig) – Model architecture and graph configuration.
train_config (TrainRunConfig) – Training hyperparameters and evaluation settings.
data_config (DataConfig) – Data loading and forcing parameters.
compute_config (ComputeConfig) – Compute devices, seed, and precision settings.
logging_config (LoggingConfig) – Experiment tracking and logging settings.
config (NeuralLAMConfig or None, optional) – Loaded Neural-LAM configuration.
datastore (BaseDatastore or None, optional) – Initialized datastore instance.
datastore_boundary (BaseDatastore or None, optional) – Initialized boundary datastore, used together with
configanddatastore. Loaded fromconfig_pathotherwise.config_path (str or None, optional) – Path to the configuration file, used if config or datastore is None.
- Returns:
Object containing paths to run outputs and saved checkpoints.
- Return type:
- neural_lam.train_model.load_forecasting_module_from_checkpoint(ckpt_path: str, config: neural_lam.config.NeuralLAMConfig, datastore: neural_lam.datastore.base.BaseDatastore, datastore_boundary: neural_lam.datastore.base.BaseDatastore | None = None) neural_lam.models.modules.base.BaseForecastingModule[source]#
Reconstruct a forecasting module from a checkpoint without requiring the caller to know the original architecture kwargs.
The checkpoint must have been saved with args in hyper_parameters (i.e. created via train_model.main), so that model class and architecture kwargs can be recovered automatically. Graph-EFM architecture and objective options are restored from the saved arguments.
- Parameters:
ckpt_path (str) – Path to the checkpoint.
config (NeuralLAMConfig) – Neural-LAM configuration.
datastore (BaseDatastore) – Interior datastore.
datastore_boundary (BaseDatastore, optional) – Boundary datastore, needed to restore the boundary standardization statistics of a checkpoint trained with one.
- Returns:
The restored module.
- Return type:
DeterministicForecastingModule or ProbabilisticForecastingModule
- neural_lam.train_model.main(input_args: list[str] | None = None) None[source]#
Main function for training and evaluating models.
- neural_lam.train_model.run(args: argparse.Namespace, config: neural_lam.config.NeuralLAMConfig | None = None, datastore: neural_lam.datastore.base.BaseDatastore | None = None, datastore_boundary: neural_lam.datastore.base.BaseDatastore | None = None) Run[source]#
Run the training or evaluation loop from parsed CLI arguments.
- Parameters:
args (Namespace) – Parsed arguments from
build_parser().config (NeuralLAMConfig or None, optional) – Loaded configuration, loaded from
args.config_pathifNone.datastore (BaseDatastore or None, optional) – Interior datastore, used together with
config.datastore_boundary (BaseDatastore or None, optional) – Boundary datastore, used together with
config.
- Returns:
Paths to the run outputs and saved checkpoints.
- Return type: