gresil 0.1.0-alpha.9

Spiking neural networks in no_std Rust, i16 fixed point, for microcontrollers
Documentation
// Generated by `cargo run -p gresil --example trace --features unstable-stdp,unstable-freeze -- write` from
// tests/traces/cases.rs (`cases::freeze`); do not edit it by hand.
// tests/traces.rs regenerates it and compares line for line.
//
// Every plasticity-off case of tests/traces/ as the arrays a FixedNetwork
// steps: N neurons and S synapses, the time step, the run, whether the
// trace keeps spiking steps only, the trace's header line verbatim, the
// neurons as built, each one a constructor call and one setter per
// parameter (every parameter written, default or not), the synapses in
// the CSR order, and the drive as runs of equal steps, (count,
// currents). plasticity-on is not here: a FixedNetwork has no
// plasticity.
//
// Included by #[path] with #[rustfmt::skip] on the `mod frozen;` line, so
// rustfmt leaves it as written: by tests/traces.rs, and by firmware, since
// it needs only core and gresil. One allow, builtin: dead_code, since
// an includer reads only the constants it needs.
#![allow(dead_code)]

pub mod neuron_reference {
    use gresil::{FixedSynapse, LIFNeuron, NeuronType, VoltageResolution};

    pub const N: usize = 1;
    pub const S: usize = 0;
    pub const DT_US: u32 = 1000;
    pub const STEPS: u32 = 150;
    pub const SPIKES_ONLY: bool = false;
    pub const HEADER: &str = "# neuralos-trace v1 case=neuron-reference kind=reference n=1 dt_us=1000 res=cmV plasticity=off divisor=10 steps=150 rows=all";
    pub const NEURONS: [LIFNeuron; N] = [
        LIFNeuron::new(0, NeuronType::Excitatory, VoltageResolution::CentiMillivolt).with_resting_potential(-7000).with_threshold(32767).with_reset_potential(-8000).with_tau_membrane_us(20000).with_refractory_period_us(2000).with_resistance_mohm(100).with_noise_amplitude_pa(0).with_adaptation_enabled(true),
    ];
    pub const SYNAPSES: [FixedSynapse; S] = [];
    pub const DRIVE: &[(u32, [i16; N])] = &[
        (40, [160]),
        (30, [32767]),
        (30, [-32768]),
        (50, [0]),
    ];
}

pub mod one_neuron_board {
    use gresil::{FixedSynapse, LIFNeuron, NeuronType, VoltageResolution};

    pub const N: usize = 1;
    pub const S: usize = 0;
    pub const DT_US: u32 = 1000;
    pub const STEPS: u32 = 10000;
    pub const SPIKES_ONLY: bool = true;
    pub const HEADER: &str = "# neuralos-trace v1 case=one-neuron-board kind=regression n=1 dt_us=1000 res=cmV plasticity=off divisor=10 steps=10000 rows=spikes";
    pub const NEURONS: [LIFNeuron; N] = [
        LIFNeuron::new(0, NeuronType::Excitatory, VoltageResolution::CentiMillivolt).with_resting_potential(-7000).with_threshold(-5500).with_reset_potential(-8000).with_tau_membrane_us(20000).with_refractory_period_us(2000).with_resistance_mohm(100).with_noise_amplitude_pa(0).with_adaptation_enabled(true),
    ];
    pub const SYNAPSES: [FixedSynapse; S] = [];
    pub const DRIVE: &[(u32, [i16; N])] = &[
        (10000, [160]),
    ];
}

pub mod chain_3 {
    use gresil::{FixedSynapse, LIFNeuron, NeuronType, VoltageResolution};

