Skip to content

Commit

Permalink
use defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian-B committed Dec 18, 2024
1 parent 4aac533 commit 1fb96be
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,21 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Iterable, List
from typing import Iterable, List, Literal, Optional, Union
from typing_extensions import TypeAlias

from spinn_utilities.overrides import overrides

from pacman.model.routing_info import BaseKeyAndMask
from pacman.model.graphs.application import ApplicationSpiNNakerLinkVertex

from spinn_front_end_common.abstract_models import (
AbstractSendMeMulticastCommandsVertex)
from spinn_front_end_common.utility_models import MultiCastCommand

from spynnaker.pyNN.exceptions import SpynnakerException
from spynnaker.pyNN.models.common import PopulationApplicationVertex
from spynnaker.pyNN.models.defaults import defaults

# robot with 7 7 1

Expand Down Expand Up @@ -49,6 +55,7 @@ def get_spike_value_from_robot_retina(key: int) -> int:
return (key >> 14) & 0x1


@defaults
class MunichRetinaDevice(
ApplicationSpiNNakerLinkVertex, PopulationApplicationVertex,
AbstractSendMeMulticastCommandsVertex):
Expand All @@ -72,30 +79,28 @@ class MunichRetinaDevice(

UP_POLARITY = "UP"
DOWN_POLARITY = "DOWN"
MERGED_POLARITY = "MERGED"
MERGED_POLARITY: Literal["MERGED"] = "MERGED"
_T_POLARITY: TypeAlias = \
Union[Literal["UP"], Literal["DOWN"], Literal["MERGED"], None]

#: Select the left retina
LEFT_RETINA = "LEFT"
#: Select the right retina
RIGHT_RETINA = "RIGHT"
_RETINAS = frozenset((LEFT_RETINA, RIGHT_RETINA))

default_parameters = {
'label': "MunichRetinaDevice",
'polarity': None,
'board_address': None}
_T_RETINAS: TypeAlias = Union[Literal["LEFT"], Literal["RIGHT"]]

def __init__(
self, retina_key, spinnaker_link_id, position,
label=default_parameters['label'],
polarity=default_parameters['polarity'],
board_address=default_parameters['board_address']):
self, retina_key: int, spinnaker_link_id: int,
position: _T_RETINAS, label: str = "MunichRetinaDevice",
polarity: _T_POLARITY = None,
board_address: Optional[str] = None):
"""
:param int retina_key:
:param int spinnaker_link_id:
The SpiNNaker link to which the retina is connected
:param str position: ``LEFT`` or ``RIGHT``
:param str label:
:param label:
:param str polarity: ``UP``, ``DOWN`` or ``MERGED``
:param board_address:
:type board_address: str or None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Optional

from pacman.model.graphs.application import ApplicationSpiNNakerLinkVertex
from spynnaker.pyNN.external_devices_models.push_bot.ethernet import (
PushBotEthernetLaserDevice)
from spynnaker.pyNN.models.common import PopulationApplicationVertex
from spynnaker.pyNN.models.defaults import defaults


@defaults
class PushBotSpiNNakerLinkLaserDevice(
PushBotEthernetLaserDevice, ApplicationSpiNNakerLinkVertex,
PopulationApplicationVertex):
Expand All @@ -26,26 +30,22 @@ class PushBotSpiNNakerLinkLaserDevice(
"""
__slots__ = ()

default_parameters = {
'n_neurons': 1, 'label': None, 'board_address': None,
'start_active_time': 0, 'start_total_period': 0, 'start_frequency': 0}

def __init__(
self, laser, protocol, spinnaker_link_id,
n_neurons=default_parameters['n_neurons'],
label=default_parameters['label'],
board_address=default_parameters['board_address'],
start_active_time=default_parameters['start_active_time'],
start_total_period=default_parameters['start_total_period'],
start_frequency=default_parameters['start_frequency']):
n_neurons: int = 1,
label: Optional[str] = None,
board_address: Optional[str] = None,
start_active_time: int = 0,
start_total_period: int = 0,
start_frequency: int = 0):
"""
:param PushBotLaser laser: Which laser device to control
:param MunichIoSpiNNakerLinkProtocol protocol:
The protocol instance to get commands from
:param int spinnaker_link_id:
The SpiNNakerLink that the PushBot is connected to
:param int n_neurons: The number of neurons in the device
:param str label: A label for the device
:param label: A label for the device
:param board_address:
The IP address of the board that the device is connected to
:type board_address: str or None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ class PushBotSpiNNakerLinkMotorDevice(
"""
__slots__ = ()

default_parameters = {
'n_neurons': 1,
'label': None,
'board_address': None}

