Skip to content

Commit

Permalink
Ability to get/set synaptic weights (#359)
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]>

* SCIF neuron model for QUBO, CSP, etc.

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

* Minor import fix

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

* Enabled Get/Set for synaptic weights

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

Signed-off-by: Risbud, Sumedh <[email protected]>
Co-authored-by: Marcus G K Williams <[email protected]>
  • Loading branch information
srrisbud and mgkwill authored Sep 22, 2022
1 parent 59f32ee commit 80c3f94
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
13 changes: 12 additions & 1 deletion src/lava/magma/compiler/var_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -117,6 +123,11 @@ class LoihiNeuronVarModel(LoihiVarModel):
pass


@dataclass
class LoihiSynapseVarModel(LoihiVarModel):
pass


@dataclass
class CVarModel(LoihiVarModel):
pass
Expand Down
8 changes: 5 additions & 3 deletions src/lava/magma/runtime/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion src/lava/proc/scif/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/lava/proc/scif/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@


class TestCspScifModels(unittest.TestCase):
"""Tests for sigma delta neuron"""
"""Tests for CspScif neuron"""

def run_test(
self,
Expand Down

0 comments on commit 80c3f94

Please sign in to comment.