code: def test_loops_restore(tmpdir):
      """Test that required loop state_dict is loaded correctly by checkpoint connector."""
      model = BoringModel()
      checkpoint_callback = ModelCheckpoint(
          dirpath=tmpdir, save_last=True
      )
      trainer_args = {
          "default_root_dir": tmpdir,
          "max_epochs": 1,
          "limit_train_batches": 1,
          "limit_val_batches": 1,
          "logger": False,
          "callbacks": [checkpoint_callback],
          "num_sanity_val_steps": 0,
      }
      trainer = Trainer(**trainer_args)
      trainer.fit(model)
  
      ckpt_path = str(tmpdir / "last.ckpt")
  
      trainer = Trainer(**trainer_args)
      trainer.strategy.connect(model)
  
      trainer_fns = list(TrainerFn)
      for fn in trainer_fns:
          trainer_fn = getattr(trainer, f"{fn.value}_loop")
          trainer_fn.load_state_dict = mock.Mock()
  
      for fn in trainer_fns:
          trainer.state.fn = fn
          trainer._checkpoint_connector.resume_start(ckpt_path)
          trainer._checkpoint_connector.restore_loops()
  
          trainer_loop = getattr(trainer, f"{fn.value}_loop")
          trainer_loop.load_state_dict.assert_called()
          trainer_loop.load_state_dict.reset_mock()
  
          for fn2 in trainer_fns:
              if fn2 != fn:
                  trainer_loop2 = getattr(trainer, f"{fn2.value}_loop")
                  trainer_loop2.load_state_dict.assert_not_called()
  
file_path: pytorch-lightning/tests/tests_pytorch/trainer/connectors/test_checkpoint_connector.py
imports: import os
  from unittest import mock
  from unittest.mock import Mock
  import pytest
  import torch
  from lightning.pytorch import Trainer
  from lightning.pytorch.callbacks import ModelCheckpoint
  from lightning.pytorch.demos.boring_classes import BoringModel
  from lightning.pytorch.trainer.states import TrainerFn
  from lightning.pytorch.utilities.migration.utils import _set_version
label_desc: Use image node_id 5 for calling a global function with example usage: test_loops_restore(tmpdir) without return types