:py:mod:`gnn_tracking.utils.lightning`
======================================

.. py:module:: gnn_tracking.utils.lightning


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

Classes
~~~~~~~

.. autoapisummary::

   gnn_tracking.utils.lightning.StandardError
   gnn_tracking.utils.lightning.SimpleTqdmProgressBar



Functions
~~~~~~~~~

.. autoapisummary::

   gnn_tracking.utils.lightning.save_sub_hyperparameters
   gnn_tracking.utils.lightning.load_obj_from_hparams
   gnn_tracking.utils.lightning.obj_from_or_to_hparams
   gnn_tracking.utils.lightning.get_object_from_path
   gnn_tracking.utils.lightning.get_lightning_module
   gnn_tracking.utils.lightning.get_model
   gnn_tracking.utils.lightning.find_latest_checkpoint



.. py:function:: save_sub_hyperparameters(self: pytorch_lightning.core.mixins.HyperparametersMixin, key: str, obj: pytorch_lightning.core.mixins.HyperparametersMixin | dict, errors: Literal[warn, raise] = 'warn') -> None

   Take hyperparameters from `obj` and save them to `self` under the
   key `key`.

   :param self: The object to save the hyperparameters to.
   :param key: The key under which to save the hyperparameters.
   :param obj: The object to take the hyperparameters from.
   :param errors: Whether to raise an error or just warn


.. py:function:: load_obj_from_hparams(hparams: dict[str, Any], key: str = '') -> Any

   Load object from hyperparameters.


.. py:function:: obj_from_or_to_hparams(self: pytorch_lightning.core.mixins.HyperparametersMixin, key: str, obj: Any) -> Any

   Used to support initializing python objects from hyperparameters:
   If `obj` is a python object other than a dictionary, its hyperparameters are
   saved (its class path and init args) to `self.hparams[key]`.
   If `obj` is instead a dictionary, its assumed that we have to restore an object
   based on this information.


.. py:function:: get_object_from_path(path: str, init_args: dict[str, Any] | None = None) -> Any

   Get object from path (string) to its code location.


.. py:function:: get_lightning_module(class_path: str, chkpt_path: str = '', *, freeze: bool = True, device: str | None = None) -> pytorch_lightning.LightningModule | None

   Get model (specified by `class_path`, a string) and
   load a checkpoint.


.. py:function:: get_model(class_path: str, chkpt_path: str = '', freeze: bool = False, whole_module: bool = False, device: None | str = None) -> torch.nn.Module | None

   Get torch model (specified by `class_path`, a string) and load a checkpoint.
   Uses `get_lightning_module` to get the model.

   :param class_path: The path to the lightning module class
   :param chkpt_path: The path to the checkpoint. If no checkpoint is specified, we
                      return None.
   :param freeze: Whether to freeze the model
   :param whole_module: Whether to return the whole lightning module or just the model
   :param device:


.. py:class:: StandardError


   Bases: :py:obj:`torchmetrics.Metric`

   A torch metric that computes the standard error.
   This is necessary, because LightningModule.log doesn't take custom
   reduce functions.

   .. py:method:: update(x: torch.Tensor)


   .. py:method:: compute()



.. py:class:: SimpleTqdmProgressBar


   Bases: :py:obj:`pytorch_lightning.callbacks.ProgressBar`

   Fallback progress bar that creates a new tqdm bar for each epoch.
   Adapted from https://github.com/Lightning-AI/lightning/issues/2189 , reply
   https://github.com/Lightning-AI/lightning/issues/2189#issuecomment-1510439811

   .. py:property:: is_enabled


   .. py:method:: on_train_epoch_start(trainer, pl_module)


   .. py:method:: on_train_batch_end(trainer, pl_module, outputs, batch, batch_idx)


   .. py:method:: on_validation_epoch_end(trainer, pl_module) -> None


   .. py:method:: disable()



.. py:function:: find_latest_checkpoint(log_dir: os.PathLike, trial_name: str = '') -> pathlib.Path

   Find latest lightning checkpoint

   :param log_dir: Path to the directory of your trial or to the
                   directory of the experiment if `trial_name` is specified.
   :type log_dir: os.PathLike
   :param trial_name: Name of the trial if `log_dir` is the
                      directory of the experiment.
   :type trial_name: str, optional


