Skip to content

Commit 24bbcd9

Browse files
committed
Initial public release
0 parents  commit 24bbcd9

24 files changed

Lines changed: 2279 additions & 0 deletions

.github/workflows/ci.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: ["main", "master"]
6+
pull_request:
7+
8+
jobs:
9+
tests:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
16+
- name: Set up Python
17+
uses: actions/setup-python@v5
18+
with:
19+
python-version: "3.10"
20+
21+
- name: Install project
22+
run: |
23+
python -m pip install --upgrade pip
24+
pip install -e .
25+
26+
- name: Run XOR subset scan
27+
run: python -m thermolab.experiments.xor.subset_scan --repeats 1 --max_subset 2
28+
29+
- name: Run XOR THRML lab
30+
run: python -m thermolab.experiments.xor.thrml --repeats 4 --steps 10 --benchmark-samples 1000 --weight-threshold 0.1
31+
32+
- name: Run Iris experiment
33+
run: python -m thermolab.experiments.iris --classes 0,1 --positive-class 0 --steps 10 --benchmark-samples 1000 --max-subset 2
34+
35+
- name: Run Breast Cancer experiment
36+
run: python -m thermolab.experiments.breast_cancer --steps 10 --benchmark-samples 5000 --top-features 3 --max-subset 1

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Extropic Labs
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.

README.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Thermodynamic Sampling Lab
2+
3+
Massive random sampling can collapse the search space for sparse polynomials. This lab shows how thermodynamic sampling units (TSUs) can learn supervised models by identifying the interaction structure—then optionally export the resulting polynomial to a deterministic CPU implementation. The goal is not production quality; it is to demonstrate the style of thinking this approach enables.
4+
5+
## Quick Start
6+
7+
**What you'll see:** TSUs discovering that XOR needs a 2-way interaction,
8+
Iris needing 3-5 key features, and breast cancer reducing 127 potential
9+
edges to ~12 significant ones—then deploying each as a fast sparse polynomial.
10+
11+
Install the package (installs all runtime dependencies):
12+
13+
```bash
14+
pip install -e .
15+
```
16+
17+
Then launch the core experiments:
18+
19+
```bash
20+
python -m thermolab.experiments.xor.subset_scan
21+
python -m thermolab.experiments.xor.thrml
22+
python -m thermolab.experiments.iris
23+
python -m thermolab.experiments.breast_cancer
24+
```
25+
26+
Optional explorations:
27+
28+
```bash
29+
python -m thermolab.experiments.xor.high_order # explicit three-spin XOR factor
30+
python -m thermolab.experiments.ising # toy Ising sampler + benchmarking
31+
```
32+
33+
## Expected Runtime & Results
34+
35+
| Command | Approx. runtime* | Key metrics (train / test) | Dense vs. sparse time (speedup) |
36+
| --- | --- | --- | --- |
37+
| `python -m thermolab.experiments.xor.subset_scan` | < 1 s | Consistency report only | n/a |
38+
| `python -m thermolab.experiments.xor.thrml` | ~1 s | 1.00 / 1.00 accuracy | 0.0023 s vs. 0.0012 s (1.9×) |
39+
| `python -m thermolab.experiments.iris` | ~1 s | 1.00 / 1.00 accuracy | 0.0016 s vs. 0.0036 s (0.46×) |
40+
| `python -m thermolab.experiments.breast_cancer` | ~1 min | 0.90 / 0.92 accuracy | 4.41 s vs. 0.24 s (18×) |
41+
42+
## Why These Experiments
43+
44+
Many TSU discussions fixate on the specific demos Extropic has demonstrated (e.g. Fashion MNIST denoising using DTMs). The key insight is broader: massive random sampling can collapse the search for high-order interactions, letting you learn sparse polynomials and move the final evaluation to conventional hardware. This lab walks through that progression.
45+
46+
### XOR First
47+
48+
Every new modelling idea I test starts with XOR—XOR is the simplest possible test of whether a method can discover non-linear structure.
49+
50+
Four binary patterns—`[1,1,-1]`, `[1,-1,1]`, `[-1,1,1]`, `[-1,-1,-1]`—live on an XY plane where no linear separator exists. By scanning feature subsets we see immediately that single spins stay ambiguous while the two-spin interaction resolves the task. That’s the minimum bar: can the method recover the need for higher-order terms in the simplest non-linearly separable problem?
51+
52+
### Binary Classification
53+
54+
The Iris binary subset and the breast-cancer dataset illustrate classical “spin + polynomial” pipelines. Features are thresholded into bits, optional interaction columns are added where subset agreement indicates necessity, and pseudo-likelihood with L1 sparsity learns THRML weights. Each run reports deterministic accuracy and the speedup from dropping negligible edges—highlighting how a TSU can discover the structure and then hand it to a classical evaluator.
55+
56+
### Multi-Class via One-vs-Rest
57+
58+
When you pass `--classes 0,1,2` to `experiments/iris.py`, each run picks one class as positive and collapses the rest into a negative label. Repeating the pipeline for each class yields three polynomials that together cover the multi-class decision surface. This keeps the workflow simple while still showing how TSUs can support multi-way decisions.
59+
60+
### Complex Binning and Interactions
61+
62+
`experiments/breast_cancer.py` demonstrates richer binning. It thresholds dozens of features, then builds pairwise interaction terms for the most reliable single features. That mirrors real-world cases where you might quantise sensors into multiple bins or engineer domain-specific interactions. The lab exposes how those choices change disagreement, weight sparsity, and deterministic evaluation speed.
63+
64+
### Thermal-to-Classical Conversion
65+
66+
All experiments finish by benchmarking the learned polynomial in dense vs. sparsified form. That makes the optional conversion explicit: run the search on a TSU (or a simulator), keep only the significant edges, and deploy the lean polynomial on conventional hardware.
67+
68+
---
69+
70+
The lab is deliberately minimal. Use it as a sandbox for new binning strategies, higher-order factors, or alternative learning rules—and as a reminder that thermodynamic computing is ultimately about shrinking search, not just recreating familiar demos.
71+
72+
---
73+
74+
### Author
75+
76+
**Sam Martin** ([@_sammartin](https://twitter.com/_sammartin))
77+
78+
Licensed under the MIT License (see `LICENSE`).

pyproject.toml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[build-system]
2+
requires = ["setuptools>=64", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "thermolab"
7+
version = "0.1.0"
8+
description = "Thermodynamic sampling lab for sparse polynomial experiments."
9+
readme = "README.md"
10+
requires-python = ">=3.10"
11+
license = { file = "LICENSE" }
12+
authors = [
13+
{ name = "Extropic Labs" }
14+
]
15+
dependencies = [
16+
"jax==0.6.2",
17+
"jaxlib==0.6.2",
18+
"numpy==1.26.4",
19+
"thrml==0.1.3",
20+
]
21+
22+
[tool.setuptools.packages.find]
23+
where = ["."]
24+
include = ["thermolab*"]
25+
26+
[tool.setuptools.package-data]
27+
"thermolab.data" = ["*.csv"]

requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
jax==0.6.2
2+
jaxlib==0.6.2
3+
numpy==1.26.4
4+
thrml==0.1.3

thermolab/__init__.py

Whitespace-only changes.

thermolab/data/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)