TGraphX › Insights › Release Hardening in TGraphX: Validation, Serialization Round-Trips, and Metadata
← Back to Insights

Release Hardening in TGraphX: Validation, Serialization Round-Trips, and Metadata

Topic: APIs, tooling and research-engineering workflow

The features that make a research package dependable rarely show up in a feature list: a saved file still loads after an upgrade, a fixed bug stays fixed, invalid input fails with a clear message, and a changed default announces itself. This article reads the TGraphX CHANGELOG as a record of that kind of work, checks the parts you can check from an installed package, and says where the guarantees stop.

This is the second of two version-evolution articles; the first covered API stability and aliases. Examples tested with TGraphX 1.5.1.

Serialization that round-trips

The 1.4.2 entry records that .tgx bundles gained Graph.edge_labels and Graph.graph_features, so edge-level targets and graph-level inputs now survive a save and load:

python
import torch
import tgraphx as tgx
from tgraphx import Graph

g = Graph(node_features=torch.randn(4, 3, 8, 8),          # [N, C, H, W]
          edge_index=torch.tensor([[0, 1, 2], [1, 2, 3]]),
          edge_labels=torch.tensor([1, 0, 1]),
          graph_features=torch.randn(5))

tgx.save_tgraphx(g, "runs/hardening/demo.tgx")
back = tgx.load_tgraphx("runs/hardening/demo.tgx")
for field in ("node_features", "edge_index", "edge_labels", "graph_features"):
    assert torch.equal(getattr(back, field), getattr(g, field)), field

The same entry states that older bundles without those two keys still load unchanged. You can imitate such a payload by deleting the keys. This is a simulation of the older layout, not a file written by an old release:

python
# torch.load unpickles: only open bundles you trust
bundle = torch.load("runs/hardening/demo.tgx", weights_only=False)
del bundle["payload"]["edge_labels"], bundle["payload"]["graph_features"]
torch.save(bundle, "runs/hardening/older_layout.tgx")

old = tgx.load_tgraphx("runs/hardening/older_layout.tgx")
assert old.edge_labels is None and old.graph_features is None
assert torch.equal(old.node_features, g.node_features)

Two limits are worth knowing. save_tgraphx records the writing version under tgraphx_version, but the loader does not compare it; it checks only the bundle's format tag (tgx-v1). And loading a bundle can execute pickled code, so treat .tgx files like any pickle (load_tgraphx(path, trust_source=False) refuses to load at all). If old files matter to you, keep one written by the version you pinned and load it in your own tests after each upgrade. For the format details, see Serializing Tensor Graphs.

Regression tests added with releases

A useful sign of hardening is a test suite that grows in response to reported problems. The changelog lists test files added with these releases, several of them for reported bugs:

Release Test file What the entry says it covers
v1.3.4 tests/test_colab_regressions_v134.py (33 tests) reported Colab and API bugs
v1.3.5 tests/test_colab_regressions_v135.py (51 tests) public Colab and API regressions
v1.3.6 tests/test_colab_notebook_regressions_v136.py (27 tests) public notebook regressions
v1.3.7 tests/test_advanced_notebook_workflows_v137.py (23 tests) advanced notebook workflows
v1.4.2 tests/test_audit_fixes_v142.py (17 tests) audit fixes, including the .tgx fields above
v1.5.0 tests/test_explicit_dropout_v150.py (22 tests) the dropout change described below

A test pinned to a bug means that reintroducing the bug makes the suite fail. The changelog also reports full-suite results, for example 3332 passed and 25 skipped for v1.4.1, and 3412 passed and 23 skipped for v1.5.0. These are the project's own reports. The pip wheel does not include tests/, so rerunning them requires the repository.

Changed defaults: the 1.5.0 dropout fix

Hardening is not the same as never changing behaviour. The changelog does record a case where an old default was deliberately kept (a 1.3.3 note says deterministic=False in easy mode is preserved for backward compatibility). Version 1.5.0 went the other way, because the old 0.3 was a hidden default that users had not asked for:

  • Up to 1.4.2, CNNEncoder and DeepCNNAggregator (used by ConvMessagePassing) applied dropout 0.3 when you did not ask for it. The default is now 0.0.
  • make_layer("conv", dropout=X) and build_model(layer="conv", dropout=X) previously ignored X; they now apply it.
  • Omitting the value emits DropoutDefaultChangeWarning. This is a warning in the release that changed the default, not an earlier deprecation period.

Parameter layout is unchanged, so checkpoints load either way and evaluation output is unaffected. Training behaviour is what changes:

python
import warnings
from tgraphx import ConvMessagePassing, DropoutDefaultChangeWarning, LEGACY_CNN_DROPOUT_PROB

with warnings.catch_warnings(record=True) as caught:
    warnings.simplefilter("always")
    ConvMessagePassing((3, 8, 8), (8, 8, 8))