def __init__(
self, motor: PushBotMotor, protocol: MunichIoSpiNNakerLinkProtocol,
spinnaker_link_id: int, n_neurons: int = 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from spynnaker.pyNN.external_devices_models.push_bot import (
AbstractPushBotRetinaDevice)
from spynnaker.pyNN.models.common import PopulationApplicationVertex
from spynnaker.pyNN.models.defaults import defaults


class DelayedPayloadMultiCastCommand(MultiCastCommand):
Expand All @@ -45,6 +46,7 @@ def is_payload(self) -> bool:
return self.payload is not None


@defaults
class PushBotSpiNNakerLinkRetinaDevice(
AbstractPushBotRetinaDevice, ApplicationSpiNNakerLinkVertex,
PopulationApplicationVertex):
Expand All @@ -53,20 +55,17 @@ class PushBotSpiNNakerLinkRetinaDevice(
"""
__slots__ = ("__new_key_command", )

default_parameters = {'label': None, 'board_address': None,
'n_machine_vertices': 1}

def __init__(
self, spinnaker_link_id, protocol, resolution,
board_address=default_parameters['board_address'],
label=default_parameters['label'],
n_machine_vertices=default_parameters['n_machine_vertices']):
board_address: Optional[str] = None,
label: Optional[str] = None,
n_machine_vertices: int = 1):
"""
:param int spinnaker_link_id:
:param MunichIoSpiNNakerLinkProtocol protocol:
:param PushBotRetinaResolution resolution:
:param str board_address:
:param str label:
:param board_address:
:param label:
:param int n_machine_vertices:
"""
super().__init__(protocol, resolution)
Expand All @@ -77,7 +76,8 @@ def __init__(
n_machine_vertices=n_machine_vertices)

# stores for the injection aspects
self.__new_key_command = None
self.__new_key_command: Optional[DelayedPayloadMultiCastCommand] = \
None

def new_key_command_payload(self):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,20 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Optional

from pacman.model.graphs.application import ApplicationSpiNNakerLinkVertex

from spynnaker.pyNN.external_devices_models.push_bot.ethernet import (
PushBotEthernetSpeakerDevice)
from spynnaker.pyNN.external_devices_models.push_bot.parameters import (
PushBotSpeaker)
from spynnaker.pyNN.models.common import PopulationApplicationVertex
from spynnaker.pyNN.models.defaults import defaults
from spynnaker.pyNN.protocols import MunichIoSpiNNakerLinkProtocol


@defaults
class PushBotSpiNNakerLinkSpeakerDevice(
PushBotEthernetSpeakerDevice, ApplicationSpiNNakerLinkVertex,
PopulationApplicationVertex):
Expand All @@ -26,37 +34,30 @@ class PushBotSpiNNakerLinkSpeakerDevice(
"""
__slots__ = ()

default_parameters = {
'n_neurons': 1, 'label': None,
'board_address': None,
'start_active_time': 50,
'start_total_period': 100,
'start_frequency': None,
'start_melody': None}

def __init__(
self, speaker, protocol, spinnaker_link_id,
n_neurons=default_parameters['n_neurons'],
label=default_parameters['label'],
board_address=default_parameters['board_address'],
start_active_time=default_parameters['start_active_time'],
start_total_period=default_parameters['start_total_period'],
start_frequency=default_parameters['start_frequency'],
start_melody=default_parameters['start_melody']):
self, speaker: PushBotSpeaker,
protocol: MunichIoSpiNNakerLinkProtocol, spinnaker_link_id: int,
n_neurons: int = 1,
label: Optional[str] = None,
board_address: Optional[str] = None,
start_active_time: int = 50,
start_total_period: int = 100,
start_frequency: Optional[int] = None,
start_melody: Optional[int] = None):
"""
:param PushBotSpeaker speaker: Which speaker device to control
:param MunichIoSpiNNakerLinkProtocol protocol:
The protocol instance to get commands from
:param int spinnaker_link_id: The SpiNNakerLink connected to
:param int n_neurons: The number of neurons in the device
:param str label: The label of the device
:param label: The label of the device
:param board_address:
The IP address of the board that the device is connected to
:type board_address: str or None
:param int start_active_time: The "active time" to set at the start
:param int start_total_period: The "total period" to set at the start
:param int start_frequency: The "frequency" to set at the start
:param int start_melody: The "melody" to set at the start
:param start_frequency: The "frequency" to set at the start
:param start_melody: The "melody" to set at the start
"""
# pylint: disable=too-many-arguments
super().__init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
BYTES_PER_WORD, BYTES_PER_SHORT)

