Skip to content
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
8 changes: 5 additions & 3 deletions pyNN/standardmodels/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,12 @@ class StandardPostSynapticResponse(StandardModelType, models.BasePostSynapticRes
"""Base class for standardized post-synaptic receptor models."""

def get_schema(self):
# Derive the validation schema from default_parameters so that it always
# matches the actual parameters of each subclass. All post-synaptic
# response parameters are floats except "locations".
return {
"locations": SynapseDistribution,
"e_syn": float,
"tau_syn": float # should be a tuple, if multiple time constants
name: (SynapseDistribution if name == "locations" else float)
for name in self.default_parameters
}

def set_parent(self, parent):
Expand Down
42 changes: 42 additions & 0 deletions test/unittests/test_standardmodels.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
from pyNN.standardmodels import build_translations, StandardModelType, \
STDPWeightDependence, STDPTimingDependence
from pyNN.standardmodels.synapses import StaticSynapse, STDPMechanism
from pyNN.standardmodels.receptors import (
CurrExpPostSynapticResponse,
CondExpPostSynapticResponse,
CondAlphaPostSynapticResponse,
CondBetaPostSynapticResponse,
)
from pyNN import errors
from pyNN.parameters import ParameterSpace
from unittest.mock import Mock
Expand Down Expand Up @@ -216,3 +222,39 @@ def test_STDPMechanism_create_invalid_types():
# test STDPWeightDependence

# test STDPTimingDependence


# post-synaptic response models: the validation schema must track each model's
# default_parameters (see issue #837)

@pytest.mark.parametrize("cls", [
CurrExpPostSynapticResponse,
CondExpPostSynapticResponse,
CondAlphaPostSynapticResponse,
CondBetaPostSynapticResponse,
])
def test_psr_schema_matches_default_parameters(cls):
"""The schema used for validation must expose exactly the model's parameters."""
assert set(cls().get_schema()) == set(cls.default_parameters)


def test_CondBetaPostSynapticResponse_accepts_tau_rise_tau_decay():
"""Regression test for issue #837: beta receptor must accept its own parameters."""
psr = CondBetaPostSynapticResponse(e_syn=0.0, tau_rise=0.2, tau_decay=1.5)
assert set(psr.get_schema()) == {"locations", "e_syn", "tau_rise", "tau_decay"}


def test_CondBetaPostSynapticResponse_rejects_tau_syn():
"""The beta receptor has no tau_syn parameter, so it must be rejected."""
with pytest.raises(errors.NonExistentParameterError):
CondBetaPostSynapticResponse(tau_syn=5.0)


def test_CurrExpPostSynapticResponse_rejects_e_syn():
"""Current-based response has no reversal potential, so e_syn must be rejected."""
with pytest.raises(errors.NonExistentParameterError):
CurrExpPostSynapticResponse(e_syn=0.0)


def test_CurrExpPostSynapticResponse_accepts_tau_syn():
CurrExpPostSynapticResponse(tau_syn=5.0)