code: def apply_rank_size_from_pattern(
      filename, rank, size, create_dir=True
  ):
      if not re.search(r"\{rank\}", filename):
          logging.warning(
              "Keyword `{rank}` is not found in file pattern: %s, which may cause collision in file access."
              % filename
          )
  
      filename = re.sub(
          r"\{rank\}",
          str(rank),
          re.sub(r"\{size\}", str(size), filename),
      )
      if create_dir:
          filedir = os.path.dirname(filename)
          if filedir:
              try:
                  os.makedirs(filedir)
              except FileExistsError:
                  pass
      return filename
  
file_path: tutel/tutel/system.py
imports: import os, sys
  import re
  import logging
label_desc: Use image node_id 8 for calling a global function with example usage: apply_rank_size_from_pattern(filename, rank, size, create_dir) and returns: filename