class_docstr: PyTorch Lightning callback to prune unpromising trials.
  
  See `the example <https://github.com/optuna/optuna-examples/blob/
  main/pytorch/pytorch_lightning_simple.py>`__
  if you want to add a pruning callback which observes accuracy.
  
  Args:
      trial:
          A :class:`~optuna.trial.Trial` corresponding to the current evaluation of the
          objective function.
      monitor:
          An evaluation metric for pruning, e.g., ``val_loss`` or
          ``val_acc``. The metrics are obtained from the returned dictionaries from e.g.
          ``lightning.pytorch.LightningModule.training_step`` or
          ``lightning.pytorch.LightningModule.validation_epoch_end`` and the names thus depend on
          how this dictionary is formatted.
  
  
  .. note::
      For the distributed data parallel training, the version of PyTorchLightning needs to be
      higher than or equal to v1.6.0. In addition, :class:`~optuna.study.Study` should be
      instantiated with RDB storage.
  
  
  .. note::
      If you would like to use PyTorchLightningPruningCallback in a distributed training
      environment, you need to evoke `PyTorchLightningPruningCallback.check_pruned()`
      manually so that :class:`~optuna.exceptions.TrialPruned` is properly handled.
docstr: Raise :class:`optuna.TrialPruned` manually if pruned.
  
  Currently, ``intermediate_values`` are not properly propagated between processes due to
  storage cache. Therefore, necessary information is kept in trial_system_attrs when the
  trial runs in a distributed situation. Please call this method right after calling
  ``lightning.pytorch.Trainer.fit()``.
  If a callback doesn't have any backend storage for DDP, this method does nothing.
docstr_tok: ["Raise",":","class",":","`","optuna.TrialPruned","`","manually","if","pruned",".","Currently",",","``","intermediate_values","``","are","not","properly","propagated","between","processes","due","to","storage","cache",".","Therefore",",","necessary","information","is","kept","in","trial_system_attrs","when","the","trial","runs","in","a","distributed","situation",".","Please","call","this","method","right","after","calling","``","lightning.pytorch.Trainer.fit","(",")","``",".","If","a","callback","does","n't","have","any","backend","storage","for","DDP",",","this","method","does","nothing","."]
code: def check_pruned(self) -> None:
      """Raise :class:`optuna.TrialPruned` manually if pruned.
  
      Currently, ``intermediate_values`` are not properly propagated between processes due to
      storage cache. Therefore, necessary information is kept in trial_system_attrs when the
      trial runs in a distributed situation. Please call this method right after calling
      ``lightning.pytorch.Trainer.fit()``.
      If a callback doesn't have any backend storage for DDP, this method does nothing.
      """
  
      _trial_id = self._trial._trial_id
      _study = self._trial.study
      # Confirm if storage is not InMemory in case this method is called in a non-distributed
      # situation by mistake.
      if not isinstance(_study._storage, _CachedStorage):
          return
  
      _trial_system_attrs = (
          _study._storage._backend.get_trial_system_attrs(_trial_id)
      )
      is_pruned = _trial_system_attrs.get(_PRUNED_KEY)
      intermediate_values = _trial_system_attrs.get(_INTERMEDIATE_VALUE)
  
      # Confirm if DDP backend is used in case this method is called from a non-DDP situation by
      # mistake.
      if intermediate_values is None:
          return
      for epoch, score in intermediate_values.items():
          self._trial.report(score, step=int(epoch))
      if is_pruned:
          epoch = _trial_system_attrs.get(_EPOCH_KEY)
          raise optuna.TrialPruned(
              f"Trial was pruned at epoch {epoch}."
          )
  
file_path: optuna/optuna/integration/pytorch_lightning.py
imports: import warnings
  from packaging import version
  import optuna
  from optuna.storages._cached_storage import _CachedStorage
  from optuna.storages._rdb.storage import RDBStorage
label_desc: Use image node_id 4 for calling the PyTorchLightningPruningCallback obj's underlying member method code with example usage: obj.check_pruned() without return types