code: def main(
      core_context,
      latest_checkpoint,
      trial_id,
      increment_by,
      metric_as_dict,
  ):
      x = 0
  
      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)
  
      batch = starting_batch
      last_checkpoint_batch = None
      for op in core_context.searcher.operations():
          while batch < op.length:
              x += increment_by
              steps_completed = batch + 1
              if steps_completed % 100 == 0:
                  core_context.train.report_metrics(
                      group=util._LEGACY_TRAINING,
                      steps_completed=steps_completed,
                      metrics={"validation_error": x},
                  )
  
                  op.report_progress(batch)
  
                  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)
                  last_checkpoint_batch = steps_completed
                  if core_context.preempt.should_preempt():
                      return
              batch += 1
  
          core_context.train.report_metrics(
              group="validation",
              steps_completed=steps_completed,
              metrics={"validation_error": x},
          )
          op.report_completed({"foo": x} if metric_as_dict else x)
  
      if last_checkpoint_batch != steps_completed:
          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)
  
file_path: determined/e2e_tests/tests/fixtures/custom_searcher/model_coreapi.py
imports: import logging
  import pathlib
  import sys
  import determined
  from determined.common import util
label_desc: Use image node_id 3 for calling a global function with example usage: main(core_context, latest_checkpoint, trial_id, increment_by, metric_as_dict) without return types