code: def test_pytorch_lightning_pruning_callback_ddp_monitor(
      storage_mode: str,
  ) -> None:
      def objective(trial: optuna.trial.Trial) -> float:
          callback = PyTorchLightningPruningCallback(
              trial, monitor="accuracy"
          )
          trainer = pl.Trainer(
              max_epochs=2,
              accelerator="cpu",
              devices=2,
              enable_checkpointing=False,
              callbacks=[callback],
              strategy="ddp_spawn",
          )
  
          model = ModelDDP()
          trainer.fit(model)
  
          # Evoke pruning manually.
          callback.check_pruned()
  
          return 1.0
  
      with StorageSupplier(storage_mode) as storage:
          study = optuna.create_study(
              storage=storage, pruner=DeterministicPruner(True)
          )
          study.optimize(objective, n_trials=1)
          assert study.trials[0].state == optuna.trial.TrialState.PRUNED
          assert list(study.trials[0].intermediate_values.keys()) == [0]
          np.testing.assert_almost_equal(
              study.trials[0].intermediate_values[0], 0.45
          )
  
          study = optuna.create_study(
              storage=storage, pruner=DeterministicPruner(False)
          )
          study.optimize(objective, n_trials=1)
          assert (
              study.trials[0].state == optuna.trial.TrialState.COMPLETE
          )
          assert study.trials[0].value == 1.0
          assert list(study.trials[0].intermediate_values.keys()) == [
              0,
              1,
          ]
          np.testing.assert_almost_equal(
              study.trials[0].intermediate_values[0], 0.45
          )
          np.testing.assert_almost_equal(
              study.trials[0].intermediate_values[1], 0.45
          )
  
imports: from __future__ import annotations
  from collections.abc import Sequence
  import numpy
  import pytest
  import optuna
  from optuna._imports import try_import
  from optuna.integration import PyTorchLightningPruningCallback
  from optuna.testing.pruners import DeterministicPruner
  from optuna.testing.storages import StorageSupplier
label_desc: Use image node_id 3 for calling a global function with example usage: test_pytorch_lightning_pruning_callback_ddp_monitor(storage_mode) and returns: int