<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def sort_topologically(dag):
 """Sort the dag breath first topologically. Only the nodes inside the dag are returned, i.e. the nodes that are also keys. Returns: a topological ordering of the DAG. Raises: an error if this is not possible (graph is not valid). """

    dag = copy.deepcopy(dag)
    sorted_nodes = []
    independent_nodes = deque(get_independent_nodes(dag))
    while independent_nodes:
        node = independent_nodes.popleft()
        sorted_nodes.append(node)
        # this alters the dag so that we are sure we are visiting the nodes only once
        downstream_nodes = dag[node]
        while downstream_nodes:
            downstream_node = downstream_nodes.pop(0)
            if downstream_node not in dag:
                continue
            if not has_dependencies(downstream_node, dag):
                independent_nodes.append(downstream_node)

    if len(sorted_nodes) != len(dag.keys()):
        raise ValueError('graph is not acyclic')
    return sorted_nodes