Skip to main content

sc_neurocore_engine/bindings/
izhikevich.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 PyO3 binding
8
9//! Python binding for the floating-point Izhikevich neuron.
10
11use pyo3::prelude::*;
12use pyo3::types::PyDict;
13
14use crate::neuron;
15
16/// Register the floating-point Izhikevich neuron with the extension module.
17pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> {
18    module.add_class::<PyIzhikevich>()?;
19    Ok(())
20}
21
22#[pyclass(
23    name = "Izhikevich",
24    module = "sc_neurocore_engine.sc_neurocore_engine"
25)]
26pub struct PyIzhikevich {
27    inner: neuron::Izhikevich,
28}
29
30#[pymethods]
31impl PyIzhikevich {
32    #[new]
33    #[pyo3(signature = (a=0.02, b=0.2, c=-65.0, d=8.0, dt=1.0))]
34    fn new(a: f64, b: f64, c: f64, d: f64, dt: f64) -> Self {
35        Self {
36            inner: neuron::Izhikevich::new(a, b, c, d, dt),
37        }
38    }
39
40    fn step(&mut self, current: f64) -> i32 {
41        self.inner.step(current)
42    }
43
44    fn reset(&mut self) {
45        self.inner.reset();
46    }
47
48    fn reset_state(&mut self) {
49        self.reset();
50    }
51
52    fn get_state(&self, py: Python<'_>) -> PyResult<Py<PyAny>> {
53        let dict = PyDict::new(py);
54        dict.set_item("v", self.inner.v)?;
55        dict.set_item("u", self.inner.u)?;
56        Ok(dict.into_any().unbind())
57    }
58}