class_docstr: Utility static functions to handle model directories.
class_docstr_tok: ["Utility","static","functions","to","handle","model","directories","."]
docstr: Returns the trial id - best effort, None if unable.
  
  Args:
    directory: model directory (string).
    phoenix_spec: PhoenixSpec proto.
  
  Returns:
    an integer holding the trial id. Works for regular trial runs where the
    trial id is the directory name, and for TFX pipelines, where the trial
    id is encoded in the path as "Trial-xxxxxx".
    Returns None in other cases.
docstr_tok: ["Returns","the","trial","id","-","best","effort",",","None","if","unable",".","Args",":","directory",":","model","directory","(","string",")",".","phoenix_spec",":","PhoenixSpec","proto",".","Returns",":","an","integer","holding","the","trial","id",".","Works","for","regular","trial","runs","where","the","trial","id","is","the","directory","name",",","and","for","TFX","pipelines",",","where","the","trial","id","is","encoded","in","the","path","as","``","Trial-xxxxxx","''",".","Returns","None","in","other","cases","."]
code: def get_trial_id(directory, phoenix_spec):
      """Returns the trial id - best effort, None if unable.
  
      Args:
        directory: model directory (string).
        phoenix_spec: PhoenixSpec proto.
  
      Returns:
        an integer holding the trial id. Works for regular trial runs where the
        trial id is the directory name, and for TFX pipelines, where the trial
        id is encoded in the path as "Trial-xxxxxx".
        Returns None in other cases.
      """
      if (
          phoenix_spec.HasField("replay")
          and len(phoenix_spec.replay.towers) == 1
      ):
          return 1
  
      dir_name = os.path.basename(directory)
      if dir_name.isdigit():
          return int(dir_name)
      elif dir_name.startswith("trial_"):
          trial_number = dir_name[len("trial_") :]
          if all(c in string.hexdigits for c in trial_number):
              return int(int(trial_number, 16) % 1e8)
  
      tfx_trial_prefix = "Trial-"
      dirs = directory.split("/")
      for level in dirs:
          if level.startswith(tfx_trial_prefix):
              return int(level[len(tfx_trial_prefix) :])
  
      return None
  
imports: import collections
  import os
  import string
  import time
  from absl import flags
  from absl import logging
  from model_search import block
  from model_search import block_builder
  from model_search import hparam
  from model_search import utils
  from model_search.proto import hparam_pb2
  from model_search.proto import phoenix_spec_pb2
  from model_search.proto import transfer_learning_spec_pb2
  import numpy
  import tensorflow.compat.v2
  import tf_slim
  from google.protobuf import text_format
label_desc: Use image node_id 1 for calling the DirectoryHandler obj's underlying member method code with example usage: obj.get_trial_id(directory, phoenix_spec) and returns: None, int, int, int, int