Skip to main content

sc_neurocore_engine/bindings/hardware/
dpi.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 — DPI neuron PyO3 binding
8
9use pyo3::prelude::*;
10use pyo3::types::PyDict;
11
12use crate::neurons;
13
14type DpiCompletePythonPacket = (Vec<f64>, Vec<f64>, Vec<f64>, Vec<u8>, f64, f64, f64);
15
16py_neuron_default!(
17    "DPINeuron",
18    PyDPINeuron,
19    neurons::DPINeuron,
20    state i_mem,
21    state i_ahp,
22    state refractory_time
23);
24
25pub(super) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> {
26    module.add_class::<PyDPINeuron>()?;
27    module.add_function(wrap_pyfunction!(dpi_neuron_simulate_complete, module)?)?;
28    Ok(())
29}
30
31/// Execute the complete configurable DPI contract in one checked Rust batch.
32#[pyfunction]
33#[allow(clippy::too_many_arguments)]
34fn dpi_neuron_simulate_complete(
35    i_mem: f64,
36    i_ahp: f64,
37    refractory_time: f64,
38    i_threshold: f64,
39    i_reset: f64,
40    i_rest: f64,
41    i_tau: f64,
42    i_g: f64,
43    i_tau_ahp: f64,
44    i_ga: f64,
45    i_spike: f64,
46    i_0: f64,
47    kappa: f64,
48    alpha: f64,
49    tau: f64,
50    tau_ahp: f64,
51    refractory_period: f64,
52    dt: f64,
53    n_steps: usize,
54    current: f64,
55) -> PyResult<DpiCompletePythonPacket> {
56    let mut model = neurons::DPINeuron {
57        i_mem,
58        i_ahp,
59        refractory_time,
60        i_threshold,
61        i_reset,
62        i_rest,
63        i_tau,
64        i_g,
65        i_tau_ahp,
66        i_ga,
67        i_spike,
68        i_0,
69        kappa,
70        alpha,
71        tau,
72        tau_ahp,
73        refractory_period,
74        dt,
75    };
76    let (i_mem_trace, i_ahp_trace, refractory_trace, events) = model
77        .simulate_complete(n_steps, current)
78        .map_err(|error| pyo3::exceptions::PyValueError::new_err(error.to_owned()))?;
79    Ok((
80        i_mem_trace,
81        i_ahp_trace,
82        refractory_trace,
83        events,
84        model.i_mem,
85        model.i_ahp,
86        model.refractory_time,
87    ))
88}