Skip to main content

sc_neurocore_engine/bindings/
wilson_hr.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 — Wilson-HR neuron PyO3 binding
8
9//! Python binding for the Wilson-HR polynomial cortical neuron.
10
11use numpy::{IntoPyArray, PyArray1};
12use pyo3::prelude::*;
13use pyo3::types::PyDict;
14
15use crate::neurons::WilsonHRNeuron;
16
17py_neuron_default!("WilsonHRNeuron", PyWilsonHRNeuron, WilsonHRNeuron, state v, state r);
18
19/// Register the Wilson-HR class and simulator with the extension module.
20pub(super) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> {
21    module.add_class::<PyWilsonHRNeuron>()?;
22    module.add_function(wrap_pyfunction!(py_wilson_hr_simulate, module)?)?;
23    Ok(())
24}
25
26/// N-step Wilson (1999) polynomial cortical-neuron simulation.
27///
28/// Parity contract with
29/// `sc_neurocore.neurons.models.wilson_hr.WilsonHRNeuron.simulate`: for the same
30/// parameters and constant input the returned `v` trace (already hard-reset to
31/// `-0.7` on spiking steps), spike count, and final `(v, r)` state are
32/// bit-identical to the Python RK4 reference (the right-hand side is exact
33/// polynomial arithmetic — no transcendental functions).
34#[pyfunction]
35#[pyo3(signature = (v0, r0, tau_r, v_peak, dt, n_steps, current))]
36#[allow(clippy::too_many_arguments)]
37fn py_wilson_hr_simulate<'py>(
38    py: Python<'py>,
39    v0: f64,
40    r0: f64,
41    tau_r: f64,
42    v_peak: f64,
43    dt: f64,
44    n_steps: usize,
45    current: f64,
46) -> (Bound<'py, PyArray1<f64>>, i64, f64, f64) {
47    let mut neuron = WilsonHRNeuron {
48        v: v0,
49        r: r0,
50        tau_r,
51        v_peak,
52        dt,
53    };
54    let (trace, spikes) = neuron.simulate(n_steps, current);
55    (trace.into_pyarray(py), spikes, neuron.v, neuron.r)
56}