GraphNeuralNetworks.jl

repository·master·Indexed 43 days ago

https://github.com/juliagraphs/graphneuralnetworks.jl

A suite of Julia libraries for deep learning on graphs, providing specialized convolutional layers and message-passing frameworks. The ecosystem includes GraphNeuralNetworks.jl for Flux.jl users, GNNLux.jl for Lux.jl users, GNNGraphs.jl for graph data structures (including GNNGraph, GNNHeteroGraph, and TemporalSnapshotsGNNGraph), and GNNlib.jl for framework-agnostic building blocks. It supports batched graph computation, CUDA and AMDGPU, and integration with Graphs.jl and MLDatasets.jl.

Tokens
30.2K
Snippets
93
Records
123
Agent score
56%

What's inside GraphNeuralNetworks.jl

  1. Overview of GNNlib.jl

    master

    GNNlib.jl provides a collection of framework-agnostic building blocks for deep learning on graphs. It includes message passing operators and various implementations of graph convolutional layers.

    Because it is framework-agnostic, it serves as a core library that can be used by different deep learning frontends in the Julia ecosystem. If you are looking for a specific deep learning framework integration, consider using:

    • GraphNeuralNetworks.jl: For a Flux-based frontend.
    • GNNLux.jl: For a Lux-based frontend.
  2. Overview of GraphNeuralNetworks.jl ecosystem

    master

    The project is split into several packages to support different deep learning backends while sharing core logic:

    • GraphNeuralNetworks.jl: The frontend package for Flux.jl users, providing graph convolutional layers.
    • GNNLux.jl: The frontend package for Lux.jl users, providing graph convolutional layers.
    • GNNGraphs.jl: Provides graph data structures and helper functions. Re-exported by the frontend packages.
    • GNNlib.jl: The core implementation of the message-passing framework (gather/scatter or sparse matrix multiplication). It is not intended for direct use but is re-exported by the frontend packages.

    Both frontend packages support:

    • Common graph convolutional layers.
    • Batched graph computation.
    • Custom layer definitions.
    • CUDA and AMDGPU support.
    • Integration with Graphs.jl.
    • Heterogeneous and dynamical graphs/convolutions.
  3. What is GNNlib.jl and when to use it

    master

    GNNlib.jl provides low-level implementations of basic message passing functions and functional graph convolutional layers.

    When to use GNNlib.jl: Use this package if you are a developer looking to create new GNN architectures from scratch. It is designed to work with both Flux.jl and Lux.jl frameworks.

    When to use other packages: For most standard users, it is recommended to use the higher-level packages instead:

    • GraphNeuralNetworks.jl: For Flux.jl-based workflows.
    • GNNLux.jl: For Lux.jl-based workflows.
  4. Use TemporalSnapshotsGNNGraph for time-varying graphs

    master
    The TemporalSnapshotsGNNGraph type is used to represent graphs that change over time. It is specifically designed to handle graphs where both the topology (edges/nodes) and the features associated with them vary across different time snapshots. This type is part of the GNNGraphs module and is intended for use in temporal Graph Neural Network tasks.
  5. How GNNGraph objects represent graph data

    master

    In GNNLux.jl, a graph is represented by a GNNGraph object. This object stores all information required for Graph Neural Network operations across three main NamedTuple attributes:

    • g.ndata: Contains node-related information (e.g., node features x, labels y, or training masks train_mask).
    • g.edata: Holds edge-related information.
    • g.gdata: Stores global data that is neither node-specific nor edge-specific.

    You can access specific feature arrays using dot notation, such as g.ndata.x.

    g = GNNGraph(base_graph, ndata = (; x = node_features, y = labels, train_mask = mask))
  6. Use the GNNGraph type for graph neural networks

    master

    The GNNGraph type is the primary graph representation in GNNGraphs.jl. It inherits from Graphs.AbstractGraph, meaning you can use the extensive functionality provided by Graphs.jl alongside GNN-specific features. You can use Base.copy to create copies of a GNNGraph instance.

    # Example usage of GNNGraph
    using GNNGraphs
    using Graphs
    
    # Assuming a GNNGraph object 'g' exists
    g_copy = copy(g)
  7. Understand the supported graph types in GNNGraphs.jl

    master

    GNNGraphs.jl provides three specialized graph types designed for different neural network application scenarios:

    1. Static graph (GNNGraph): The basic graph type where nodes and edges can have associated features. Use this when the graph structure is fixed, but node or edge features may change.
    2. Heterogeneous graph (GNNHeteroGraph): Supports multiple types of nodes and edges, each with its own properties and relationships. Ideal for multi-relational data like citation graphs.
    3. Temporal graph (TemporalSnapshotsGNNGraph): Represents graphs that change over time. Use this for tracking time-dependent relationships (e.g., social networks) where edges and features evolve dynamically.
  8. Define sequential models using GNNChain

    master

    The GNNChain type is a concise alternative to Flux.Chain. It allows you to compose layers sequentially while automatically propagating both the input graph and the node features.

    Key Behavior:

    • It propagates the graph as the first argument to any layer that subtypes GNNLayer.
    • It only propagates the graph and node features. If your model needs to update or use edge features, you must use the Explicit Modeling style instead.
    • It supports Flux.Parallel branches, correctly propagating the graph into those branches.

    Use GNNChain for standard architectures where node features are transformed through a sequence of graph convolutional layers.

    model = GNNChain(GraphConv(din => d),
                     BatchNorm(d),
                     x -> relu.(x),
                     GraphConv(d => d, relu),
                     Dropout(0.5),
                     Dense(d, dout))
  9. What are Heterogeneous Graphs (Heterographs)?

    master

    In GNNGraphs.jl, heterogeneous graphs (or heterographs) are graphs where nodes and edges have specific types.

    • Node Types: Represented by symbols (e.g., :user, :movie).
    • Edge Types: Represented as a triplet (source_node_type, relation_type, target_node_type), such as (:user, :rate, :movie).

    Heterographs allow different node and edge types to store distinct groups of features, making them highly flexible for complex data modeling. They are implemented using the GNNHeteroGraph type.