TopoModelX (TMX)

repository·main·Indexed 43 days ago

https://github.com/pyt-team/topomodelx

A Python module for topological deep learning (TDL) used to implement topological neural networks (TNNs) for science and engineering applications. It provides specialized components for modeling cell complexes, hypergraphs, and simplicial complexes, including implementations like the Simplicial Attention Network (SAN) and Cell Attention Network (CAN). The package includes tools for handling Laplacians and incidence matrices, and integrates with TopoNetX and PyTorch.

Tokens
29.2K
Snippets
68
Records
86
Agent score
50%

What's inside TopoModelX

  1. What is TopoModelX (TMX)?

    main
    TopoModelX (TMX) is a Python package designed for Topological Deep Learning (TDL). It enables performing deep learning on topological domains, following the TDL blueprint established in recent research. The package is built to reproduce and extend topological neural networks (TNNs).
  2. Overview of TopoModelX modules

    main

    The TopoModelX package is organized into three primary modules that handle different aspects of topological modeling:

    • base: Implements core mathematical concepts, specifically the fundamental mechanics of message passing.
    • nn: Contains neural network layers, which are categorized by their topological domains.
    • utils: Provides utility functions, such as operations for computing with sparse tensors.
  3. Overview of the TopoModelX nn module

    main

    The nn module in TopoModelX provides neural network components specifically designed for topological data structures. It is organized into three primary submodules based on the type of topological structure being modeled:

    1. cell: Components for cell complexes.
    2. hypergraph: Components for hypergraph-based neural networks.
    3. simplicial: Components for simplicial complex-based neural networks.

    Users should select the submodule that corresponds to the mathematical structure of their input data (e.g., use simplicial for simplicial complexes or hypergraph for hypergraphs).

  4. Overview of the Cell base class components

    main

    The Cell base class in TopoModelX is implemented through six primary classes that form the core of the neural network cell architecture. These classes are categorized into layers and their corresponding functional units:

    • CAN: Can_Layer and Can
    • CCXN: CCXN_Layer and CCXN
    • CWN: CWN_Layer and CWN
  5. Requirements for implementing a TopoModelX layer

    main

    When implementing a {Name of model}Layer, follow these structural and technical guidelines:

    • Domain Placement: Store the file in topomodelx/nn/simplicial, topomodelx/nn/cell, topomodelx/nn/hypergraph, or topomodelx/nn/combinatorial based on the model's domain.
    • Primitives: Use TopoModelX computational primitives. If you must modify topomodelx/base to add new primitives, you must provide unit tests for every new function added.
    • Logic: One layer should be equivalent to the message passing depicted in the tensor diagram representation for the model.
    • Testing: Use pytest (not unittest) for all unit tests.
  6. Understand the components of the Base class

    main

    The Base class in TopoModelX is a foundational structure composed of three primary functional layers used to build topological models:

    1. Aggregation: Defines the message passing layer, determining how information is combined.
    2. Conv: Responsible for building the message passing neighborhood structure.
    3. Message Passing: The core class defining the message passing structure itself.
  7. Getting started with TopoModelX

    main
    To begin using TopoModelX, refer to the official tutorials which provide a step-by-step guide through loading datasets, preparing topological features (like Laplacians), defining networks, and performing forward passes.
  8. Install TopoModelX via pip

    main

    You can install the core topomodelx package using pip. Note that you must also install torch and specific PyTorch geometric dependencies (torch-scatter, torch-sparse, and torch-cluster) compatible with your CUDA version to ensure full functionality.

    pip install topomodelx
    
    # Example for CUDA 11.3 (replace ${CUDA} with cpu, cu102, cu113, or cu115)
    pip install torch==2.0.1 --extra-index-url https://download.pytorch.org/whl/cu113
    pip install torch-scatter torch-sparse -f https://data.pyg.org/whl/torch-2.0.1+cu113.html
    pip install torch-cluster -f https://data.pyg.org/whl/torch-2.0.0+cu113.html
  9. Dataset loading and lifting for TNN tutorials

    main

    When creating the {name_of_model}_train.ipynb tutorial, use the following patterns for data preparation:

    For models requiring features on faces or rank-2 neighborhood matrices:

    Use TopoNetX to load:

    • shrec16: Suitable for complex-level classification.
    • Karate Club: Suitable for node-level classification.

    For models requiring only node/edge features and rank-0/1 neighborhood matrices:

    Use TopoNetX or Torch Geometric to load benchmark graph datasets.

    Lifting to Topological Domains:

    After loading the graph dataset, you must lift it from the graph domain to the chosen topological domain (hypergraph, simplicial complex, cell complex, or combinatorial complex) using TopoNetX.

  10. Explore Topological Neural Net tutorials

    main

    TopoModelX provides specialized tutorials for implementing Topological Neural Networks (TNNs) across different mathematical structures. You can find detailed notebooks for the following domains:

    • Cellular Complexes: Tutorials located in ../notebooks/cell/.
    • Hypergraphs: Tutorials located in ../notebooks/hypergraph/.
    • Simplicial Complexes: Tutorials located in ../notebooks/simplicial/.

    Each tutorial typically follows a workflow of loading a dataset, preparing Laplacians and features, defining the network architecture, and performing forward passes.

  11. Submit a Topological Neural Network (TNN) implementation

    main

    To contribute a new model to TopoModelX, you must submit a Pull Request containing a specific set of files that implement a pre-existing model from the literature (specifically those listed in Fig. 11 of the survey Architectures of Topological Deep Learning).

    Your submission must include three specific files:

    1. Model Layer: {name_of_model}_layer.py

      • Location: topomodelx/nn/{domain} (where domain is simplicial, cell, hypergraph, or combinatorial).
      • Requirement: Must contain a single class {Name of model}Layer that uses TopoModelX computational primitives to implement one layer (one message passing step).
    2. Training Notebook: {name_of_model}_train.ipynb

      • Location: tutorials/{domain}.
      • Requirement: Must demonstrate:
        • Pre-processing: Importing the layer, loading a dataset (e.g., shrec16 or Karate Club via TopoNetX), and lifting the dataset to the target topological domain.
        • Network Creation: A class {Name of model} inheriting from torch.nn.Module using your layer.
        • Training: A simple training loop for a classification task.
    3. Unit Tests: test_{name_of_model}_layer.py

      • Location: test/nn/{domain}.
      • Requirement: Must contain a class Test{Name of model}Layer using pytest to test all functions in your layer class.

    Important: All code must pass the TopoModelX GitHub Action workflow, including tests, linting (flake8), and formatting (Black, isort).

  12. Develop TopoModelX from source

    main

    To contribute to TMX, it is recommended to use Python 3.12 or later. Follow these steps to set up a local development environment:

    1. Create and activate a conda environment:
      conda create -n tmx python=3.12
      conda activate tmx
    2. Clone the repository and install in editable mode:
      git clone git@github.com:pyt-team/TopoModelX.git
      cd TopoModelX
      pip install -e '.[all]'
      Note: On Windows, use pip install -e .[all] without quotes.
    3. Install PyTorch and its dependencies (torch-scatter, torch-sparse, torch-cluster) as described in the installation guide.
    4. Run the test suite using pytest and install pre-commit hooks with pre-commit install.