sc_neurocore_engine/bindings/
izhikevich.rs1use pyo3::prelude::*;
12use pyo3::types::PyDict;
13
14use crate::neuron;
15
16pub(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}