A JAX library for connectivity modelling at scale
Project description
JAXScape is a minimal JAX library for connectivity analysis at scales. It provide key utilities to build your own connectivity analysis workflow, including
- differentiable and GPU-accelerated graph distance metrics
- differentiable raster to graph and graph to raster mappings
- moving window utilities for implementing large-scale connectivity analysis pipelines
JAXScape implements custom methods and leverages JAX's capabilities to accelerate distance computations on CPUs/GPUs/TPUs, while ensuring differentiability across the codebase for awesome sensitivity analysis and optimization.
Installation
uv add jaxscape
For GPU compatibility, install JAX following the official JAX installation guide. JAXScape will automatically use the JAX backend you have configured.
You may be required to install optional linear solvers for large-scale resistance distance computations. CholmodSolver, PyAMGSolver, and AMJaxCGSolver are documented on the linear solver page.
Quick start
1. Download sample data
curl -sL https://github.com/vboussange/jaxscape/releases/download/v0.0.6/data.zip -o data.zip && unzip -q data.zip && rm data.zip
2. Run the analysis
import numpy as np
import matplotlib.pyplot as plt
import jax.numpy as jnp
from jaxscape import GridGraph
from jaxscape import LCPDistance, ResistanceDistance, RSPDistance
permeability = jnp.array(np.loadtxt("data/permeability.csv", delimiter=",")) + 0.001
barriers = np.asarray(permeability <= 0.1)
# Create a grid graph where edge weights are the average permeability of the two nodes
grid = GridGraph(grid=permeability, fun=lambda x, y: (x + y) / 2)
# We set the source to the top left pixel, and compute distances to all other pixels with three different distance metrics
source = grid.coord_to_index(jnp.array([0]), jnp.array([0]))
distances = {
"LCP distance": LCPDistance(),
"Resistance distance": ResistanceDistance(),
"RSP distance": RSPDistance(theta=0.01, cost=lambda x: -jnp.log(x)),
}
distance_cmap = plt.cm.magma.copy()
distance_cmap.set_bad(color="lightgray")
fig, axs = plt.subplots(1, 4, figsize=(12, 4))
permeability_im = axs[0].imshow(permeability, cmap="gray", vmin=0, vmax=1)
axs[0].set_xticks([])
axs[0].set_yticks([])
for spine in axs[0].spines.values():
spine.set_visible(True)
axs[0].set_title("Permeability")
fig.colorbar(permeability_im, ax=axs[0], shrink=0.2)
for ax, (title, distance) in zip(axs[1:], distances.items()):
# Compute distances from all nodes to the source
dist_to_node = distance(grid, source)
# Convert from node values to a 2D array and hide barrier cells
dist_array = np.asarray(grid.node_values_to_array(dist_to_node.ravel()))
dist_array = np.ma.masked_where(barriers, dist_array)
# Plotting
im = ax.imshow(dist_array, cmap=distance_cmap)
ax.axis("off")
ax.set_title(title)
fig.colorbar(im, ax=ax, shrink=0.2)
fig.suptitle("Permeability and distance to the top-left pixel")
plt.tight_layout()
plt.show()
But what's really cool about JAXscape is that you can autodiff through thoses distances! Check out the documentation to learn about applications and more!
Documentation
Comprehensive documentation is available at https://vboussange.github.io/jaxscape
Benchmarking
JAXScape includes a benchmark workspace that profiles internal JAXScape
implementations and compares them with external landscape-connectivity tools.
Published results and task definitions are available in the
benchmark documentation.
To reproduce the suite or run it on a local CPU/GPU device, follow the
instructions in benchmark/README.md.
License
jaxscape is distributed under the terms of the MIT license.
Related packages
- gdistance
- ConScape
- Circuitscape
- graphhab
- conefor
- resistanceGA
- landscapemetrics
- radish
Citation
If you use JAXScape in your research, please cite:
@software{jaxscape2024,
author = {Boussange, Victor},
title = {JAXScape: A minimal JAX library for connectivity modelling at scale},
year = {2025},
doi = {10.5281/zenodo.15267703},
url = {https://github.com/vboussange/jaxscape}
}
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jaxscape-0.0.9.tar.gz.
File metadata
- Download URL: jaxscape-0.0.9.tar.gz
- Upload date:
- Size: 3.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
76da5d95cf9da55053682bfb7675b6d8ccd914cc6c22e16e9a03bfb4413deb2c
|
|
| MD5 |
a163deaf0de88bbb41731619c992c22a
|
|
| BLAKE2b-256 |
0cecacad1910d82dbf55beec54d8567c0dd20f6e578503b518b585cb4f5e366f
|
File details
Details for the file jaxscape-0.0.9-py3-none-any.whl.
File metadata
- Download URL: jaxscape-0.0.9-py3-none-any.whl
- Upload date:
- Size: 42.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7ae5045c618e592f1b5ef0fff0216bcf292719fdcd3b92afffab660410644198
|
|
| MD5 |
ef406deb5fb5f838cc19063dc1e2b940
|
|
| BLAKE2b-256 |
6e3e184f6cb5421a045aebf91a9b95f678710b372af47d5a1083f589e45dc119
|