def remap_dict(d, map):
    """
    Utility function to remap state dict keys according to var_map.
    """
    out = {}
    for new_key, key in map.iteritems():
        out[new_key] = d[key]
    return out