from spynnaker.pyNN.data import SpynnakerDataView
from spynnaker.pyNN.models.defaults import defaults
from spynnaker.pyNN.models.neuron.plasticity.stdp.synapse_structure import (
SynapseStructureWeightAccumulator)
from spynnaker.pyNN.models.neuron.plasticity.stdp.common import (
Expand All @@ -34,6 +35,7 @@
from .abstract_timing_dependence import AbstractTimingDependence


@defaults
class TimingDependenceRecurrent(AbstractTimingDependence):
"""
A timing dependence STDP rule based on recurrences.
Expand All @@ -51,18 +53,11 @@ class TimingDependenceRecurrent(AbstractTimingDependence):
'accumulator_depression', 'accumulator_potentiation',
'mean_pre_window', 'mean_post_window', 'dual_fsm')

default_parameters = {
'accumulator_depression': -6, 'accumulator_potentiation': 6,
'mean_pre_window': 35.0, 'mean_post_window': 35.0, 'dual_fsm': True}

def __init__(
self, accumulator_depression: int = cast(int, default_parameters[
'accumulator_depression']),
accumulator_potentiation: int = cast(int, default_parameters[
'accumulator_potentiation']),
mean_pre_window: float = default_parameters['mean_pre_window'],
mean_post_window: float = default_parameters['mean_post_window'],
dual_fsm: bool = cast(bool, default_parameters['dual_fsm']),
self, accumulator_depression: int = -6,
accumulator_potentiation: int = 6,
mean_pre_window: float = 35.0, mean_post_window: float = 35.0,
dual_fsm: bool = True,
A_plus: float = 0.01, A_minus: float = 0.01):
"""
:param int accumulator_depression:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from spinn_front_end_common.interface.ds import DataSpecificationBase

from spynnaker.pyNN.data import SpynnakerDataView
from spynnaker.pyNN.models.defaults import defaults
from spynnaker.pyNN.models.neuron.plasticity.stdp.common import (
get_exp_lut_array)
from spynnaker.pyNN.models.neuron.plasticity.stdp.synapse_structure import (
Expand All @@ -31,6 +32,7 @@
from .abstract_timing_dependence import AbstractTimingDependence


@defaults
class TimingDependenceSpikeNearestPair(AbstractTimingDependence):
"""
A timing dependence STDP rule based on nearest pairs.
Expand All @@ -43,10 +45,8 @@ class TimingDependenceSpikeNearestPair(AbstractTimingDependence):
"__a_plus",
"__a_minus")
__PARAM_NAMES = ('tau_plus', 'tau_minus')
default_parameters = {'tau_plus': 20.0, 'tau_minus': 20.0}

def __init__(self, tau_plus: float = default_parameters['tau_plus'],
tau_minus: float = default_parameters['tau_minus'],
def __init__(self, tau_plus: float = 20.0, tau_minus: float = 20.0,
A_plus: float = 0.01, A_minus: float = 0.01):
r"""
:param float tau_plus: :math:`\tau_+`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
BYTES_PER_WORD, BYTES_PER_SHORT)

from spynnaker.pyNN.data import SpynnakerDataView
from spynnaker.pyNN.models.defaults import defaults
from spynnaker.pyNN.models.neuron.plasticity.stdp.timing_dependence import (
AbstractTimingDependence)
from spynnaker.pyNN.models.neuron.plasticity.stdp.synapse_structure import (
Expand All @@ -33,6 +34,7 @@
float_to_fixed, get_exp_lut_array)


@defaults
class TimingDependenceVogels2011(AbstractTimingDependence):
"""
A timing dependence STDP rule due to Vogels (2011).
Expand All @@ -44,9 +46,8 @@ class TimingDependenceVogels2011(AbstractTimingDependence):
"__a_plus",
"__a_minus")
__PARAM_NAMES = ('alpha', 'tau')
default_parameters = {'tau': 20.0}

def __init__(self, alpha: float, tau: float = default_parameters['tau'],
def __init__(self, alpha: float, tau: float = 20.0,
A_plus: float = 0.01, A_minus: float = 0.01):
r"""
:param float alpha: :math:`\alpha`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@
DataType, DataSpecificationBase)
from spinn_front_end_common.utilities.constants import BYTES_PER_WORD

from spynnaker.pyNN.models.defaults import defaults

from .abstract_has_a_plus_a_minus import AbstractHasAPlusAMinus
from .abstract_weight_dependence import AbstractWeightDependence

# Six words per synapse type
_SPACE_PER_SYNAPSE_TYPE = 6 * BYTES_PER_WORD


@defaults
class WeightDependenceAdditiveTriplet(
AbstractHasAPlusAMinus, AbstractWeightDependence):
"""
Expand All @@ -41,15 +44,10 @@ class WeightDependenceAdditiveTriplet(
"__w_min")
__PARAM_NAMES = ('w_min', 'w_max', 'A3_plus', 'A3_minus')

default_parameters = {'w_min': 0.0, 'w_max': 1.0, 'A3_plus': 0.01,
'A3_minus': 0.01}

# noinspection PyPep8Naming
def __init__(
self, w_min: float = default_parameters['w_min'],
w_max: float = default_parameters['w_max'],
A3_plus: float = default_parameters['A3_plus'],
A3_minus: float = default_parameters['A3_minus']):
self, w_min: float = 0.0, w_max: float = 1.0,
A3_plus: float = 0.01, A3_minus: float = 0.01):
"""
:param float w_min: :math:`w^{min}`
:param float w_max: :math:`w^{max}`
Expand Down
Loading

0 comments on commit 1fb96be

Please sign in to comment.