import hashlib
import logging


def uniquify_server_name(server_name: str, experiment_name: str) -> str:
  """Create a unique name for the server.

  Args:
    server_name: name of server. There could be multiple of these per single
      training job.
    experiment_name: name of the experiemnt. This is shared across all machines
      for a given training job. Often this is the log directory.

  Returns:
    name: The name of the server.
  """

  hmod = hashlib.sha256()
  hmod.update(experiment_name.encode("utf-8"))
  hval = hmod.hexdigest()[0:20]
  logging.info(f"Hashing experiment name [{experiment_name}] => {str(hval)}")  #. pylint: disable=logging-fstring-interpolation
  return str(hval) + "__" + server_name