Skip to main content

MLX-Cluster

High-performance graph algorithms optimized for Apple's MLX framework, featuring random walks, biased random walks, and neighbor sampling.

PyPI version License: MIT Python 3.8+

Documentation | Quickstart |

Features

  • ** MLX Optimized**: Built specifically for Apple's MLX framework with GPU acceleration
  • ** High Performance**: Optimized C++ implementations with Metal shaders for Apple Silicon
  • ** Graph Algorithms**:
    • Uniform random walks
    • Biased random walks (Node2Vec style with p/q parameters)
    • Multi-hop neighbor sampling (GraphSAGE style)

Installation

From PyPI (Recommended)

pip install mlx-cluster

From Source

git clone https://github.com/vinayhpandya/mlx_cluster.git
cd mlx_cluster
pip install -e .

Development Installation

git clone https://github.com/vinayhpandya/mlx_cluster.git
cd mlx_cluster
pip install -e . --verbose

Dependencies

Required:

  • Python 3.8+
  • MLX framework
  • NumPy

Optional (for examples and testing):

  • MLX-Graphs
  • PyTorch (for dataset utilities)
  • pytest

Quick Start

Random Walks

import mlx.core as mx
import numpy as np
from mlx_cluster import random_walk
from mlx_graphs.datasets import PlanetoidDataset
from mlx_graphs.utils.sorting import sort_edge_index

# Load dataset
cora = PlanetoidDataset(name="cora")
edge_index = cora.graphs[0].edge_index.astype(mx.int64)

# Convert to CSR format
sorted_edge_index = sort_edge_index(edge_index=edge_index)
row = sorted_edge_index[0][0]
col = sorted_edge_index[0][1]
_, counts = np.unique(np.array(row, copy=False), return_counts=True)
row_ptr = mx.concatenate([mx.array([0]), mx.array(counts.cumsum())])

# Generate random walks
num_walks = 1000
walk_length = 10
start_nodes = mx.array(np.random.randint(0, cora.graphs[0].num_nodes, num_walks))
rand_values = mx.random.uniform(shape=[num_walks, walk_length])

mx.eval(rowptr,col, start_nodes, rand_values)
# Perform walks
node_sequences, edge_sequences = random_walk(
    row_ptr, col, start_nodes, rand_values, walk_length, stream=mx.gpu
)

print(f"Generated {num_walks} walks of length {walk_length + 1}")
print(f"Shape: {node_sequences.shape}")

Biased Random Walks (Node2Vec)

from mlx_cluster import rejection_sampling

# Biased random walks with p/q parameters
node_sequences, edge_sequences = rejection_sampling(
    row_ptr, col, start_nodes, walk_length,
    p=1.0,  # Return parameter
    q=2.0,  # In-out parameter
    stream=mx.gpu
)

Neighbor Sampling

from mlx_cluster import neighbor_sample

# Convert to CSC format (required for neighbor sampling)
def create_csc_format(edge_index, num_nodes):
    sources, targets = edge_index[0].tolist(), edge_index[1].tolist()
    edges = sorted(zip(sources, targets), key=lambda x: x[1])
    
    colptr = np.zeros(num_nodes + 1, dtype=np.int64)
    for _, target in edges:
        colptr[target + 1] += 1
    colptr = np.cumsum(colptr)
    
    sorted_sources = [source for source, _ in edges]
    return mx.array(colptr), mx.array(sorted_sources, dtype=mx.int64)

colptr, row = create_csc_format(edge_index, cora.graphs[0].num_nodes)

# Multi-hop neighbor sampling
input_nodes = mx.array([0, 1, 2], dtype=mx.int64)
num_neighbors = [10, 5]  # 10 neighbors in first hop, 5 in second
mx.eval(colptr, row, input_nodes)
samples, rows, cols, edges = neighbor_sample(
    colptr, row, input_nodes, num_neighbors,
    replace=True, directed=True
)

print(f"Sampled {len(samples)} nodes and {len(edges)} edges")

Documentation

For comprehensive documentation, examples, and API reference, visit: Documentation

Testing

Run the test suite:

# Install test dependencies
pip install pytest mlx-graphs torch

# Run tests
pytest -s -v

Performance

MLX-Cluster is optimized for Apple Silicon and shows significant speedups:

  • Apple M1/M2/M3: 2-5x faster than CPU-only implementations
  • GPU Acceleration: Automatic optimization for Metal Performance Shaders
  • Memory Efficient: Optimized sparse graph representations
  • Batch Processing: Efficient handling of thousands of concurrent walks

Contributing

We welcome contributions!

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/new-feature)
  3. Commit your changes (git commit -m 'Add new algorithm')
  4. Push to the branch (git push origin feature/new-feature)
  5. Open a Pull Request For installation and test intructions please visit the documentation

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

Citation

If you use MLX-Cluster in your research, please cite:

