code: def main(core_context, latest_checkpoint, trial_id, increment_by):
      x = 0
  
      # NEW: load a checkpoint if one was provided.
      starting_batch = 0
      if latest_checkpoint is not None:
          with core_context.checkpoint.restore_path(
              latest_checkpoint
          ) as path:
              x, starting_batch = load_state(trial_id, path)
  
      for batch in range(starting_batch, 100):
          x += increment_by
          steps_completed = batch + 1
          time.sleep(0.1)
          logging.info(f"x is now {x}")
          if steps_completed % 10 == 0:
              core_context.train.report_training_metrics(
                  steps_completed=steps_completed, metrics={"x": x}
              )
  
              # NEW: write checkpoints at regular intervals to limit lost progress
              # in case of a crash during training.
              checkpoint_metadata = {"steps_completed": steps_completed}
              with core_context.checkpoint.store_path(
                  checkpoint_metadata
              ) as (path, uuid):
                  save_state(x, steps_completed, trial_id, path)
  
              # NEW: check for a preemption signal.  This could originate from a
              # higher-priority task bumping us off the cluster, or for a user pausing
              # the experiment via the WebUI or CLI.
              if core_context.preempt.should_preempt():
                  # At this point, a checkpoint was just saved, so training can exit
                  # immediately and resume when the trial is reactivated.
                  return
  
      core_context.train.report_validation_metrics(
          steps_completed=steps_completed, metrics={"x": x}
      )
  
file_path: determined/examples/tutorials/core_api/2_checkpoints.py
imports: import logging
  import pathlib
  import sys
  import time
  import determined
label_desc: Use image node_id 3 for calling a global function with example usage: main(core_context, latest_checkpoint, trial_id, increment_by) without return types