Topological Deep Learning
Project description
Building Topological Neural Networks for Topological Deep Learning
Contributing to TMX • References
TopoModelX
(TMX) is a Python module for topological deep learning. It offers simple and efficient tools to implement topological neural networks for science and engineering.
Note: TMX is still under development.
Quick Tour for New Users
In this quick tour, we highlight the ease of creating and training a TNN model with only a few lines of code.
#Train your own TNN model
Below is a minimal example of using TopoModelX to load a simplicial complex dataset, define a simplicial attention network (SAN), and perform a forward pass:
import numpy as np
import torch
from topomodelx.datasets.graph import karate_club
from topomodelx.nn.simplicial.san import SAN
from topomodelx.utils.sparse import from_sparse
# Step 1: Load the Karate Club dataset
dataset = karate_club(complex_type="simplicial")
# Step 2: Prepare Laplacians and node/edge features
laplacian_down = from_sparse(dataset.down_laplacian_matrix(rank=1))
laplacian_up = from_sparse(dataset.up_laplacian_matrix(rank=1))
incidence_0_1 = from_sparse(dataset.incidence_matrix(rank=1))
x_0 = torch.tensor(np.stack(list(dataset.get_simplex_attributes("node_feat").values())))
x_1 = torch.tensor(np.stack(list(dataset.get_simplex_attributes("edge_feat").values())))
x = x_1 + torch.sparse.mm(incidence_0_1.T, x_0)
# Step 3: Define the network
class Network(torch.nn.Module):
def __init__(self, in_channels, hidden_channels, out_channels):
super().__init__()
self.base_model = SAN(in_channels, hidden_channels, n_layers=2)
self.linear = torch.nn.Linear(hidden_channels, out_channels)
def forward(self, x, laplacian_up, laplacian_down):
x = self.base_model(x, laplacian_up, laplacian_down)
return torch.sigmoid(self.linear(x))
# Step 4: Initialize the network and perform a forward pass
model = Network(in_channels=x.shape[-1], hidden_channels=16, out_channels=2)
y_hat_edge = model(x, laplacian_up=laplacian_up, laplacian_down=laplacian_down)
🦾 Contributing to TMX
To develop tmx on your machine, here are some tips.
First, we recommend using Python 3.11.3, which is the python version used to run the unit-tests.
For example, create a conda environment:
conda create -n tmx python=3.11.3
conda activate tmx
Then:
-
Clone a copy of tmx from source:
git clone git@github.com:pyt-team/TopoModelX.git cd TopoModelX
-
Install tmx in editable mode:
pip install -e '.[all]'
Notes:
- Requires pip >= 21.3. Refer: PEP 660.
- On Windows, use
pip install -e .[all]
instead (without quotes around[all]
).
-
Install torch, torch-scatter, torch-sparse with or without CUDA depending on your needs.
pip install torch==2.0.1 --extra-index-url https://download.pytorch.org/whl/${CUDA} pip install torch-scatter torch-sparse -f https://data.pyg.org/whl/torch-2.0.1+${CUDA}.html pip install torch-cluster -f https://data.pyg.org/whl/torch-2.0.0+${CUDA}.html
where
${CUDA}
should be replaced by eithercpu
,cu102
,cu113
, orcu115
depending on your PyTorch installation (torch.version.cuda
). -
Ensure that you have a working tmx installation by running the entire test suite with
pytest
In case an error occurs, please first check if all sub-packages (
torch-scatter
,torch-sparse
,torch-cluster
andtorch-spline-conv
) are on its latest reported version. -
Install pre-commit hooks:
pre-commit install
🔍 References
TMX is a part of TopoX, a suite of Python packages for machine learning on topological domains. If you find TMX useful please consider citing our software paper:
- Hajij et al. 2023. TopoX: a suite of Python packages for machine learning on topological domains
To learn more about the blueprint topological deep learning that topomodelx follows :
- Mustafa Hajij, Ghada Zamzmi, Theodore Papamarkou, Nina Miolane, Aldo Guzmán-Sáenz, Karthikeyan Natesan Ramamurthy, Tolga Birdal, Tamal K. Dey, Soham Mukherjee, Shreyas N. Samaga, Neal Livesay, Robin Walters, Paul Rosen, Michael T. Schaub.
Topological Deep Learning: Going Beyond Graph Data (arXiv) • Topological Deep Learning: A Book
TMX topological neural networks are surveyed in:
- Papillon et al. 2023. Architectures of Topological Deep Learning: A Survey on Topological Neural Networks.
@misc{hajij2023topological,
title={Topological Deep Learning: Going Beyond Graph Data},
author={Mustafa Hajij and Ghada Zamzmi and Theodore Papamarkou and Nina Miolane and Aldo Guzmán-Sáenz and Karthikeyan Natesan Ramamurthy and Tolga Birdal and Tamal K. Dey and Soham Mukherjee and Shreyas N. Samaga and Neal Livesay and Robin Walters and Paul Rosen and Michael T. Schaub},
year={2023},
eprint={2206.00606},
archivePrefix={arXiv},
primaryClass={cs.LG}
}
@article{hajij2024topox,
title={TopoX: a suite of Python packages for machine learning on topological domains},
author={PYT-Team},
journal={arXiv preprint arXiv:2402.02441},
year={2024}
}
@article{papillon2023architectures,
title={Architectures of Topological Deep Learning: A Survey of Message-Passing Topological Neural Networks},
author={Papillon, Mathilde and Sanborn, Sophia and Hajij, Mustafa and Miolane, Nina},
journal={arXiv preprint arXiv:2304.10031},
year={2023}
}
Funding
Partially funded by the European Union (ERC, HIGH-HOPeS, 101039827). Views and opinions expressed are however those of the author(s) only and do not necessarily reflect those of the European Union or the European Research Council Executive Agency. Neither the European Union nor the granting authority can be held responsible for them.
Partially funded by the National Science Foundation (DMS-2134231, DMS-2134241).
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
File details
Details for the file topomodelx-0.0.1.tar.gz
.
File metadata
- Download URL: topomodelx-0.0.1.tar.gz
- Upload date:
- Size: 66.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d804cb6201dbfa3836061472f1ef48a6758410a6d424dc700546b47271f10efd |
|
MD5 | 5838c2b5083fd48138a21c9f6bf7ff2a |
|
BLAKE2b-256 | 124c01f0d9a21f982d049915e4f16fe8d0b553e9ab7c1a112c9a3537d27a4ce7 |
File details
Details for the file TopoModelX-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: TopoModelX-0.0.1-py3-none-any.whl
- Upload date:
- Size: 107.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b5ebf3109715003ccfb73d1fb9aa9cdb3ac19ce968ecfafaade6a8220c711d4 |
|
MD5 | 579ccca9c96a584691aae616c8938584 |
|
BLAKE2b-256 | 506fedd56d8e4e726b311df85cbe8f3ad79f4706e9f1328e52922a4a868f8aa0 |