Skip to main content

sc_neurocore_engine/bindings/
ibarz_tanaka_map.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 — Ibarz-Tanaka map PyO3 binding
8
9//! Python binding for the Ibarz-Tanaka spiking map.
10
11use numpy::{IntoPyArray, PyArray1};
12use pyo3::exceptions::PyFloatingPointError;
13use pyo3::prelude::*;
14use pyo3::types::PyDict;
15
16use crate::neurons::IbarzTanakaMapNeuron;
17
18py_neuron_default!("IbarzTanakaMapNeuron", PyIbarzTanakaMapNeuron, IbarzTanakaMapNeuron, state v, state u);
19
20/// Register the Ibarz-Tanaka map class and simulator with the extension module.
21pub(super) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> {
22    module.add_class::<PyIbarzTanakaMapNeuron>()?;
23    module.add_function(wrap_pyfunction!(py_ibarz_tanaka_map_simulate, module)?)?;
24    Ok(())
25}
26
27/// Parity contract with
28/// `sc_neurocore.neurons.models.ibarz_tanaka_map.IbarzTanakaMapNeuron.simulate`:
29/// for the same parameters and constant input the returned `v` trace, reset-
30/// branch event count, and final `(v, u)` state are bit-identical to the Python
31/// reference. The implementation follows Eqs. 2-3 of Ibarz et al. (2007).
32#[pyfunction]
33#[pyo3(signature = (v0, u0, alpha, mu, sigma, n_steps, current))]
34fn py_ibarz_tanaka_map_simulate<'py>(
35    py: Python<'py>,
36    v0: f64,
37    u0: f64,
38    alpha: f64,
39    mu: f64,
40    sigma: f64,
41    n_steps: usize,
42    current: f64,
43) -> PyResult<(Bound<'py, PyArray1<f64>>, i64, f64, f64)> {
44    let mut neuron = IbarzTanakaMapNeuron {
45        v: v0,
46        u: u0,
47        alpha,
48        mu,
49        sigma,
50    };
51    let (trace, events) = neuron
52        .simulate(n_steps, current)
53        .map_err(PyFloatingPointError::new_err)?;
54    Ok((trace.into_pyarray(py), events, neuron.v, neuron.u))
55}