Skip to main content

sc_neurocore_engine/bindings/trivial/
quadratic_if.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 — Quadratic integrate-and-fire neuron PyO3 binding
8
9use numpy::{IntoPyArray, PyArray1};
10use pyo3::exceptions::PyFloatingPointError;
11use pyo3::prelude::*;
12use pyo3::types::PyDict;
13
14use crate::neurons;
15
16py_neuron_default!("QuadraticIFNeuron", PyQuadraticIFNeuron, neurons::QuadraticIFNeuron, state v);
17
18type QuadraticIFCompletePacket<'py> = (Bound<'py, PyArray1<f64>>, Bound<'py, PyArray1<u8>>, f64);
19
20#[pyfunction]
21#[pyo3(signature = (v, v_reset, v_peak, dt, source_profile, n_steps, current))]
22#[allow(clippy::too_many_arguments)]
23fn quadratic_if_simulate_complete<'py>(
24    py: Python<'py>,
25    v: f64,
26    v_reset: f64,
27    v_peak: f64,
28    dt: f64,
29    source_profile: bool,
30    n_steps: usize,
31    current: f64,
32) -> PyResult<QuadraticIFCompletePacket<'py>> {
33    let model = neurons::QuadraticIFNeuron {
34        v,
35        v_reset,
36        v_peak,
37        dt,
38        source_profile,
39    };
40    let (voltage, events, final_v) = model
41        .simulate_complete(n_steps, current)
42        .map_err(|error| PyFloatingPointError::new_err(error.to_string()))?;
43    Ok((voltage.into_pyarray(py), events.into_pyarray(py), final_v))
44}
45
46/// Register the quadratic integrate-and-fire neuron class.
47pub(super) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> {
48    module.add_class::<PyQuadraticIFNeuron>()?;
49    module.add_function(wrap_pyfunction!(quadratic_if_simulate_complete, module)?)?;
50    Ok(())
51}