nncf/experimental/torch/search_building_blocks/search_blocks.py
def check_graph_has_no_hanging_edges_after_block_removal(graph: SearchGraph,
                                                         start_node: SearchGraphNode,
                                                         end_node: SearchGraphNode) -> bool:
    """
    The subgraph is traversed starting with the start_node and ending with the end_node
    to determine that after deleting such a block there are no dangling edges in the graph.
    """
    #            A
    #           / \
    #          /   \
    #         /     \
    #    start_node  |   Edge A-C is dangling edges
    #        |       |
    #         \     /
    #          \   /
    #            C
    #            |
    #           ...
    #            |
    #         end_node

    q = deque([start_node])
    addit_nodes = set()
    nodes = []
    current_node = start_node
    potential_end_nodes = []
    while len(q) != 0:
        current_node = q.pop()
        if current_node.main_id != start_node.main_id:
            prev_nodes = graph.get_prev_nodes(current_node.node_key)
            if len(prev_nodes) > 1:
                for pn in prev_nodes:
                    if pn.bottom_id < start_node.bottom_id:
                        return False  # there is extra edge
                    addit_nodes.add(pn)
        if current_node.node_key == end_node.node_key:
            continue
        if current_node.main_id > end_node.main_id:
            return False
        if current_node not in nodes:
            nodes.append(current_node)
            next_nodes = graph.get_next_nodes(current_node.node_key)
            if len(next_nodes) == 0:
                potential_end_nodes.append(current_node)
            for next_node in next_nodes:
                q.appendleft(next_node)
    if len(q) > 0 or len(potential_end_nodes) > 0:
        return False
    for node in addit_nodes:
        if node not in nodes:
            return False
    nodes.append(end_node)
    return True

    The subgraph is traversed starting with the start_node and ending with the end_node
    to determine that after deleting such a block there are no dangling edges in the graph.
    
The subgraph is traversed starting with the start_node and ending with the end_node
to determine that after deleting such a block there are no dangling edges in the graph.
The subgraph is traversed starting with the start_node and ending with the end_node to determine that after deleting such a block there are no dangling edges in the graph .
def check_graph_has_no_hanging_edges_after_block_removal(graph: SearchGraph,
                                                         start_node: SearchGraphNode,
                                                         end_node: SearchGraphNode) -> bool:
    q = deque([start_node])
    addit_nodes = set()
    nodes = []
    current_node = start_node
    potential_end_nodes = []
    while len(q) != 0:
        current_node = q.pop()
        if current_node.main_id != start_node.main_id:
            prev_nodes = graph.get_prev_nodes(current_node.node_key)
            if len(prev_nodes) > 1:
                for pn in prev_nodes:
                    if pn.bottom_id < start_node.bottom_id:
                        return False  
                    addit_nodes.add(pn)
        if current_node.node_key == end_node.node_key:
            continue
        if current_node.main_id > end_node.main_id:
            return False
        if current_node not in nodes:
            nodes.append(current_node)
            next_nodes = graph.get_next_nodes(current_node.node_key)
            if len(next_nodes) == 0:
                potential_end_nodes.append(current_node)
            for next_node in next_nodes:
                q.appendleft(next_node)
    if len(q) > 0 or len(potential_end_nodes) > 0:
        return False
    for node in addit_nodes:
        if node not in nodes:
            return False
    nodes.append(end_node)
    return True
def check_graph_has_no_hanging_edges_after_block_removal ( graph : SearchGraph , start_node : SearchGraphNode , end_node : SearchGraphNode ) -> bool : q = deque ( [ start_node ] ) addit_nodes = set ( ) nodes = [ ] current_node = start_node potential_end_nodes = [ ] while len ( q ) != 0 : current_node = q . pop ( ) if current_node . main_id != start_node . main_id : prev_nodes = graph . get_prev_nodes ( current_node . node_key ) if len ( prev_nodes ) > 1 : for pn in prev_nodes : if pn . bottom_id < start_node . bottom_id : return False addit_nodes . add ( pn ) if current_node . node_key == end_node . node_key : continue if current_node . main_id > end_node . main_id : return False if current_node not in nodes : nodes . append ( current_node ) next_nodes = graph . get_next_nodes ( current_node . node_key ) if len ( next_nodes ) == 0 : potential_end_nodes . append ( current_node ) for next_node in next_nodes : q . appendleft ( next_node ) if len ( q ) > 0 or len ( potential_end_nodes ) > 0 : return False for node in addit_nodes : if node not in nodes : return False nodes . append ( end_node ) return True
The subgraph is traversed starting with the start_node and ending with the end_node
to determine that after deleting such a block there are no dangling edges in the graph.
The subgraph is traversed starting with the start_node and ending with the end_node to determine that after deleting such a block there are no dangling edges in the graph .
"""
    The subgraph is traversed starting with the start_node and ending with the end_node
    to determine that after deleting such a block there are no dangling edges in the graph.
    """ #            A #           / \ #          /   \ #         /     \ #    start_node  |   Edge A-C is dangling edges #        |       | #         \     / #          \   / #            C #            | #           ... #            | #         end_node # there is extra edge
graph
SearchGraph
start_node
SearchGraphNode
end_node
SearchGraphNode