spikeforge is a spike-encoding playground for spiking neural networks
(SNNs), built on snnTorch and PyTorch. It
loads MNIST-style datasets, converts samples into rate, latency,
delta, and random spike codes, and drives them through a fully
connected LIF network for training, inference, and matplotlib/MP4 exports.
spikeforge/— importable Python package: datasets, spike encoders, the FC LIFSpikingNet, the training loop, checkpointing, and exporters.server/— FastAPI backend that runs encoding/training and streams results to the client over a JSON WebSocket protocol.main.py/main_encodings.py— thin CLI entry points that run the encoder pipelines and write artifacts intobuild/.client/— the React + TypeScript dashboard (Vite + React 18).
- Single source of truth for encoding math.
SpikeEncoderowns rate/latency/delta/random conversion. The viewer and the training path both call it; nothing else re-implements coding logic. Datasets likewise flow through one sharedtransform()so normalization stays identical everywhere. - One class per file, grouped by subdirectory. Small, focused modules are preferred over large multi-purpose ones.
- Legacy compatibility is deliberate, not accidental. The original trainer
classes and the raw-pixel input path stay importable and behavior-compatible
so old checkpoints and
main_encodings.pykeep working.
TopologySpecis the single source of truth. Every model is declared as a spec and rendered twice — into the snnTorch module (build_module) and into the NIR graph (to_nir) — so the two cannot silently diverge.nir/nirtorchimports stay confined tonir_bridge/api.py. Every other module reaches the packages through that isolated probe, which contains upstream API churn to one file.- Exactly one temporal loop lives in
simulator/. Modelforwards never contain a time loop; each stage is a pure(input, state)step and the single runner drives them over time. - Validation stays independent. The reference NIR interpreter executes the exported graph from its node parameters alone and never calls snnTorch, so a drift check is a genuine cross-check, not a tautology.
- Legacy compatibility is deliberate.
fc_legacypreserves theSpikingNetparameter names, method contracts, and state-dict keys, so old checkpoints keep loading and inferring unchanged.
Website text, application text, documentation, and product descriptions follow
COPY_POLICY.md. Read it before drafting or editing any of
them. It governs the landing page under landing/, the model hub page rendered
by scripts/build_hub_page.py, README.md, and docs/.
Two points that bite most often here:
- Do not invent quantities or capabilities. Check the implemented behavior. A count on the landing page (walkthroughs, datasets, targets) is a claim, and claims get verified before they ship.
- The landing page is translated into seventeen locales. An English change
that is not carried into
landing/locales.jsandlanding/cta-locales.jsleaves sixteen languages stating the old copy.
Required disclosures stay: the pre-1.0 warning, the "Implications and boundaries" link, and the hub's curation, licensing, and "not tuned attempts at state of the art" notices. Shortening copy is not a reason to remove any of them.
- No file over 250 lines.
- No class over 200 lines.
- No function or method over 20 lines.
- One class per file. Group related classes into a subdirectory rather than stacking them in one module.
- Maximum line length: 79 characters (PEP 8 / ruff
E501).
When a limit is reached, split the logic — extract a helper function or move a class/module into its own file. Do not grow a file just past the limit.
- Follow PEP 8. Lint and format with
ruff(the declared dev dependency). - Use type hints on every function and method signature, including return types. Annotate non-obvious attributes and properties too.
- Add docstrings to public modules, classes, and functions.
- Write comments where they explain why, not what — skip comments that merely restate the code. Prefer clear names over narration.
- Write sparse, DRY, easy-to-maintain code. No dense, clever, or repeated logic: extract shared behavior into small helpers instead of copy-pasting it. Favor explicit, readable code over compact one-liners.
- Never use
# noqa/# noqa: ...to silence linter warnings. Fix the underlying issue, and remove existingnoqacomments while fixing what they masked. - Never use stopgaps, shims, hacks, or monkeypatches to paper over a
problem — this includes
type: ignorecomments, stub overrides, and runtime attribute injection. Implement the correct, first-class solution.
- Run tests with
pytest(withpytest-covfor coverage) from thedevextra before considering a change done. - Keep static checks clean:
rufffor lint/format and type annotations for the code you touch.
- No file over 250 lines.
- No React component over 200 lines (mirrors the class limit).
- No hook or helper function over 120 lines.
- One exported component per file. Group related helpers into a subdirectory rather than stacking components in one module.
- Maximum line length: 80 characters.
When a limit is reached, extract a hook, a helper, or a presentational component into its own file. Do not grow a file just past the limit.
- Follow the existing Prettier conventions: double quotes, semicolons, trailing commas, and 2-space indentation.
- Type everything.
strictis on; never fall back toany. Use a precise type, a discriminated union, orunknownplus a narrowing guard. - Model protocol shapes as discriminated unions on a literal
typefield and narrow them with aswitch. - Keep stateful logic in custom hooks (
useSomething) and keep components presentational. - Prefer derived values computed during render over duplicated state, and prefer function components over class components.
- Declare props as a local
interface Propsand keep them read-only. - Naming:
PascalCasefor components and types,useSomethingfor hooks,camelCasefor values/functions,UPPER_SNAKE_CASEfor module constants. - Write comments where they explain why, not what. Extract shared helpers instead of copy-pasting JSX or logic.
- Never use
any/as any,@ts-ignore,@ts-expect-error,@ts-nocheck, oreslint-disable. Fix the underlying type instead. - Do not paper over nullable values with non-null assertions; guard or narrow
them. (The one allowed exception is the
#rootmount inmain.tsx.) - No stopgaps, shims, dead code, or unused exports.
npm run build(runstsc -bthenvite build) must pass with no type errors before a change is considered done.- Keep every file within the limits above.
- No file over 300 lines.
- Maximum line length: 80 characters.
- Keep selectors flat and short — no descendant chains deeper than needed.
- Define every colour as a custom property in the theme blocks (
:rootand[data-theme="light"]); never hard-code a colour inside a rule. - Group rules under a
/* --- section --- */banner and keep related rules together, so the cascade order stays stable when a file is split. - Class names are kebab-case and name the component or role, not the appearance.
- Prefer class selectors. Avoid IDs except the
#rootmount. - Keep shared element defaults (e.g.
canvas) in the base layer, and component-specific overrides after them.
- Never use
!important. Fix the selector/specificity instead. - No inline
style={{ ... }}except values that genuinely cannot be expressed in CSS (e.g. JS-computed canvas sizes or positions). - No unused rules.
- The dashboard must still render correctly in both the dark and light themes; every colour change flows through a custom property.