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

Change in GetStructrualPlasticityStatus format #775

Merged
merged 7 commits into from Jul 11, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions nestkernel/sp_manager.cpp
Expand Up @@ -85,8 +85,6 @@ SPManager::get_status( DictionaryDatum& d )
{
DictionaryDatum sp_synapses = DictionaryDatum( new Dictionary() );
DictionaryDatum sp_synapse;


def< DictionaryDatum >(
d, names::structural_plasticity_synapses, sp_synapses );
for ( std::vector< SPBuilder* >::const_iterator i = sp_conn_builders_.begin();
Expand Down
19 changes: 16 additions & 3 deletions pynest/nest/lib/hl_api_simulation.py
Expand Up @@ -234,14 +234,27 @@ def SetStructuralPlasticityStatus(params):


@check_stack
def GetStructuralPlasticityStatus(params):
def GetStructuralPlasticityStatus(keys=None):
"""Get the current structural plasticity parameters for the network
simulation.

Parameters
---------
keys : str or list, optional
Keys indicating the values of interest to be retrieved by the get call
"""

sps(params)
sps({})
sr('GetStructuralPlasticityStatus')
return spp()
d = spp()
if keys is None:
return d
elif is_literal(keys):
return d[keys]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, keys can only be a single key, so why the plural? And wouldn't it make more sense to allow a list of keys, as in GetStatus?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left it plural but allow now a list like in GetStatus :)

elif is_iterable(keys):
return tuple(d[k] for k in keys)
else:
raise TypeError("keys must be either empty, a string or a list")


@check_stack
Expand Down
3 changes: 3 additions & 0 deletions pynest/nest/tests/test_sp/test_all.py
Expand Up @@ -29,6 +29,8 @@
from . import test_disconnect
from . import test_disconnect_multiple
from . import test_enable_multithread
from . import test_get_sp_status

HAVE_MPI = nest.sli_func("statusdict/have_mpi ::")
if HAVE_MPI:
print ("Testing with MPI")
Expand Down Expand Up @@ -63,6 +65,7 @@ def suite():
test_suite.addTest(test_disconnect.suite())
test_suite.addTest(test_disconnect_multiple.suite())
test_suite.addTest(test_enable_multithread.suite())
test_suite.addTest(test_get_sp_status.suite())

return test_suite

Expand Down
103 changes: 103 additions & 0 deletions pynest/nest/tests/test_sp/test_get_sp_status.py
@@ -0,0 +1,103 @@
# -*- coding: utf-8 -*-
#
# test_get_sp_status.py
#
# This file is part of NEST.
#
# Copyright (C) 2004 The NEST Initiative
#
# NEST is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# NEST is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with NEST. If not, see <http://www.gnu.org/licenses/>.

"""
Structural Plasticity GetStatus Test
-----------------------
This tests the functionality of the GetStructuralPlasticityStatus
function
"""

import nest
import unittest

__author__ = 'sdiaz'


class TestGetStructuralPlasticityStatus(unittest.TestCase):
neuron_model = 'iaf_psc_alpha'
nest.CopyModel('static_synapse', 'synapse_ex')
nest.SetDefaults('synapse_ex', {'weight': 1.0, 'delay': 1.0})
nest.SetStructuralPlasticityStatus({
'structural_plasticity_synapses': {
'synapse_ex': {
'model': 'synapse_ex',
'post_synaptic_element': 'Den_ex',
'pre_synaptic_element': 'Axon_ex',
},
}
})

growth_curve = {
'growth_curve': "gaussian",
'growth_rate': 0.0001, # (elements/ms)
'continuous': False,
'eta': 0.0, # Ca2+
'eps': 0.05
}

'''
Now we assign the growth curves to the corresponding synaptic
elements
'''
synaptic_elements = {
'Den_ex': growth_curve,
'Den_in': growth_curve,
'Axon_ex': growth_curve,
}
nodes = nest.Create(neuron_model,
2,
{'synaptic_elements': synaptic_elements}
)
all = nest.GetStructuralPlasticityStatus()
print (all)
assert ('structural_plasticity_synapses' in all)
assert ('syn1' in all['structural_plasticity_synapses'])
assert ('structural_plasticity_update_interval' in all)
assert (all['structural_plasticity_update_interval'] == 1000)

sp_synapses = nest.GetStructuralPlasticityStatus(
'structural_plasticity_synapses'
)
print (sp_synapses)
syn = sp_synapses['syn1']
assert ('pre_synaptic_element' in syn)
assert ('post_synaptic_element' in syn)
assert (syn['pre_synaptic_element'] == 'Axon_ex')
assert (syn['post_synaptic_element'] == 'Den_ex')

sp_interval = nest.GetStructuralPlasticityStatus(
'structural_plasticity_update_interval'
)
print (sp_interval)
assert (sp_interval == 1000)


def suite():
test_suite = unittest.makeSuite(
TestGetStructuralPlasticityStatus,
'test'
)
return test_suite


if __name__ == '__main__':
unittest.main()