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