What We Can and Cannot Infer from a GNN Library's Source Code
Reading a library's source is one of the most direct ways to learn what it does. It also has limits. You can learn a lot about the API, the control flow and the scope; you cannot learn runtime speed or generalisation by reading. This article maps that boundary, using TGraphX 1.5.1 as the worked case.
Everything below refers to the installed 1.5.1 package. File paths are relative to its tgraphx/ directory, and the examples were tested on CPU. A claim about source code without a version is hard to check and goes stale quietly.
What source code can establish
1. API contract and dependencies
Signatures, accepted arguments and declared requirements are facts you can read off directly:
import inspect
from importlib.metadata import requires
import tgraphx
print(tgraphx.__version__) # this article: 1.5.1
print([r for r in requires("tgraphx") if "extra" not in r])
# ['torch>=1.13', 'torchvision>=0.14', 'pyyaml>=5.4']
print(list(inspect.signature(tgraphx.Graph.__init__).parameters)[1:9])
# ['node_features', 'edge_index', 'edge_weight', 'edge_features',
# 'node_labels', 'edge_labels', 'graph_label', 'metadata']
The signature shows something a summary would hide: the third positional argument of Graph is edge_weight, not edge_features. Pass these by keyword. The constructor (core/graph.py) also validates shapes, index ranges and devices, and Graph.to() moves the tensor fields and the masks stored in metadata, but not other tensors you put into metadata.
The published wheel is tagged py3-none-any: apart from the dashboard's CSS and JavaScript it is Python source, with no compiled code and no C++ or CUDA files. So installing TGraphX itself compiles nothing, and the package ships no custom CUDA kernels of its own. GPU work goes through PyTorch operations.
The names in tgraphx.__all__ are the top-level API. They are not the whole public surface: tgraphx.experiments and tgraphx.kg are public subpackages with their own exports. A leading underscore, as in layers/_scatter.py, marks a module as internal.
2. Which operations run, path by path
layers/base.py shows that TensorMessagePassingLayer aggregates with index_add for sum and mean and with a scatter_reduce_-based helper for max. ConvMessagePassing and LinearMessagePassing inherit from it. TensorGraphSAGELayer, TensorGATLayer and TensorGINLayer do not; they call helpers in layers/_scatter.py or run their own chunked loops. So a sentence about the base class does not automatically describe them.
The same care applies to numerical details. edge_softmax in _scatter.py computes in float32 when given float16 or bfloat16 scores, then casts back. It would be easy to write "TGraphX attention upcasts to float32". But layers/gat.py has a second, chunked forward path, used when you pass a chunk_size smaller than the number of edges (including added self-loops), that normalises attention without calling edge_softmax. Reading finds this; a short check confirms it:
import torch
import tgraphx.layers.gat as gat_module
calls = []
original = gat_module.edge_softmax
def spy(scores, target, num_nodes):
calls.append(scores.dtype)
return original(scores, target, num_nodes)
x = torch.randn(10, 3, 4, 4)
edge_index = torch.randint(0, 10, (2, 30))
layer = tgraphx.TensorGATLayer(3, 8, num_heads=2).eval()
gat_module.edge_softmax = spy
try:
full = layer(x, edge_index)
calls_full = len(calls)
chunked = layer(x, edge_index, chunk_size=4)
calls_chunked = len(calls) - calls_full
finally:
gat_module.edge_softmax = original
print(calls_full, calls_chunked) # 1 0
assert torch.allclose(full, chunked, atol=1e-5) # same result in float32
The two paths agree here in float32. Whether they behave the same under low precision is a question for a test, not for reading.
3. Scope: what is there
distributed.py states in its docstring that TGraphX does not ship a distributed training framework. The same module defines helpers, including maybe_wrap_ddp, which wraps a model in DistributedDataParallel when a process group is initialised. Both facts matter: "no distributed support at all" would be wrong, and so would "handles distributed training".
4. Scope: what is absent
Absence claims are the risky ones. "I saw no sampling module, so the library has no graph sampling" is a tempting inference, and for TGraphX it would be false. An absence claim needs a complete search of a stated version:
import ast
from pathlib import Path
root = Path(tgraphx.__file__).parent
hits = {}
for path in sorted(root.rglob("*.py")):
tree = ast.parse(path.read_text(encoding="utf-8"))
names = [
node.name for node in tree.body
if isinstance(node, ast.ClassDef) and not node.name.startswith("_")
and ("Sampler" in node.name or "Loader" in node.name)
]
if names:
hits[path.relative_to(root).as_posix()] = names
for file, names in hits.items():
print(f"{file}: {', '.join(names)}")
assert "NeighborLoader" in hits["loaders.py"]
assert "GraphSAINTNodeSampler" in hits["graphsaint.py"]
assert "ClusterLoader" in hits["cluster_gcn.py"]
assert "hetero_sampling.py" not in hits # it defines functions, not classes
Neighbour sampling, GraphSAINT and Cluster-GCN loaders are all there. Note the last line: even this search is incomplete, because sampling.py, hetero_sampling.py and temporal_sampling.py offer sampling as functions such as neighbor_sample and hetero_neighbor_sample. State what you searched and how. "No class of this name in version X" is a much weaker claim than "the library cannot do this".
5. Error handling
Source shows when errors are raised and what they say, and where nothing is checked. Reading can also expose traps. The signature check_leakage(graph=None, train_mask=None, val_mask=None, test_mask=None, *, strict=True) shows that passing three masks positionally would bind the first one to graph.
6. Tests
A test suite shows which behaviours the developers chose to pin down. The 1.5.1 wheel contains no tests, so judging coverage means reading the repository at the matching tag. A missing test does not show that a behaviour is broken, only that nothing you saw would catch it if it were.
Inferable or not
| Question | From reading source? |
|---|---|
| Which aggregation primitive does a layer call? | Yes, per code path |
| Is there a Python loop over nodes? | Yes, after reading the whole forward path |
Which inputs does Graph reject? |
Yes |
| Is a feature present? | Yes |
| Is a feature absent? | Only relative to a complete search of a stated version |
| Does my distributed job work and scale? | No |
| How does cost grow with graph size? | Partly (asymptotics, not constants) |
| How fast is it on my GPU? | No |
| How much memory will it use? | Estimates only |
| Is the documentation accurate? | Claim by claim, yes |
| Are there bugs? | Reading can find some; it cannot show there are none |
| Will it generalise to my task? | No |
What source code cannot tell you
Runtime performance
Source shows which primitives run, not how fast they are on your hardware, graph sizes and batch sizes. A good primitive does not guarantee good performance: it can be fed badly shaped data or surrounded by unnecessary copies. Measure. A related audit is in how optimized is TGraphX?.
Generalisation
Whether an architecture works on your data distribution is an empirical question, whatever the theory says about its expressiveness.
Correctness
Reading and running find different problems. A check against a definition or an independent implementation is often the quickest test. By definition, modularity is 0 when every node is in one community:
import networkx as nx
from tgraphx import mining
karate_edges, num_nodes = mining.karate_club_graph()
one_community = torch.zeros(num_nodes, dtype=torch.long)
reference = nx.Graph(karate_edges.t().tolist())
print(nx.community.modularity(reference, [set(range(num_nodes))])) # 0.0
print(float(mining.modularity(karate_edges, one_community, num_nodes))) # about 0.40
In 1.5.1, tgraphx.mining.modularity does not return 0 here, so use networkx.community.modularity for modularity values. The function's name and signature give no hint of this; a two-line check does.
Documentation accuracy over time
Implementation and documentation drift apart. When they conflict, report what the code does for the version you read, and file the discrepancy as a bug.
How to report a source review honestly
- Name the version and file. "Confirmed in
layers/_scatter.py, 1.5.1" can be checked. - Separate reading from inference. "The base class calls
index_add" is read. "No layer loops over nodes" is an inference that needs every forward path. - Do not infer performance from primitives.
- Say what you did not read.
- Run something when you can, and say which claims were run.
Applying this to TGraphX 1.5.1
Supported by reading the source, with the files to check:
- Aggregation in the tensor layers uses PyTorch index and scatter operations; the loops in their chunked paths run over edge chunks, not nodes (
layers/). edge_softmaxupcasts low-precision scores; the chunkedTensorGATLayerpath does not use it (layers/_scatter.py,layers/gat.py).- There is no distributed training framework, but there are DDP helpers (
distributed.py). Graphvalidates at construction (core/graph.py,core/graph_utils.py).- Neighbour, GraphSAINT and Cluster-GCN sampling exist (
loaders.py,graphsaint.py,cluster_gcn.py).
Not supported by reading: speed compared with other libraries, behaviour at particular graph sizes, suitability for a research task, or the absence of bugs.
For a walk through one data structure, see reading the TGraphX source; for turning verified facts into documentation, see source-grounded documentation.