Skip to content

Commit

Permalink
UsesDefaults
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian-B committed Jan 9, 2025
1 parent 15d2a77 commit d467ef4
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 19 deletions.
Empty file modified pylint.bash
100644 → 100755
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
AbstractOneAppOneMachineVertex)
from spinn_front_end_common.abstract_models import (
AbstractVertexWithEdgeToDependentVertices)
from spynnaker.pyNN.models.defaults import defaults
from spynnaker.pyNN.models.defaults import defaults, UsesDefaults
from spynnaker.pyNN.models.common import PopulationApplicationVertex
from .machine_munich_motor_device import MachineMunichMotorDevice


class _MunichMotorDevice(ApplicationSpiNNakerLinkVertex):
class _MunichMotorDevice(ApplicationSpiNNakerLinkVertex, UsesDefaults):
__slots__ = ()

def __init__(self, spinnaker_link_id, board_address=None):
Expand Down
11 changes: 11 additions & 0 deletions spynnaker/pyNN/models/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,22 @@
import logging
from types import MappingProxyType
from typing import Any, Callable, FrozenSet, Iterable, List, Mapping, Optional
from spinn_utilities.abstract_base import abstractmethod
from spinn_utilities.log import FormatAdapter

logger = FormatAdapter(logging.getLogger(__name__))


class UsesDefaults(object):
"""" foo bar"""

@property
@abstractmethod
def default_parameters(self):
"""
Will be filled in with the parameters in the init bu @defaults
"""

def _check_args(
args_to_find: FrozenSet[str], default_args: List[str],
init_method: Callable):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
# limitations under the License.

from spynnaker.pyNN.exceptions import SpynnakerException
from spynnaker.pyNN.models.defaults import defaults, default_initial_values
from spynnaker.pyNN.models.defaults import (
defaults, default_initial_values, UsesDefaults)


# pylint: disable=wrong-spelling-in-docstring
@defaults
class EIFConductanceAlphaPopulation(object):
class EIFConductanceAlphaPopulation(UsesDefaults):
"""
Exponential integrate and fire neuron with spike triggered and
sub-threshold adaptation currents (isfa, ista reps.)
Expand Down
5 changes: 3 additions & 2 deletions spynnaker/pyNN/models/neuron/builds/hh_cond_exp.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
# limitations under the License.

from spynnaker.pyNN.exceptions import SpynnakerException
from spynnaker.pyNN.models.defaults import defaults, default_initial_values
from spynnaker.pyNN.models.defaults import (
defaults, default_initial_values, UsesDefaults)


@defaults
class HHCondExp(object):
class HHCondExp(UsesDefaults):
"""
Single-compartment Hodgkin-Huxley model with exponentially decaying
current input.
Expand Down
5 changes: 3 additions & 2 deletions spynnaker/pyNN/models/neuron/builds/if_cond_alpha.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
# limitations under the License.

from spynnaker.pyNN.exceptions import SpynnakerException
from spynnaker.pyNN.models.defaults import defaults, default_initial_values
from spynnaker.pyNN.models.defaults import (
defaults, default_initial_values, UsesDefaults)


@defaults
class IFCondAlpha(object):
class IFCondAlpha(UsesDefaults):
"""
Leaky integrate and fire neuron with an alpha-shaped current input.
Expand Down
5 changes: 3 additions & 2 deletions spynnaker/pyNN/models/neuron/builds/if_facets_hardware1.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
# limitations under the License.

from spynnaker.pyNN.exceptions import SpynnakerException
from spynnaker.pyNN.models.defaults import defaults, default_initial_values
from spynnaker.pyNN.models.defaults import (
defaults, default_initial_values, UsesDefaults)


@defaults
class IFFacetsConductancePopulation(object):
class IFFacetsConductancePopulation(UsesDefaults):
"""
Leaky integrate and fire neuron with conductance-based synapses and
fixed threshold as it is resembled by the FACETS Hardware Stage 1.
Expand Down
5 changes: 3 additions & 2 deletions unittests/model_tests/neuron/test_abstract_neuron_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
from spynnaker.pyNN.models.abstract_pynn_model import AbstractPyNNModel
from spynnaker.pyNN.models.neuron.abstract_pynn_neuron_model import (
AbstractPyNNNeuronModel)
from spynnaker.pyNN.models.defaults import default_initial_values, defaults
from spynnaker.pyNN.models.defaults import (
default_initial_values, defaults, UsesDefaults)
from spynnaker.pyNN.exceptions import SpynnakerException


@defaults
class _MyPyNNModelImpl(AbstractPyNNModel):
class _MyPyNNModelImpl(AbstractPyNNModel, UsesDefaults):

default_population_parameters = {}

Expand Down
14 changes: 7 additions & 7 deletions unittests/model_tests/neuron/test_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from spinn_utilities.abstract_base import AbstractBase, abstractmethod
from spynnaker.pyNN.config_setup import unittest_setup
from spynnaker.pyNN.models.defaults import (
defaults, default_parameters, default_initial_values)
defaults, default_parameters, default_initial_values, UsesDefaults)
from testfixtures import LogCapture # type: ignore[import]
import re
# pylint: disable=no-member
Expand All @@ -25,7 +25,7 @@ def test_nothing():
unittest_setup()

@defaults
class _AClass(object):
class _AClass(UsesDefaults):
def __init__(self, param_1=1, param_2=2, param_3=3):
pass
assert (_AClass.default_parameters == {
Expand All @@ -37,7 +37,7 @@ def test_parameters():
unittest_setup()

@defaults
class _AClass(object):
class _AClass(UsesDefaults):

@default_parameters({"param_1"})
def __init__(self, param_1=1, param_2=2, param_3=3):
Expand All @@ -50,7 +50,7 @@ def test_state_variables():
unittest_setup()

@defaults
class _AClass(object):
class _AClass(UsesDefaults):

@default_initial_values({"param_1"})
def __init__(self, param_1=1, param_2=2, param_3=3):
Expand All @@ -63,15 +63,15 @@ def test_both():
unittest_setup()

@defaults
class _AClass(object):
class _AClass(UsesDefaults):

@default_parameters({"param_1"})
@default_initial_values({"param_2"})
def __init__(self, param_1=1, param_2=2, param_3=3):
pass

@defaults
class _AnotherClass(object):
class _AnotherClass(UsesDefaults):

@default_initial_values({"param_1"})
@default_parameters({"param_2"})
Expand Down Expand Up @@ -101,7 +101,7 @@ def default_initial_values():
pass

@defaults
class _AClass(BaseClass):
class _AClass(BaseClass, UsesDefaults):

default_parameters = None
default_initial_values = None
Expand Down

0 comments on commit d467ef4

Please sign in to comment.