def group_by_simulation(d):
    """
    Group metrics by simulation (gset, awset, ...).
    """

    r = {}

    for type in d:
        simulation = type.split("~")[0]

        if not simulation in r:
            r[simulation] = {}

        r[simulation][type] = d[type]

    return r