Skip to content

Requirements

Python version

Python 3.9 or newer is required.


Base install

pip install spatial_graph_algorithms

Installs everything needed for simulation, MDS/STRND reconstruction, metrics, and plotting.

Package Version Used for
numpy ≥ 1.21 Array operations throughout
scipy ≥ 1.7 Sparse matrices, shortest paths, Procrustes alignment
pandas ≥ 1.3 Edge/node metadata DataFrames
networkx ≥ 2.8 Graph operations, clustering coefficient
python-igraph ≥ 0.10 Fast graph conversion (to_igraph)
scikit-learn ≥ 1.0 MDS, nearest neighbours
matplotlib ≥ 3.5 All plotting functions
Pillow ≥ 9.0 Bundled shape/image loading
pecanpy ≥ 2.0 Node2Vec biased random walks for STRND
umap-learn ≥ 0.5 Dimensionality reduction for STRND

Optional extras

Compatibility note: Two runtime shims are applied automatically when STRND is first called, patching known incompatibilities between pecanpy/gensim and newer scipy/sklearn. No user action is needed.

Leiden community detection

pip install "spatial_graph_algorithms[leiden]"
Package Version Used for
leidenalg ≥ 0.9 Community-based edge filtering

GSE reconstruction

pip install "spatial_graph_algorithms[gse]"

Required for reconstruct(sg, method="gse").

Package Version Used for
annoy ≥ 1.17 Approximate nearest-neighbour backend
faiss-cpu ≥ 1.7 FAISS approximate nearest-neighbour backend
pymetis ≥ 2023.1 Graph partitioning backend
numba ≥ 0.57 JIT acceleration

All optional features

pip install "spatial_graph_algorithms[all]"

Installs Leiden + GSE + PyTorch + PyMDE + PaCMAP and optional acceleration / embedding backends.

Package Version Used for
torch ≥ 2.0 Optional embedding backends
pymde ≥ 0.1 Optional manifold embedding experiments
pacmap ≥ 0.7 Optional manifold embedding experiments
annoy ≥ 1.17 Approximate nearest-neighbour backend
faiss-cpu ≥ 1.7 FAISS approximate nearest-neighbour backend
pymetis ≥ 2023.1 Graph partitioning backend

Development install

git clone https://github.com/DavidFernandezBonet/spatial-graph-algorithms
cd spatial-graph-algorithms
pip install -e ".[dev]"
pytest tests/

The dev extra adds pytest, pytest-cov, and ruff.


Operating systems

Tested on Linux and macOS. Windows should work but is not explicitly tested.

The base package has no compiled C extensions. Some optional extras, including faiss-cpu and pymetis under [all], install compiled wheels.


Checking your install

import spatial_graph_algorithms
print(spatial_graph_algorithms.__version__)

from spatial_graph_algorithms.simulate import generate
from spatial_graph_algorithms.reconstruct import reconstruct
from spatial_graph_algorithms.metrics import evaluate

sg     = generate(n=100, seed=42)
sg_rec = reconstruct(sg, method="mds", seed=42)
m      = evaluate(sg_rec)
print("CPD:", m["cpd"])   # should be > 0.5