MiniBatchĀ¶

class dgl.graphbolt.MiniBatch(seed_nodes: Optional[Union[torch.Tensor, Dict[str, torch.Tensor]]] = None, node_pairs: Optional[Union[Tuple[torch.Tensor, torch.Tensor], Dict[str, Tuple[torch.Tensor, torch.Tensor]]]] = None, labels: Optional[Union[torch.Tensor, Dict[str, torch.Tensor]]] = None, negative_srcs: Optional[Union[torch.Tensor, Dict[str, torch.Tensor]]] = None, negative_dsts: Optional[Union[torch.Tensor, Dict[str, torch.Tensor]]] = None, sampled_subgraphs: Optional[List[dgl.graphbolt.sampled_subgraph.SampledSubgraph]] = None, input_nodes: Optional[Union[torch.Tensor, Dict[str, torch.Tensor]]] = None, node_features: Optional[Union[Dict[str, torch.Tensor], Dict[Tuple[str, str], torch.Tensor]]] = None, edge_features: Optional[List[Union[Dict[str, torch.Tensor], Dict[Tuple[str, str], torch.Tensor]]]] = None, compacted_node_pairs: Optional[Union[Tuple[torch.Tensor, torch.Tensor], Dict[str, Tuple[torch.Tensor, torch.Tensor]]]] = None, compacted_negative_srcs: Optional[Union[torch.Tensor, Dict[str, torch.Tensor]]] = None, compacted_negative_dsts: Optional[Union[torch.Tensor, Dict[str, torch.Tensor]]] = None)[source]Ā¶

Bases: object

A composite data class for data structure in the graphbolt.

It is designed to facilitate the exchange of data among different components involved in processing data. The purpose of this class is to unify the representation of input and output data across different stages, ensuring consistency and ease of use throughout the loading process.

edge_ids(layer_id: int)Union[Dict[str, torch.Tensor], torch.Tensor][source]Ā¶

Get the edge ids of a layer.

node_ids()Union[torch.Tensor, Dict[str, torch.Tensor]][source]Ā¶

A representation of input nodes in the outermost layer. Contains all nodes in the sampled_subgraphs. - If input_nodes is a tensor: It indicates the graph is homogeneous. - If input_nodes is a dictionary: The keys should be node type and the

value should be corresponding heterogeneous node id.

num_layers()int[source]Ā¶

Return the number of layers.

set_edge_features(edge_features: List[Union[Dict[str, torch.Tensor], Dict[Tuple[str, str], torch.Tensor]]])None[source]Ā¶

Set edge features.

set_node_features(node_features: Union[Dict[str, torch.Tensor], Dict[Tuple[str, str], torch.Tensor]])None[source]Ā¶

Set node features.

to(device: torch.device)[source]Ā¶

Copy MiniBatch to the specified device using reflection.

property blocksĀ¶

Extracts DGL blocks from MiniBatch to construct a graphical structure and ID mappings.

compacted_negative_dsts: Union[torch.Tensor, Dict[str, torch.Tensor]] = NoneĀ¶

Representation of compacted nodes corresponding to ā€˜negative_dstsā€™, where all node ids inside are compacted.

compacted_negative_srcs: Union[torch.Tensor, Dict[str, torch.Tensor]] = NoneĀ¶

Representation of compacted nodes corresponding to ā€˜negative_srcsā€™, where all node ids inside are compacted.

compacted_node_pairs: Union[Tuple[torch.Tensor, torch.Tensor], Dict[str, Tuple[torch.Tensor, torch.Tensor]]] = NoneĀ¶

Representation of compacted node pairs corresponding to ā€˜node_pairsā€™, where all node ids inside are compacted.

edge_features: List[Union[Dict[str, torch.Tensor], Dict[Tuple[str, str], torch.Tensor]]] = NoneĀ¶

Edge features associated with the ā€˜sampled_subgraphsā€™. - If keys are single strings: It means the graph is homogeneous, and the keys are feature names. - If keys are tuples: It means the graph is heterogeneous, and the keys are tuples of ā€˜(edge_type, feature_name)ā€™. Note, edge type is single string of format ā€˜str:str:strā€™.

input_nodes: Union[torch.Tensor, Dict[str, torch.Tensor]] = NoneĀ¶
A representation of input nodes in the outermost layer. Conatins all nodes

