sc_neurocore_engine/bindings/learning/
eprop_alif.rs1use pyo3::prelude::*;
10use pyo3::types::PyDict;
11
12use crate::neurons;
13
14#[pyclass(
15 name = "EPropALIFNeuron",
16 module = "sc_neurocore_engine.sc_neurocore_engine"
17)]
18#[derive(Clone)]
19pub struct PyEPropALIFNeuron {
20 inner: neurons::EPropALIFNeuron,
21}
22
23#[pymethods]
24impl PyEPropALIFNeuron {
25 #[new]
26 #[pyo3(signature = (tau_m=20.0, tau_a=200.0, dt=1.0))]
27 fn new(tau_m: f64, tau_a: f64, dt: f64) -> Self {
28 Self {
29 inner: neurons::EPropALIFNeuron::new(tau_m, tau_a, dt),
30 }
31 }
32
33 fn step(&mut self, current: f64) -> i32 {
34 self.inner.step(current)
35 }
36
37 fn reset(&mut self) {
38 self.inner.reset();
39 }
40
41 fn get_state(&self, py: Python<'_>) -> PyResult<Py<PyAny>> {
42 let d = PyDict::new(py);
43 d.set_item("v", self.inner.v)?;
44 d.set_item("a", self.inner.a)?;
45 d.set_item("e_trace", self.inner.e_trace)?;
46 Ok(d.into_any().unbind())
47 }
48}
49
50pub(super) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> {
51 module.add_class::<PyEPropALIFNeuron>()?;
52 Ok(())
53}