code: def _prepare_folder(
      self, trainer: ITrainer, *, check_num_keep: bool = True
  ) -> str:
      state = trainer.state
      sub_folder = os.path.join(trainer.workspace, self.key)
      os.makedirs(sub_folder, exist_ok=True)
      if not check_num_keep:
          sub_folder = os.path.join(sub_folder, str(state.step))
          os.makedirs(sub_folder, exist_ok=True)
          return sub_folder
      current_steps = sorted(map(int, os.listdir(sub_folder)))
      if len(current_steps) >= self.num_keep:
          must_keep = set()
          checkpoint_folder = trainer.checkpoint_folder
          if checkpoint_folder is not None:
              score_path = os.path.join(checkpoint_folder, SCORES_FILE)
              if os.path.isfile(score_path):
                  with open(score_path, "r") as f:
                      for key in json.load(f):
                          name = os.path.splitext(key)[0]
                          must_keep.add(int(name[len(PT_PREFIX) :]))
          num_left = len(current_steps)
          for step in current_steps:
              if step in must_keep:
                  continue
              shutil.rmtree(os.path.join(sub_folder, str(step)))
              num_left -= 1
              if num_left < self.num_keep:
                  break
      sub_folder = os.path.join(sub_folder, str(state.step))
      os.makedirs(sub_folder, exist_ok=True)
      return sub_folder
  
imports: import os
  import json
  import time
  import shutil
  import getpass
  import platform
  from typing import Any
  from typing import Dict
  from typing import Optional
  from cftool.misc import lock_manager
  from cftool.misc import print_warning
  from cftool.misc import fix_float_to_length
  from ..schema import ITrainer
  from ..schema import StepOutputs
  from ..schema import TrainerState
  from ..schema import MetricsOutputs
  from ..schema import TrainerCallback
  from ..constants import PT_PREFIX
  from ..constants import SCORES_FILE
label_desc: Use image node_id 2 for calling the ArtifactCallback obj's underlying member method code with example usage: obj._prepare_folder(trainer) and returns: sub_folder, sub_folder