Skip to content

Commit

Permalink
SCIF neuron model: Minor fixes (lava-nc#367)
Browse files Browse the repository at this point in the history
* SCIF neuron model for QUBO, CSP, etc.

Signed-off-by: Risbud, Sumedh <[email protected]>

* Minor import fix

Signed-off-by: Risbud, Sumedh <[email protected]>

* SCIF: Enabled QUBO support

Signed-off-by: Risbud, Sumedh <[email protected]>

* Minor fixes post review by @phstratmann

Signed-off-by: Risbud, Sumedh <[email protected]>
  • Loading branch information
srrisbud committed Sep 23, 2022
1 parent 46b455c commit 7120a21
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 23 deletions.
9 changes: 4 additions & 5 deletions src/lava/proc/scif/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/lava/proc/scif/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 0 additions & 18 deletions tests/lava/proc/scif/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7120a21

Please sign in to comment.