Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to get/set synaptic weights #359

Merged
merged 7 commits into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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