physarum-labs 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Alvin Chang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,162 @@
1
+ Metadata-Version: 2.4
2
+ Name: physarum-labs
3
+ Version: 0.2.0
4
+ Summary: Differentiable Linear Programming via Physarum dynamics
5
+ Home-page: https://github.com/Physarum-Lab/physarum-labs
6
+ Author: Alvin Chang
7
+ License: MIT
8
+ Project-URL: Homepage, https://github.com/Physarum-Lab/physarum-labs
9
+ Project-URL: Bug Tracker, https://github.com/Physarum-Lab/physarum-labs/issues
10
+ Project-URL: Source, https://github.com/Physarum-Lab/physarum-labs
11
+ Project-URL: Paper (Meng 2021), https://arxiv.org/abs/2004.14539
12
+ Project-URL: Paper (Solé 2025), https://arxiv.org/abs/2511.08531
13
+ Keywords: physarum,slime-mold,linear-programming,optimal-transport,differentiable,variational,bio-inspired,biological-computing,unconventional-computing
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.8
20
+ Classifier: Programming Language :: Python :: 3.9
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
24
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
25
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
26
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
27
+ Requires-Python: >=3.8
28
+ Description-Content-Type: text/markdown
29
+ License-File: LICENSE
30
+ Requires-Dist: torch>=1.10
31
+ Requires-Dist: numpy>=1.18
32
+ Provides-Extra: dev
33
+ Requires-Dist: pytest>=6.0; extra == "dev"
34
+ Requires-Dist: scipy>=1.7; extra == "dev"
35
+ Requires-Dist: matplotlib>=3.4; extra == "dev"
36
+ Provides-Extra: compare
37
+ Requires-Dist: scipy>=1.7; extra == "compare"
38
+ Requires-Dist: matplotlib>=3.4; extra == "compare"
39
+ Dynamic: home-page
40
+ Dynamic: license-file
41
+ Dynamic: requires-python
42
+
43
+ # physarum labs
44
+
45
+ ![Physarum Labs — variational programming from biological dynamics](assets/readme_header.png)
46
+
47
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
48
+ [![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
49
+ [![Tests](https://img.shields.io/badge/tests-26%2F26%20passing-brightgreen.svg)](tests/)
50
+ [![arXiv](https://img.shields.io/badge/arXiv-2004.14539-b31b1b.svg)](https://arxiv.org/abs/2004.14539)
51
+
52
+ A clean MIT-licensed PyTorch implementation of Physarum-inspired
53
+ differentiable solvers, unifying four lines of recent research:
54
+
55
+ 1. **Meng, Ravi, Singh (AAAI 2021)** — Differentiable LP layer via Physarum dynamics
56
+ 2. **Solé & Pla-Mauri (arXiv Nov 2025)** — Lagrangian variational framework
57
+ 3. **Schick et al. (PRX Life 2026)** — Peristaltic mechanism (substrate inspiration)
58
+ 4. **Pietak & Levin (iScience 2025)** — Regulatory Network Machine paradigm
59
+
60
+ ## What's here
61
+
62
+ - **`physarum_labs/lp.py`** — Clean MIT-licensed PyTorch reimplementation of the
63
+ Physarum-inspired differentiable LP solver. Drop-in replacement for
64
+ Sinkhorn-based optimal transport layers. **No Magic Leap license** — completely
65
+ independent of the SuperGlue codebase.
66
+
67
+ - **`physarum_labs/variational.py`** — End-to-end `VariationalNetworkMachine`
68
+ combining the LP solver with Solé's Lagrangian framework. Shows how to add
69
+ transport dissipation, sparsity, and entropy regularization on top of the
70
+ base solver, and how to learn edge affinities end-to-end.
71
+
72
+ - **`examples/cvxpy_comparison.py`** — Validates the Physarum solver against
73
+ `scipy.optimize.linprog` on a range of problem sizes and iteration counts,
74
+ and produces a convergence plot at `assets/convergence.png`.
75
+
76
+ ## Why this exists
77
+
78
+ The only public working implementation of Meng 2021 lives inside the
79
+ `yingxin-jia/Superglue-with-Physarum-Dynamics` repository, which inherits
80
+ Magic Leap's **non-commercial academic use only** license. Anyone wanting
81
+ to commercialize Physarum Labs must reimplement — which is what this codebase
82
+ does, cleanly.
83
+
84
+ ## Quick start
85
+
86
+ ### Install via PyPI
87
+ ```bash
88
+ pip install physarum-labs
89
+ ```
90
+
91
+ ### Install from source
92
+ ```bash
93
+ git clone https://github.com/Physarum-Lab/physarum-labs
94
+ cd physarum-labs
95
+ pip install -e ".[dev]" # includes scipy and matplotlib for benchmarks
96
+ ```
97
+
98
+ ### Run the demos
99
+ ```bash
100
+ python -m physarum_labs.lp # LP solver self-test
101
+ python -m physarum_labs.variational # maze, matching, learning loop
102
+ python examples/cvxpy_comparison.py # validates against scipy LP solver
103
+ ```
104
+
105
+ ### Run the tests
106
+ ```bash
107
+ pytest tests/ -v
108
+ ```
109
+
110
+ ```python
111
+ import torch
112
+ from physarum_labs import PhysarumLPLayer
113
+
114
+ # Cost matrix (lower = better match)
115
+ scores = torch.rand(4, 5)
116
+ solver = PhysarumLPLayer(unmatch_score=-1.0, max_iter=20)
117
+ transport_plan, loss = solver(scores)
118
+
119
+ # transport_plan shape: (5, 6) — augmented with bin for unmatched
120
+ # transport_plan[:-1, :-1] gives the actual matching scores
121
+ ```
122
+
123
+ ## The algorithm
124
+
125
+ Physarum dynamics solve a doubly-stochastic optimal transport problem by
126
+ iteratively updating a flux vector:
127
+
128
+ ```
129
+ x_{k+1} = (1 - h) * x_k + h * W * A^T * p
130
+ ```
131
+
132
+ where `W = diag(x/c)`, `c` is the cost vector, `A` encodes row/column sum
133
+ constraints, and `p` solves `(A W A^T) p = 1`.
134
+
135
+ This is mathematically equivalent to a steepest-descent on the LP problem
136
+ (see Meng 2021), and to a least-action variational principle (see
137
+ Solé & Pla-Mauri 2025). It's also the same family of dynamics that
138
+ Pietak & Levin use to describe gene regulatory networks as analog computers.
139
+
140
+ ## License
141
+
142
+ MIT. Use freely, including commercially.
143
+
144
+ ## References
145
+
146
+ - Meng, Z., Ravi, S. N., & Singh, V. (2021). Physarum Powered Differentiable
147
+ Linear Programming Layers and Applications. AAAI.
148
+ arXiv:2004.14539
149
+
150
+ - Solé, R., & Pla-Mauri, J. (2025). Cognition as least action: the Physarum
151
+ Lagrangian. arXiv:2511.08531
152
+
153
+ - Schick, L., et al. (2026). Decision-Making in Light-Trapped Slime Molds
154
+ Involves Active Mechanical Processes. PRX Life. DOI: 10.1103/rv7g-d9kx
155
+
156
+ - Pietak, A., & Levin, M. (2025). Harnessing the analog computing power of
157
+ regulatory networks with the Regulatory Network Machine. iScience.
158
+ DOI: 10.1016/j.isci.2025.112536
159
+
160
+ - Bajpai, S., Lucas-DeMott, A., Murugan, N. J., Levin, M., & Kurian, P.
161
+ (2025). Morphological computational capacity of Physarum polycephalum.
162
+ arXiv:2510.19976
@@ -0,0 +1,120 @@
1
+ # physarum labs
2
+
3
+ ![Physarum Labs — variational programming from biological dynamics](assets/readme_header.png)
4
+
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+ [![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
7
+ [![Tests](https://img.shields.io/badge/tests-26%2F26%20passing-brightgreen.svg)](tests/)
8
+ [![arXiv](https://img.shields.io/badge/arXiv-2004.14539-b31b1b.svg)](https://arxiv.org/abs/2004.14539)
9
+
10
+ A clean MIT-licensed PyTorch implementation of Physarum-inspired
11
+ differentiable solvers, unifying four lines of recent research:
12
+
13
+ 1. **Meng, Ravi, Singh (AAAI 2021)** — Differentiable LP layer via Physarum dynamics
14
+ 2. **Solé & Pla-Mauri (arXiv Nov 2025)** — Lagrangian variational framework
15
+ 3. **Schick et al. (PRX Life 2026)** — Peristaltic mechanism (substrate inspiration)
16
+ 4. **Pietak & Levin (iScience 2025)** — Regulatory Network Machine paradigm
17
+
18
+ ## What's here
19
+
20
+ - **`physarum_labs/lp.py`** — Clean MIT-licensed PyTorch reimplementation of the
21
+ Physarum-inspired differentiable LP solver. Drop-in replacement for
22
+ Sinkhorn-based optimal transport layers. **No Magic Leap license** — completely
23
+ independent of the SuperGlue codebase.
24
+
25
+ - **`physarum_labs/variational.py`** — End-to-end `VariationalNetworkMachine`
26
+ combining the LP solver with Solé's Lagrangian framework. Shows how to add
27
+ transport dissipation, sparsity, and entropy regularization on top of the
28
+ base solver, and how to learn edge affinities end-to-end.
29
+
30
+ - **`examples/cvxpy_comparison.py`** — Validates the Physarum solver against
31
+ `scipy.optimize.linprog` on a range of problem sizes and iteration counts,
32
+ and produces a convergence plot at `assets/convergence.png`.
33
+
34
+ ## Why this exists
35
+
36
+ The only public working implementation of Meng 2021 lives inside the
37
+ `yingxin-jia/Superglue-with-Physarum-Dynamics` repository, which inherits
38
+ Magic Leap's **non-commercial academic use only** license. Anyone wanting
39
+ to commercialize Physarum Labs must reimplement — which is what this codebase
40
+ does, cleanly.
41
+
42
+ ## Quick start
43
+
44
+ ### Install via PyPI
45
+ ```bash
46
+ pip install physarum-labs
47
+ ```
48
+
49
+ ### Install from source
50
+ ```bash
51
+ git clone https://github.com/Physarum-Lab/physarum-labs
52
+ cd physarum-labs
53
+ pip install -e ".[dev]" # includes scipy and matplotlib for benchmarks
54
+ ```
55
+
56
+ ### Run the demos
57
+ ```bash
58
+ python -m physarum_labs.lp # LP solver self-test
59
+ python -m physarum_labs.variational # maze, matching, learning loop
60
+ python examples/cvxpy_comparison.py # validates against scipy LP solver
61
+ ```
62
+
63
+ ### Run the tests
64
+ ```bash
65
+ pytest tests/ -v
66
+ ```
67
+
68
+ ```python
69
+ import torch
70
+ from physarum_labs import PhysarumLPLayer
71
+
72
+ # Cost matrix (lower = better match)
73
+ scores = torch.rand(4, 5)
74
+ solver = PhysarumLPLayer(unmatch_score=-1.0, max_iter=20)
75
+ transport_plan, loss = solver(scores)
76
+
77
+ # transport_plan shape: (5, 6) — augmented with bin for unmatched
78
+ # transport_plan[:-1, :-1] gives the actual matching scores
79
+ ```
80
+
81
+ ## The algorithm
82
+
83
+ Physarum dynamics solve a doubly-stochastic optimal transport problem by
84
+ iteratively updating a flux vector:
85
+
86
+ ```
87
+ x_{k+1} = (1 - h) * x_k + h * W * A^T * p
88
+ ```
89
+
90
+ where `W = diag(x/c)`, `c` is the cost vector, `A` encodes row/column sum
91
+ constraints, and `p` solves `(A W A^T) p = 1`.
92
+
93
+ This is mathematically equivalent to a steepest-descent on the LP problem
94
+ (see Meng 2021), and to a least-action variational principle (see
95
+ Solé & Pla-Mauri 2025). It's also the same family of dynamics that
96
+ Pietak & Levin use to describe gene regulatory networks as analog computers.
97
+
98
+ ## License
99
+
100
+ MIT. Use freely, including commercially.
101
+
102
+ ## References
103
+
104
+ - Meng, Z., Ravi, S. N., & Singh, V. (2021). Physarum Powered Differentiable
105
+ Linear Programming Layers and Applications. AAAI.
106
+ arXiv:2004.14539
107
+
108
+ - Solé, R., & Pla-Mauri, J. (2025). Cognition as least action: the Physarum
109
+ Lagrangian. arXiv:2511.08531
110
+
111
+ - Schick, L., et al. (2026). Decision-Making in Light-Trapped Slime Molds
112
+ Involves Active Mechanical Processes. PRX Life. DOI: 10.1103/rv7g-d9kx
113
+
114
+ - Pietak, A., & Levin, M. (2025). Harnessing the analog computing power of
115
+ regulatory networks with the Regulatory Network Machine. iScience.
116
+ DOI: 10.1016/j.isci.2025.112536
117
+
118
+ - Bajpai, S., Lucas-DeMott, A., Murugan, N. J., Levin, M., & Kurian, P.
119
+ (2025). Morphological computational capacity of Physarum polycephalum.
120
+ arXiv:2510.19976
@@ -0,0 +1,35 @@
1
+ """
2
+ physarum_labs — Differentiable Linear Programming via Physarum dynamics
3
+ =========================================================================
4
+
5
+ A clean, MIT-licensed PyTorch implementation of Physarum-inspired
6
+ differentiable solvers, unifying four lines of recent research:
7
+
8
+ 1. Meng, Ravi, Singh (AAAI 2021) — Differentiable LP layer via Physarum dynamics
9
+ 2. Solé & Pla-Mauri (arXiv Nov 2025) — Lagrangian variational framework
10
+ 3. Schick et al. (PRX Life 2026) — Peristaltic mechanism (substrate inspiration)
11
+ 4. Pietak & Levin (iScience 2025) — Regulatory Network Machine paradigm
12
+
13
+ Public API
14
+ ----------
15
+ from physarum_labs import (
16
+ PhysarumLPLayer, # differentiable LP layer
17
+ VariationalPhysarumSolver, # LP layer + Lagrangian regularization
18
+ VariationalNetworkMachine, # end-to-end graph/transport learner
19
+ )
20
+
21
+ License: MIT
22
+ """
23
+
24
+ from __future__ import annotations
25
+
26
+ from physarum_labs.lp import PhysarumLPLayer, VariationalPhysarumSolver
27
+ from physarum_labs.variational import VariationalNetworkMachine
28
+
29
+ __all__ = [
30
+ "PhysarumLPLayer",
31
+ "VariationalPhysarumSolver",
32
+ "VariationalNetworkMachine",
33
+ ]
34
+
35
+ __version__ = "0.2.0"