neural_lam.models.modules.probabilistic
=======================================

.. py:module:: neural_lam.models.modules.probabilistic

.. autoapi-nested-parse::

   Lightning module evaluating probabilistic forecasters.



Classes
-------

.. autoapisummary::

   neural_lam.models.modules.probabilistic.ProbabilisticForecastingModule


Module Contents
---------------

.. py:class:: ProbabilisticForecastingModule(forecaster: neural_lam.models.forecasters.probabilistic.BaseProbabilisticForecaster, config: neural_lam.config.NeuralLAMConfig, datastore: neural_lam.datastore.base.BaseDatastore, *, eval_ensemble_size: int, datastore_boundary: neural_lam.datastore.base.BaseDatastore | None = None, lr: float = 0.001, restore_opt: bool = False, n_example_pred: int = 1, create_gif: bool = False, val_steps_to_log: list[int] | None = None, train_steps_to_log: list[int] | None = None, metrics_watch: list[str] | None = None, var_leads_metrics_watch: dict[int, list[int]] | None = None, args: Any | None = None)

   Bases: :py:obj:`neural_lam.models.modules.base.BaseForecastingModule`


   Lightning module evaluating a forecaster by sampling an ensemble.

   Training is inherited unchanged from ``BaseForecastingModule``: the
   wrapped forecaster assembles its own training loss. Validation and
   testing are ensemble based instead of deterministic: an ensemble is
   sampled through ``forecaster.sample_ensemble`` and its mean scored per
   lead time and variable, with validation additionally reporting the
   forecaster's own objective. The module makes no assumption on how the
   members are produced, only that repeated sampling is what an ensemble
   is made of.

   Initialize the module and store the evaluation ensemble size.

   :param forecaster: The forecaster to evaluate. Its ``forward`` returns one sampled
                      forecast; ``sample_ensemble`` draws the ensemble evaluated
                      during validation and testing.
   :type forecaster: BaseProbabilisticForecaster
   :param config: Configuration object for the neural LAM model.
   :type config: NeuralLAMConfig
   :param datastore: Datastore providing grid metadata and data access.
   :type datastore: BaseDatastore
   :param eval_ensemble_size: Number of ensemble members sampled during validation and
                              testing. Keyword-only and required: how many members to draw is
                              a choice this module cannot sensibly default.
   :type eval_ensemble_size: int
   :param datastore_boundary: Boundary forcing datastore, used for its standardization
                              statistics.
   :type datastore_boundary: BaseDatastore, optional
   :param lr: Learning rate for the optimizer.
   :type lr: float, default 1e-3
   :param restore_opt: Whether to restore optimizer state from checkpoint.
   :type restore_opt: bool, default False
   :param n_example_pred: Number of example predictions to plot during testing. Unused
                          here, since ``test_step`` plots no examples.
   :type n_example_pred: int, default 1
   :param create_gif: Whether to create GIFs of example predictions. Unused here, for
                      the same reason.
   :type create_gif: bool, default False
   :param val_steps_to_log: Specific predicted steps to log during validation/testing.
                            Unused here: nothing this module reports decomposes per step,
                            since the ensemble metrics are logged for every step at once as
                            heatmaps and the objective is a single scalar.
   :type val_steps_to_log: list of int, optional
   :param train_steps_to_log: Specific predicted steps to log during training. Has no effect
                              unless the forecaster's objective decomposes per step; see
                              ``BaseForecastingModule.training_step``.
   :type train_steps_to_log: list of int, optional
   :param metrics_watch: List of metrics to watch and log specifically.
   :type metrics_watch: list of str, optional
   :param var_leads_metrics_watch: Mapping from variable index to a list of predicted steps to log
                                   individually for the configured metrics.
   :type var_leads_metrics_watch: dict of {int: list of int}, optional
   :param args: Pre-refactor ``ARModel`` checkpoint hyperparameters; see
                ``BaseForecastingModule.__init__``.
   :type args: argparse.Namespace, optional

   :raises ValueError: If ``eval_ensemble_size`` is less than 1.


   .. py:method:: on_test_epoch_end() -> None

      Perform actions at the end of the test epoch.

      Aggregates the ensemble test metrics. Implements
      ``BaseForecastingModule.on_test_epoch_end`` without the spatial loss
      maps and example plots that ``DeterministicForecastingModule`` adds,
      since ``test_step`` here does not populate them.



   .. py:method:: test_step(batch: neural_lam.models.modules.base.Batch, batch_idx: int) -> None

      Perform a single ensemble test step.

      Scores the ensemble mean against the target states (see
      ``_ensemble_step``) and collects per-variable ensemble-mean MSE for
      epoch-end aggregation.

      :param batch: The batch of data.
      :type batch: tuple
      :param batch_idx: The index of the batch.
      :type batch_idx: int



   .. py:method:: validation_step(batch: neural_lam.models.modules.base.Batch, batch_idx: int) -> None

      Perform a single ensemble validation step.

      Logs the forecaster's objective as ``val_mean_loss``, scores the
      ensemble mean against the target states (see ``_ensemble_step``) and
      collects per-variable ensemble-mean MSE for epoch-end aggregation.

      :param batch: The batch of data.
      :type batch: tuple
      :param batch_idx: The index of the batch.
      :type batch_idx: int



   .. py:attribute:: eval_ensemble_size


   .. py:attribute:: forecaster
      :type:  neural_lam.models.forecasters.probabilistic.BaseProbabilisticForecaster


   .. py:attribute:: test_metrics


   .. py:attribute:: val_metrics


