Trainable graph adjacency parameterizations with ODE integration and Lightning training helpers.
Project description
GradNet
GradNet is a PyTorch-based framework for AI-enabled optimization of networks. Define static or dynamical objectives and constraints, then discover the optimal network structures.
It encodes the network structure as a differentiable object with optional budget and structure constraints. It lets the users directly optimize static objectives using a lightweight PyTorch Lightning training loop. Alternatively, built-in ODE solvers can be used to define and optimize dynamical objectives.
Illustration of the gradient-based optimization pipeline for network structure.
A random network rewires itself with GradNet to optimize synchronization in the Kuramoto model.
Highlights
- Learn dense or sparse adjacency updates with norm, sign, and symmetry constraints.
- Projected parameterizations that stay differentiable and GPU friendly.
- Torchdiffeq-backed integration utilities for graph-driven dynamical systems.
- Minimal Lightning trainer that wraps loss functions in just a few lines.
Installation
Install the released package from PyPI:
pip install gradnet
To work off the latest sources instead, clone the repository and install in editable mode:
pip install -e .
GradNet targets Python 3.10+ and requires pip 21.3+ (run pip install --upgrade pip if needed). It depends on PyTorch, PyTorch Lightning, torchdiffeq, NumPy, and tqdm (installed automatically by the command above). Install the optional NetworkX helpers with pip install 'gradnet[networkx]' when you need conversions to networkx graphs or plotting utilities that rely on it.
Documentation
Full API documentation, tutorials, and background material live at gradnet.readthedocs.io.
Quickstart
The examples folder contains several examples of how to use GradNet.
Spectral optimization (algebraic connectivity)
Demonstrates a simple example of Configuring a GradNet object restricted to a grid lattice.
It defines a simple static loss function (the algebraic connectivity).
Then it uses fit to optimize the network structure, all in the first code cell of the notebook.
The rest of the notebook is analysis of the optimal grid and comparison of dense and sparse backends.
Kuramoto network optimization
A simple example of dynamical loss and usage of integrate_ode.
Demonstrates structural optimization emergent sparsity with no mask.
Zachary's karate club
An xample showing how to optimally modify existing networks.
Modules at a glance
gradnet.GradNet: wraps dense and sparse parameterizations, supports directed/undirected networks, masking, custom edge-building costs etc.gradnet.integrate_ode: torchdiffeq-powered solver with adjoint and event support for adjacency-dependent dynamics.gradnet.fit: PyTorch Lightning loop that optimizes aGradNetusing user-supplied loss functions.gradnet.utils: various helpers functions.
Credits
GradNet relies on (and is inspired by) the following open-source projects:
License
GradNet is released under the BSD 3-Clause License. See LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gradnet-0.4.0.tar.gz.
File metadata
- Download URL: gradnet-0.4.0.tar.gz
- Upload date:
- Size: 32.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff0c685ee10b254624d587383f3b45a9c43d6573ca85b869fecae1f9c8af7e04
|
|
| MD5 |
dca3474c5116ab2d287b6d2ae2b894d0
|
|
| BLAKE2b-256 |
33a1cc00bba17cdb3df4f1db08151203924d7798c5774c184e897ada9c70ed23
|
File details
Details for the file gradnet-0.4.0-py3-none-any.whl.
File metadata
- Download URL: gradnet-0.4.0-py3-none-any.whl
- Upload date:
- Size: 34.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8bbafeb7a65ebe49075041d74a8340f4767a00f58f4c06da30267071a5c06b28
|
|
| MD5 |
a47600c67f048948fbdb589b78067507
|
|
| BLAKE2b-256 |
85e78dbd08f125f00220092e6841d5e0a61ed91e335d5b655112646d97982aa4
|