中文说明请见 README_zh.md
CANNs is a Python library built on top of the Brain Simulation Ecosystem (brainstate, brainunit) that streamlines experimentation with continuous attractor neural networks and related brain-inspired models. It delivers ready-to-use models, task generators, analysis tools, and pipelines so neuroscience and AI researchers can move from ideas to reproducible simulations quickly.
- Model families –
canns.models.basicships 1D/2D CANNs (including SFA variants and hierarchical networks), whilecanns.models.brain_inspiredadds Hopfield-style systems. - Task-first API –
canns.task.trackingandcanns.task.open_loop_navigationgenerate smooth tracking inputs, population coding stimuli, or import experimental trajectories. - Rich analysis suite –
canns.analyzercovers energy landscapes, tuning curves, spike embeddings, UMAP/TDA helpers, and theta-sweep animations. - Unified training –
canns.trainer.HebbianTrainerimplements generic Hebbian learning and prediction, layered on the abstractTrainerbase. - Pipelines out of the box –
canns.pipeline.ThetaSweepPipelineorchestrates navigation tasks, direction/grid-cell networks, and visualisation in a single call. - Extensible foundations – base classes (
BasicModel,Task,Trainer,Pipeline) keep custom components consistent with the built-in ecosystem.
# CPU-only installation
pip install canns
# Optional accelerators (Linux only)
pip install canns[cuda12]
pip install canns[tpu]import brainstate
from canns.models.basic import CANN1D
from canns.task.tracking import SmoothTracking1D
brainstate.environ.set(dt=0.1)
cann = CANN1D(num=512)
cann.init_state()
task = SmoothTracking1D(
cann_instance=cann,
Iext=(0.0, 0.5, 1.0, 1.5),
duration=(5.0, 5.0, 5.0, 5.0),
time_step=brainstate.environ.get_dt(),
)
task.get_data()
def step(t, stimulus):
cann(stimulus)
return cann.u.value, cann.inp.value
us, inputs = brainstate.transform.for_loop(
step,
task.run_steps,
task.data,
pbar=brainstate.transform.ProgressBar(10),
)For an end-to-end theta sweep workflow, see examples/pipeline/theta_sweep_from_external_data.py or the ThetaSweepPipeline notebook in the docs.
- Quick Start Guide – condensed tour of the library layout.
- Design Philosophy – detailed design rationale for each module.
- Interactive launchers:
# Create the dev environment (uv-based)
make install
# Format and lint (ruff, codespell, etc.)
make lint
# Run the test suite (pytest)
make testAdditional scripts live under devtools/ and scripts/.
src/canns/ Core library modules (models, tasks, analyzers, trainer, pipeline)
docs/ Sphinx documentation and notebooks
examples/ Ready-to-run scripts for models, analysis, and pipelines
tests/ Pytest coverage for key behaviours
If you use CANNs in your research, please cite it using the information from our CITATION.cff file or use the following:
@software{he_2025_canns,
author = {He, Sichao},
title = {CANNs: Continuous Attractor Neural Networks Toolkit},
year = 2025,
publisher = {Zenodo},
version = {v0.9.0},
doi = {10.5281/zenodo.17412545},
url = {https://github.com/Routhleck/canns}
}Contributions are welcome! Please open an issue or discussion if you plan significant changes. Pull requests should follow the existing lint/test workflow (make lint && make test).
Apache License 2.0. See LICENSE for details.