    pub const N: usize = 3;
    pub const S: usize = 2;
    pub const DT_US: u32 = 1000;
    pub const STEPS: u32 = 100;
    pub const SPIKES_ONLY: bool = false;
    pub const HEADER: &str = "# neuralos-trace v1 case=chain-3 kind=regression n=3 dt_us=1000 res=cmV plasticity=off divisor=1 steps=100 rows=all";
    pub const NEURONS: [LIFNeuron; N] = [
        LIFNeuron::new(0, NeuronType::Excitatory, VoltageResolution::CentiMillivolt).with_resting_potential(-7000).with_threshold(-5500).with_reset_potential(-8000).with_tau_membrane_us(20000).with_refractory_period_us(2000).with_resistance_mohm(100).with_noise_amplitude_pa(0).with_adaptation_enabled(true),
        LIFNeuron::new(1, NeuronType::Excitatory, VoltageResolution::CentiMillivolt).with_resting_potential(-7000).with_threshold(-5500).with_reset_potential(-8000).with_tau_membrane_us(20000).with_refractory_period_us(2000).with_resistance_mohm(100).with_noise_amplitude_pa(0).with_adaptation_enabled(true),
        LIFNeuron::new(2, NeuronType::Excitatory, VoltageResolution::CentiMillivolt).with_resting_potential(-7000).with_threshold(-5500).with_reset_potential(-8000).with_tau_membrane_us(20000).with_refractory_period_us(2000).with_resistance_mohm(100).with_noise_amplitude_pa(0).with_adaptation_enabled(true),
    ];
    pub const SYNAPSES: [FixedSynapse; S] = [
        FixedSynapse::new(0, 1, 5000),
        FixedSynapse::new(1, 2, 5000),
    ];
    pub const DRIVE: &[(u32, [i16; N])] = &[
        (100, [600, 0, 0]),
    ];
}

pub mod feedforward_8 {
    use gresil::{FixedSynapse, LIFNeuron, NeuronType, VoltageResolution};

    pub const N: usize = 8;
    pub const S: usize = 6;
    pub const DT_US: u32 = 1000;
    pub const STEPS: u32 = 150;
    pub const SPIKES_ONLY: bool = false;
    pub const HEADER: &str = "# neuralos-trace v1 case=feedforward-8 kind=regression n=8 dt_us=1000 res=cmV plasticity=off divisor=1 steps=150 rows=all";
    pub const NEURONS: [LIFNeuron; N] = [
        LIFNeuron::new(0, NeuronType::Excitatory, VoltageResolution::CentiMillivolt).with_resting_potential(-7000).with_threshold(-5500).with_reset_potential(-8000).with_tau_membrane_us(20000).with_refractory_period_us(2000).with_resistance_mohm(100).with_noise_amplitude_pa(5).with_adaptation_enabled(true),
        LIFNeuron::new(1, NeuronType::Excitatory, VoltageResolution::CentiMillivolt).with_resting_potential(-7000).with_threshold(-5500).with_reset_potential(-8000).with_tau_membrane_us(20000).with_refractory_period_us(2000).with_resistance_mohm(100).with_noise_amplitude_pa(5).with_adaptation_enabled(true),
        LIFNeuron::new(2, NeuronType::Excitatory, VoltageResolution::CentiMillivolt).with_resting_potential(-7000).with_threshold(-5500).with_reset_potential(-8000).with_tau_membrane_us(20000).with_refractory_period_us(2000).with_resistance_mohm(100).with_noise_amplitude_pa(5).with_adaptation_enabled(true),
        LIFNeuron::new(3, NeuronType::Excitatory, VoltageResolution::CentiMillivolt).with_resting_potential(-7000).with_threshold(-5500).with_reset_potential(-8000).with_tau_membrane_us(20000).with_refractory_period_us(2000).with_resistance_mohm(100).with_noise_amplitude_pa(5).with_adaptation_enabled(true),
        LIFNeuron::new(4, NeuronType::Excitatory, VoltageResolution::CentiMillivolt).with_resting_potential(-7000).with_threshold(-5500).with_reset_potential(-8000).with_tau_membrane_us(20000).with_refractory_period_us(2000).with_resistance_mohm(100).with_noise_amplitude_pa(5).with_adaptation_enabled(true),
        LIFNeuron::new(5, NeuronType::Excitatory, VoltageResolution::CentiMillivolt).with_resting_potential(-7000).with_threshold(-5500).with_reset_potential(-8000).with_tau_membrane_us(20000).with_refractory_period_us(2000).with_resistance_mohm(100).with_noise_amplitude_pa(5).with_adaptation_enabled(true),
        LIFNeuron::new(6, NeuronType::Inhibitory, VoltageResolution::CentiMillivolt).with_resting_potential(-7000).with_threshold(-5000).with_reset_potential(-8000).with_tau_membrane_us(10000).with_refractory_period_us(2000).with_resistance_mohm(100).with_noise_amplitude_pa(5).with_adaptation_enabled(true),
        LIFNeuron::new(7, NeuronType::Inhibitory, VoltageResolution::CentiMillivolt).with_resting_potential(-7000).with_threshold(-5000).with_reset_potential(-8000).with_tau_membrane_us(10000).with_refractory_period_us(2000).with_resistance_mohm(100).with_noise_amplitude_pa(5).with_adaptation_enabled(true),
    ];
    pub const SYNAPSES: [FixedSynapse; S] = [
        FixedSynapse::new(0, 3, 100),
        FixedSynapse::new(1, 4, 100),
        FixedSynapse::new(2, 5, 100),
        FixedSynapse::new(3, 6, 100),
        FixedSynapse::new(4, 7, 100),
        FixedSynapse::new(5, 6, 100),
    ];
    pub const DRIVE: &[(u32, [i16; N])] = &[
        (150, [600, 600, 600, 148, 148, 148, 199, 199]),
    ];
}

