A modern, header-only C++20 library for the simulation of dynamical systems, designed for modeling neural networks with high performance. Built on C++20 concepts for type safety and compile-time validation.
Forked from: https://code.launchpad.net/~elferdo/neun/trunk
- Header-only: No compilation required, just include and use
- C++20 concepts: Type-safe interfaces with clear concept requirements
- Zero runtime overhead: All concept checks happen at compile time
- Template-based: Highly optimized generic code
- Modular design: Mix and match models, integrators, and wrappers
- Extensive model library: Wide range of neuron and synapse models
- C++20 compatible compiler: GCC 10+, Clang 10+, or MSVC 2019+
- CMake 3.5+ (for building tests and installation)
Since Neun is header-only, you can simply copy the headers:
git clone <repository-url>
cd neun
# Copy to your project
cp -r include/ integrators/ concepts/ archetypes/ models/ wrappers/ /your/project/include/neun/
# Or install system-wide
sudo cp -r include/ integrators/ concepts/ archetypes/ models/ wrappers/ /usr/local/include/neun/If you want CMake package support (allows find_package(neun)):
git clone <repository-url>
cd neun
mkdir build && cd build
cmake ..
sudo make installThis installs headers to /usr/local/include/neun/ and creates CMake config files for easy integration.
Note: Since Neun is header-only, the "build" step only validates concept compliance tests. No compilation of the library itself occurs.
include(FetchContent)
FetchContent_Declare(
neun
GIT_REPOSITORY <repository-url>
GIT_TAG main
)
FetchContent_MakeAvailable(neun)
target_link_libraries(your_target PRIVATE neun::neun)find_package(neun REQUIRED)
target_link_libraries(your_target PRIVATE neun::neun)#include <iostream>
#include "IzhikevichModel.h"
#include "SystemWrapper.h"
#include "IzhikevichSystemWrapper.h"
#include "IntegratedSystemWrapper.h"
#include "RungeKutta4.h"
int main() {
// Define your integrator
typedef RungeKutta4 Integrator;
// Create a neuron with proper wrapping
typedef IntegratedSystemWrapper<
IzhikevichSystemWrapper<double>,
Integrator
> Neuron;
// Configure the neuron
Neuron::ConstructorArgs args;
args.params[Neuron::parameter::a] = 0.02;
args.params[Neuron::parameter::b] = 0.2;
args.params[Neuron::parameter::c] = -65.0;
args.params[Neuron::parameter::d] = 8.0;
args.params[Neuron::parameter::threshold] = 30.0;
Neuron neuron(args);
// Set initial conditions
neuron.set(Neuron::variable::v, -65.0);
neuron.set(Neuron::variable::u, neuron.get(Neuron::parameter::b)
* neuron.get(Neuron::variable::v));
// Simulate
double dt = 0.1; // ms
double t_max = 100.0; // ms
for (double t = 0; t < t_max; t += dt) {
neuron.step(dt);
std::cout << t << " " << neuron.get(Neuron::variable::v) << std::endl;
}
return 0;
}g++ -std=c++20 -O3 -I/usr/local/include/neun simulation.cpp -o simulation
./simulationNeun uses C++20 concepts to define clear interfaces:
- ModelConcept: Basic model with eval() method
- SystemConcept: Adds get/set for variables and parameters
- NeuronConcept: Extends System with synaptic inputs
- IntegratorConcept: Numerical integration interface
- DynamicalSystemConcept: Time evolution with step()
- IntegratableSystemConcept: System ready for integration
Wrappers provide functionality layers:
- SystemWrapper: Adds get/set interface to models
- DynamicalSystemWrapper: Adds time evolution
- DifferentialNeuronWrapper: Combines neuron + integrator
- IntegratedSystemWrapper: Full integration pipeline
- IzhikevichSystemWrapper: Model-specific reset logic
- Stepper: Fixed step integrator base
- Euler: First-order Euler method
- RungeKutta4: Fourth-order Runge-Kutta (RK4)
- RungeKutta6: Sixth-order Runge-Kutta (RK6)
- HodgkinHuxleyModel: Conductance-based model (Hodgkin & Huxley, 1952)
- IzhikevichModel: Simplified spiking model (Izhikevich, 2003)
- HindmarshRoseModel: Bursting neuron (Hindmarsh & Rose, 1984)
- VavoulisModel: Detailed conductance model (Vavoulis et al., 2007)
- VavoulisCGCModel: Vavoulis with calcium-gated currents
- VavoulisCGCModelQ10: Temperature-dependent variant
| Model | Class Name | Description |
|---|---|---|
| Hodgkin-Huxley | HodgkinHuxleyModel | Classic conductance-based model |
| Hindmarsh-Rose | HindmarshRoseModel | Simplified bursting model |
| Izhikevich | IzhikevichModel | Spiking neuron model (Izhikevich, 2003) |
| Vavoulis | VavoulisModel | Detailed conductance model (Vavoulis et al., 2007) |
| Vavoulis CGC | VavoulisCGCModel | Vavoulis with calcium-gated currents |
| Vavoulis CGC Q10 | VavoulisCGCModelQ10 | Temperature-dependent variant |
| Model | Class Name | Description |
|---|---|---|
| Rulkov | RulkovMapModel | Discrete-time neuron (Rulkov, 2002) |
| BistableRulkovMapModel | BistableRulkovMapModel | Bistable variant |
| Model | Class Name | Description |
|---|---|---|
| **Simple oscillator | SimpleOscillatorModel | Basic oscillator |
| Matsuoka | MatsuokaOscillatorModel | CPG oscillator (Matsuoka, 1985) |
| RowatSelverston | RowatSelverstonModel | Rowat and Selverston model (1997) |
| Model | Class Name | Description |
|---|---|---|
| DiffusionSynapse | DiffusionSynapseModel | Chemical synapse (Destexhe et al., 1994) |
| Gradual activation synapse | GradualActivationSynapseModel | Gradual activation model |
| Gap junction | ElectricalSynapse | Gap junction |
| Direct synapse | DirectSynapse | Direct conductance coupling |
| Sigmoidal activation | SigmoidalDirectSynapse | Sigmoidal activation |
- CurrentPulse: Inject current pulses
- CurrentSource: Custom current injection
- NeuronBase: Base class for neuron models
- ModelBase: Base class for all models
The library includes comprehensive compile-time tests:
cd build
cmake ..
make check_conceptsTests verify that all archetypes satisfy their concepts. See tests/README.md for details.
All interfaces are enforced through C++20 concepts, providing:
- Clear compiler error messages
- Self-documenting code
- Compile-time validation
All abstractions compile away:
- No virtual functions (except where explicitly needed)
- Template-based polymorphism
- Inline everything
Mix and match components:
- Any model with any integrator
- Multiple wrapper layers
- Custom wrappers for specific models
Examples have been moved to a separate repository to keep this library focused on the core functionality. See the examples repository for complete working examples.
- Library overview: This README
- Testing guide: tests/README.md
- Concept reference: See headers in
concepts/
Contributions are welcome! When adding new features:
- Define appropriate concepts in
concepts/ - Create archetypes in
archetypes/ - Add tests in
tests/test_concept_compliance.cpp - Ensure all concept assertions pass
- Document public interfaces
Neun is designed for high performance:
- Zero-overhead abstractions
- Header-only means no library linking overhead
- Aggressive inlining
- Template specialization opportunities
Typical performance: 10,000+ neurons at >1kHz real-time on modern hardware.
BSD 3-Clause License. See Copyright file for details.
If you use Neun in your research, please cite:
@software{neun2024,
title={Neun: A C++20 Library for Neural Network Simulation},
author={Lareo, Angel and Herrero Carrón, Fernando},
year={2024},
url={https://github.com/GNB-UAM/neun}
}
- Maintainer: Angel Lareo (angel.lareo@uam.es)
- Organization: Grupo de Neurocomputación Biológica, UAM
- Issues: Use GitHub issue tracker
Original implementation by Fernando Herrero Carrón. Modernized and refactored by Angel Lareo.