spinchain 0.1.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.
- spinchain-0.1.0/PKG-INFO +242 -0
- spinchain-0.1.0/README.md +217 -0
- spinchain-0.1.0/pyproject.toml +42 -0
- spinchain-0.1.0/src/spinchain/__init__.py +3 -0
- spinchain-0.1.0/src/spinchain/__main__.py +5 -0
- spinchain-0.1.0/src/spinchain/analyze.py +326 -0
- spinchain-0.1.0/src/spinchain/formulation/__init__.py +5 -0
- spinchain-0.1.0/src/spinchain/formulation/coefficient_builder.py +108 -0
- spinchain-0.1.0/src/spinchain/formulation/fragment_extractor.py +115 -0
- spinchain-0.1.0/src/spinchain/formulation/qubo_builder.py +66 -0
- spinchain-0.1.0/src/spinchain/pipeline/__init__.py +2 -0
- spinchain-0.1.0/src/spinchain/py.typed +0 -0
- spinchain-0.1.0/src/spinchain/server.py +226 -0
- spinchain-0.1.0/src/spinchain/solvers/__init__.py +4 -0
- spinchain-0.1.0/src/spinchain/solvers/base.py +36 -0
- spinchain-0.1.0/src/spinchain/solvers/simulated_annealing.py +42 -0
- spinchain-0.1.0/src/spinchain/tracing.py +172 -0
spinchain-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: spinchain
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Inference-time reasoning optimization using QUBO/Ising formulations
|
|
5
|
+
Author: Ameya Khot
|
|
6
|
+
Author-email: Ameya Khot <ameyakhot18@gmail.com>
|
|
7
|
+
Requires-Dist: mcp>=1.0.0
|
|
8
|
+
Requires-Dist: dwave-neal>=0.6.0
|
|
9
|
+
Requires-Dist: dimod>=0.12.0
|
|
10
|
+
Requires-Dist: pyqubo>=1.5.0
|
|
11
|
+
Requires-Dist: sentence-transformers>=3.0.0
|
|
12
|
+
Requires-Dist: numpy>=1.26.0
|
|
13
|
+
Requires-Dist: scipy>=1.12.0
|
|
14
|
+
Requires-Dist: pytest>=8.0.0 ; extra == 'dev'
|
|
15
|
+
Requires-Dist: ruff>=0.4.0 ; extra == 'dev'
|
|
16
|
+
Requires-Dist: qiskit>=1.0.0 ; extra == 'quantum'
|
|
17
|
+
Requires-Dist: qiskit-aer>=0.15.0 ; extra == 'quantum'
|
|
18
|
+
Requires-Dist: qiskit-optimization>=0.6.0 ; extra == 'quantum'
|
|
19
|
+
Requires-Dist: anthropic>=0.42.0 ; extra == 'standalone'
|
|
20
|
+
Requires-Python: >=3.11
|
|
21
|
+
Provides-Extra: dev
|
|
22
|
+
Provides-Extra: quantum
|
|
23
|
+
Provides-Extra: standalone
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# SpinChain
|
|
27
|
+
|
|
28
|
+
Inference-time reasoning optimization for LLMs using QUBO/Ising formulations. Built as an MCP server for Claude Code.
|
|
29
|
+
|
|
30
|
+
SpinChain takes multiple diverse reasoning chains, extracts fragments, formulates their selection as a QUBO problem (following [QCR-LLM](https://arxiv.org/abs/2510.24509)), solves it with simulated annealing, and returns the most stable and coherent fragment subset.
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
### Prerequisites
|
|
35
|
+
|
|
36
|
+
- Python 3.11+
|
|
37
|
+
- [uv](https://docs.astral.sh/uv/) (recommended) or pip
|
|
38
|
+
|
|
39
|
+
### Install skills (recommended)
|
|
40
|
+
|
|
41
|
+
Install SpinChain skills into Claude Code via the plugin marketplace:
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
/plugin marketplace add ameyakhot/spinchain
|
|
45
|
+
/plugin install spinchain-skills@spinchain
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
This gives you 6 skills: `spinchain-optimize`, `analyze-spinchain`, `test-spinchain`, `spinchain-status`, `spinchain-bench`, `spinchain-trace`.
|
|
49
|
+
|
|
50
|
+
### Clone and install the server
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
git clone https://github.com/ameyakhot/spinchain.git
|
|
54
|
+
cd spinchain
|
|
55
|
+
uv sync
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
To install with dev dependencies (pytest, ruff):
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
uv sync --extra dev
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Register as an MCP server in Claude Code
|
|
65
|
+
|
|
66
|
+
Add SpinChain to your Claude Code config (`~/.claude.json`):
|
|
67
|
+
|
|
68
|
+
```json
|
|
69
|
+
{
|
|
70
|
+
"mcpServers": {
|
|
71
|
+
"spinchain": {
|
|
72
|
+
"type": "stdio",
|
|
73
|
+
"command": "uv",
|
|
74
|
+
"args": [
|
|
75
|
+
"run",
|
|
76
|
+
"--directory",
|
|
77
|
+
"/path/to/spinchain",
|
|
78
|
+
"python",
|
|
79
|
+
"-m",
|
|
80
|
+
"spinchain"
|
|
81
|
+
],
|
|
82
|
+
"env": {
|
|
83
|
+
"SPINCHAIN_TRACE_DIR": "/path/to/spinchain/traces"
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Replace `/path/to/spinchain` with the actual path to your cloned repo.
|
|
91
|
+
|
|
92
|
+
Restart Claude Code. The `optimize_reasoning` tool will be available as `mcp__spinchain__optimize_reasoning`.
|
|
93
|
+
|
|
94
|
+
## How it works
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
User asks a complex reasoning question
|
|
98
|
+
│
|
|
99
|
+
▼
|
|
100
|
+
Claude generates N diverse reasoning chains
|
|
101
|
+
│
|
|
102
|
+
▼
|
|
103
|
+
Claude calls optimize_reasoning(completions=[...])
|
|
104
|
+
│
|
|
105
|
+
▼
|
|
106
|
+
┌─────────────────────────────────────────────┐
|
|
107
|
+
│ SpinChain Pipeline │
|
|
108
|
+
│ │
|
|
109
|
+
│ 1. Fragment Extraction │
|
|
110
|
+
│ Split into sentences, embed with │
|
|
111
|
+
│ sentence-transformers, deduplicate │
|
|
112
|
+
│ by cosine similarity │
|
|
113
|
+
│ │
|
|
114
|
+
│ 2. QUBO Formulation (QCR-LLM) │
|
|
115
|
+
│ Linear: -μ·popularity + α·risk │
|
|
116
|
+
│ Quadratic: -β·(correlation - λ²·sim) │
|
|
117
|
+
│ │
|
|
118
|
+
│ 3. Simulated Annealing (dwave-neal) │
|
|
119
|
+
│ 100 reads × 1000 sweeps │
|
|
120
|
+
│ │
|
|
121
|
+
│ 4. Stability Ranking │
|
|
122
|
+
│ Select fragments appearing in ≥50% │
|
|
123
|
+
│ of low-energy solutions │
|
|
124
|
+
└─────────────────────────────────────────────┘
|
|
125
|
+
│
|
|
126
|
+
▼
|
|
127
|
+
Claude receives optimized fragments
|
|
128
|
+
and synthesizes final answer
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Usage
|
|
132
|
+
|
|
133
|
+
### As an MCP server (primary use)
|
|
134
|
+
|
|
135
|
+
Once registered, Claude calls SpinChain automatically when using the `optimize_reasoning` tool. No manual invocation needed.
|
|
136
|
+
|
|
137
|
+
### Standalone example
|
|
138
|
+
|
|
139
|
+
Run the bundled example with synthetic reasoning chains (no API key needed):
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
uv run python examples/basic_usage.py
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Trace analysis
|
|
146
|
+
|
|
147
|
+
Every MCP call is logged to `SPINCHAIN_TRACE_DIR/spinchain_traces.jsonl`. Analyze with:
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
# Human-readable report
|
|
151
|
+
uv run python -m spinchain.analyze
|
|
152
|
+
|
|
153
|
+
# JSON output
|
|
154
|
+
uv run python -m spinchain.analyze --json
|
|
155
|
+
|
|
156
|
+
# Last 10 calls only
|
|
157
|
+
uv run python -m spinchain.analyze --last 10
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Run tests
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
uv run --extra dev python -m pytest tests/ -v
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## Skills
|
|
167
|
+
|
|
168
|
+
Install via `/plugin marketplace add ameyakhot/spinchain` in Claude Code, or use as slash commands when working inside the project directory.
|
|
169
|
+
|
|
170
|
+
| Skill | Description |
|
|
171
|
+
|-------|-------------|
|
|
172
|
+
| `spinchain-optimize` | Core skill — teaches Claude how to generate diverse chains and call `optimize_reasoning` effectively |
|
|
173
|
+
| `analyze-spinchain` | Run trace analysis — usage stats, latency breakdown, anomalies |
|
|
174
|
+
| `test-spinchain` | Run the full test suite (71 tests) |
|
|
175
|
+
| `spinchain-status` | Health check — config, imports, trace summary |
|
|
176
|
+
| `spinchain-bench` | Run the example benchmark and inspect pipeline output |
|
|
177
|
+
| `spinchain-trace` | Inspect raw trace records — recent calls, specific trace IDs |
|
|
178
|
+
|
|
179
|
+
## Project structure
|
|
180
|
+
|
|
181
|
+
```
|
|
182
|
+
spinchain/
|
|
183
|
+
├── src/spinchain/
|
|
184
|
+
│ ├── server.py # MCP server — optimize_reasoning tool
|
|
185
|
+
│ ├── tracing.py # JSONL trace logger
|
|
186
|
+
│ ├── analyze.py # Trace analysis CLI
|
|
187
|
+
│ ├── formulation/
|
|
188
|
+
│ │ ├── fragment_extractor.py # Sentence splitting, embedding, dedup
|
|
189
|
+
│ │ ├── coefficient_builder.py # QCR-LLM linear + quadratic weights
|
|
190
|
+
│ │ └── qubo_builder.py # BQM construction + cardinality constraint
|
|
191
|
+
│ └── solvers/
|
|
192
|
+
│ ├── base.py # Abstract solver interface
|
|
193
|
+
│ └── simulated_annealing.py # dwave-neal SA solver
|
|
194
|
+
├── tests/ # 71 tests
|
|
195
|
+
├── examples/
|
|
196
|
+
│ └── basic_usage.py # Synthetic benchmark
|
|
197
|
+
├── .claude/commands/ # Claude Code slash commands
|
|
198
|
+
└── traces/ # Trace logs (created at runtime)
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## Configuration
|
|
202
|
+
|
|
203
|
+
### Environment variables
|
|
204
|
+
|
|
205
|
+
| Variable | Default | Description |
|
|
206
|
+
|----------|---------|-------------|
|
|
207
|
+
| `SPINCHAIN_TRACE_DIR` | `~/.spinchain/traces/` | Directory for JSONL trace logs |
|
|
208
|
+
|
|
209
|
+
### optimize_reasoning parameters
|
|
210
|
+
|
|
211
|
+
| Parameter | Default | Description |
|
|
212
|
+
|-----------|---------|-------------|
|
|
213
|
+
| `completions` | required | List of reasoning chain strings (min 2) |
|
|
214
|
+
| `num_reads` | 100 | SA samples per solve |
|
|
215
|
+
| `num_sweeps` | 1000 | MC sweeps per sample |
|
|
216
|
+
| `similarity_threshold` | 0.85 | Cosine similarity for fragment dedup |
|
|
217
|
+
| `selection_threshold` | 0.25 | Fraction of low-energy solutions for ranking |
|
|
218
|
+
| `inclusion_threshold` | 0.50 | Min frequency to include a fragment |
|
|
219
|
+
| `cardinality_k` | None | Target number of fragments to select |
|
|
220
|
+
|
|
221
|
+
### QUBO hyperparameters (in code)
|
|
222
|
+
|
|
223
|
+
| Parameter | Default | Description |
|
|
224
|
+
|-----------|---------|-------------|
|
|
225
|
+
| `mu` | 1.0 | Fragment popularity weight |
|
|
226
|
+
| `alpha` | 0.5 | Risk/variance penalty |
|
|
227
|
+
| `beta` | 1.0 | Pairwise coherence weight |
|
|
228
|
+
| `lambda_sim` | 0.3 | Semantic similarity penalty factor |
|
|
229
|
+
| `penalty_strength` | 5.0 | Cardinality constraint weight |
|
|
230
|
+
|
|
231
|
+
## Solver roadmap
|
|
232
|
+
|
|
233
|
+
1. **Simulated Annealing** (current) — dwave-neal, pure Python
|
|
234
|
+
2. **COBI Ising chip** — millisecond solves, hardware accelerated
|
|
235
|
+
3. **Quanfluence CIM** — optical coherent Ising machine
|
|
236
|
+
4. **IBM Quantum QAOA** — gate-based quantum validation
|
|
237
|
+
|
|
238
|
+
All solvers share the same `BaseSolver` interface and QUBO formulation.
|
|
239
|
+
|
|
240
|
+
## License
|
|
241
|
+
|
|
242
|
+
MIT
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
# SpinChain
|
|
2
|
+
|
|
3
|
+
Inference-time reasoning optimization for LLMs using QUBO/Ising formulations. Built as an MCP server for Claude Code.
|
|
4
|
+
|
|
5
|
+
SpinChain takes multiple diverse reasoning chains, extracts fragments, formulates their selection as a QUBO problem (following [QCR-LLM](https://arxiv.org/abs/2510.24509)), solves it with simulated annealing, and returns the most stable and coherent fragment subset.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
### Prerequisites
|
|
10
|
+
|
|
11
|
+
- Python 3.11+
|
|
12
|
+
- [uv](https://docs.astral.sh/uv/) (recommended) or pip
|
|
13
|
+
|
|
14
|
+
### Install skills (recommended)
|
|
15
|
+
|
|
16
|
+
Install SpinChain skills into Claude Code via the plugin marketplace:
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
/plugin marketplace add ameyakhot/spinchain
|
|
20
|
+
/plugin install spinchain-skills@spinchain
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
This gives you 6 skills: `spinchain-optimize`, `analyze-spinchain`, `test-spinchain`, `spinchain-status`, `spinchain-bench`, `spinchain-trace`.
|
|
24
|
+
|
|
25
|
+
### Clone and install the server
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
git clone https://github.com/ameyakhot/spinchain.git
|
|
29
|
+
cd spinchain
|
|
30
|
+
uv sync
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
To install with dev dependencies (pytest, ruff):
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
uv sync --extra dev
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Register as an MCP server in Claude Code
|
|
40
|
+
|
|
41
|
+
Add SpinChain to your Claude Code config (`~/.claude.json`):
|
|
42
|
+
|
|
43
|
+
```json
|
|
44
|
+
{
|
|
45
|
+
"mcpServers": {
|
|
46
|
+
"spinchain": {
|
|
47
|
+
"type": "stdio",
|
|
48
|
+
"command": "uv",
|
|
49
|
+
"args": [
|
|
50
|
+
"run",
|
|
51
|
+
"--directory",
|
|
52
|
+
"/path/to/spinchain",
|
|
53
|
+
"python",
|
|
54
|
+
"-m",
|
|
55
|
+
"spinchain"
|
|
56
|
+
],
|
|
57
|
+
"env": {
|
|
58
|
+
"SPINCHAIN_TRACE_DIR": "/path/to/spinchain/traces"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Replace `/path/to/spinchain` with the actual path to your cloned repo.
|
|
66
|
+
|
|
67
|
+
Restart Claude Code. The `optimize_reasoning` tool will be available as `mcp__spinchain__optimize_reasoning`.
|
|
68
|
+
|
|
69
|
+
## How it works
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
User asks a complex reasoning question
|
|
73
|
+
│
|
|
74
|
+
▼
|
|
75
|
+
Claude generates N diverse reasoning chains
|
|
76
|
+
│
|
|
77
|
+
▼
|
|
78
|
+
Claude calls optimize_reasoning(completions=[...])
|
|
79
|
+
│
|
|
80
|
+
▼
|
|
81
|
+
┌─────────────────────────────────────────────┐
|
|
82
|
+
│ SpinChain Pipeline │
|
|
83
|
+
│ │
|
|
84
|
+
│ 1. Fragment Extraction │
|
|
85
|
+
│ Split into sentences, embed with │
|
|
86
|
+
│ sentence-transformers, deduplicate │
|
|
87
|
+
│ by cosine similarity │
|
|
88
|
+
│ │
|
|
89
|
+
│ 2. QUBO Formulation (QCR-LLM) │
|
|
90
|
+
│ Linear: -μ·popularity + α·risk │
|
|
91
|
+
│ Quadratic: -β·(correlation - λ²·sim) │
|
|
92
|
+
│ │
|
|
93
|
+
│ 3. Simulated Annealing (dwave-neal) │
|
|
94
|
+
│ 100 reads × 1000 sweeps │
|
|
95
|
+
│ │
|
|
96
|
+
│ 4. Stability Ranking │
|
|
97
|
+
│ Select fragments appearing in ≥50% │
|
|
98
|
+
│ of low-energy solutions │
|
|
99
|
+
└─────────────────────────────────────────────┘
|
|
100
|
+
│
|
|
101
|
+
▼
|
|
102
|
+
Claude receives optimized fragments
|
|
103
|
+
and synthesizes final answer
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Usage
|
|
107
|
+
|
|
108
|
+
### As an MCP server (primary use)
|
|
109
|
+
|
|
110
|
+
Once registered, Claude calls SpinChain automatically when using the `optimize_reasoning` tool. No manual invocation needed.
|
|
111
|
+
|
|
112
|
+
### Standalone example
|
|
113
|
+
|
|
114
|
+
Run the bundled example with synthetic reasoning chains (no API key needed):
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
uv run python examples/basic_usage.py
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Trace analysis
|
|
121
|
+
|
|
122
|
+
Every MCP call is logged to `SPINCHAIN_TRACE_DIR/spinchain_traces.jsonl`. Analyze with:
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
# Human-readable report
|
|
126
|
+
uv run python -m spinchain.analyze
|
|
127
|
+
|
|
128
|
+
# JSON output
|
|
129
|
+
uv run python -m spinchain.analyze --json
|
|
130
|
+
|
|
131
|
+
# Last 10 calls only
|
|
132
|
+
uv run python -m spinchain.analyze --last 10
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Run tests
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
uv run --extra dev python -m pytest tests/ -v
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Skills
|
|
142
|
+
|
|
143
|
+
Install via `/plugin marketplace add ameyakhot/spinchain` in Claude Code, or use as slash commands when working inside the project directory.
|
|
144
|
+
|
|
145
|
+
| Skill | Description |
|
|
146
|
+
|-------|-------------|
|
|
147
|
+
| `spinchain-optimize` | Core skill — teaches Claude how to generate diverse chains and call `optimize_reasoning` effectively |
|
|
148
|
+
| `analyze-spinchain` | Run trace analysis — usage stats, latency breakdown, anomalies |
|
|
149
|
+
| `test-spinchain` | Run the full test suite (71 tests) |
|
|
150
|
+
| `spinchain-status` | Health check — config, imports, trace summary |
|
|
151
|
+
| `spinchain-bench` | Run the example benchmark and inspect pipeline output |
|
|
152
|
+
| `spinchain-trace` | Inspect raw trace records — recent calls, specific trace IDs |
|
|
153
|
+
|
|
154
|
+
## Project structure
|
|
155
|
+
|
|
156
|
+
```
|
|
157
|
+
spinchain/
|
|
158
|
+
├── src/spinchain/
|
|
159
|
+
│ ├── server.py # MCP server — optimize_reasoning tool
|
|
160
|
+
│ ├── tracing.py # JSONL trace logger
|
|
161
|
+
│ ├── analyze.py # Trace analysis CLI
|
|
162
|
+
│ ├── formulation/
|
|
163
|
+
│ │ ├── fragment_extractor.py # Sentence splitting, embedding, dedup
|
|
164
|
+
│ │ ├── coefficient_builder.py # QCR-LLM linear + quadratic weights
|
|
165
|
+
│ │ └── qubo_builder.py # BQM construction + cardinality constraint
|
|
166
|
+
│ └── solvers/
|
|
167
|
+
│ ├── base.py # Abstract solver interface
|
|
168
|
+
│ └── simulated_annealing.py # dwave-neal SA solver
|
|
169
|
+
├── tests/ # 71 tests
|
|
170
|
+
├── examples/
|
|
171
|
+
│ └── basic_usage.py # Synthetic benchmark
|
|
172
|
+
├── .claude/commands/ # Claude Code slash commands
|
|
173
|
+
└── traces/ # Trace logs (created at runtime)
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## Configuration
|
|
177
|
+
|
|
178
|
+
### Environment variables
|
|
179
|
+
|
|
180
|
+
| Variable | Default | Description |
|
|
181
|
+
|----------|---------|-------------|
|
|
182
|
+
| `SPINCHAIN_TRACE_DIR` | `~/.spinchain/traces/` | Directory for JSONL trace logs |
|
|
183
|
+
|
|
184
|
+
### optimize_reasoning parameters
|
|
185
|
+
|
|
186
|
+
| Parameter | Default | Description |
|
|
187
|
+
|-----------|---------|-------------|
|
|
188
|
+
| `completions` | required | List of reasoning chain strings (min 2) |
|
|
189
|
+
| `num_reads` | 100 | SA samples per solve |
|
|
190
|
+
| `num_sweeps` | 1000 | MC sweeps per sample |
|
|
191
|
+
| `similarity_threshold` | 0.85 | Cosine similarity for fragment dedup |
|
|
192
|
+
| `selection_threshold` | 0.25 | Fraction of low-energy solutions for ranking |
|
|
193
|
+
| `inclusion_threshold` | 0.50 | Min frequency to include a fragment |
|
|
194
|
+
| `cardinality_k` | None | Target number of fragments to select |
|
|
195
|
+
|
|
196
|
+
### QUBO hyperparameters (in code)
|
|
197
|
+
|
|
198
|
+
| Parameter | Default | Description |
|
|
199
|
+
|-----------|---------|-------------|
|
|
200
|
+
| `mu` | 1.0 | Fragment popularity weight |
|
|
201
|
+
| `alpha` | 0.5 | Risk/variance penalty |
|
|
202
|
+
| `beta` | 1.0 | Pairwise coherence weight |
|
|
203
|
+
| `lambda_sim` | 0.3 | Semantic similarity penalty factor |
|
|
204
|
+
| `penalty_strength` | 5.0 | Cardinality constraint weight |
|
|
205
|
+
|
|
206
|
+
## Solver roadmap
|
|
207
|
+
|
|
208
|
+
1. **Simulated Annealing** (current) — dwave-neal, pure Python
|
|
209
|
+
2. **COBI Ising chip** — millisecond solves, hardware accelerated
|
|
210
|
+
3. **Quanfluence CIM** — optical coherent Ising machine
|
|
211
|
+
4. **IBM Quantum QAOA** — gate-based quantum validation
|
|
212
|
+
|
|
213
|
+
All solvers share the same `BaseSolver` interface and QUBO formulation.
|
|
214
|
+
|
|
215
|
+
## License
|
|
216
|
+
|
|
217
|
+
MIT
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "spinchain"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Inference-time reasoning optimization using QUBO/Ising formulations"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [
|
|
7
|
+
{ name = "Ameya Khot", email = "ameyakhot18@gmail.com" }
|
|
8
|
+
]
|
|
9
|
+
requires-python = ">=3.11"
|
|
10
|
+
dependencies = [
|
|
11
|
+
"mcp>=1.0.0",
|
|
12
|
+
"dwave-neal>=0.6.0",
|
|
13
|
+
"dimod>=0.12.0",
|
|
14
|
+
"pyqubo>=1.5.0",
|
|
15
|
+
"sentence-transformers>=3.0.0",
|
|
16
|
+
"numpy>=1.26.0",
|
|
17
|
+
"scipy>=1.12.0",
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
[project.optional-dependencies]
|
|
21
|
+
dev = [
|
|
22
|
+
"pytest>=8.0.0",
|
|
23
|
+
"ruff>=0.4.0",
|
|
24
|
+
]
|
|
25
|
+
standalone = [
|
|
26
|
+
"anthropic>=0.42.0",
|
|
27
|
+
]
|
|
28
|
+
quantum = [
|
|
29
|
+
"qiskit>=1.0.0",
|
|
30
|
+
"qiskit-aer>=0.15.0",
|
|
31
|
+
"qiskit-optimization>=0.6.0",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
[project.scripts]
|
|
35
|
+
spinchain-server = "spinchain.server:main"
|
|
36
|
+
|
|
37
|
+
[build-system]
|
|
38
|
+
requires = ["uv_build>=0.9.5,<0.10.0"]
|
|
39
|
+
build-backend = "uv_build"
|
|
40
|
+
|
|
41
|
+
[tool.ruff]
|
|
42
|
+
line-length = 100
|