Skip to content

Installation

Python 3.11 recommended (3.9–3.12 supported). The package is pure Python — no compiled extensions.


Gives you a fully isolated environment with Python 3.11, all dependencies, and the package installed in editable mode so your source changes are picked up immediately.

git clone https://github.com/DavidFernandezBonet/spatial-graph-algorithms
cd spatial-graph-algorithms
conda env create -f environment.yml
conda activate spatial-graph-algorithms

Verify:

pytest tests/ -q          # should show 50 passed
python -c "import spatial_graph_algorithms; print(spatial_graph_algorithms.__version__)"

Option B — pip (end users)

# Base install: simulate, MDS/STRND reconstruction, metrics, plotting
pip install spatial_graph_algorithms

# Add Leiden community detection (for the denoise module, coming in v0.2)
pip install "spatial_graph_algorithms[leiden]"

Option C — uv (fastest for pip users)

uv is a fast drop-in replacement for pip + venv.

pip install uv
uv venv --python 3.11
source .venv/bin/activate          # or .venv\Scripts\activate on Windows
uv pip install spatial_graph_algorithms

Verify your install

import spatial_graph_algorithms as sga
print(sga.__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=200, seed=42)
m  = evaluate(reconstruct(sg, method="mds", seed=42))
print("CPD:", round(m["cpd"], 3))    # > 0.9 on a clean graph

Dependencies

Package Min version Installed by Used for
numpy 1.21 base Arrays throughout
scipy 1.7 base Sparse matrices, shortest paths, Procrustes
pandas 1.3 base Edge/node metadata
networkx 2.8 base Graph operations, clustering coefficient
python-igraph 0.10 base Fast graph conversion
scikit-learn 1.0 base MDS, nearest neighbours
matplotlib 3.5 base All plots
umap-learn 0.5 base UMAP reduction for STRND
pecanpy 2.0 base Node2Vec random walks
leidenalg 0.9 [leiden] Leiden community detection
annoy 1.17 [gse], [all] Approximate nearest-neighbour backend
faiss-cpu 1.7 [gse], [all] FAISS approximate nearest-neighbour backend
pymetis 2023.1 [gse], [all] Graph partitioning backend

Full details: REQUIREMENTS.md


Compatibility notes

When spatial_graph_algorithms.reconstruct.strnd is imported for the first time, two runtime shims are applied automatically:

  • scipy.linalg.triu — removed in newer scipy; restored for pecanpy/gensim.
  • sklearn check_array force_all_finite — renamed ensure_all_finite in sklearn 1.6+.

No user action is needed. These are isolated to the STRND module.