r/madeinpython • u/TastyCollege9639 • 1d ago
Built necklink: 6 Python + C99 packages compiling fruit-fly connectome circuits and testing them against 100 rewired brains
Sharing v3.0.0 of NeckLink (pip install necklink, MIT licensed, Python 3.9+ with only NumPy required at runtime), a monorepo of six packages that compile subgraphs from the 157,789-neuron adult fruit-fly connectome (BANC v888) into runnable Python controllers and zero-float C99 cores.
All 6 packages on PyPI:
- necklink-cns: unified 4-organ reflex controller (11 brain populations -> 10 descending neurons -> 6 motor pools) with MAVLink v2 and ROS 2 bridges, plus necklink_cns.connectome tools for extracting BANC v888 subgraphs and running Maslov-Sneppen degree-preserving shuffles.
- neckcompass: central-complex ring-attractor heading and GPS-denied homing.
- necksight: optic-lobe LPLC2 + LC4 collision / thin-wire looming reflex with 3-DOF gyro derotation.
- neckcord: VNC 6x6 leg inhibition (emergent tripod gait), bounded rotor/thruster allocator, ESC fault observer, and 18-servo IK.
- necksense: mushroom-body 1,024 Kenyon-cell sparse projection for novelty detection and continual memory.
- pynltp: loss-healing asyncio UDP transport (LZ4 + X25519/ChaCha20-Poly1305 + GF(2^8) Cauchy FEC) for streaming reflex commands and telemetry across noisy wireless hops.
Minimal Python example:
import numpy as np
from necklink_cns import NeckLinkCNS
# Uses compiled BANC v888 connectome weights by default (or pass connectome_weights="v2_analytic")
cns = NeckLinkCNS(vehicle="hexacopter", grid_size=32)
out = cns.step(
dt=0.02,
speed_m_s=1.8,
gyro_xyz=np.array([0.02, -0.01, 0.05]),
accel_xyz=np.array([0.2, -0.1, 9.80]),
mag_xyz=np.array([0.45, 0.05, 0.89]),
camera_frame=np.full((32, 32), 160.0),
)
print(out.descending.behavior_mode, len(out.cervical_wire_4b), hex(out.mavlink_manual_pkt[0]))
The most interesting part of building v3.0.0 was auditing whether the real connectome wiring actually beats degree-preserving random rewiring (K = 100 Maslov-Sneppen shuffles where every neuron keeps its exact in-degree, out-degree, and weight multiset) and classical baselines:
- Specific wiring matters on spatial geometry and coordination: scrambling the central complex or VNC matrices breaks closed-loop homing (100% arrival -> 4.7%, p = 0.0099), wave + 125 deg magnetic spike heading (12.84 deg RMS -> 62.82 deg, p = 0.0099), and emergent tripod gait (0.855 -> 0.411, p = 0.0099).
- Specific wiring does not matter in the mushroom body: on UCI gas drift novelty detection, real Kenyon claws (0.666 AUROC) and shuffled claws (0.672 AUROC, p = 0.74) tie, while One-Class SVM hits 0.698.
- Classical / symmetric models win raw accuracy: real fly circuits have biological left/right asymmetries (for example ~10 deg/s compass drift in darkness), so an EKF (0.81 deg RMS) or connectome_weights="v2_analytic" (80.0% closed-loop boat arrival vs 66.7% for BANC v888) beats raw biological weights when you just want the cleanest filter.
Live browser WASM simulator:
https://indian-aman.github.io/necklink/
GitHub repo & reproducible v3 benchmark suite:
https://github.com/indian-aman/necklink