Install. Validate. Run.

From pip install to your first tensor-native graph training run. Below: install, check the environment, then four worked examples — node classification, KG completion, graph generation, and graph RL. Run the blocks in order; they were tested with TGraphX 1.5.1.

install
$pip install tgraphx$python -m tgraphx readiness

1. Tensor node classification

Classify nodes whose features are images, patches, or any [C, H, W] tensor.

●node_classification.pypython
import torch import tgraphx as tgx torch.manual_seed(0) images = torch.randn(64, 3, 8, 8) # 64 nodes, each a [C, H, W] tensor edge_index = torch.randint(0, 64, (2, 256)) # [2, E] y = torch.randint(0, 3, (64,)) # synthetic labels graph = tgx.Graph(x=images, edge_index=edge_index, labels=y) graph = graph.to("cuda" if torch.cuda.is_available() else "cpu") tgx.validate_graph(graph, strict=True) result = tgx.classify_nodes( x=images, edge_index=edge_index, labels=y, model="tensor_gcn", seed=42, device="auto", ) print(result.metrics) # synthetic labels: the accuracy itself means nothing

2. Knowledge-graph completion

●kg_completion.pypython
triples = torch.stack([ torch.randint(0, 50, (400,)), # head torch.randint(0, 4, (400,)), # relation torch.randint(0, 50, (400,)), # tail ], dim=1) result = tgx.kg_completion(triples=triples, num_entities=50, num_relations=4, model="transe", seed=42) print(result.metrics)

3. Graph generation

●generate.pypython
g = tgx.generate_graph("ba", num_nodes=100, m=3, node_shape=(3, 8, 8), seed=42) tgx.describe(g)

4. Graph reinforcement learning

●graph_rl.pypython
rl = tgx.train_graph_rl(env="maxcut", algorithm="random", episodes=5, seed=42)

5. Save & load .tgx

●artifacts.pypython
tgx.save(graph, "runs/exp/graph.tgx") graph_back = tgx.load("runs/exp/graph.tgx") # pickle-based: only load files you trust tgx.classify_nodes(x=images, edge_index=edge_index, labels=y, out_dir="runs/exp") report = tgx.dashboard_audit("runs/exp", return_markdown=True) print(report["ok"], report["files_missing"])

Further reading