Differentiable Linear Programming via Physarum dynamics
Project description
physarum labs
A clean MIT-licensed PyTorch implementation of Physarum-inspired differentiable solvers, unifying four lines of recent research:
- Meng, Ravi, Singh (AAAI 2021) — Differentiable LP layer via Physarum dynamics
- Solé & Pla-Mauri (arXiv Nov 2025) — Lagrangian variational framework
- Schick et al. (PRX Life 2026) — Peristaltic mechanism (substrate inspiration)
- Pietak & Levin (iScience 2025) — Regulatory Network Machine paradigm
What's here
-
physarum_labs/lp.py— Clean MIT-licensed PyTorch reimplementation of the Physarum-inspired differentiable LP solver. Drop-in replacement for Sinkhorn-based optimal transport layers. No Magic Leap license — completely independent of the SuperGlue codebase. -
physarum_labs/variational.py— End-to-endVariationalNetworkMachinecombining the LP solver with Solé's Lagrangian framework. Shows how to add transport dissipation, sparsity, and entropy regularization on top of the base solver, and how to learn edge affinities end-to-end. -
examples/cvxpy_comparison.py— Validates the Physarum solver againstscipy.optimize.linprogon a range of problem sizes and iteration counts, and produces a convergence plot atassets/convergence.png.
Why this exists
The only public working implementation of Meng 2021 lives inside the
yingxin-jia/Superglue-with-Physarum-Dynamics repository, which inherits
Magic Leap's non-commercial academic use only license. Anyone wanting
to commercialize Physarum Labs must reimplement — which is what this codebase
does, cleanly.
Quick start
Install via PyPI
pip install physarum-labs
Install from source
git clone https://github.com/Physarum-Lab/physarum-labs
cd physarum-labs
pip install -e ".[dev]" # includes scipy and matplotlib for benchmarks
Run the demos
python -m physarum_labs.lp # LP solver self-test
python -m physarum_labs.variational # maze, matching, learning loop
python examples/cvxpy_comparison.py # validates against scipy LP solver
Run the tests
pytest tests/ -v
import torch
from physarum_labs import PhysarumLPLayer
# Cost matrix (lower = better match)
scores = torch.rand(4, 5)
solver = PhysarumLPLayer(unmatch_score=-1.0, max_iter=20)
transport_plan, loss = solver(scores)
# transport_plan shape: (5, 6) — augmented with bin for unmatched
# transport_plan[:-1, :-1] gives the actual matching scores
The algorithm
Physarum dynamics solve a doubly-stochastic optimal transport problem by iteratively updating a flux vector:
x_{k+1} = (1 - h) * x_k + h * W * A^T * p
where W = diag(x/c), c is the cost vector, A encodes row/column sum
constraints, and p solves (A W A^T) p = 1.
This is mathematically equivalent to a steepest-descent on the LP problem (see Meng 2021), and to a least-action variational principle (see Solé & Pla-Mauri 2025). It's also the same family of dynamics that Pietak & Levin use to describe gene regulatory networks as analog computers.
License
MIT. Use freely, including commercially.
References
-
Meng, Z., Ravi, S. N., & Singh, V. (2021). Physarum Powered Differentiable Linear Programming Layers and Applications. AAAI. arXiv:2004.14539
-
Solé, R., & Pla-Mauri, J. (2025). Cognition as least action: the Physarum Lagrangian. arXiv:2511.08531
-
Schick, L., et al. (2026). Decision-Making in Light-Trapped Slime Molds Involves Active Mechanical Processes. PRX Life. DOI: 10.1103/rv7g-d9kx
-
Pietak, A., & Levin, M. (2025). Harnessing the analog computing power of regulatory networks with the Regulatory Network Machine. iScience. DOI: 10.1016/j.isci.2025.112536
-
Bajpai, S., Lucas-DeMott, A., Murugan, N. J., Levin, M., & Kurian, P. (2025). Morphological computational capacity of Physarum polycephalum. arXiv:2510.19976
Project details
Release history Release notifications | RSS feed
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 physarum_labs-0.2.1.tar.gz.
File metadata
- Download URL: physarum_labs-0.2.1.tar.gz
- Upload date:
- Size: 19.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be32acdf4b7ff178183977b917b6553094cdc41da35529a199b4d214bea49e6a
|
|
| MD5 |
bd77d8c5f76ceb0146753803ded43d46
|
|
| BLAKE2b-256 |
e41010c884508a967047c37dae3be88495094d27bea2f5adf5b6d3b4a5fc8ee4
|
Provenance
The following attestation bundles were made for physarum_labs-0.2.1.tar.gz:
Publisher:
release.yml on Physarum-Lab/physarum-labs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
physarum_labs-0.2.1.tar.gz -
Subject digest:
be32acdf4b7ff178183977b917b6553094cdc41da35529a199b4d214bea49e6a - Sigstore transparency entry: 2009684771
- Sigstore integration time:
-
Permalink:
Physarum-Lab/physarum-labs@1c685def7dbf6fb55a40b02af822b34ce4691e58 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/Physarum-Lab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@1c685def7dbf6fb55a40b02af822b34ce4691e58 -
Trigger Event:
push
-
Statement type:
File details
Details for the file physarum_labs-0.2.1-py3-none-any.whl.
File metadata
- Download URL: physarum_labs-0.2.1-py3-none-any.whl
- Upload date:
- Size: 14.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
781eb0d15f02164816e633ed4cea58c11e7171f9e8c17cb84d3777853b235c38
|
|
| MD5 |
305f3725cc26b0c8a604593a57849526
|
|
| BLAKE2b-256 |
e1ea1caa85a206eb66e3e21582f205b923773e69d8676f5b2ba7c49616e56c22
|
Provenance
The following attestation bundles were made for physarum_labs-0.2.1-py3-none-any.whl:
Publisher:
release.yml on Physarum-Lab/physarum-labs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
physarum_labs-0.2.1-py3-none-any.whl -
Subject digest:
781eb0d15f02164816e633ed4cea58c11e7171f9e8c17cb84d3777853b235c38 - Sigstore transparency entry: 2009684890
- Sigstore integration time:
-
Permalink:
Physarum-Lab/physarum-labs@1c685def7dbf6fb55a40b02af822b34ce4691e58 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/Physarum-Lab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@1c685def7dbf6fb55a40b02af822b34ce4691e58 -
Trigger Event:
push
-
Statement type: