docstr: Test that the state gets checkpointed without any errors, but only on the
  right phase_type and only if the checkpoint directory exists.
docstr_tok: ["Test","that","the","state","gets","checkpointed","without","any","errors",",","but","only","on","the","right","phase_type","and","only","if","the","checkpoint","directory","exists","."]
code: def test_state_checkpointing(self) -> None:
      """
      Test that the state gets checkpointed without any errors, but only on the
      right phase_type and only if the checkpoint directory exists.
      """
      config = get_test_task_config()
      task = build_task(config)
      task.prepare()
  
      checkpoint_folder = self.base_dir + "/checkpoint_end_test/"
      input_args = {"foo": "bar"}
  
      # create a checkpoint hook
      checkpoint_hook = CheckpointHook(
          checkpoint_folder, input_args, phase_types=["train"]
      )
  
      # checkpoint directory doesn't exist
      # call the on start function
      with self.assertRaises(FileNotFoundError):
          checkpoint_hook.on_start(task)
      # call the on end phase function
      with self.assertRaises(AssertionError):
          checkpoint_hook.on_phase_end(task)
      # try loading a non-existent checkpoint
      checkpoint = load_checkpoint(checkpoint_folder)
      self.assertIsNone(checkpoint)
  
      # create checkpoint dir, verify on_start hook runs
      os.mkdir(checkpoint_folder)
      checkpoint_hook.on_start(task)
  
      # Phase_type is test, expect no checkpoint
      task.train = False
      # call the on end phase function
      checkpoint_hook.on_phase_end(task)
      checkpoint = load_checkpoint(checkpoint_folder)
      self.assertIsNone(checkpoint)
  
      task.train = True
      # call the on end phase function
      checkpoint_hook.on_phase_end(task)
      # model should be checkpointed. load and compare
      checkpoint = load_checkpoint(checkpoint_folder)
      self.assertIsNotNone(checkpoint)
      for key in ["input_args", "classy_state_dict"]:
          self.assertIn(key, checkpoint)
      # not testing for equality of classy_state_dict, that is tested in
      # a separate test
      self.assertDictEqual(checkpoint["input_args"], input_args)
  
imports: import copy
  import importlib
  import os
  import shutil
  import tempfile
  import torch
  from classy_vision.generic.util import load_checkpoint
  from classy_vision.hooks import CheckpointHook
  from classy_vision.tasks import build_task
  from classy_vision.trainer import LocalTrainer
  from fvcore.common import file_io
  from fvcore.common.file_io import PathHandler, PathManager
  from test.generic.config_utils import get_fast_test_task_config, get_test_task_config
  from test.generic.hook_test_utils import HookTestBase
label_desc: Use image node_id 5 for calling the TestCheckpointHook obj's underlying member method code with example usage: obj.test_state_checkpointing() without return types