TGraphX documentation
Overview
TGraphX is a tensor-native graph intelligence framework for PyTorch research. A common Graph object serves GNNs, graph generation, evolutionary optimization, graph reinforcement learning and graph mining; knowledge graphs have their own container.
Why this exists
Most built-in GNN layers expect one feature vector per node. TGraphX lets nodes carry tensors, for example [C, H, W] patches or [C, D, H, W] volumes. The tensor layers keep that layout through message passing; other shapes can be stored but need your own encoder.
The five surfaces
tgx.Graph— the central data objecttgx.classify_nodes/tgx.kg_completion/tgx.generate_graph/tgx.train_graph_rl— high-level task entrypointstgx.validate_graph,tgx.describe— diagnosticstgx.save,tgx.load—.tgxfilestgx.dashboard_audit— run-level reports
Core concepts
A TGraphX Graph is a typed bundle: per-node feature tensor x, an edge_index, optional edge_attr, optional labels, masks, and metadata. Every field carries explicit shapes.
Tensor shape system
Graph construction rejects inconsistent node counts and edge indices. Layers check rank and channel layout, but do not necessarily reject a different spatial size, so check shapes yourself where it matters.
Validators
validate_graph checks node features, edge_index shape and range, edge-feature length, mask lengths and devices (NaN/Inf with check_finite=True). It runs when you call it.
Artifacts
A .tgx file is a torch.save bundle holding a Graph or KnowledgeGraph: its tensors (moved to CPU), metadata, a format tag and the TGraphX version. It does not record seeds, operation history or the environment. Because it uses pickle, loading a .tgx file can execute code: only load files you created or trust.
Tensor-aware GNNs
classify_nodes supports tensor_gcn for tensor features; easy.train_node_classifier also offers tensor_sage. For GAT and GIN, use the layer classes.
Knowledge graphs
kg_completion accepts transe, distmult and rescal. ComplEx and RotatE (experimental) and SimplE are available as model classes; in 1.5.1 pass an explicit sampler to KGTrainer.
Graph generation
Generators include Erdős–Rényi, Barabási–Albert, Watts–Strogatz and the stochastic block model, each accepting a node_shape for tensor-valued node features. In 1.5.1 use the short names "er", "ba", "ws" and "sbm"; the full method names raise an error. Experimental.
Graph reinforcement learning
train_graph_rl runs environments such as max_cut (alias maxcut), graph_coloring, graph_navigation, shortest_path and vertex_cover. Observations are dictionaries with edge_index and node_features. Experimental.
Graph mining
Motif counting, structural features, kernels and similarity, plus exploratory frequent-pattern primitives (not a gSpan implementation). Results are plain dictionaries and tensors.
Dashboards
A local, read-only dashboard (tgraphx-dashboard --logdir RUNS, with --export-html) displays run artifacts; dashboard_audit reports which expected files are present.
CLI
Errors & aliases
Some entry points accept aliases; list_aliases(name) lists the recorded names and explain_error(e) suggests fixes. In 1.5.1 not every recorded name is defined; the API page lists second names that work.
Interop
to_pyg_data / from_pyg_data (tgraphx.interop, needs torch_geometric) move graphs to and from PyG. Graph.to_networkx() exports topology only.