def graph_to_groups(graph):
    """ Transform a qubit graph into a list of grouped nodes """
    groups = []
    for nodeID in graph.nodes:
        node = graph.nodes[nodeID]
        if "contraction" in node:
            groups.append((nodeID, *(eaten for eaten in node["contraction"]), ))
        else:
            groups.append((nodeID, ))
    return tuple(groups)