A Python Library for Continuous Attractor Neural Networks
Project description
CANNs: Continuous Attractor Neural Networks Toolkit
中文说明请见 README_zh.md
Overview
CANNs (Continuous Attractor Neural Networks toolkit) is a research toolkit built on BrainPy and JAX, with optional Rust-accelerated canns-lib for selected performance-critical routines (e.g., TDA/Ripser and task generation). It bundles model collections, task generators, analyzers, and the ASA pipeline (GUI/TUI) so researchers can run simulations and analyze results in a consistent workflow. The API separates models, tasks, analyzers, and trainers to keep experiments modular and extensible.
Architecture
Layer hierarchy of the CANNs library showing five levels: Application (Pipeline orchestration), Functional (Task, Trainer, Analyzer, Utils modules), Core Models (CANN implementations), Foundation (BrainPy/JAX and Rust FFI backends), and Hardware (CPU/GPU/TPU support)
The CANNs library follows a modular architecture guided by two core principles: separation of concerns and extensibility through base classes. The design separates functional responsibilities into five independent modules:
- Models (
canns.models) define neural network dynamics; - Tasks (
canns.task) generate experimental paradigms and input data; - Analyzers (
canns.analyzer) provide visualization and analysis tools; - Trainers (
canns.trainer) implement learning rules for brain-inspired models; - Pipeline (
canns.pipeline) orchestrates complete workflows.
Each module focuses on a single responsibility—models don't generate input data, tasks don't analyze results, and analyzers don't modify
parameters. This separation ensures maintainability, testability, and extensibility. All major components inherit from abstract base classes
(BasicModel, BrainInspiredModel, Trainer) that define standard interfaces, enabling users to create custom implementations that
seamlessly integrate with the built-in ecosystem.
Core Features
- Model collections: basic CANNs (1D/2D, SFA), hierarchical path integration, theta-sweep models, brain-inspired models (e.g., Amari-Hopfield, linear/spiking layers)
- Task generators: smooth tracking, population coding, template matching, open/closed-loop navigation
- Analyzer suite: energy landscapes, tuning curves, raster/firing-rate plots, TDA and decoding utilities, cell classification
- ASA pipeline & GUI/TUI: end-to-end workflow for preprocessing, TDA, decoding, and result visualization (e.g., CohoMap/CohoSpace/PathCompare/FR/FRM/GridScore)
- Training & extensibility: HebbianTrainer plus base classes for consistent extension
- Optional acceleration:
canns-libfor selected performance-critical routines
Analyzer Visuals
Overview of Neural Dynamics Models. Comparison of three basic models: (A) 1D CANN, (B) 2D CANN, and (C) Grid Cell Network
Rich Analyzer Visualization Results
ASA GUI preview
Smooth Tracking 1DActivity bump following a moving stimulus |
CANN2D Encoding2D population encoding patterns over time |
Theta Sweep AnimationTheta-modulated sweep dynamics |
|
Bump AnalysisBump fitting and stability diagnostics |
Torus BumpBump dynamics projected onto a torus manifold |
Quick Start
1D CANN smooth tracking (imports → simulation → visualization)
import brainpy.math as bm
from canns.analyzer.visualization import PlotConfigs, energy_landscape_1d_animation
from canns.models.basic import CANN1D
from canns.task.tracking import SmoothTracking1D
# simulation time step
bm.set_dt(0.1)
# build model
cann = CANN1D(num=512)
# build tracking task (Iext length = duration length + 1)
task = SmoothTracking1D(
cann_instance=cann,
Iext=(0.0, 0.5, 1.0, 1.5),
duration=(5.0, 5.0, 5.0),
time_step=bm.get_dt(),
)
task.get_data()
# one-step simulation callback
def step(t, stimulus):
cann(stimulus)
return cann.u.value, cann.inp.value
# run simulation loop
us, inputs = bm.for_loop(
step,
operands=(task.run_steps, task.data),
)
# visualize with energy landscape animation
config = PlotConfigs.energy_landscape_1d_animation(
time_steps_per_second=int(1 / bm.get_dt()),
fps=20,
title="Smooth Tracking 1D",
xlabel="State",
ylabel="Activity",
show=True,
)
energy_landscape_1d_animation(
data_sets={"u": (cann.x, us), "Iext": (cann.x, inputs)},
config=config,
)
Installation
# CPU-only
pip install canns
# Optional accelerators (Linux)
pip install canns[cuda12]
pip install canns[cuda13]
pip install canns[tpu]
# GUI (ASA Pipeline)
pip install canns[gui]
Optional (uv):
uv pip install canns
Docs & Examples
- Documentation and tutorials: https://routhleck.com/canns/
- Local scripts:
examples/ - Sphinx docs and notebooks:
docs/ - ASA GUI entry:
canns-gui
Citation
If you use CANNs in your research, please cite:
@software{he_2026_canns,
author = {He, Sichao and
Tuerhong, Aiersi and
She, Shangjun and
Chu, Tianhao and
Wu, Yuling and
Zuo, Junfeng and
Wu, Si},
title = {CANNs: Continuous Attractor Neural Networks Toolkit},
month = feb,
year = 2026,
publisher = {Zenodo},
version = {v1.0.0},
doi = {10.5281/zenodo.18453893},
url = {https://doi.org/10.5281/zenodo.18453893}
}
Plain text:
He, S., Tuerhong, A., She, S., Chu, T., Wu, Y., Zuo, J., & Wu, S. (2026). CANNs: Continuous Attractor Neural Networks Toolkit (v1.0.0). Zenodo. https://doi.org/10.5281/zenodo.18453893
Contributing & License
Contributions are welcome. Please read CONTRIBUTING.md before opening a PR.
Apache License 2.0. See LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file canns-1.0.1.tar.gz.
File metadata
- Download URL: canns-1.0.1.tar.gz
- Upload date:
- Size: 431.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ccff717ff4156e84609fecc1cf3e0a48724903fb61d0658b2a1c9df1b411d2a4
|
|
| MD5 |
a0893b3173dada285580566456b22eef
|
|
| BLAKE2b-256 |
2d80f1cb8ba09a74cc8fbd90e2ecf17d765e93a822abb5156de12f4dd94f01e8
|
Provenance
The following attestation bundles were made for canns-1.0.1.tar.gz:
Publisher:
publish.yml on Routhleck/canns
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
canns-1.0.1.tar.gz -
Subject digest:
ccff717ff4156e84609fecc1cf3e0a48724903fb61d0658b2a1c9df1b411d2a4 - Sigstore transparency entry: 923061602
- Sigstore integration time:
-
Permalink:
Routhleck/canns@d16b32519cc78b47ee021da136af99d6a3a77380 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/Routhleck
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d16b32519cc78b47ee021da136af99d6a3a77380 -
Trigger Event:
release
-
Statement type:
File details
Details for the file canns-1.0.1-py3-none-any.whl.
File metadata
- Download URL: canns-1.0.1-py3-none-any.whl
- Upload date:
- Size: 501.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6004784d702b39eb2c4f562220c30461754e65f66dff5015b0c0de90e3a8edeb
|
|
| MD5 |
2323befea4642eaf5861b729bcafff32
|
|
| BLAKE2b-256 |
f4d54270bfc1aacda6eb9e296d889f8e0335320b754f42b519094511660a4613
|
Provenance
The following attestation bundles were made for canns-1.0.1-py3-none-any.whl:
Publisher:
publish.yml on Routhleck/canns
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
canns-1.0.1-py3-none-any.whl -
Subject digest:
6004784d702b39eb2c4f562220c30461754e65f66dff5015b0c0de90e3a8edeb - Sigstore transparency entry: 923061645
- Sigstore integration time:
-
Permalink:
Routhleck/canns@d16b32519cc78b47ee021da136af99d6a3a77380 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/Routhleck
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d16b32519cc78b47ee021da136af99d6a3a77380 -
Trigger Event:
release
-
Statement type: