Skip to main content

A hackable TensorFlow GraphNets library

Project description

TensorFlow compatibility and test status

Tests Coverage

TensorFlow TensorFlow Probability Status
2.17.x 0.24.x TF 2.17 TFP 0.24
2.18.x 0.25.x TF 2.18 TFP 0.25
2.19.x 0.25.x TF 2.19 TFP 0.25
2.20.x 0.25.x TF 2.20 TFP 0.25
2.21.x 0.25.x TF 2.21 TFP 0.25

The matrix above is validated by scripts/run_tf_matrix_tests.sh and in CI (.github/workflows/tests.yml).

tf_gnns - A Hackable GraphNets library

alt-img A library for easy construction of message-passing networks in TensorFlow Keras. It is largely inspired by this DeepMind paper and the corresponding open-source library (original graph_nets library).

The tf_gnns library has no external dependencies except TensorFlow 2.x (there is no support for TF 1.x graph/session-based computation). It implements alternative design constraints from graph_nets, taking advantage of Keras facilities to build complex models easily and without large drops in performance.

tf_gnns is built to support arbitrary node/edge/global attributes and update functions. A set of utility functions for MLP construction with Keras is also provided (i.e., handling input/output sizes for valid networks), replacing Sonnet.

The main motivation for this library was the absence of a relatively short and efficient implementation of GNNs explicitly created to take advantage of Keras functionality. GNN implementations that take advantage of tensorflow_probability functionality are planned for future releases (such as the one used in [2]).

Installing tf_gnns


NOTE

The current tested matrix is TensorFlow 2.17 through 2.21 with the matching TensorFlow Probability versions shown above.


Install with uv (recommended):

uv sync

Or install with pip:

# optional - recommended:
# pip install tensorflow==2.15 
# pip install tensorflow_probability==0.22
pip install tf_gnns

Run tests:

uv sync --group dev
uv run pytest -v

Run tests with coverage and update badge payload:

scripts/run_coverage.sh

Run compatibility tests across TensorFlow versions:

scripts/run_tf_matrix_tests.sh 2.17 2.18 2.19 2.20 2.21

Build the Docker test image for a specific TensorFlow version:

docker build --build-arg TENSORFLOW_VERSION=2.17 -t tf-gnns:test .

Use through Docker

You can build a Docker image that uses tf_gnns with the following command, based on Ubuntu 22:

docker build . -t tf_gnns_215 --network host  --build-arg TENSORFLOW_VERSION=2.15

The container implements some logic to sort out the necessary dependencies. Namely,

  • Numpy 1.x is required for tf <= 2.14
  • Keras 2 support needs to be enabled for tf >= 2.16
  • The tensorflow_probability version is selected through a mapping given the tensorflow version.

Examples

tf_gnns basics

You can inspect some basic functionality in the following Colab notebook:

Open In Colab

List sorting example

(Example from the original deepmind/graph_nets library) If you are familiar with the original graph_nets library, this example will help you understand how you can transition to tf_gnns.

Sort a list of elements. This notebook and the accompanying code demonstrates how to use the Graph Nets library to learn to sort a list of elements.

A list of elements is treated as a fully connected graph between the elements. The network is trained to label the start node, and which (directed) edges correspond to the links to the next largest element, for each node.

After training, prediction ability is tested by comparing output to true sorted lists. Then the network's ability to generalize is tested by using it to sort larger lists.

Open In Colab

Protein-Protein Interaction example

This example shows how to adapt torch_geometric (aka PyG) inputs to tf_gnns inputs. The notebook can be run end-to-end in Google Colab, and out of the box it gives a test-set F1 score that is competitive with SOTA. Open In Colab

Performance

From initial tests, the performance of tf_gnns seems to be at least as good as deepmind/graph_nets when using tensor dictionaries.

Publications using tf_gnns

The library has been used so far in the following publications:

[1] Bayesian graph neural networks for strain-based crack localization

[2] Remaining Useful Life Estimation Under Uncertainty with Causal GraphNets

[3] Relational VAE: A Continuous Latent Variable Model for Graph Structured Data

Project details


Download files

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

Source Distribution

tf_gnns-0.1.9.tar.gz (32.2 kB view details)

Uploaded Source

Built Distribution

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

tf_gnns-0.1.9-py3-none-any.whl (34.8 kB view details)

Uploaded Python 3

File details

Details for the file tf_gnns-0.1.9.tar.gz.

File metadata

  • Download URL: tf_gnns-0.1.9.tar.gz
  • Upload date:
  • Size: 32.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tf_gnns-0.1.9.tar.gz
Algorithm Hash digest
SHA256 9e8bab2996016854944740e1abf6b93659af2cd8f4fa072d75b2fb1e58ebf85a
MD5 d3ed0c506fa70a09a36fbdb43a43cb26
BLAKE2b-256 6987d08cd4ee76a5364c99d920c52ba8a858f9dacb18fb84b9c74958166f50f8

See more details on using hashes here.

Provenance

The following attestation bundles were made for tf_gnns-0.1.9.tar.gz:

Publisher: release-pypi.yml on mylonasc/tf_gnns

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tf_gnns-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: tf_gnns-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 34.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tf_gnns-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 12df34aaf943dae3de1e00e3306f337a9cf30853e94fe432e3188b4661e98168
MD5 e559f2ce29778dc4f5ce9355562cebee
BLAKE2b-256 da8fec7ef433bfb14a1e83a0b5bc36c18e6ea9ee2572c38a28d8f711b0e0ba09

See more details on using hashes here.

Provenance

The following attestation bundles were made for tf_gnns-0.1.9-py3-none-any.whl:

Publisher: release-pypi.yml on mylonasc/tf_gnns

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page