@software{mlx_cluster,
  author = {Vinay Pandya},
  title = {MLX-Cluster: High-Performance Graph Algorithms for Apple MLX},
  url = {https://github.com/vinayhpandya/mlx_cluster},
  version = {0.0.6},
  year = {2025}
}

Related Projects


Metadata

Release files for mlx-cluster 0.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mlx-cluster 0.0.7
File Size Uploaded
mlx_cluster-0.0.7.tar.gz 20.5 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for mlx-cluster 0.0.7
File
mlx_cluster-0.0.7-cp313-cp313-macosx_14_0_universal2.whl CPython 3.13 CPython 3.13 macOS 14.0+ universal2 (ARM64, x86-64) Details
mlx_cluster-0.0.7-cp312-cp312-macosx_14_0_universal2.whl CPython 3.12 CPython 3.12 macOS 14.0+ universal2 (ARM64, x86-64) Details
mlx_cluster-0.0.7-cp311-cp311-macosx_14_0_universal2.whl CPython 3.11 CPython 3.11 macOS 14.0+ universal2 (ARM64, x86-64) Details
mlx_cluster-0.0.7-cp310-cp310-macosx_14_0_universal2.whl CPython 3.10 CPython 3.10 macOS 14.0+ universal2 (ARM64, x86-64) Details
mlx_cluster-0.0.7-cp39-cp39-macosx_14_0_universal2.whl CPython 3.9 CPython 3.9 macOS 14.0+ universal2 (ARM64, x86-64) Details

Total release size: 408.8 kB

Release files / mlx_cluster-0.0.7.tar.gz

Download URL mlx_cluster-0.0.7.tar.gz
Size 20.5 kB
Tags Source
SHA-256 checksum
How to use checksums
5e7772541d44b9dad13a53e4dbe210d3f020d69fb64e4ca2e3e1d78b9d637c08
BLAKE2b-256 checksum
How to use checksums
9bedaaa4272bd1dcf1e79ef109bb4b757b5ddd6eb0b81d33b68240e351b83ad3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 2, 2026.

Transparency log

Release files / mlx_cluster-0.0.7-cp313-cp313-macosx_14_0_universal2.whl

Download URL mlx_cluster-0.0.7-cp313-cp313-macosx_14_0_universal2.whl
Size 77.5 kB
Tags CPython 3.13 macOS 14.0+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
c850f1d537baa8ddc7f3f52b45d27614f90034a60a8063d18d913c807e8c4dd1
BLAKE2b-256 checksum
How to use checksums
653837f3011ca5b88a955c487d1e19d975d5b120b7f73b3b3cb125457e81fb64
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 3, 2026.

Transparency log

Release files / mlx_cluster-0.0.7-cp312-cp312-macosx_14_0_universal2.whl

Download URL mlx_cluster-0.0.7-cp312-cp312-macosx_14_0_universal2.whl
Size 77.4 kB
Tags CPython 3.12 macOS 14.0+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
8cd79d06460d1ea234e2aeb493ea5cafe534b236da341ba77cc5e9766299c486
BLAKE2b-256 checksum
How to use checksums
52f0f390d7e3e7298108de49c776be8483fe95eefccac1543091ae04d28d3708
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 2, 2026.

Transparency log

Release files / mlx_cluster-0.0.7-cp311-cp311-macosx_14_0_universal2.whl

Download URL mlx_cluster-0.0.7-cp311-cp311-macosx_14_0_universal2.whl
Size 77.8 kB
Tags CPython 3.11 macOS 14.0+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
7c5efc67564c569ef72f80ab4e401b150162a951fa70e376bb862189f3307a81
BLAKE2b-256 checksum
How to use checksums
85e214f2d6a3438422c2a271d38d1fc7fae3972099db5308ebed901e774e4e14
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 3, 2026.

Transparency log

Release files / mlx_cluster-0.0.7-cp310-cp310-macosx_14_0_universal2.whl

Download URL mlx_cluster-0.0.7-cp310-cp310-macosx_14_0_universal2.whl
Size 77.9 kB
Tags CPython 3.10 macOS 14.0+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
51e6ea8ef80ce7777adba2abe94bb3d7876e8dd58969d1e790e79f8d38de9f32
BLAKE2b-256 checksum
How to use checksums
297b8e3cdb5567fcd8b2bebf2c9e00b7f6d7d556345cd6de51bff315b90197a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 3, 2026.

Transparency log

Release files / mlx_cluster-0.0.7-cp39-cp39-macosx_14_0_universal2.whl

Download URL mlx_cluster-0.0.7-cp39-cp39-macosx_14_0_universal2.whl
Size 77.7 kB
Tags CPython 3.9 macOS 14.0+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
776e5016e4de83a09a27dd8fdd0c2f02d872668829fa8f1dcc0ed2e2f5ca3866
BLAKE2b-256 checksum
How to use checksums
d373dbb5273ccd84401eb99d6ecdee7fa1199d04bc559bf678bd2056d4ddb4c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 3, 2026.

Transparency log

Release history Release notifications | RSS feed

0.0.9

2 release files

This release

0.0.7 This release

6 release files

0.0.6

6 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page