code: def test_trainer_properties_restore_ckpt_path(tmpdir):
      """Test that required trainer properties are set correctly when resuming from checkpoint in different phases."""
  
      class CustomClassifModel(ClassificationModel):
          def configure_optimizers(self):
              optimizer = torch.optim.Adam(
                  self.parameters(), lr=self.lr
              )
              lr_scheduler = torch.optim.lr_scheduler.StepLR(
                  optimizer, step_size=1
              )
              return [optimizer], [lr_scheduler]
  
      model = CustomClassifModel()
      dm = ClassifDataModule()
      checkpoint_callback = ModelCheckpoint(
          dirpath=tmpdir, save_last=True
      )
      trainer_args = {
          "default_root_dir": tmpdir,
          "max_epochs": 1,
          "limit_train_batches": 2,
          "limit_val_batches": 2,
          "limit_test_batches": 2,
          "limit_predict_batches": 2,
          "logger": False,
          "callbacks": [checkpoint_callback],
          "num_sanity_val_steps": 0,
      }
      trainer = Trainer(**trainer_args)
      trainer.fit(model, datamodule=dm)
  
      resume_ckpt = str(tmpdir / "last.ckpt")
      state_dict = torch.load(resume_ckpt)
  
      trainer_args.update(
          {
              "max_epochs": 3,
              "enable_checkpointing": False,
              "callbacks": [],
          }
      )
  
      class CustomClassifModel(CustomClassifModel):
          def _is_equal(self, a, b):
              if isinstance(a, Tensor):
                  return torch.all(torch.eq(a, b))
  
              if isinstance(a, Mapping):
                  return all(
                      self._is_equal(a.get(k, None), b.get(k, None))
                      for k in b
                  )
  
              return a == b
  
          def _check_optimizers(self):
              return all(
                  self._is_equal(optimizer.state_dict(), state)
                  for optimizer, state in zip(
                      self.trainer.optimizers,
                      state_dict["optimizer_states"],
                  )
              )
  
          def _check_schedulers(self):
              return all(
                  self._is_equal(config.scheduler.state_dict(), state)
                  for config, state in zip(
                      self.trainer.lr_scheduler_configs,
                      state_dict["lr_schedulers"],
                  )
              )
  
          def _check_model_state_dict(self):
              return all(
                  self._is_equal(actual, expected)
                  for actual, expected in zip(
                      self.state_dict(), state_dict["state_dict"]
                  )
              )
  
          def _test_on_val_test_predict_start(self):
              assert self.trainer.current_epoch == state_dict["epoch"]
              assert self.trainer.global_step == 0
              assert self._check_model_state_dict()
  
          def on_train_start(self):
              assert (
                  self.trainer.current_epoch == state_dict["epoch"] + 1
              )
              assert (
                  self.trainer.global_step == state_dict["global_step"]
              )
              assert self._check_model_state_dict()
              assert self._check_optimizers()
              assert self._check_schedulers()
  
          def on_validation_start(self):
              if self.trainer.state.fn == TrainerFn.VALIDATING:
                  self._test_on_val_test_predict_start()
  
          def on_test_start(self):
              self._test_on_val_test_predict_start()
  
      for fn in ("fit", "validate", "test", "predict"):
          model = CustomClassifModel()
          dm = ClassifDataModule()
          trainer = Trainer(**trainer_args)
          trainer_fn = getattr(trainer, fn)
          trainer_fn(model, datamodule=dm, ckpt_path=resume_ckpt)
  
imports: import glob
  import logging
  import os
  import pickle
  from copy import deepcopy
  from typing import Generic, Mapping, TypeVar
  import cloudpickle
  import pytest
  import torch
  from lightning.fabric import seed_everything
  from lightning.pytorch import Callback, Trainer
  from lightning.pytorch.callbacks import ModelCheckpoint
  from lightning.pytorch.demos.boring_classes import BoringModel
  from lightning.pytorch.trainer.states import TrainerFn
  from lightning_utilities.test.warning import no_warning_call
  from torch import Tensor
  import tests_pytorch.helpers.pipelines
  import tests_pytorch.helpers.utils
  from tests_pytorch.helpers.datamodules import ClassifDataModule
  from tests_pytorch.helpers.runif import RunIf
  from tests_pytorch.helpers.simple_models import ClassificationModel
  from tests_pytorch.loops.test_loops import CustomException
label_desc: Use image node_id 2 for calling a global function with example usage: test_trainer_properties_restore_ckpt_path(tmpdir) and returns: list,  list, unknown, all, all, all, torch, all