import re


def parse_results_for_ipus_used(output):
    """Finds the number of IPUs used in the model by looking for
       string with format ' On 2 IPUs.' in output"""
    shards_regex = r" On ([\d.]+) IPUs."
    for line in output.split("\n"):
        matches = re.match(shards_regex, line)
        if matches:
            shards = matches.group(1)
            return int(shards)
    raise AssertionError("Expecting line detailing IPU usage "
                         "eg. ' On 2 IPUs.'")