pub mod recurrent_transmission {
    use gresil::{FixedSynapse, LIFNeuron, NeuronType, VoltageResolution};

    pub const N: usize = 2;
    pub const S: usize = 1;
    pub const DT_US: u32 = 1000;
    pub const STEPS: u32 = 30;
    pub const SPIKES_ONLY: bool = false;
    pub const HEADER: &str = "# neuralos-trace v1 case=recurrent-transmission kind=regression n=2 dt_us=1000 res=mV plasticity=off divisor=10 steps=30 rows=all";
    pub const NEURONS: [LIFNeuron; N] = [
        LIFNeuron::new(0, NeuronType::Excitatory, VoltageResolution::Millivolt).with_resting_potential(-70).with_threshold(-55).with_reset_potential(-80).with_tau_membrane_us(20000).with_refractory_period_us(2000).with_resistance_mohm(100).with_noise_amplitude_pa(0).with_adaptation_enabled(true),
        LIFNeuron::new(1, NeuronType::Inhibitory, VoltageResolution::Millivolt).with_resting_potential(-70).with_threshold(-50).with_reset_potential(-80).with_tau_membrane_us(10000).with_refractory_period_us(2000).with_resistance_mohm(100).with_noise_amplitude_pa(0).with_adaptation_enabled(true),
    ];
    pub const SYNAPSES: [FixedSynapse; S] = [
        FixedSynapse::new(0, 1, 200),
    ];
    pub const DRIVE: &[(u32, [i16; N])] = &[
        (1, [3000, 0]),
        (29, [0, 0]),
    ];
}

pub mod centi_mv_grid {
    use gresil::{FixedSynapse, LIFNeuron, NeuronType, VoltageResolution};

    pub const N: usize = 2;
    pub const S: usize = 1;
    pub const DT_US: u32 = 1000;
    pub const STEPS: u32 = 30;
    pub const SPIKES_ONLY: bool = false;
    pub const HEADER: &str = "# neuralos-trace v1 case=centi-mv-grid kind=regression n=2 dt_us=1000 res=cmV plasticity=off divisor=10 steps=30 rows=all";
    pub const NEURONS: [LIFNeuron; N] = [
        LIFNeuron::new(0, NeuronType::Excitatory, VoltageResolution::CentiMillivolt).with_resting_potential(-7000).with_threshold(-5500).with_reset_potential(-8000).with_tau_membrane_us(20000).with_refractory_period_us(2000).with_resistance_mohm(100).with_noise_amplitude_pa(0).with_adaptation_enabled(true),
        LIFNeuron::new(1, NeuronType::Inhibitory, VoltageResolution::CentiMillivolt).with_resting_potential(-7000).with_threshold(-5000).with_reset_potential(-8000).with_tau_membrane_us(10000).with_refractory_period_us(2000).with_resistance_mohm(100).with_noise_amplitude_pa(0).with_adaptation_enabled(true),
    ];
    pub const SYNAPSES: [FixedSynapse; S] = [
        FixedSynapse::new(0, 1, 12),
    ];
    pub const DRIVE: &[(u32, [i16; N])] = &[
        (1, [3000, 0]),
        (29, [0, 0]),
    ];
}

