Architecture
Five modules, one Protocol, one swap-point. The whole point is that the caller never knows whether they are talking to silicon or biology.
The stack
┌─────────────────────────────┐
│ Task Router (silicon vs. │
│ wetware, deterministic) │
└──────────────┬──────────────┘
│
┌──────────────┴──────────────┐
│ Harness API │
│ stimulate() · read() · fit │
└──────────────┬──────────────┘
│
┌───────────┴───────────┐
│ CorticalShim │
│ (single swap-point) │
└─────┬───────────┬─────┘
│ │
┌───────┴──┐ ┌──┴─────────────────┐
│ Dish │ │ Real biological │
│ (LIF+ │ │ backend │
│ STDP) │ │ (CL1 / FinalSpark │
└──────────┘ │ / future) │
└────────────────────┘
Every backend implements the same WetwareBackend Protocol — three methods and a snapshot:
class WetwareBackend(Protocol):
def stimulate(self, electrode_currents: np.ndarray, duration_ms: float) -> None: ...
def read_spikes(self) -> np.ndarray: ...
def snapshot(self) -> dict: ...
Dish · LIF + STDP
A grid of leaky-integrate-and-fire neurons. Each neuron integrates input current with a membrane time constant, leaks toward resting potential, fires when it crosses threshold, then enters a brief refractory period. Weights update via spike-timing-dependent plasticity — pre-then-post spike pairs potentiate (LTP), post-then-pre depress (LTD).
Defaults: 1024 neurons, 15% sparse connectivity, 32 input electrodes, 8 output electrodes. Membrane time constant 20 ms. STDP magnitudes A+ = 0.008, A- = 0.009 (slightly larger LTD than LTP is standard for stability). Homeostatic scaling target 10.0 (opt-in), weight decay 0.002 per stimulate() call (opt-in).
The plasticity gate
_step() function as stimulus, so STDP writes weights on feedback-pulse timing instead of stimulus-response timing.
Fix: stimulate() takes a plasticity: bool = True flag. apply_feedback() hard-forces plasticity=False — can't be misused. Reward and punishment drive the network dynamics without writing to synapses.
The trace reset
Dish.reset_traces() clears the last_spike array between trials so THIS trial's STDP only sees THIS trial's timing. Without it, cross-trial timing from feedback stimulation contaminates plasticity in the next trial, potentiating paths that should be class-independent. FreeEnergyTrainer.trial() calls it automatically at trial start.
Harness · closed-loop I/O
The programming surface. Deliberately shaped like cl-sdk:
from wetware import Dish, DishConfig, Harness
with Harness(Dish(DishConfig(seed=7332))) as h:
h.stimulate(stimulus_vector, duration_ms=30)
spikes = h.read()
# or: prediction = h.infer(stimulus_vector, duration_ms=30)
Every method delegates to the underlying WetwareBackend. When you swap the backend to CorticalShim(endpoint="finalspark", api_key=...), the call sites don't change.
FreeEnergyTrainer · reward + punishment
Karl Friston's Free Energy Principle in one sentence: biological systems minimize surprise — they rewire to keep the input predictable. Cortical Labs uses this practically: when the culture behaves correctly, the environment delivers rhythmic, predictable stimulation. When it errs, chaotic Poisson stimulation. Neurons rewire (via STDP) to keep the input predictable — which coincides with solving the task.
Rhythmic reward defaults to 40 Hz gamma-band. Chaotic punishment defaults to 60 Hz Poisson. Both are cheap; both are honest to the biology.
The trainer records per-trial correct, cumulative total_reward_ms, and total_punishment_ms — those are the honest telemetry, not accuracy on a benchmark.
Router · silicon vs wetware
A deterministic keyword classifier. Not itself an LLM.
from wetware import route, TaskKind
route("classify this EEG signal")
# Route(kind=TaskKind.PATTERN, backend='wetware', confidence=1.0)
route("write me a summary of this document")
# Route(kind=TaskKind.LANGUAGE, backend='silicon', confidence=1.0)
Categories: PATTERN, CONTROL → wetware. LANGUAGE, REASONING, KNOWLEDGE → silicon. Falls back to silicon on ambiguity.
CorticalShim · the swap-point
The whole hardware-portability story lives in one class. When cl-sdk or another biological backend is importable, CorticalShim binds through it and implements the WetwareBackend Protocol. When it isn't, calling any method raises a helpful error.
from wetware import CorticalShim, Harness
# Local sim — default
h_local = Harness(Dish())
# Real hardware — same interface, one line change
h_bio = Harness(CorticalShim(endpoint="cortical-cloud", api_key=os.environ["CL_API_KEY"]))
# Everything else stays identical:
h_bio.stimulate(vec, duration_ms=30)
spikes = h_bio.read()
This is the shape any hardware-swappable component should have. One env var, one implementation of the Protocol, no downstream changes. Compliance adapters, LLM backends, custody providers — the same pattern applies.
Persistence · save / load
Dish.save(path) serializes weights, membrane state, refractory clocks, STDP traces, electrode mappings, sim clock, RNG bit-generator state, and full config to a single .npz file. Dish.load(path) restores byte-identical weights AND the exact RNG state, so subsequent stimulations produce identical trajectories.
This is verified by a round-trip test: save, load, stimulate both dishes with identical input, assert byte-identical spike output. The RNG-bit-state property is what makes replay determinism meaningful — without it, "restored" is aspirational.
Mode flag · SIMULATED / CLOUD / PHYSICAL
Every backend-facing response carries a mode field. When integrated into a larger system, this must be surfaced in every UI panel that shows a result. Never conflate:
- SIMULATED — local LIF simulator. Results are structurally faithful but biologically fictional.
- CLOUD — hosted biological backend (e.g. FinalSpark). Results are real, but the input data left this machine.
- PHYSICAL — bench-local device (e.g. CL1). Results are real, data stayed local.