code: def trainable(config):
      # Checkpoint loading
      checkpoint = train.get_checkpoint()
      start = 1
      if checkpoint:
          with checkpoint.as_directory() as checkpoint_dir:
              with open(
                  os.path.join(checkpoint_dir, "checkpoint.json"), "r"
              ) as f:
                  state = json.load(f)
          start = state["epoch"] + 1
  
      for epoch in range(start, config["num_epochs"]):
          # Do some training...
  
          # Checkpoint saving
          with tempfile.TemporaryDirectory() as temp_checkpoint_dir:
              with open(
                  os.path.join(temp_checkpoint_dir, "checkpoint.json"),
                  "w",
              ) as f:
                  json.dump({"epoch": epoch}, f)
              train.report(
                  {"epoch": epoch},
                  checkpoint=Checkpoint.from_directory(
                      temp_checkpoint_dir
                  ),
              )
  
file_path: ray/doc/source/tune/doc_code/fault_tolerance.py
imports: import json
  import os
  import tempfile
  from ray import train, tune
  from ray.train import Checkpoint
  import os
  from ray import train, tune
  import ray
  from ray import train, tune
  from ray import train, tune
label_desc: Use image node_id 1 for calling a global function with example usage: trainable(config) without return types