sc_neurocore_engine/bindings/izhikevich2007.rs
1// SPDX-License-Identifier: AGPL-3.0-or-later
2// Commercial license available
3// © Concepts 1996–2026 Miroslav Šotek. All rights reserved.
4// © Code 2020–2026 Miroslav Šotek. All rights reserved.
5// ORCID: 0009-0009-3560-0851
6// Contact: www.anulum.li | protoscience@anulum.li
7// SC-NeuroCore — Izhikevich 2007 PyO3 binding
8
9//! Python binding for the NeuroML Izhikevich 2007 model.
10
11use numpy::{IntoPyArray, PyArray1};
12use pyo3::prelude::*;
13
14/// Register the Izhikevich 2007 batch simulator with the extension module.
15pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> {
16 module.add_function(wrap_pyfunction!(py_izhikevich2007_simulate, module)?)?;
17 Ok(())
18}
19
20/// Parity contract with
21/// `sc_neurocore.neurons.models.izhikevich2007.Izhikevich2007Neuron.simulate`:
22/// for the same parameters and constant input the returned `v` trace, spike
23/// count, and final `(v, u)` state are bit-identical to the Python RK4 reference
24/// (the NeuroML right-hand side `k (v-vr)(v-vt)/C` is exact arithmetic — products,
25/// a sum and a division, no transcendental functions).
26#[pyfunction]
27#[pyo3(signature = (v0, u0, cap, k, vr, vt, vpeak, a, b, c, d, dt, n_steps, current))]
28#[allow(clippy::too_many_arguments)]
29fn py_izhikevich2007_simulate<'py>(
30 py: Python<'py>,
31 v0: f64,
32 u0: f64,
33 cap: f64,
34 k: f64,
35 vr: f64,
36 vt: f64,
37 vpeak: f64,
38 a: f64,
39 b: f64,
40 c: f64,
41 d: f64,
42 dt: f64,
43 n_steps: usize,
44 current: f64,
45) -> (Bound<'py, PyArray1<f64>>, i64, f64, f64) {
46 let mut neuron = crate::rk4_neurons::Izhikevich2007Rk4 {
47 v: v0,
48 u: u0,
49 cap,
50 k,
51 vr,
52 vt,
53 vpeak,
54 a,
55 b,
56 c,
57 d,
58 dt,
59 };
60 let (trace, spikes) = neuron.simulate(n_steps, current);
61 (trace.into_pyarray(py), spikes, neuron.v, neuron.u)
62}