pub mod inhibitory {
    use gresil::{FixedSynapse, LIFNeuron, NeuronType, VoltageResolution};

    pub const N: usize = 2;
    pub const S: usize = 1;
    pub const DT_US: u32 = 1000;
    pub const STEPS: u32 = 100;
    pub const SPIKES_ONLY: bool = false;
    pub const HEADER: &str = "# neuralos-trace v1 case=inhibitory kind=regression n=2 dt_us=1000 res=cmV plasticity=off divisor=10 steps=100 rows=all";
    pub const NEURONS: [LIFNeuron; N] = [
        LIFNeuron::new(0, NeuronType::Inhibitory, VoltageResolution::CentiMillivolt).with_resting_potential(-7000).with_threshold(-5000).with_reset_potential(-8000).with_tau_membrane_us(10000).with_refractory_period_us(2000).with_resistance_mohm(100).with_noise_amplitude_pa(0).with_adaptation_enabled(true),
        LIFNeuron::new(1, NeuronType::Excitatory, VoltageResolution::CentiMillivolt).with_resting_potential(-7000).with_threshold(-5500).with_reset_potential(-8000).with_tau_membrane_us(20000).with_refractory_period_us(2000).with_resistance_mohm(100).with_noise_amplitude_pa(0).with_adaptation_enabled(true),
    ];
    pub const SYNAPSES: [FixedSynapse; S] = [
        FixedSynapse::new(0, 1, -1000),
    ];
    pub const DRIVE: &[(u32, [i16; N])] = &[
        (100, [250, 250]),
    ];
}

pub mod refractory {
    use gresil::{FixedSynapse, LIFNeuron, NeuronType, VoltageResolution};

    pub const N: usize = 1;
    pub const S: usize = 0;
    pub const DT_US: u32 = 1000;
    pub const STEPS: u32 = 40;
    pub const SPIKES_ONLY: bool = false;
    pub const HEADER: &str = "# neuralos-trace v1 case=refractory kind=regression n=1 dt_us=1000 res=cmV plasticity=off divisor=10 steps=40 rows=all";
    pub const NEURONS: [LIFNeuron; N] = [
        LIFNeuron::new(0, NeuronType::Excitatory, VoltageResolution::CentiMillivolt).with_resting_potential(-7000).with_threshold(-5500).with_reset_potential(-8000).with_tau_membrane_us(20000).with_refractory_period_us(2000).with_resistance_mohm(100).with_noise_amplitude_pa(0).with_adaptation_enabled(true),
    ];
    pub const SYNAPSES: [FixedSynapse; S] = [];
    pub const DRIVE: &[(u32, [i16; N])] = &[
        (40, [3000]),
    ];
}

pub mod plasticity_off {
    use gresil::{FixedSynapse, LIFNeuron, NeuronType, VoltageResolution};

    pub const N: usize = 2;
    pub const S: usize = 1;
    pub const DT_US: u32 = 1000;
    pub const STEPS: u32 = 150;
    pub const SPIKES_ONLY: bool = false;
    pub const HEADER: &str = "# neuralos-trace v1 case=plasticity-off kind=regression n=2 dt_us=1000 res=cmV plasticity=off divisor=1 steps=150 rows=all";
    pub const NEURONS: [LIFNeuron; N] = [
        LIFNeuron::new(0, NeuronType::Excitatory, VoltageResolution::CentiMillivolt).with_resting_potential(-7000).with_threshold(-5500).with_reset_potential(-8000).with_tau_membrane_us(20000).with_refractory_period_us(2000).with_resistance_mohm(100).with_noise_amplitude_pa(0).with_adaptation_enabled(true),
        LIFNeuron::new(1, NeuronType::Excitatory, VoltageResolution::CentiMillivolt).with_resting_potential(-7000).with_threshold(-5500).with_reset_potential(-8000).with_tau_membrane_us(20000).with_refractory_period_us(2000).with_resistance_mohm(100).with_noise_amplitude_pa(0).with_adaptation_enabled(true),
    ];
    pub const SYNAPSES: [FixedSynapse; S] = [
        FixedSynapse::new(0, 1, 1000),
    ];
    pub const DRIVE: &[(u32, [i16; N])] = &[
        (150, [600, 200]),
    ];
}

