code: def _follow_test_experiment_logs(
      sess: api.Session, exp_id: int
  ) -> None:
      def print_progress(active_stage: int, ended: bool) -> None:
          # There are four sequential stages of verification. Track the
          # current stage with an index into this list.
          stages = [
              "Scheduling task",
              "Testing training",
              "Testing validation",
              "Testing checkpointing",
          ]
  
          for idx, stage in enumerate(stages):
              if active_stage > idx:
                  color = "green"
                  checkbox = "✔"
              elif active_stage == idx:
                  color = "red" if ended else "yellow"
                  checkbox = "✗" if ended else " "
              else:
                  color = "white"
                  checkbox = " "
              print(
                  termcolor.colored(
                      stage + (25 - len(stage)) * ".", color
                  ),
                  end="",
              )
              print(
                  termcolor.colored(" [" + checkbox + "]", color),
                  end="",
              )
  
              if idx == len(stages) - 1:
                  print("\n" if ended else "\r", end="")
              else:
                  print(", ", end="")
  
      while True:
          exp = bindings.get_GetExperiment(
              sess, experimentId=exp_id
          ).experiment
          trials = bindings.get_GetExperimentTrials(
              sess, experimentId=exp_id
          ).trials
  
          # Wait for experiment to start and initialize a trial.
          runner_state = trials[0].runnerState if trials else None
  
          # Update the active_stage by examining the experiment state and trial runner state.
          if exp.state == bindings.experimentv1State.COMPLETED:
              active_stage = 4
          elif runner_state == "checkpointing":
              active_stage = 3
          elif runner_state == "validating":
              active_stage = 2
          elif runner_state in (None, "UNSPECIFIED", "training"):
              active_stage = 1
          else:
              active_stage = 0
  
          # If the experiment is in a terminal state, output the appropriate
          # message and exit. Otherwise, sleep and repeat.
          if exp.state == bindings.experimentv1State.COMPLETED:
              print_progress(active_stage, ended=True)
              print(
                  termcolor.colored(
                      "Model definition test succeeded! 🎉", "green"
                  )
              )
              return
          elif exp.state == bindings.experimentv1State.CANCELED:
              print_progress(active_stage, ended=True)
              print(
                  termcolor.colored(
                      f"Model definition test (ID: {exp_id}) canceled before "
                      "model test could complete. Please re-run the command.",
                      "yellow",
                  )
              )
              sys.exit(1)
          elif exp.state == bindings.experimentv1State.ERROR:
              print_progress(active_stage, ended=True)
              trial_id = trials[0].id
              try:
                  tlogs = logs.trial_logs(sess, trial_id)
                  logs.pprint_logs(tlogs)
              finally:
                  print(
                      termcolor.colored(
                          "Trial log stream ended. To reopen log stream, run: "
                          "det trial logs -f {}".format(trial_id),
                          "green",
                      )
                  )
              sys.exit(1)
          else:
              print_progress(active_stage, ended=False)
              time.sleep(0.2)
  
imports: import base64
  import json
  import numbers
  import pathlib
  import sys
  import time
  from argparse import ArgumentError, FileType, Namespace
  from pathlib import Path
  from pprint import pformat
  from typing import Any, Dict, Iterable, List, Optional, Sequence, Set, Tuple, Union
  import tabulate
  import termcolor
  import determined
  import determined.cli.render
  import determined.experimental
  import determined.load
  from determined import cli
  from determined.cli import checkpoint, render
  from determined.cli.errors import CliError
  from determined.cli.ntsc import CONFIG_DESC, parse_config_overrides
  from determined.common import api, context, set_logger, util
  from determined.common.api import authentication, bindings, logs
  from determined.common.declarative_argparse import Arg, Cmd, Group
  from determined.experimental import client
  from .checkpoint import render_checkpoint
  from .project import project_by_name
  from .trial import logs_args_description
label_desc: Use image node_id 7 for calling a global function with example usage: _follow_test_experiment_logs(sess, exp_id) without return types