From c91a734c7b37f0ecdd149ca1983ec3c07c0fdf4e Mon Sep 17 00:00:00 2001 From: "Risbud, Sumedh" Date: Fri, 23 Sep 2022 08:34:34 -0700 Subject: [PATCH] SCIF neuron model: Minor fixes (#367) * SCIF neuron model for QUBO, CSP, etc. Signed-off-by: Risbud, Sumedh * Minor import fix Signed-off-by: Risbud, Sumedh * SCIF: Enabled QUBO support Signed-off-by: Risbud, Sumedh * Minor fixes post review by @phstratmann Signed-off-by: Risbud, Sumedh --- src/lava/proc/scif/models.py | 9 ++++----- src/lava/proc/scif/process.py | 1 + tests/lava/proc/scif/test_models.py | 18 ------------------ 3 files changed, 5 insertions(+), 23 deletions(-) diff --git a/src/lava/proc/scif/models.py b/src/lava/proc/scif/models.py index 472912144..c467217c9 100644 --- a/src/lava/proc/scif/models.py +++ b/src/lava/proc/scif/models.py @@ -37,19 +37,18 @@ def __init__(self, proc_params): super(AbstractPyModelScifFixed, self).__init__(proc_params) self.a_in_data = np.zeros(proc_params['shape']) - def _prng(self, shape_like): + def _prng(self, intg_idx_): """Pseudo-random number generator """ # ToDo: Choosing a 16-bit signed random integer. For bit-accuracy, # need to replace it with Loihi-conformant LFSR function - prand = np.zeros_like(shape_like) + prand = np.zeros(shape=(len(intg_idx_),)) if prand.size > 0: rand_nums = \ np.random.randint(-2 ** 15, 2 ** 15 - 1, size=prand.size) # Assign random numbers only to neurons, for which noise is enabled - prand = rand_nums * self.noise_ampl - + prand = rand_nums * self.noise_ampl[intg_idx_] return prand def _update_buffers(self): @@ -71,7 +70,7 @@ def _integration_dynamics(self, intg_idx): spk_hist_to_intg = self.spk_hist[intg_idx] # beta to be integrated step_size_to_intg = self.step_size[intg_idx] # bias to be integrated - lfsr = self._prng(shape_like=state_to_intg) + lfsr = self._prng(intg_idx_=intg_idx) state_to_intg = state_to_intg + lfsr + cnstr_to_intg + step_size_to_intg np.clip(state_to_intg, a_min=0, a_max=2 ** 23 - 1, out=state_to_intg) diff --git a/src/lava/proc/scif/process.py b/src/lava/proc/scif/process.py index fccb101b0..d4a4ae29c 100644 --- a/src/lava/proc/scif/process.py +++ b/src/lava/proc/scif/process.py @@ -4,6 +4,7 @@ import typing as ty from numpy import typing as npty + import numpy as np from lava.magma.core.process.process import AbstractProcess diff --git a/tests/lava/proc/scif/test_models.py b/tests/lava/proc/scif/test_models.py index 889a99fc4..f986051f4 100644 --- a/tests/lava/proc/scif/test_models.py +++ b/tests/lava/proc/scif/test_models.py @@ -128,12 +128,6 @@ def test_scif_fixed_pt_no_noise(self) -> None: neg_tau_ref=neg_tau_ref, wt=wt, t_inj_spk={}) - # voltages = np.hstack((np.arange(num_steps).reshape(num_steps, 1), - # v_scif, - # v_lif_wta, - # v_lif_sig)) - # np.set_printoptions(linewidth=np.inf, threshold=np.inf) - # print(voltages) spk_idxs = np.array([theta // step_size - 1 + j * total_period for j in range(num_epochs)]).astype(int) wta_pos_spk_idxs = spk_idxs + 1 @@ -364,12 +358,6 @@ def test_scif_fixed_pt_no_noise(self) -> None: neg_tau_ref=neg_tau_ref, wt=wt, t_inj_spk={}) - # voltages = np.hstack((np.arange(num_steps).reshape(num_steps, 1), - # v_scif, - # v_lif_wta, - # v_lif_sig)) - # np.set_printoptions(linewidth=np.inf, threshold=np.inf) - # print(voltages) spk_idxs = np.array([theta // step_size - 1 + j * total_period for j in range(num_epochs)]).astype(int) wta_pos_spk_idxs = spk_idxs + 1 @@ -410,12 +398,6 @@ def test_scif_fp_no_noise_interrupt_rfct_mid(self) -> None: neg_tau_ref=neg_tau_ref, wt=wt, t_inj_spk=t_inj_spk) - # voltages = np.hstack((np.arange(num_steps).reshape(num_steps, 1), - # v_scif, - # v_lif_wta, - # v_lif_sig)) - # np.set_printoptions(linewidth=np.inf, threshold=np.inf) - # print(voltages) # Test pre-inhibitory-injection SCIF voltage and spiking spk_idxs_pre_inj = np.array([theta // step_size]).astype(int) - 1 wta_pos_spk_pre_inj = spk_idxs_pre_inj + 1