pub mod saturation_floor_ceiling {
    use gresil::{FixedSynapse, LIFNeuron, NeuronType, VoltageResolution};

    pub const N: usize = 1;
    pub const S: usize = 0;
    pub const DT_US: u32 = 1000;
    pub const STEPS: u32 = 100;
    pub const SPIKES_ONLY: bool = false;
    pub const HEADER: &str = "# neuralos-trace v1 case=saturation-floor-ceiling kind=regression n=1 dt_us=1000 res=mV plasticity=off divisor=10 steps=100 rows=all";
    pub const NEURONS: [LIFNeuron; N] = [
        LIFNeuron::new(0, NeuronType::Excitatory, VoltageResolution::Millivolt).with_resting_potential(-70).with_threshold(32767).with_reset_potential(-80).with_tau_membrane_us(20000).with_refractory_period_us(2000).with_resistance_mohm(100).with_noise_amplitude_pa(0).with_adaptation_enabled(true),
    ];
    pub const SYNAPSES: [FixedSynapse; S] = [];
    pub const DRIVE: &[(u32, [i16; N])] = &[
        (20, [32767]),
        (30, [0]),
        (20, [-32768]),
        (30, [0]),
    ];
}

pub mod nir_chain_fixture {
    use gresil::{FixedSynapse, LIFNeuron, NeuronType, VoltageResolution};

    pub const N: usize = 1;
    pub const S: usize = 0;
    pub const DT_US: u32 = 1000;
    pub const STEPS: u32 = 100;
    pub const SPIKES_ONLY: bool = false;
    pub const HEADER: &str = "# neuralos-trace v1 case=nir-chain-fixture kind=regression n=1 dt_us=1000 res=mV plasticity=off divisor=10 steps=100 rows=all";
    pub const NEURONS: [LIFNeuron; N] = [
        LIFNeuron::new(0, NeuronType::Excitatory, VoltageResolution::Millivolt).with_resting_potential(-70).with_threshold(-55).with_reset_potential(-80).with_tau_membrane_us(20000).with_refractory_period_us(1000).with_resistance_mohm(100).with_noise_amplitude_pa(0).with_adaptation_enabled(true),
    ];
    pub const SYNAPSES: [FixedSynapse; S] = [];
    pub const DRIVE: &[(u32, [i16; N])] = &[
        (100, [655]),
    ];
}

pub mod ternary_weights {
    use gresil::{FixedSynapse, LIFNeuron, NeuronType, VoltageResolution};

    pub const N: usize = 3;
    pub const S: usize = 3;
    pub const DT_US: u32 = 1000;
    pub const STEPS: u32 = 100;
    pub const SPIKES_ONLY: bool = false;
    pub const HEADER: &str = "# neuralos-trace v1 case=ternary-weights kind=regression n=3 dt_us=1000 res=mV plasticity=off divisor=1 steps=100 rows=all";
    pub const NEURONS: [LIFNeuron; N] = [
        LIFNeuron::new(0, NeuronType::Excitatory, VoltageResolution::Millivolt).with_resting_potential(-70).with_threshold(-55).with_reset_potential(-80).with_tau_membrane_us(20000).with_refractory_period_us(2000).with_resistance_mohm(100).with_noise_amplitude_pa(0).with_adaptation_enabled(true),
        LIFNeuron::new(1, NeuronType::Excitatory, VoltageResolution::Millivolt).with_resting_potential(-70).with_threshold(-55).with_reset_potential(-80).with_tau_membrane_us(20000).with_refractory_period_us(2000).with_resistance_mohm(100).with_noise_amplitude_pa(0).with_adaptation_enabled(true),
        LIFNeuron::new(2, NeuronType::Excitatory, VoltageResolution::Millivolt).with_resting_potential(-70).with_threshold(-55).with_reset_potential(-80).with_tau_membrane_us(20000).with_refractory_period_us(2000).with_resistance_mohm(100).with_noise_amplitude_pa(0).with_adaptation_enabled(true),
    ];
    pub const SYNAPSES: [FixedSynapse; S] = [
        FixedSynapse::new(0, 1, 1600),
        FixedSynapse::new(0, 2, 1600),
        FixedSynapse::new(1, 2, -1600),
    ];
    pub const DRIVE: &[(u32, [i16; N])] = &[
        (100, [600, 300, 300]),
    ];
}

