fly-harness 0.4.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.
- fly_harness-0.4.0/.github/workflows/ci.yml +27 -0
- fly_harness-0.4.0/.github/workflows/publish.yml +30 -0
- fly_harness-0.4.0/.gitignore +9 -0
- fly_harness-0.4.0/LICENSE +21 -0
- fly_harness-0.4.0/PKG-INFO +368 -0
- fly_harness-0.4.0/README.md +340 -0
- fly_harness-0.4.0/examples/biorouter_loop.py +14 -0
- fly_harness-0.4.0/examples/mcp_flygym_loop.py +14 -0
- fly_harness-0.4.0/pyproject.toml +54 -0
- fly_harness-0.4.0/scripts/generate_fixtures.py +56 -0
- fly_harness-0.4.0/src/fly_harness/__init__.py +31 -0
- fly_harness-0.4.0/src/fly_harness/backend.py +360 -0
- fly_harness-0.4.0/src/fly_harness/brain_state.py +94 -0
- fly_harness-0.4.0/src/fly_harness/connectome_loader.py +285 -0
- fly_harness-0.4.0/src/fly_harness/demo/__init__.py +6 -0
- fly_harness-0.4.0/src/fly_harness/demo/biorouter_loop.py +190 -0
- fly_harness-0.4.0/src/fly_harness/demo/codec.py +92 -0
- fly_harness-0.4.0/src/fly_harness/demo/composed.py +261 -0
- fly_harness-0.4.0/src/fly_harness/demo/connectome.py +114 -0
- fly_harness-0.4.0/src/fly_harness/demo/loaded_circuit.py +74 -0
- fly_harness-0.4.0/src/fly_harness/demo/reflex.py +75 -0
- fly_harness-0.4.0/src/fly_harness/flygym/__init__.py +44 -0
- fly_harness-0.4.0/src/fly_harness/flygym/decoder.py +106 -0
- fly_harness-0.4.0/src/fly_harness/flygym/detect.py +34 -0
- fly_harness-0.4.0/src/fly_harness/flygym/encoder.py +62 -0
- fly_harness-0.4.0/src/fly_harness/flygym/schema.py +185 -0
- fly_harness-0.4.0/src/fly_harness/flygym/wrapper.py +194 -0
- fly_harness-0.4.0/src/fly_harness/harness.py +158 -0
- fly_harness-0.4.0/src/fly_harness/http_backend.py +151 -0
- fly_harness-0.4.0/src/fly_harness/mcp/__init__.py +17 -0
- fly_harness-0.4.0/src/fly_harness/mcp/__main__.py +6 -0
- fly_harness-0.4.0/src/fly_harness/mcp/detect.py +20 -0
- fly_harness-0.4.0/src/fly_harness/mcp/handlers.py +102 -0
- fly_harness-0.4.0/src/fly_harness/mcp/server.py +63 -0
- fly_harness-0.4.0/src/fly_harness/protocols.py +96 -0
- fly_harness-0.4.0/src/fly_harness/router/__init__.py +39 -0
- fly_harness-0.4.0/src/fly_harness/router/__main__.py +6 -0
- fly_harness-0.4.0/src/fly_harness/router/registry.py +54 -0
- fly_harness-0.4.0/src/fly_harness/router/server.py +221 -0
- fly_harness-0.4.0/tests/fixtures/mini_circuit.csv +9 -0
- fly_harness-0.4.0/tests/fixtures/mini_circuit.npz +0 -0
- fly_harness-0.4.0/tests/fixtures/mini_circuit_neuron_ids.txt +6 -0
- fly_harness-0.4.0/tests/test_backend.py +267 -0
- fly_harness-0.4.0/tests/test_biorouter_example.py +70 -0
- fly_harness-0.4.0/tests/test_brain_state.py +50 -0
- fly_harness-0.4.0/tests/test_composed_example.py +123 -0
- fly_harness-0.4.0/tests/test_connectome_loader.py +117 -0
- fly_harness-0.4.0/tests/test_flygym_adapter.py +216 -0
- fly_harness-0.4.0/tests/test_harness.py +48 -0
- fly_harness-0.4.0/tests/test_mcp_extension.py +128 -0
- fly_harness-0.4.0/tests/test_protocols.py +40 -0
- fly_harness-0.4.0/tests/test_router.py +173 -0
- fly_harness-0.4.0/tests/test_version.py +7 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: read
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
test:
|
|
13
|
+
name: pytest (Python ${{ matrix.python-version }})
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
strategy:
|
|
16
|
+
fail-fast: false
|
|
17
|
+
matrix:
|
|
18
|
+
python-version: ["3.10", "3.12"]
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@v4
|
|
21
|
+
- uses: actions/setup-python@v5
|
|
22
|
+
with:
|
|
23
|
+
python-version: ${{ matrix.python-version }}
|
|
24
|
+
- name: Install core + dev extras
|
|
25
|
+
run: pip install -e ".[dev]"
|
|
26
|
+
- name: Run pytest
|
|
27
|
+
run: pytest -q
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
workflow_dispatch:
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: read
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
pypi-publish:
|
|
13
|
+
name: Upload to PyPI
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
permissions:
|
|
16
|
+
contents: read
|
|
17
|
+
id-token: write
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v4
|
|
20
|
+
- uses: actions/setup-python@v5
|
|
21
|
+
with:
|
|
22
|
+
python-version: "3.12"
|
|
23
|
+
- name: Build sdist and wheel
|
|
24
|
+
run: |
|
|
25
|
+
python -m pip install --upgrade pip build
|
|
26
|
+
python -m build
|
|
27
|
+
- name: Publish to PyPI
|
|
28
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
29
|
+
with:
|
|
30
|
+
attestations: false
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 fly-harness contributors
|
|
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,368 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: fly-harness
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Summary: A minimal microkernel for sparse fly-inspired neural harnesses
|
|
5
|
+
Author: fly-harness contributors
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Keywords: connectome,microkernel,neuroscience,sparse
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Science/Research
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
17
|
+
Requires-Python: >=3.10
|
|
18
|
+
Requires-Dist: numpy>=1.24
|
|
19
|
+
Requires-Dist: scipy>=1.10
|
|
20
|
+
Provides-Extra: biorouter
|
|
21
|
+
Provides-Extra: dev
|
|
22
|
+
Requires-Dist: pytest>=7.4; extra == 'dev'
|
|
23
|
+
Provides-Extra: flygym
|
|
24
|
+
Requires-Dist: flygym-gymnasium>=1.2.0; extra == 'flygym'
|
|
25
|
+
Provides-Extra: mcp
|
|
26
|
+
Requires-Dist: fastmcp>=2.0; extra == 'mcp'
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# fly-harness
|
|
30
|
+
|
|
31
|
+
**v0.4.0** — a sparse neural **harness**, not a fly-brain simulation.
|
|
32
|
+
|
|
33
|
+
Formula: **Agent = deployed bio-sim Model + harness**. The harness docks to a
|
|
34
|
+
**running** sim through a stable contract. FlyWire / MaleCNS files are weight
|
|
35
|
+
dumps, not that contract.
|
|
36
|
+
|
|
37
|
+
The public contract is:
|
|
38
|
+
|
|
39
|
+
1. **`BrainState`** — membrane potentials, sparse synaptic weights (`scipy.sparse` CSR), timestamp, JSON save/load
|
|
40
|
+
2. **`FlyHarness.step(obs) -> action`** — encode → **`ModelBackend.tick`** → decode (default backend is the in-process LIF/rate circuit)
|
|
41
|
+
3. **`Encoder` / `Decoder`** — `typing.Protocol` contracts (optional `BaseEncoder` / `BaseDecoder` ABCs; no string class-name checks)
|
|
42
|
+
4. **`load_connectome`** — load a **circuit subset** from a local sparse edge list (`.npz` / `.csv`) into `BrainState`
|
|
43
|
+
5. **`ModelBackend`** — swappable Model port: `tick` (encoded input → neural output), `reset`, `n_neurons`, `model_id`
|
|
44
|
+
|
|
45
|
+
The 24-neuron touch-reflex loop is a **test/demo fixture**. It is not the model, and it is not a scaled-down FlyWire brain.
|
|
46
|
+
|
|
47
|
+
## What this is not
|
|
48
|
+
|
|
49
|
+
- **Not** a 140k-neuron FlyWire connectome, upload, or dense 140k×140k matrix
|
|
50
|
+
- **Not** an arbitrary-scale whole-brain runtime (memory is bounded by the loaded subset)
|
|
51
|
+
- **Not** `caveclient` or a built-in biomechanics engine — FlyGym/NeuroMechFly is an **optional body extra**, not the core product
|
|
52
|
+
- **Not** an MCP microkernel or FastAPI service — MCP is an **optional protocol extra**, not the core product
|
|
53
|
+
- **Not** OpenRouter-the-company, a marketplace, billing system, hosted cloud gateway, or public bio-sim catalog — `BioSimRouter` is a harness-side **port**; **biorouter** is an optional **local** HTTP process (stdlib, `127.0.0.1` by default)
|
|
54
|
+
- **Not** a consciousness/upload claim
|
|
55
|
+
|
|
56
|
+
## Install
|
|
57
|
+
|
|
58
|
+
Python 3.10+ with `numpy` and `scipy`. Core install stays numpy/scipy-only:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
pip install -e ".[dev]"
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
FlyGym is optional:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pip install -e ".[flygym]"
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
MCP is optional (stdio server via FastMCP):
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
pip install -e ".[mcp]"
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
**biorouter** is optional and **stdlib-only** (no FastAPI). The extra exists so it stays an extension of this repo, not a second product or GitHub repository:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
pip install -e ".[biorouter]"
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## The step loop
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
from fly_harness import BrainState, FlyHarness
|
|
86
|
+
from fly_harness.protocols import Decoder, Encoder
|
|
87
|
+
|
|
88
|
+
harness = FlyHarness(state, encoder, decoder)
|
|
89
|
+
result = harness.step(observation)
|
|
90
|
+
action = result.action
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
`step` encodes the observation into a length-`n_neurons` current vector, advances the docked **Model** one tick, and decodes an action from the neural output.
|
|
94
|
+
|
|
95
|
+
Default construction still wraps the in-process LIF/rate dynamics (`InProcessLifBackend`). `FlyHarness.step(obs) -> action` is the same public call.
|
|
96
|
+
|
|
97
|
+
`BrainState` can be snapshotted independently of the harness:
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
state.save("brain.json")
|
|
101
|
+
restored = BrainState.load("brain.json")
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Docking modes
|
|
105
|
+
|
|
106
|
+
Two ways to attach a running Model. This package is the **port**, not a hosted catalog of sims.
|
|
107
|
+
|
|
108
|
+
### 1. Direct — one backend per vendor / deployed sim
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
from fly_harness import DirectBioSimBackend, FlyHarness
|
|
112
|
+
|
|
113
|
+
backend = DirectBioSimBackend(n_neurons=8, model_id="vendor.fake")
|
|
114
|
+
harness = FlyHarness(encoder=encoder, decoder=decoder, backend=backend)
|
|
115
|
+
result = harness.step(observation)
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
`DirectBioSimBackend` docks to **one** running sim. The in-process `FakeDeployedSim` is enough for tests. A thin HTTP client is available if you already host a sim (`url=...`, bodies include a `model` field). There are no FlyWire / CAVE / neuPrint clients and no 140k dense matrices.
|
|
119
|
+
|
|
120
|
+
### 2. Router — one entry, select by model id
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
from fly_harness import BioSimRouter, DirectBioSimBackend, FlyHarness, UnknownModelError
|
|
124
|
+
|
|
125
|
+
router = BioSimRouter(
|
|
126
|
+
{
|
|
127
|
+
"vendor.a": DirectBioSimBackend(n_neurons=8, model_id="vendor.a"),
|
|
128
|
+
"vendor.b": DirectBioSimBackend(n_neurons=8, model_id="vendor.b"),
|
|
129
|
+
},
|
|
130
|
+
model_id="vendor.a",
|
|
131
|
+
)
|
|
132
|
+
harness = FlyHarness(encoder=encoder, decoder=decoder, backend=router)
|
|
133
|
+
harness.step(observation)
|
|
134
|
+
router.use("vendor.b")
|
|
135
|
+
harness.step(observation)
|
|
136
|
+
|
|
137
|
+
# unknown model_id raises UnknownModelError (this is a port, not a marketplace)
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
`BioSimRouter` is OpenRouter-**shaped**: one entry, a `model` / `model_id` field, unknown ids fail clearly. Optional `remote_url=` forwards that `model` field to **biorouter** (`HttpModelBackend`). This repo does not ship a hosted marketplace.
|
|
141
|
+
|
|
142
|
+
You can also pass a backend positionally: `FlyHarness(backend, encoder, decoder)`.
|
|
143
|
+
|
|
144
|
+
## biorouter
|
|
145
|
+
|
|
146
|
+
OpenRouter routes existing LLMs. **biorouter** routes existing **deployed biological simulation models**. Same idea (`model` id), different substrate.
|
|
147
|
+
|
|
148
|
+
This extra is **not** the harness, **not** FlyWire dumps, and **not** a marketplace. It is a local HTTP process (`127.0.0.1` by default) that already-deployed harness clients call: `HttpModelBackend`, `DirectBioSimBackend(url=...)`, `BioSimRouter(remote_url=...)`. Stdlib `http.server` only — no FastAPI, no billing, no cloud gateway.
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
pip install -e ".[biorouter]" # empty extra; core install is enough to run the CLI
|
|
152
|
+
biorouter
|
|
153
|
+
# or
|
|
154
|
+
python -m fly_harness.router --host 127.0.0.1 --port 8765
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Endpoints (JSON; bodies/query include an OpenRouter-shaped `model` field):
|
|
158
|
+
|
|
159
|
+
- `POST /tick` — `{"model": "...", "input": [...]}` → neural output
|
|
160
|
+
- `POST /reset` — `{"model": "...", "potentials": null | [...]}`
|
|
161
|
+
- `GET /status?model=...`
|
|
162
|
+
|
|
163
|
+
Default in-process registry: the 24-neuron LIF **fixture** (`fly-harness.in-process-lif`) plus `FakeDeployedSim` ids (`fake.deployed`, `fake.deployed.gain`). Unknown `model` → HTTP 404 → harness `UnknownModelError`.
|
|
164
|
+
|
|
165
|
+
```python
|
|
166
|
+
from fly_harness import DirectBioSimBackend, FlyHarness
|
|
167
|
+
|
|
168
|
+
backend = DirectBioSimBackend(
|
|
169
|
+
url="http://127.0.0.1:8765",
|
|
170
|
+
model_id="fake.deployed",
|
|
171
|
+
n_neurons=8,
|
|
172
|
+
)
|
|
173
|
+
harness = FlyHarness(encoder=encoder, decoder=decoder, backend=backend)
|
|
174
|
+
harness.step(observation)
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
`FlyHarness.step(obs) -> action` is unchanged. This extra is not a 140k FlyWire runtime and does not download MaleCNS.
|
|
178
|
+
|
|
179
|
+
## Example: biorouter through FlyHarness.step
|
|
180
|
+
|
|
181
|
+
OpenRouter routes existing LLMs; **biorouter** routes existing deployed bio-sims. This example starts a **local** stdlib server (or attaches with `--url`), docks `HttpModelBackend` / `DirectBioSimBackend(url=...)`, and calls `FlyHarness.step`. It uses the 8-neuron `FakeDeployedSim` fixture — **not** FlyWire / MaleCNS, **not** a marketplace.
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
python examples/biorouter_loop.py
|
|
185
|
+
# or, after install:
|
|
186
|
+
python -m fly_harness.demo.biorouter_loop
|
|
187
|
+
fly-harness-biorouter-demo
|
|
188
|
+
# attach to a process you already started:
|
|
189
|
+
biorouter --host 127.0.0.1 --port 8765
|
|
190
|
+
python examples/biorouter_loop.py --url http://127.0.0.1:8765
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## Load a sparse connectome
|
|
194
|
+
|
|
195
|
+
`load_connectome` maps global neuron ids (any integers) onto contiguous local indices and builds a CSR weight matrix of shape `(n_subset, n_subset)`.
|
|
196
|
+
|
|
197
|
+
```python
|
|
198
|
+
from fly_harness import FlyHarness, load_connectome
|
|
199
|
+
|
|
200
|
+
loaded = load_connectome("tests/fixtures/mini_circuit.npz")
|
|
201
|
+
# loaded.state.weights is scipy.sparse CSR, shape (n_subset, n_subset)
|
|
202
|
+
# loaded.neuron_ids maps local index -> global neuron id
|
|
203
|
+
# loaded.id_to_index maps global id -> local index
|
|
204
|
+
|
|
205
|
+
harness = FlyHarness(loaded.state, encoder=..., decoder=...)
|
|
206
|
+
result = harness.step(observation)
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
fly-harness-loader-demo
|
|
211
|
+
# or
|
|
212
|
+
python -m fly_harness.demo.loaded_circuit
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
Supported files:
|
|
216
|
+
|
|
217
|
+
- **NPZ** — arrays `pre`, `post`, `weight` (int ids + float weights); optional `neuron_ids` for the circuit subset
|
|
218
|
+
- **CSV** — header `pre_id,post_id,weight`
|
|
219
|
+
|
|
220
|
+
Pass an explicit subset with `neuron_ids=[...]` or `neuron_ids_file="ids.txt"` (one id per line). Only synapses whose pre and post are both in the subset are kept.
|
|
221
|
+
|
|
222
|
+
## Fixture: 24-neuron reflex
|
|
223
|
+
|
|
224
|
+
Shipped only so the contract is executable without an external connectome file. Left touch biases a right turn (and the reverse). Do not treat this as a biological circuit.
|
|
225
|
+
|
|
226
|
+
```bash
|
|
227
|
+
fly-harness-reflex-demo
|
|
228
|
+
# or
|
|
229
|
+
python -m fly_harness.demo.reflex
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
```python
|
|
233
|
+
from fly_harness import FlyHarness
|
|
234
|
+
from fly_harness.demo import ReflexDecoder, ReflexEncoder, build_reflex_connectome
|
|
235
|
+
from fly_harness.demo.codec import TouchObservation
|
|
236
|
+
|
|
237
|
+
state = build_reflex_connectome()
|
|
238
|
+
harness = FlyHarness(state, ReflexEncoder(), ReflexDecoder())
|
|
239
|
+
result = harness.step(TouchObservation(touch_left=1.0))
|
|
240
|
+
print(result.action) # ReflexAction(turn=1, forward=..., brake=...)
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
## Optional body: FlyGym / NeuroMechFly
|
|
244
|
+
|
|
245
|
+
This is an **extension**, not the core product. It does not ship a 140k-neuron brain, does not rewrite FlyGym, and does not run MuJoCo unless you install the extra.
|
|
246
|
+
|
|
247
|
+
`FlyGymEncoder` / `FlyGymDecoder` map NeuroMechFly observations (joint angles, contact forces) and actions (joint targets, per-leg adhesion, optional muscle/tendon commands) onto `FlyHarness.step`. They work on dicts — no MuJoCo import. `FlyGymHarnessEnv` is a thin wrapper around an env **you** construct with FlyGym.
|
|
248
|
+
|
|
249
|
+
```python
|
|
250
|
+
from fly_harness import FlyHarness
|
|
251
|
+
from fly_harness.demo.connectome import SENSORY_INDICES, build_reflex_connectome
|
|
252
|
+
from fly_harness.flygym import FlyGymDecoder, FlyGymEncoder, FlyGymHarnessEnv
|
|
253
|
+
|
|
254
|
+
state = build_reflex_connectome() # fixture circuit, not FlyWire
|
|
255
|
+
harness = FlyHarness(
|
|
256
|
+
state,
|
|
257
|
+
FlyGymEncoder(state.n_neurons),
|
|
258
|
+
FlyGymDecoder(state.n_neurons),
|
|
259
|
+
sensory_indices=SENSORY_INDICES,
|
|
260
|
+
)
|
|
261
|
+
# env = your FlyGym / NeuroMechFly simulation (not constructed here)
|
|
262
|
+
body = FlyGymHarnessEnv(env, harness)
|
|
263
|
+
obs, info = body.reset()
|
|
264
|
+
result = body.step()
|
|
265
|
+
# result.action.as_env_dict() -> {"joints": ..., "adhesion": ...}
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
Gymnasium FlyGym (`flygym-gymnasium`, installed by the extra; import name `flygym` or `flygym_gymnasium`) takes `env.step({"joints", "adhesion"})`. FlyGym 2.x `Simulation` is duck-typed via `set_actuator_inputs` / `set_leg_adhesion_states` when you pass `actuator_type`.
|
|
269
|
+
|
|
270
|
+
## Optional protocol: MCP
|
|
271
|
+
|
|
272
|
+
This is an **extension pack**, not the microkernel. `BrainState` / `FlyHarness` stay numpy/scipy-only and do not import MCP. The default server steps the 24-neuron reflex **fixture**, not a 140k FlyWire brain.
|
|
273
|
+
|
|
274
|
+
```bash
|
|
275
|
+
pip install -e ".[mcp]"
|
|
276
|
+
# stdio (default FastMCP transport) — point an MCP host at this command:
|
|
277
|
+
fly-harness-mcp
|
|
278
|
+
# or
|
|
279
|
+
python -m fly_harness.mcp
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
Tools (no live client required to unit-test the handlers):
|
|
283
|
+
|
|
284
|
+
- `harness_step(touch_left, touch_right)` — one `FlyHarness.step`
|
|
285
|
+
- `harness_reset()` — zero potentials and the clock
|
|
286
|
+
- `harness_status()` — neuron count, timestamp, package version
|
|
287
|
+
|
|
288
|
+
Handlers are importable without FastMCP:
|
|
289
|
+
|
|
290
|
+
```python
|
|
291
|
+
from fly_harness.mcp import HarnessSession
|
|
292
|
+
|
|
293
|
+
session = HarnessSession()
|
|
294
|
+
print(session.step(touch_left=1.0)["action"])
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
## Example: protocol + body through the harness
|
|
298
|
+
|
|
299
|
+
This proves optional **MCP** and **FlyGym** extras can attach to the same `FlyHarness.step`. It uses the 24-neuron reflex **fixture**. It is **not** a 140k FlyWire or ~166k MaleCNS upload, and it does not rewrite FlyGym or the MCP pack.
|
|
300
|
+
|
|
301
|
+
```bash
|
|
302
|
+
python examples/mcp_flygym_loop.py
|
|
303
|
+
# or, after install:
|
|
304
|
+
python -m fly_harness.demo.composed
|
|
305
|
+
fly-harness-composed-demo
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
Default run uses an in-process body stub (no MuJoCo). `--try-flygym` attempts a real NeuroMechFly sim and falls back to the stub. `--serve` starts the optional FastMCP stdio server on that composed session (`pip install -e ".[mcp]"`):
|
|
309
|
+
|
|
310
|
+
```bash
|
|
311
|
+
python examples/mcp_flygym_loop.py --serve
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
An MCP host that calls `harness_step(touch_left, touch_right)` therefore steps the harness and applies the decoded joint/adhesion command to the body.
|
|
315
|
+
|
|
316
|
+
## Tests
|
|
317
|
+
|
|
318
|
+
GitHub Actions on `main` and pull requests runs `pip install -e ".[dev]"` then `pytest` — no FlyGym/MCP extras, no MuJoCo. Skip/mock tests in those extras still pass. The **biorouter** extra is stdlib-only, so its tests run in that same core CI.
|
|
319
|
+
|
|
320
|
+
Default local suite does **not** need MuJoCo. The FlyGym smoke test skips unless `flygym` imports and a NeuroMechFly sim can start:
|
|
321
|
+
|
|
322
|
+
```bash
|
|
323
|
+
pytest
|
|
324
|
+
# with the FlyGym extra, still skip-friendly if MuJoCo/display is missing:
|
|
325
|
+
pytest -q
|
|
326
|
+
# FlyGym smoke only:
|
|
327
|
+
pytest tests/test_flygym_adapter.py -k smoke
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
Model-backend docking (default LIF, fake deployed sim, router `model_id` switch, unknown-id error) is core and needs no extras:
|
|
331
|
+
|
|
332
|
+
```bash
|
|
333
|
+
pytest tests/test_backend.py tests/test_harness.py
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
The optional **biorouter** process starts a stdlib server and ticks through `HttpModelBackend` / `FlyHarness` (still no FastAPI, no extras required):
|
|
337
|
+
|
|
338
|
+
```bash
|
|
339
|
+
pytest tests/test_router.py
|
|
340
|
+
# after install:
|
|
341
|
+
biorouter --help
|
|
342
|
+
python -m fly_harness.router --help
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
The biorouter example is in-thread by default (no live `biorouter` daemon). Attaching to a real process is skip-gated on `BIOROUTER_URL`:
|
|
346
|
+
|
|
347
|
+
```bash
|
|
348
|
+
pytest tests/test_biorouter_example.py
|
|
349
|
+
python examples/biorouter_loop.py
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
MCP tests mock FastMCP and do **not** start a live MCP client. They pass without `fly-harness[mcp]`. With the extra, a factory smoke checks FastMCP constructs (still no stdio client):
|
|
353
|
+
|
|
354
|
+
```bash
|
|
355
|
+
pip install -e ".[mcp]"
|
|
356
|
+
pytest tests/test_mcp_extension.py
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
The composed MCP+FlyGym example is also mock/skip: no MuJoCo and no live MCP client.
|
|
360
|
+
|
|
361
|
+
```bash
|
|
362
|
+
pytest tests/test_composed_example.py
|
|
363
|
+
python examples/mcp_flygym_loop.py
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
## License
|
|
367
|
+
|
|
368
|
+
MIT — see [LICENSE](LICENSE).
|