code: def test_callbacks_state_fit_ckpt_path(tmpdir):
      """Test that resuming from a checkpoint restores callbacks that persist state."""
      dm = ClassifDataModule()
      model = ClassificationModel()
      callback_capture = CaptureCallbacksBeforeTraining()
  
      def get_trainer_args():
          checkpoint = ModelCheckpoint(
              dirpath=tmpdir, monitor="val_loss", save_last=True
          )
          assert checkpoint.best_model_path == ""
          assert checkpoint.best_model_score is None
          return {
              "default_root_dir": tmpdir,
              "limit_train_batches": 1,
              "limit_val_batches": 2,
              "max_epochs": 1,
              "logger": False,
              "callbacks": [checkpoint, callback_capture],
          }
  
      # initial training
      trainer = Trainer(**get_trainer_args())
      trainer.fit(model, datamodule=dm)
  
      callbacks_before_resume = deepcopy(trainer.callbacks)
  
      # resumed training
      trainer = Trainer(**get_trainer_args())
      trainer.fit(
          model, datamodule=dm, ckpt_path=str(tmpdir / "last.ckpt")
      )
  
      assert len(callbacks_before_resume) == len(
          callback_capture.callbacks
      )
  
      for before, after in zip(
          callbacks_before_resume, callback_capture.callbacks
      ):
          if isinstance(before, ModelCheckpoint):
              for attribute in (
                  "best_model_path",
                  "best_model_score",
                  "best_k_models",
                  "kth_best_model_path",
                  "kth_value",
                  "last_model_path",
              ):
                  assert getattr(before, attribute) == getattr(
                      after, attribute
                  ), f"{attribute}"
  
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 6 for calling a global function with example usage: test_callbacks_state_fit_ckpt_path(tmpdir) and returns: dict