pub mod snntorch_two_layer {
    use gresil::{FixedSynapse, LIFNeuron, NeuronType, VoltageResolution};

    pub const N: usize = 2;
    pub const S: usize = 1;
    pub const DT_US: u32 = 100;
    pub const STEPS: u32 = 150;
    pub const SPIKES_ONLY: bool = false;
    pub const HEADER: &str = "# neuralos-trace v1 case=snntorch-two-layer kind=regression n=2 dt_us=100 res=cmV plasticity=off divisor=10 steps=150 rows=all";
    pub const NEURONS: [LIFNeuron; N] = [
        LIFNeuron::new(0, NeuronType::Excitatory, VoltageResolution::CentiMillivolt).with_resting_potential(0).with_threshold(1001).with_reset_potential(0).with_tau_membrane_us(5000).with_refractory_period_us(0).with_resistance_mohm(500).with_noise_amplitude_pa(0).with_adaptation_enabled(false),
        LIFNeuron::new(1, NeuronType::Excitatory, VoltageResolution::CentiMillivolt).with_resting_potential(0).with_threshold(1001).with_reset_potential(0).with_tau_membrane_us(5000).with_refractory_period_us(0).with_resistance_mohm(500).with_noise_amplitude_pa(0).with_adaptation_enabled(false),
    ];
    pub const SYNAPSES: [FixedSynapse; S] = [
        FixedSynapse::new(0, 1, 1000),
    ];
    pub const DRIVE: &[(u32, [i16; N])] = &[
        (10, [1000, 0]),
        (40, [0, 0]),
        (10, [1000, 0]),
        (90, [0, 0]),
    ];
}

pub mod two_lif_neurons {
    use gresil::{FixedSynapse, LIFNeuron, NeuronType, VoltageResolution};

    pub const N: usize = 2;
    pub const S: usize = 1;
    pub const DT_US: u32 = 100;
    pub const STEPS: u32 = 150;
    pub const SPIKES_ONLY: bool = false;
    pub const HEADER: &str = "# neuralos-trace v1 case=two-lif-neurons kind=regression n=2 dt_us=100 res=cmV plasticity=off divisor=10 steps=150 rows=all";
    pub const NEURONS: [LIFNeuron; N] = [
        LIFNeuron::new(0, NeuronType::Excitatory, VoltageResolution::CentiMillivolt).with_resting_potential(1200).with_threshold(1001).with_reset_potential(0).with_tau_membrane_us(10000).with_refractory_period_us(0).with_resistance_mohm(10).with_noise_amplitude_pa(0).with_adaptation_enabled(false),
        LIFNeuron::new(1, NeuronType::Excitatory, VoltageResolution::CentiMillivolt).with_resting_potential(0).with_threshold(1001).with_reset_potential(0).with_tau_membrane_us(10000).with_refractory_period_us(0).with_resistance_mohm(1).with_noise_amplitude_pa(0).with_adaptation_enabled(false),
    ];
    pub const SYNAPSES: [FixedSynapse; S] = [
        FixedSynapse::new(0, 1, 1000),
    ];
    pub const DRIVE: &[(u32, [i16; N])] = &[
        (150, [1000, 0]),
    ];
}

/// Applies the caller's macro to every frozen case, in file order.
macro_rules! for_each_frozen {
    ($m:ident) => {
        $m!(neuron_reference);
        $m!(one_neuron_board);
        $m!(chain_3);
        $m!(feedforward_8);
        $m!(recurrent_transmission);
        $m!(centi_mv_grid);
        $m!(inhibitory);
        $m!(refractory);
        $m!(plasticity_off);
        $m!(saturation_floor_ceiling);
        $m!(nir_chain_fixture);
        $m!(ternary_weights);
        $m!(snntorch_two_layer);
        $m!(two_lif_neurons);
    };
}
pub(crate) use for_each_frozen;