Skip to main content

sc_neurocore_engine/bindings/
rulkov_map.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 — Rulkov map PyO3 binding
8
9//! Python binding for the Rulkov spiking map.
10
11use numpy::{IntoPyArray, PyArray1};
12use pyo3::prelude::*;
13use pyo3::types::PyDict;
14
15use crate::neurons::RulkovMapNeuron;
16
17py_neuron_default!("RulkovMapNeuron", PyRulkovMapNeuron, RulkovMapNeuron, state x, state y);
18
19/// Register the Rulkov map class and simulator with the extension module.
20pub(super) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> {
21    module.add_class::<PyRulkovMapNeuron>()?;
22    module.add_function(wrap_pyfunction!(py_rulkov_map_simulate, module)?)?;
23    Ok(())
24}
25
26/// Parity contract with `sc_neurocore.neurons.models.rulkov_map.RulkovMapNeuron.simulate`:
27/// for the same parameters and constant input the returned `x` trace, upward-
28/// crossing spike count, and final `(x, y)` state are bit-identical to the
29/// Python reference (the map is exact floating-point arithmetic — one division,
30/// additions and multiplications, no transcendental functions).
31#[pyfunction]
32#[pyo3(signature = (x0, y0, alpha, sigma, mu, x_threshold, n_steps, current))]
33#[allow(clippy::too_many_arguments)]
34fn py_rulkov_map_simulate<'py>(
35    py: Python<'py>,
36    x0: f64,
37    y0: f64,
38    alpha: f64,
39    sigma: f64,
40    mu: f64,
41    x_threshold: f64,
42    n_steps: usize,
43    current: f64,
44) -> (Bound<'py, PyArray1<f64>>, i64, f64, f64) {
45    let mut neuron = RulkovMapNeuron {
46        x: x0,
47        y: y0,
48        alpha,
49        sigma,
50        mu,
51        x_threshold,
52    };
53    let (trace, spikes) = neuron.simulate(n_steps, current);
54    (trace.into_pyarray(py), spikes, neuron.x, neuron.y)
55}