import re


def parse_losses_from_log_file(file_name: str):
    """
    Read a log file produced by VISSL and extract the losses produced
    at each iteration
    """
    iterations = []
    losses = []
    regex = re.compile(r"iter: (.*?); lr: (?:.*?); loss: (.*?);")
    with open(file_name, "r") as file:
        for line in file:
            if not line.startswith("INFO"):
                continue
            match = regex.search(line)
            if match is not None:
                iteration = int(match.group(1))
                loss = float(match.group(2))
                iterations.append(iteration)
                losses.append(loss)
    return iterations, losses