compositional_graph_models/models.py
def _left_right_subgraphs(graph: dgl.DGLGraph) -> Tuple[dgl.DGLGraph, dgl.DGLGraph]:
        """
        Given a graph containing multiple equations, produce subgraphs containing just
        the left (resp. the right) expressions in those equalities.

        Works with both a typical input graph and a computational graph processed
        through _prepare_graph().

        Parameters
        ----------
        graph
            A graph containing multiple equalities.

        Returns
        -------
        left_subgraph : DGLGraph
            A graph of expressions on the left-hand side of equations in the input.
        right_subgraph : DGLGraph
            A graph of expressions on the right-hand side of equations in the input.
        """
        left_subgraph = dgl.node_subgraph(
            graph, graph.ndata[data.SIDE_FIELD] == data.SIDE_LEFT
        )
        right_subgraph = dgl.node_subgraph(
            graph, graph.ndata[data.SIDE_FIELD] == data.SIDE_RIGHT
        )

        # Workaround for https://github.com/dmlc/dgl/issues/2310.
        # Equations list all of their left nodes before all of their right nodes, so
        # count the nodes on each side by running sum, then take alternating elements.
        subexpression_node_counts = torch.unique_consecutive(
            graph.ndata[data.SIDE_FIELD], return_counts=True
        )[1]
        left_counts = subexpression_node_counts[::2]
        right_counts = subexpression_node_counts[1::2]

        left_subgraph.set_batch_num_nodes(left_counts)
        left_subgraph.set_batch_num_edges(left_counts - 1)

        right_subgraph.set_batch_num_nodes(right_counts)
        right_subgraph.set_batch_num_edges(right_counts - 1)

        return left_subgraph, right_subgraph

        Given a graph containing multiple equations, produce subgraphs containing just
        the left (resp. the right) expressions in those equalities.

        Works with both a typical input graph and a computational graph processed
        through _prepare_graph().

        Parameters
        ----------
        graph
            A graph containing multiple equalities.

        Returns
        -------
        left_subgraph : DGLGraph
            A graph of expressions on the left-hand side of equations in the input.
        right_subgraph : DGLGraph
            A graph of expressions on the right-hand side of equations in the input.
        
Given a graph containing multiple equations, produce subgraphs containing just
the left (resp. the right) expressions in those equalities.

Works with both a typical input graph and a computational graph processed
through _prepare_graph().

Parameters

graph
A graph containing multiple equalities.

Returns

left_subgraph : DGLGraph
A graph of expressions on the left-hand side of equations in the input.
right_subgraph : DGLGraph
A graph of expressions on the right-hand side of equations in the input.
Given a graph containing multiple equations produce subgraphs containing just the left ( resp . the right ) expressions in those equalities . Works with both a typical input graph and a computational graph processed through _prepare_graph () . Parameters graph A graph containing multiple equalities . Returns left_subgraph : DGLGraph A graph of expressions on the left - hand side of equations in the input . right_subgraph : DGLGraph A graph of expressions on the right - hand side of equations in the input .
def _left_right_subgraphs(graph: dgl.DGLGraph) -> Tuple[dgl.DGLGraph, dgl.DGLGraph]:
        left_subgraph = dgl.node_subgraph(
            graph, graph.ndata[data.SIDE_FIELD] == data.SIDE_LEFT
        )
        right_subgraph = dgl.node_subgraph(
            graph, graph.ndata[data.SIDE_FIELD] == data.SIDE_RIGHT
        )
        subexpression_node_counts = torch.unique_consecutive(
            graph.ndata[data.SIDE_FIELD], return_counts=True
        )[1]
        left_counts = subexpression_node_counts[::2]
        right_counts = subexpression_node_counts[1::2]
        left_subgraph.set_batch_num_nodes(left_counts)
        left_subgraph.set_batch_num_edges(left_counts - 1)
        right_subgraph.set_batch_num_nodes(right_counts)
        right_subgraph.set_batch_num_edges(right_counts - 1)
        return left_subgraph, right_subgraph
def _left_right_subgraphs ( graph : dgl . DGLGraph ) -> Tuple [ dgl . DGLGraph , dgl . DGLGraph ] : left_subgraph = dgl . node_subgraph ( graph , graph . ndata [ data . SIDE_FIELD ] == data . SIDE_LEFT ) right_subgraph = dgl . node_subgraph ( graph , graph . ndata [ data . SIDE_FIELD ] == data . SIDE_RIGHT ) subexpression_node_counts = torch . unique_consecutive ( graph . ndata [ data . SIDE_FIELD ] , return_counts = True ) [ 1 ] left_counts = subexpression_node_counts [ : : 2 ] right_counts = subexpression_node_counts [ 1 : : 2 ] left_subgraph . set_batch_num_nodes ( left_counts ) left_subgraph . set_batch_num_edges ( left_counts - 1 ) right_subgraph . set_batch_num_nodes ( right_counts ) right_subgraph . set_batch_num_edges ( right_counts - 1 ) return left_subgraph , right_subgraph
Given a graph containing multiple equations, produce subgraphs containing just
the left (resp.
Given a graph containing multiple equations produce subgraphs containing just the left ( resp .
"""
        Given a graph containing multiple equations, produce subgraphs containing just
        the left (resp. the right) expressions in those equalities.

        Works with both a typical input graph and a computational graph processed
        through _prepare_graph().

        Parameters
        ----------
        graph
            A graph containing multiple equalities.

        Returns
        -------
        left_subgraph : DGLGraph
            A graph of expressions on the left-hand side of equations in the input.
        right_subgraph : DGLGraph
            A graph of expressions on the right-hand side of equations in the input.
        """ # Workaround for https://github.com/dmlc/dgl/issues/2310. # Equations list all of their left nodes before all of their right nodes, so # count the nodes on each side by running sum, then take alternating elements.
graph
dgl.DGLGraph