from typing import Sequence
from typing import Mapping


def summarize_outer_cfg(outer_cfg: Sequence[str]) -> Mapping[str, float]:
  """Convert the outer config (hparams tuned via population) to a dict.

  This expects each entry in the outer_cfg to have gin style bindings -- so
  "Adam.learning_rate=1e-3" would be a valid config.

  Args:
    outer_cfg: Sequence of gin bindings.

  Returns:
    dictionary with floating point values.
  """
  to_write = {}
  if outer_cfg:
    for o in outer_cfg:
      name, value = o.split("=")
      try:
        value = float(value)
        to_write[f"outer_cfg/{name}"] = value
      except ValueError:
        # Failed to parse value as float. Ignore it and don't log it.
        pass
  return to_write