assert any(w.category is DropoutDefaultChangeWarning for w in caught)

new = ConvMessagePassing((3, 8, 8), (8, 8, 8), dropout_prob=0.0)
legacy = ConvMessagePassing((3, 8, 8), (8, 8, 8), dropout_prob=LEGACY_CNN_DROPOUT_PROB)  # 0.3
legacy.load_state_dict(new.state_dict())        # same parameter layout

x = torch.randn(4, 3, 8, 8)
new.eval(); legacy.eval()
assert torch.equal(new(x, g.edge_index), legacy(x, g.edge_index))

new.train(); legacy.train()
torch.manual_seed(0); a = new(x, g.edge_index)
torch.manual_seed(0); b = legacy(x, g.edge_index)
assert not torch.allclose(a, b)                 # dropout changes training-mode output

To get the pre-1.5 regularisation back, pass dropout_prob=0.3 (or dropout=0.3 to the factories for layer="conv"); to reproduce an old project as a whole, pin the release it used. The project documents the details in its 1.4 to 1.5 migration note.

Validation as a first line of defence

The Graph constructor rejects inconsistent input when the object is created:

python
try:
    Graph(node_features=torch.randn(3, 4), edge_index=torch.tensor([[0], [5]]))
    raise AssertionError("out-of-range edge index should be rejected")
except ValueError as err:
    print(err)

assert tgx.validate_graph(g, strict=True, check_finite=True)["ok"]
tgx.assert_tensor_native(g)        # raises if node features have rank < 3

train = torch.tensor([True, True, False, False])
val = torch.tensor([False, False, True, False])
test = torch.tensor([False, False, False, True])
assert tgx.check_leakage(train_mask=train, val_mask=val, test_mask=test)["ok"]

# After mutation: validate_graph misses a negative index, Graph.validate() does not
bad = g.clone()
bad.edge_index[0, 0] = -1
assert tgx.validate_graph(bad, check_finite=True)["ok"]
try:
    bad.validate()                 # re-runs the constructor's edge and label checks
    raise AssertionError("negative index should be rejected")
except ValueError as err:
    print(err)

Know what these do not cover. validate_graph (alias check_graph_invariants) checks less than the constructor: it does not catch negative indices or a wrong label length. Graph.validate() re-runs the constructor's edge and label checks on the current state, but it looks at neither mask lengths nor NaN/Inf. After mutating a graph, use both: g.validate(), and validate_graph for mask lengths and, with check_finite=True, for NaN or Inf in node and edge features. check_leakage tests node-mask overlap, nothing else, and must be given the masks by keyword. Debugging Graph Neural Networks covers how to use such checks while debugging.

Metadata and conservative claims

The changelog also records wording fixes. The 1.4.2 entry replaced "parity with reference implementations" in the heterogeneous-GNN documentation with "validated on small regression fixtures", with no claim of numerical or throughput parity. The 1.4.1 entry labels the new APIs Beta and says it makes no SOTA claims.

Metadata can still drift, so check it instead of assuming. The 1.5.0 entry notes that CITATION.cff had been stale at version 0.1.1. For stability labels, tgx.api_status(name), docs/api_stability.md and the README do not always agree in 1.5.1 (ComplExModel, for example, is experimental in the registry and Beta in the document).

A reliability checklist this record suggests

  1. Round-trip your saved artifacts, including one written by an earlier pinned version.
  2. Add a test for every bug you fix.
  3. Validate on construction. After mutation, run both g.validate() and validate_graph(g, check_finite=True), since each skips something the other catches.
  4. Treat a changed default as a breaking change for your experiments, even if the code still runs.
  5. Record versions and read stability labels per API, not per package.

Honest framing

Accumulating regression tests and compatibility handling is normal for a maintained library. A large passing test suite shows that the tested behaviours hold; it does not show that the software is free of bugs, and no test suite does. TGraphX is classified as Beta on PyPI.

What to check before depending on a release

Before pinning TGraphX in a project:

  • Read the changelog entries between your current and target versions, especially "Changed".
  • Ask for the label of each call you rely on. api_status takes a name, and some APIs are not in the registry (it raises KeyError):
python
print(tgx.__version__)
for name in ("Graph", "ConvMessagePassing", "save_tgraphx", "validate_graph"):
    print(name, "->", tgx.api_status(name))
  • Save and reload a representative graph of your own with save_tgraphx and load_tgraphx.
  • Run your tests with warnings visible.
  • Write the version into your run metadata.

None of this is specific to TGraphX; it is ordinary due diligence for any dependency.

Related guides

Conclusion

The changelog shows concrete work on serialization compatibility, regression tests, validation and honest wording, and it also shows that a release can change training behaviour, as 1.5.0 did with dropout. Depend on a release after you have confirmed, on your own graphs and your own settings, that the parts you use behave as you expect.