Skip to main content

JraphX: Graph Neural Networks with NNX

JraphX is a graph neural network (GNN) library for JAX, built on Flax NNX. It is an unofficial successor to DeepMind's archived jraph, and its API deliberately mirrors PyTorch Geometric (PyG) so that models and mental models carry over.

Everything is a plain nnx.Module, so layers compose with nnx.jit, nnx.vmap, nnx.scan, nnx.grad, and the rest of the JAX ecosystem.

What is in the box

  • Convolutions (jraphx.nn.conv): MessagePassing, GCNConv, GATConv, GATv2Conv, SAGEConv, GINConv, EdgeConv, DynamicEdgeConv, TransformerConv
  • Models (jraphx.nn.models): BasicGNN, GCN, GAT, GraphSAGE, GIN, MLP, JumpingKnowledge
  • Normalization (jraphx.nn.norm): BatchNorm, LayerNorm, GraphNorm
  • Pooling (jraphx.nn.pool): global_add_pool, global_mean_pool, global_max_pool, global_min_pool, global_sort_pool, TopKPooling, SAGPooling
  • Data containers (jraphx.data): Data and Batch, where batching concatenates graphs and offsets their node indices, exactly as in PyG
  • Utilities (jraphx.utils): scatter reductions, degree, add_self_loops, remove_self_loops, coalesce, to_undirected, to_dense_adj, to_edge_index

Installation

JraphX requires Python 3.11 or newer.

pip install jraphx

This pulls in JAX, Flax (0.12 or newer), and NumPy. For a source checkout:

git clone https://github.com/DBraun/jraphx.git
cd jraphx
pip install -e ".[dev]"

Quick start

A two-layer GCN over a four-node cycle graph:

import jax
import jax.numpy as jnp
from flax import nnx

from jraphx.data import Data
from jraphx.nn.conv import GCNConv


class GCN(nnx.Module):
    def __init__(self, in_features: int, hidden_features: int, num_classes: int, rngs: nnx.Rngs):
        self.conv1 = GCNConv(in_features, hidden_features, rngs=rngs)
        self.conv2 = GCNConv(hidden_features, num_classes, rngs=rngs)

    def __call__(self, x: jax.Array, edge_index: jax.Array) -> jax.Array:
        x = nnx.relu(self.conv1(x, edge_index))
        return self.conv2(x, edge_index)


data = Data(
    x=jnp.ones((4, 8)),
    edge_index=jnp.array([[0, 1, 2, 3], [1, 2, 3, 0]]),
)

model = GCN(in_features=8, hidden_features=16, num_classes=3, rngs=nnx.Rngs(0))


@nnx.jit
def forward(model: GCN, x: jax.Array, edge_index: jax.Array) -> jax.Array:
    return model(x, edge_index)


logits = forward(model, data.x, data.edge_index)
print(logits.shape)  # (4, 3)

The same network is available prebuilt, with configurable depth, dropout, normalization, residual connections, and jumping knowledge:

from jraphx.nn.models import GCN

model = GCN(in_features=8, hidden_features=16, num_layers=2, out_features=3, rngs=nnx.Rngs(0))
logits = model(data.x, data.edge_index)

Graphs of different sizes are combined into one disjoint graph, then reduced back to per-graph vectors by pooling against the batch vector:

from jraphx.data import Batch
from jraphx.nn.pool import global_mean_pool

batch = Batch.from_data_list([data, data])
graph_embeddings = global_mean_pool(batch.x, batch.batch)  # (2, 8)

More end-to-end scripts, including Cora node classification, GAT, and GraphSAINT sampling, live in the examples/ directory.

Relationship to PyTorch Geometric

JraphX reimplements a subset of PyG on top of JAX; it does not wrap PyG and does not depend on PyTorch. The differences you will notice when porting code:

  • Layers are nnx.Modules and take an rngs=nnx.Rngs(...) argument at construction time instead of being initialized lazily.
  • Feature dimensions are named in_features / out_features rather than PyG's in_channels / out_channels.
  • Arrays are jax.Array, and Data / Batch are immutable — transformations return new objects.
  • Because JAX traces static shapes, operations whose output size depends on the data (for example removing self-loops) are only usable outside jax.jit, or with a padded, fixed-size layout.
  • There is no dataset or dataloader ecosystem here: bring your own pipeline (for example Grain) and hand JraphX the arrays.

Layers still missing relative to PyG are tracked in the missing features page.

Documentation

Full documentation, tutorials, and the API reference: https://dirt.design/jraphx/

License and attribution

JraphX is released under the Apache License 2.0 (see LICENSE).

It contains substantial portions of code and documentation derived from PyTorch Geometric (MIT License, Copyright (c) 2023 PyG Team), and builds on Flax and DeepMind's jraph, both licensed under the Apache License 2.0. The required third-party notices, including the MIT permission notice, are collected in NOTICE and ship with every wheel and source distribution.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jraphx-0.1.0.tar.gz (73.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jraphx-0.1.0-py3-none-any.whl (93.2 kB view details)

Uploaded Python 3

File details

Details for the file jraphx-0.1.0.tar.gz.

File metadata

  • Download URL: jraphx-0.1.0.tar.gz
  • Upload date:
  • Size: 73.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for jraphx-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f523f923135630066fcae67154c5308dd042d622b1472242dd9b1917404b692e
MD5 31c223e7b91043d43578d4fae162e6a8
BLAKE2b-256 cdff009774f4c1ff6d7a2492ab2f3313f65182d8633e946ad7181448e3a8f6ad

See more details on using hashes here.

File details

Details for the file jraphx-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: jraphx-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 93.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for jraphx-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cb4deb7008531b7fcd222746bff31652d92852fd4f7ebe7fdb6f8f4534fb22f9
MD5 10c2a3a24ab10ad026244d479fb2baa3
BLAKE2b-256 083851c5fb46cf82d3e279f5a33059b788c4f6d504255f1839d242d1ab91f1fa

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

0.0.4

2 files

0.0.3

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page