Skip to main content

Haiku Geometric

Overview | Installation | Quickstart | Examples | Documentation | License

Documentation Status Python application pypi

Overview

Haiku Geometric is a collection of graph neural networks (GNNs) implemented using JAX. It tries to provide object-oriented and easy-to-use modules for GNNs.

Haiku Geometric is built on top of Haiku and Jraph. It is deeply inspired by PyTorch Geometric. In most cases, Haiku Geometric tries to replicate the API of PyTorch Geometric to allow code sharing between the two.

Haiku Geometric is still under development and I would advise against using it in production.

Installation

Haiku Geometric can be installed from source:

pip install git+https://github.com/alexOarga/haiku-geometric.git

Alternatively, you can install Haiku Geometric using pip:

pip install haiku-geometric

Quickstart

For instance, we can create a simple graph convolutional network (GCN) of 2 layers as follows:

import jax
import haiku as hk
from haiku_geometric.nn import GCNConv

class GCN(hk.Module):
    def __init__(self, hidden_channels, out_channels):
        super().__init__()
        self.conv1 = GCNConv(hidden_channels)
        self.conv2 = GCNConv(hidden_channels)
        self.linear = hk.Linear(out_channels)

    def __call__(self, nodes,senders, receivers):
        x = self.conv1(nodes, senders, receivers)
        x = jax.nn.relu(x)
        x = self.conv2(x, senders, receivers)
        x = self.linear(nodes)
        return x

def forward(nodes, senders, receivers):
    gcn = GCN(16, 7)
    return gcn(nodes, senders, receivers)

The GNN that we have defined is a Haiku Module. To convert our module in a function that can be used with JAX, we transform it using hk.transform as described in the Haiku documentation.

model = hk.transform(forward)
model = hk.without_apply_rng(model)
rng = jax.random.PRNGKey(42)
params = model.init(rng, nodes=nodes, senders=senders, receivers=receivers)

We can now run a forward pass on the model:

output = model.apply(params=params, nodes=nodes, senders=senders, receivers=receivers)

Documentation

The documentation for Haiku Geometric can be found here.

Examples

Haiku Geometric comes with a few examples that showcase the usage of the library. The following examples are available:

Link
Quickstart Example Open in Colab
Graph Convolution Networks with Karate Club dataset Open in Colab
Graph Attention Networks with CORA dataset Open in Colab
TopKPooling and GraphConv with PROTEINS dataset Open in Colab

Implemented GNNs modules

Currently, Haiku Geometric includes the following GNN modules:

Model Description
GCNConv Graph convolution layer from the Semi-Supervised Classification with Graph Convolutional Networks paper.
GATConv Graph attention layer from the Graph Attention Networks paper.
SAGEConv Graph convolution layer from the Inductive Representation Learning on Large Graphs paper.
GINConv Graph isomorphism network layer from the How Powerful are Graph Neural Networks? paper.
GINEConv Graph isomorphism network layer from the Strategies for Pre-training Graph Neural Networks paper.
GraphConv Graph convolution layer from the Weisfeiler and Leman Go Neural: Higher-order Graph Neural Networks paper.
GeneralConv A general GNN layer adapted from the Design Space for Graph Neural Networks paper.
GatedGraphConv Graph convolution layer from the Gated Graph Sequence Neural Networks paper.
EdgeConv Edge convolution layer from the Dynamic Graph CNN for Learning on Point Clouds paper.
PNAConv Propagation Network layer from the Principal Neighbourhood Aggregation for Graph Nets paper.
MetaLayer Meta layer from the Relational Inductive Biases, Deep Learning, and Graph Networks paper.
GPSLayer Graph layer from the Recipe for a General, Powerful, Scalable Graph Transformer paper.

Implemented positional encodings

The following positional encodings are currently available:

Model Description
LaplacianEncoder Laplacian positional encoding from the Rethinking Graph Transformers with Spectral Attention paper.
MagLaplacianEncoder Magnetic Laplacian positional encoding from the Transformers Meet Directed Graphs paper.

Issues

If you encounter any issue, please open an issue.

Running tests

Haiku Geometric can be tested using pytest by running the following command:

python -m pytest test/

License

License

Metadata

Release files for haiku-geometric 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for haiku-geometric 0.0.5
File Size Uploaded
haiku_geometric-0.0.5.tar.gz 118.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for haiku-geometric 0.0.5
File Interpreter ABI Platform
haiku_geometric-0.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 193.6 kB

Release files / haiku_geometric-0.0.5.tar.gz

Download URL haiku_geometric-0.0.5.tar.gz
Size 118.1 kB
Tags Source
SHA-256 checksum
How to use checksums
3d3e9cb8412f1d0f4cb5e95d98d0c86d3c3b87401bfb64f67fdeff9b7b7963d7
BLAKE2b-256 checksum
How to use checksums
63316291b06bc36873b79803dc9eaea88e0a8bdc5062b9595c41dc5b8b82f178
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / haiku_geometric-0.0.5-py3-none-any.whl

Download URL haiku_geometric-0.0.5-py3-none-any.whl
Size 75.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e0f2365719a5c7db71aec1e5a3a33694876eeacd4da1b65ded56bc624355b387
BLAKE2b-256 checksum
How to use checksums
5a03f4644548af56930076d20b128a82b4cd7854faf1770d2e7379a58efff802
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release history Release notifications | RSS feed

This release

0.0.5 This release

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release 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