Skip to main content

Trainable graph adjacency parameterizations with ODE integration and Lightning training helpers.

Project description

GradNet

GradNet provides differentiable parameterizations of graph adjacency matrices with explicit budget and structure constraints. It pairs these parameterizations with ODE solvers and a lightweight PyTorch Lightning training loop so you can prototype network optimization problems quickly.

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 custom 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 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

Learn a constrained adjacency

import torch
from gradnet import GradNet

num_nodes = 10
model = GradNet(
    num_nodes=num_nodes,
    budget=1.0,
    undirected=True,
)

adjacency = model()  # full (num_nodes, num_nodes) tensor

Pass a sparse COO mask via the mask argument to switch to the sparse backend and optimize only selected edges.

Integrate a graph-driven ODE

from gradnet import integrate_ode

# simple linear dynamics \dot{x} = Ax

def vector_field(t, x, A):
    return A @ x

x0 = torch.randn(num_nodes)
t_grid = torch.linspace(0.0, 1.0, 51)
sol_t, sol_x = integrate_ode(model, vector_field, x0, t_grid)

Optimize with your own loss

from gradnet import GradNet, fit

# encourage sparse, small-magnitude updates
def loss_fn(g: GradNet):
    delta = g.get_delta_adj()
    return delta.abs().mean()

fit(gradnet=model, loss_fn=loss_fn, num_updates=200, learning_rate=1e-2)

The trainer handles optimizer setup, logging, and checkpointing while you focus on defining the objective.

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 a GradNet using user-supplied loss functions.
  • gradnet.utils: various helpers functions.

License

GradNet is released under the BSD 3-Clause License. See LICENSE for details.

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

gradnet-0.1.5.tar.gz (24.4 kB view details)

Uploaded Source

Built Distribution

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

gradnet-0.1.5-py3-none-any.whl (26.7 kB view details)

Uploaded Python 3

File details

Details for the file gradnet-0.1.5.tar.gz.

File metadata

  • Download URL: gradnet-0.1.5.tar.gz
  • Upload date:
  • Size: 24.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.8

File hashes

Hashes for gradnet-0.1.5.tar.gz
Algorithm Hash digest
SHA256 b97678ad7700118a449e8bb6353c91f12443d2e3f24e2c511f78c2003b095574
MD5 8e6d0787a4622f6634a243af1c6fe6af
BLAKE2b-256 cd2efa9b9460dca8d06747affcd59688d12f3fcbb0e368a1f2bca7dccd84c311

See more details on using hashes here.

File details

Details for the file gradnet-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: gradnet-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 26.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.8

File hashes

Hashes for gradnet-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 2ed050cb547c10168db36eea74b9ec5d328cb8622518887b42002014193f6ea9
MD5 697dea0aa1a5679fd0b40978231d3ef2
BLAKE2b-256 799cd8f22ac7532ebab71c0786fd22620ef9c9c5f99fb22c6344cf535ed22ec4

See more details on using hashes here.

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