A disconnected graph contains separate components with no edges between them. In graph neural network workflows, a disjoint graph combines multiple independent molecular or protein graphs without creating connections between examples. section 11.5.5
Use a disconnected graph to batch variable-size inputs efficiently:
- Stack node features from every graph into one matrix. section 11.5.5
- Adjust edge indices so each edge still references the correct component. section 11.5.5
- Track each node’s original graph with a batch vector. section 11.5.5
- Apply message passing across the combined structure, then pool nodes separately by batch index. section 11.5.5
Three molecular graphs
Batching graphs with 10, 15, and 12 atoms creates 37 nodes, a 37×78 feature matrix, and a 37-entry batch vector marking each molecule. No edges cross between molecules. section 11.5.5
from torch_geometric.data import Batch
def collate(data_list):
batchA = Batch.from_data_list([data[-1] for data in data_list])
batchB = Batch.from_data_list([data[0] for data in data_list])
return batchA, batchBUse Batch.from_data_list to combine graph objects during loading, preserving separate molecular and protein graph batches. section 11.5.5
