parameters: (self, new_node, new_node_out_port: int = None)
docstring: Replaces node 'old_node' with a node 'new_node' preserving edge attributes.
          :param old_node: node to be replaced.
          :param new_node: node to replace with.
          :return: None
docstring_summary: Replaces node 'old_node' with a node 'new_node' preserving edge attributes.
          :param old_node: node to be replaced.
          :param new_node: node to replace with.
          :return: None
docstring_tokens: Replaces node old_node with a node new_node preserving edge attributes . : param old_node : node to be replaced . : param new_node : node to replace with . : return : None
function: def replace_node(self, new_node, new_node_out_port: int = None):
          """
          Replaces node 'old_node' with a node 'new_node' preserving edge attributes.
          :param old_node: node to be replaced.
          :param new_node: node to replace with.
          :return: None
          """
          assert self.graph is new_node.graph
          assert self.id != new_node.id, "New node and replaceable node are the same"
          graph = self.graph
          # save output edges and reconnect them to new node
          for _, dst_node_name, edge_attrs in graph.out_edges(self.id, data=True):
              new_edge_attrs = deepcopy(edge_attrs)
              if new_node_out_port is not None:
                  assert 'out' not in edge_attrs or edge_attrs['out'] == 0, \
                      'replace_node function can replace old node with a single output port only if new_node_out_port is ' \
                      'specified'
                  new_edge_attrs.update({'out': new_node_out_port})
              graph.add_edge(new_node.id, dst_node_name, **new_edge_attrs)
  
          # if the node for replace is output node then we propagate this attribute to a new node
          if len(self.out_nodes()) == 1 and self.out_node().has('op') and self.out_node().op == 'Result':
              graph.remove_node(self.out_node().id)
              add_opoutput(graph, new_node.id, 0, False)
          graph.remove_node(self.id)
function_tokens: def replace_node ( self , new_node , new_node_out_port : int = None ) : assert self . graph is new_node . graph assert self . id != new_node . id , "New node and replaceable node are the same" graph = self . graph # save output edges and reconnect them to new node for _ , dst_node_name , edge_attrs in graph . out_edges ( self . id , data = True ) : new_edge_attrs = deepcopy ( edge_attrs ) if new_node_out_port is not None : assert 'out' not in edge_attrs or edge_attrs [ 'out' ] == 0 , 'replace_node function can replace old node with a single output port only if new_node_out_port is ' 'specified' new_edge_attrs . update ( { 'out' : new_node_out_port } ) graph . add_edge ( new_node . id , dst_node_name , * * new_edge_attrs ) # if the node for replace is output node then we propagate this attribute to a new node if len ( self . out_nodes ( ) ) == 1 and self . out_node ( ) . has ( 'op' ) and self . out_node ( ) . op == 'Result' : graph . remove_node ( self . out_node ( ) . id ) add_opoutput ( graph , new_node . id , 0 , False ) graph . remove_node ( self . id )