in the ā€˜sampled_subgraphsā€™.

  • If input_nodes is a tensor: It indicates the graph is homogeneous.

  • If input_nodes is a dictionary: The keys should be node type and the value should be corresponding heterogeneous node id.

labels: Union[torch.Tensor, Dict[str, torch.Tensor]] = NoneĀ¶

Labels associated with seed nodes / node pairs in the graph. - If labels is a tensor: It indicates the graph is homogeneous. The value

should be corresponding labels to given ā€˜seed_nodesā€™ or ā€˜node_pairsā€™.

  • If labels is a dictionary: The keys should be node or edge type and the value should be corresponding labels to given ā€˜seed_nodesā€™ or ā€˜node_pairsā€™.

negative_dsts: Union[torch.Tensor, Dict[str, torch.Tensor]] = NoneĀ¶

Representation of negative samples for the tail nodes in the link prediction task. - If negative_dsts is a tensor: It indicates a homogeneous graph. - If negative_dsts is a dictionary: The key should be edge type, and the

value should correspond to the negative samples for head nodes of the given type.

property negative_node_pairsĀ¶

negative_node_pairs is a representation of negative graphs used for evaluating or computing loss in link prediction tasks. - If negative_node_pairs is a tuple: It indicates a homogeneous graph containing two tensors representing source-destination node pairs. - If negative_node_pairs is a dictionary: The keys should be edge type, and the value should be a tuple of tensors representing node pairs of the given type.

negative_srcs: Union[torch.Tensor, Dict[str, torch.Tensor]] = NoneĀ¶

Representation of negative samples for the head nodes in the link prediction task. - If negative_srcs is a tensor: It indicates a homogeneous graph. - If negative_srcs is a dictionary: The key should be edge type, and the

value should correspond to the negative samples for head nodes of the given type.

node_features: Union[Dict[str, torch.Tensor], Dict[Tuple[str, str], torch.Tensor]] = NoneĀ¶

A representation of node features. - If keys are single strings: It means the graph is homogeneous, and the keys are feature names. - If keys are tuples: It means the graph is heterogeneous, and the keys are tuples of ā€˜(node_type, feature_name)ā€™.

node_pairs: Union[Tuple[torch.Tensor, torch.Tensor], Dict[str, Tuple[torch.Tensor, torch.Tensor]]] = NoneĀ¶

Representation of seed node pairs utilized in link prediction tasks. - If node_pairs is a tuple: It indicates a homogeneous graph where each

tuple contains two tensors representing source-destination node pairs.

  • If node_pairs is a dictionary: The keys should be edge type, and the value should be a tuple of tensors representing node pairs of the given type.

property node_pairs_with_labelsĀ¶

Get a node pair tensor and a label tensor from MiniBatch. They are used for evaluating or computing loss. For homogeneous graph, it will return (node_pairs, labels) as result; for heterogeneous graph, the node_pairs and labels will both be a dict with etype as the key. - If itā€™s a link prediction task, node_pairs will contain both negative and positive node pairs and labels will consist of 0 and 1, indicating whether the corresponding node pair is negative or positive. - If itā€™s an edge classification task, this function will directly return compacted_node_pairs for each etype and the corresponding labels. - Otherwise it will return None.

property positive_node_pairsĀ¶

positive_node_pairs is a representation of positive graphs used for evaluating or computing loss in link prediction tasks. - If positive_node_pairs is a tuple: It indicates a homogeneous graph containing two tensors representing source-destination node pairs. - If positive_node_pairs is a dictionary: The keys should be edge type, and the value should be a tuple of tensors representing node pairs of the given type.

sampled_subgraphs: List[dgl.graphbolt.sampled_subgraph.SampledSubgraph] = NoneĀ¶

A list of ā€˜SampledSubgraphā€™s, each one corresponding to one layer, representing a subset of a larger graph structure.

seed_nodes: Union[torch.Tensor, Dict[str, torch.Tensor]] = NoneĀ¶

Representation of seed nodes used for sampling in the graph. - If seed_nodes is a tensor: It indicates the graph is homogeneous. - If seed_nodes is a dictionary: The keys should be node type and the

value should be corresponding heterogeneous node ids.