Skip to main content

sc_neurocore_engine/bindings/trivial/
theta.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 — Theta 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!("ThetaNeuron", PyThetaNeuron, neurons::ThetaNeuron, state theta);
17
18type ThetaCompletePacket<'py> = (Bound<'py, PyArray1<f64>>, Bound<'py, PyArray1<u8>>, f64);
19
20#[pyfunction]
21#[pyo3(signature = (theta, dt, n_steps, current))]
22fn theta_simulate_complete<'py>(
23    py: Python<'py>,
24    theta: f64,
25    dt: f64,
26    n_steps: usize,
27    current: f64,
28) -> PyResult<ThetaCompletePacket<'py>> {
29    let model = neurons::ThetaNeuron { theta, dt };
30    let (phase, events, final_theta) = model
31        .simulate_complete(n_steps, current)
32        .map_err(|error| PyFloatingPointError::new_err(error.to_string()))?;
33    Ok((phase.into_pyarray(py), events.into_pyarray(py), final_theta))
34}
35
36/// Register the theta neuron class.
37pub(super) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> {
38    module.add_class::<PyThetaNeuron>()?;
39    module.add_function(wrap_pyfunction!(theta_simulate_complete, module)?)?;
40    Ok(())
41}