From 80c3f9459c047c80e470655bee15dc9d93e6ccf1 Mon Sep 17 00:00:00 2001 From: "Risbud, Sumedh" Date: Thu, 22 Sep 2022 16:24:16 -0700 Subject: [PATCH] Ability to get/set synaptic weights (#359) * SCIF neuron model for QUBO, CSP, etc. Signed-off-by: Risbud, Sumedh * SCIF neuron model for QUBO, CSP, etc. Signed-off-by: Risbud, Sumedh * Minor import fix Signed-off-by: Risbud, Sumedh * Enabled Get/Set for synaptic weights Signed-off-by: Risbud, Sumedh Signed-off-by: Risbud, Sumedh Co-authored-by: Marcus G K Williams <168222+mgkwill@users.noreply.github.com> --- src/lava/magma/compiler/var_model.py | 13 ++++++++++++- src/lava/magma/runtime/runtime.py | 8 +++++--- src/lava/proc/scif/process.py | 1 - tests/lava/proc/scif/test_models.py | 2 +- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/lava/magma/compiler/var_model.py b/src/lava/magma/compiler/var_model.py index d43e1fe5b..1b48397e3 100644 --- a/src/lava/magma/compiler/var_model.py +++ b/src/lava/magma/compiler/var_model.py @@ -39,10 +39,16 @@ class LoihiAddress: @dataclass class LoihiNeuronAddress(LoihiAddress): - # Which Neuron Group on the core neuron belongs to + # To which Neuron Group on the core a neuron belongs neuron_group_id: int +@dataclass +class LoihiSynapseAddress(LoihiAddress): + # To which SynEntry on the core a synapse belongs + syn_entry_id: int + + @dataclass class AbstractVarModel(ABC): var: InitVar[Var] = None @@ -117,6 +123,11 @@ class LoihiNeuronVarModel(LoihiVarModel): pass +@dataclass +class LoihiSynapseVarModel(LoihiVarModel): + pass + + @dataclass class CVarModel(LoihiVarModel): pass diff --git a/src/lava/magma/runtime/runtime.py b/src/lava/magma/runtime/runtime.py index cd4712c7d..56abaea20 100644 --- a/src/lava/magma/runtime/runtime.py +++ b/src/lava/magma/runtime/runtime.py @@ -11,7 +11,7 @@ import numpy as np from lava.magma.compiler.channels.pypychannel import CspRecvPort, CspSendPort -from lava.magma.compiler.var_model import AbstractVarModel +from lava.magma.compiler.var_model import AbstractVarModel, LoihiSynapseVarModel from lava.magma.core.process.message_interface_enum import ActorType from lava.magma.runtime.message_infrastructure.factory import \ MessageInfrastructureFactory @@ -425,7 +425,8 @@ def set_var(self, var_id: int, value: np.ndarray, idx: np.ndarray = None): buffer = buffer[idx] buffer_shape: ty.Tuple[int, ...] = buffer.shape num_items: int = np.prod(buffer_shape).item() - buffer = buffer.reshape((1, num_items)) + reshape_order = 'F' if isinstance(ev, LoihiSynapseVarModel) else 'C' + buffer = buffer.reshape((1, num_items), order=reshape_order) # 3. Send [NUM_ITEMS, DATA1, DATA2, ...] data_port: CspSendPort = self.runtime_to_service[runtime_srv_id] @@ -476,7 +477,8 @@ def get_var(self, var_id: int, idx: np.ndarray = None) -> np.ndarray: buffer[0, i] = data_port.recv()[0] # 3. Reshape result and return - buffer = buffer.reshape(ev.shape) + reshape_order = 'F' if isinstance(ev, LoihiSynapseVarModel) else 'C' + buffer = buffer.reshape(ev.shape, order=reshape_order) if idx: return buffer[idx] else: diff --git a/src/lava/proc/scif/process.py b/src/lava/proc/scif/process.py index d4a4ae29c..fccb101b0 100644 --- a/src/lava/proc/scif/process.py +++ b/src/lava/proc/scif/process.py @@ -4,7 +4,6 @@ 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 8f64673f6..889a99fc4 100644 --- a/tests/lava/proc/scif/test_models.py +++ b/tests/lava/proc/scif/test_models.py @@ -29,7 +29,7 @@ class TestCspScifModels(unittest.TestCase): - """Tests for sigma delta neuron""" + """Tests for CspScif neuron""" def run_test( self,