Skip to main content

sc_neurocore_engine/bindings/rate/
tsodyks_markram.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 — Tsodyks-Markram neuron PyO3 binding
8
9use pyo3::prelude::*;
10use pyo3::types::PyDict;
11
12use crate::neurons;
13
14#[pyclass(
15    name = "TsodyksMarkramNeuron",
16    module = "sc_neurocore_engine.sc_neurocore_engine"
17)]
18#[derive(Clone)]
19pub struct PyTsodyksMarkramNeuron {
20    inner: neurons::TsodyksMarkramNeuron,
21}
22
23#[pymethods]
24impl PyTsodyksMarkramNeuron {
25    #[new]
26    fn new() -> Self {
27        Self {
28            inner: neurons::TsodyksMarkramNeuron::new(),
29        }
30    }
31
32    #[pyo3(signature = (current, presynaptic_spike=false))]
33    fn step(&mut self, current: f64, presynaptic_spike: bool) -> i32 {
34        self.inner.step(current, presynaptic_spike)
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("x", self.inner.x)?;
45        d.set_item("u", self.inner.u)?;
46        Ok(d.into_any().unbind())
47    }
48}
49
50pub(super) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> {
51    module.add_class::<PyTsodyksMarkramNeuron>()?;
52    Ok(())
53}