Skip to content

Commit

Permalink
updated syntax of connection rule
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Close committed Sep 11, 2015
1 parent 84efa71 commit 9f19028
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 110 deletions.
2 changes: 1 addition & 1 deletion nineml/abstraction/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ class BaseALObject(BaseNineMLObject):
RandomDistributionXMLWriter)
from .connectionrule import (
ConnectionRule, ConnectionRuleXMLLoader, ConnectionRuleXMLWriter, Number,
Mask, Preference, RepeatWhile, Selected, NumberSelected, Select)
Mask, Preference, RepeatUntil, Selected, NumberSelected, Select)
4 changes: 2 additions & 2 deletions nineml/abstraction/connectionrule/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .base import ConnectionRule
from .visitors import ConnectionRuleXMLLoader, ConnectionRuleXMLWriter
from .select import (Number, Mask, Preference, RepeatWhile, Selected,
from .select import (Number, Mask, Preference, RepeatUntil, Selected,
NumberSelected, Select)
from .visitors.xml import ConnectionRuleXMLLoader, ConnectionRuleXMLWriter
6 changes: 6 additions & 0 deletions nineml/abstraction/connectionrule/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
:license: BSD-3, see LICENSE for details.
"""
from ..componentclass import ComponentClass
<<<<<<< HEAD
from nineml.abstraction_layer.ports import PropertyReceivePort
=======
from nineml.annotations import annotate_xml, read_annotations
from nineml.abstraction.ports import PropertyReceivePort
>>>>>>> 1260b1e... updated syntax of connection rule


class ConnectionRule(ComponentClass):
Expand Down Expand Up @@ -104,6 +109,7 @@ def from_xml(cls, element, document, **kwargs): # @UnusedVariable
return ConnectionRuleXMLLoader(document).load_connectionruleclass(
element)


from .visitors.cloner import ConnectionRuleCloner
from .visitors.modifiers import (
ConnectionRuleRenameSymbol, ConnectionRuleAssignIndices)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
"""

from nineml.utils import ensure_valid_identifier
from nineml.abstraction_layer.componentclass import BaseALObject
from nineml.abstraction.componentclass import BaseALObject
from ..expressions import Expression, RandomVariable
from .utils.cloner import ConnectionRuleCloner
from nineml.base import MemberContainerObject
from nineml.utils import normalise_parameter_as_list, assert_no_duplicates
from .utils.visitors import ConnectionRuleElementFinder


class Number(BaseALObject, Expression):
Expand Down Expand Up @@ -56,7 +54,7 @@ def __repr__(self):
return "Preference('%s')" % (self.rhs)


class RepeatWhile(BaseALObject, Expression):
class RepeatUntil(BaseALObject, Expression):

def accept_visitor(self, visitor, **kwargs):
""" |VISITATION| """
Expand All @@ -73,7 +71,7 @@ def stages(self):
return self._stages

def __repr__(self):
return "RepeatWhile('{}', stages {})".format(self.rhs, self.stages)
return "RepeatUntil('{}', stages {})".format(self.rhs, self.stages)


class Selected(BaseALObject):
Expand Down Expand Up @@ -170,24 +168,24 @@ def __repr__(self):
class Select(BaseALObject, MemberContainerObject):

defining_attributes = ('_mask', '_number', '_preference',
'_was_selecteds', '_number_selecteds',
'_selecteds', '_number_selecteds',
'_random_variables', '_select',
'_repeat_while')
class_to_member_dict = {Selected: '_was_selecteds',
'_repeat_until')
class_to_member_dict = {Selected: '_selecteds',
NumberSelected: '_number_selecteds',
RandomVariable: '_random_variables',
RepeatWhile: '_repeat_whiles'}
RepeatUntil: '_repeat_untils'}

def __init__(self, mask=None, number=None, preference=None,
was_selecteds=None, number_selecteds=None,
random_variables=None, select=None, repeat_whiles=None):
selecteds=None, number_selecteds=None,
random_variables=None, select=None, repeat_untils=None):
"""Abstract class representing a transition from one |Regime| to
another.
|Transition| objects are not created directly, but via the subclasses
|OnEvent| and |OnCondition|.
:param was_selecteds: A list of the state-assignments performed
:param selecteds: A list of the state-assignments performed
when this transition occurs. Objects in this list are either
`string` (e.g A = A+13) or |Selected| objects.
:param number_selecteds: A list of |NumberSelected| objects emitted
Expand Down Expand Up @@ -215,20 +213,20 @@ def __init__(self, mask=None, number=None, preference=None,
self._select = select

# Load state-assignment objects as strings or Selected objects
was_selecteds = normalise_parameter_as_list(was_selecteds)
selecteds = normalise_parameter_as_list(selecteds)
number_selecteds = normalise_parameter_as_list(number_selecteds)
random_variables = normalise_parameter_as_list(random_variables)
repeat_whiles = normalise_parameter_as_list(repeat_whiles)
repeat_untils = normalise_parameter_as_list(repeat_untils)

assert_no_duplicates(s.name for s in was_selecteds)
assert_no_duplicates(s.name for s in selecteds)
assert_no_duplicates(ns.name for ns in number_selecteds)
assert_no_duplicates(rv.name for rv in random_variables)
assert_no_duplicates(rw.level for rw in repeat_whiles)
assert_no_duplicates(rw.level for rw in repeat_untils)

self._was_selecteds = dict((s.name, s) for s in was_selecteds)
self._selecteds = dict((s.name, s) for s in selecteds)
self._number_selecteds = dict((ns.name, ns) for ns in number_selecteds)
self._random_variables = dict((rv.name, rv) for rv in random_variables)
self._repeat_whiles = dict((rw.stages, rw) for rw in repeat_whiles)
self._repeat_untils = dict((rw.stages, rw) for rw in repeat_untils)

def __copy__(self):
return ConnectionRuleCloner(self)
Expand All @@ -253,15 +251,15 @@ def select(self):
return self._select

@property
def was_selecteds(self):
return self._was_selecteds.itervalues()
def selecteds(self):
return self._selecteds.itervalues()

def was_selected(self, name):
return self._was_selecteds[name]
def selected(self, name):
return self._selecteds[name]

@property
def was_selected_names(self):
return self._was_selecteds.iterkeys()
def selected_names(self):
return self._selecteds.iterkeys()

@property
def number_selecteds(self):
Expand All @@ -287,13 +285,16 @@ def random_variable(self, name):
return self._random_variables[name]

@property
def repeat_whiles(self):
return self._repeat_whiles.itervalues()
def repeat_untils(self):
return self._repeat_untils.itervalues()

@property
def repeat_while_stages(self):
return self._repeat_whiles.iterkeys()
def repeat_until_stages(self):
return self._repeat_untils.iterkeys()

@property
def repeat_while(self, name):
return self._repeat_whiles[name]
def repeat_until(self, name):
return self._repeat_untils[name]

from .visitors.cloner import ConnectionRuleCloner
from .visitors.queriers import ConnectionRuleElementFinder
1 change: 0 additions & 1 deletion nineml/abstraction/connectionrule/visitors/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
from .queriers import ConnectionRuleInterfaceInferer
from .xml import ConnectionRuleXMLLoader, ConnectionRuleXMLWriter
16 changes: 6 additions & 10 deletions nineml/abstraction/connectionrule/visitors/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def load_connectionruleclass(self, element, **kwargs): # @UnusedVariable
def load_select(self, element):
block_names = ('Mask', 'Number', 'Preference', 'Selected',
'NumberSelected', 'RandomVariables', 'Select', 'RepeatUntil')
blocks = self.load_blocks(element,block_names=block_names)
blocks = self.load_blocks(element, block_names=block_names)
return Select(
mask=blocks["Mask"],
number=blocks["Number"],#Does the appropriate object get expanded here
Expand All @@ -53,10 +53,7 @@ def load_select(self, element):
tag_to_loader = dict(
tuple(ComponentClassXMLLoader.tag_to_loader.iteritems()) +
(("ConnectionRule", load_connectionruleclass),
("Select", load_select),
("Alias", load_alias),
("Constant", load_constant)
))
("Select", load_select)))


class ConnectionRuleXMLWriter(ComponentClassXMLWriter):
Expand All @@ -66,12 +63,11 @@ def visit_componentclass(self, component_class, **kwargs): # @UnusedVariable @I
return E('ConnectionRule',
*self._sort(e.accept_visitor(self) for e in component_class),
name=component_class.name)

@annotate_xml
def visit_select(self, parameter):
return E(Select.element_name,
name=parameter.name,
dimension=parameter.dimension.name)
def visit_select(self, select):
return E.Select(name=select.name)


from ..base import ConnectionRule
from ..select import Select
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import unittest
import nineml.abstraction_layer as al
import nineml.abstraction as al
from IPython.utils._tokenize_py2 import Number
from nineml.abstraction_layer.connectionrule.select import Preference
from docutils.parsers.rst.directives.misc import Replace
from nineml.abstraction.connectionrule.select import Preference
# from docutils.parsers.rst.directives.misc import Replace

#al.ConnectionRuleXMLLoader

Expand All @@ -21,66 +21,67 @@ class TestConnectionRule(unittest.TestCase):
# <Parameter name="mu2" dimension="dimensionless" container="source"/>
# <Parameter name="sigma2" dimension="dimensionless" container="source"/>

def get_component():

parameters = ['k', 'mu1', 'sigma1', 'mu2', 'sigma2']
crc = al.ConnectionRuleClass("",
ConnectCondition=["abs(i-j)<= k"] #A list of strings.
SelectConnections=[]

#Number
#Preference
#Replace

al.Regime(
name="subthresholdregime",
time_derivatives=[
"-g_L*(V-E_L)/C_m + g_L*Delta*exp((V-V_T)/Delta-w/S)/C_m+ Isyn/C_m",
"dw/dt = (a*(V-E_L)-w)/tau_w", ],
transitions=al.On("V > V_T",
do=["V = E_L",
"w = w + b",
al.OutputEvent('spikeoutput')],
to="refractoryregime"),
),

al.Regime(
name="refractoryregime",
transitions=al.On("t>=tspike+trefractory",
to="subthresholdregime"),
)
],
analog_ports=[al.AnalogReducePort("Isyn", operator="+")]
)

return crc



def test_xml_round_trip(self):
#write Python objects here.
#For connection Rules.
get_component()

al.ConnectionRuleXMLWriter

ConnectionRule(
name=element.get('MF2GC'),
propertyrecieveport=blocks[""],
parameters=blocks["Parameter"],
constant=blocks["Constant"],
alias=blocks["Alias"],
select=blocks["Select"]
)

Select(
mask=blocks["mask"],
number=blocks["number"],#Does the appropriate object get expanded here
preference=blocks["preference"],
was_selecteds=blocks["was_selected"],
number_selected=blocks["number_selected"],
random_variables=blocks["random_variables"],
select=blocks["select"],
repeat_whiles=blocks["repeat_while"])
)

# def get_component():
#
# parameters = ['k', 'mu1', 'sigma1', 'mu2', 'sigma2']
# crc = al.ConnectionRuleClass("",
# ConnectCondition=["abs(i-j)<= k"] #A list of strings.
# SelectConnections=[]
#
# #Number
# #Preference
# #Replace
#
# al.Regime(
# name="subthresholdregime",
# time_derivatives=[
# "-g_L*(V-E_L)/C_m + g_L*Delta*exp((V-V_T)/Delta-w/S)/C_m+ Isyn/C_m",
# "dw/dt = (a*(V-E_L)-w)/tau_w", ],
# transitions=al.On("V > V_T",
# do=["V = E_L",
# "w = w + b",
# al.OutputEvent('spikeoutput')],
# to="refractoryregime"),
# ),
#
# al.Regime(
# name="refractoryregime",
# transitions=al.On("t>=tspike+trefractory",
# to="subthresholdregime"),
# )
# ],
# analog_ports=[al.AnalogReducePort("Isyn", operator="+")]
# )
#
# return crc
#
#
#
# def test_xml_round_trip(self):
# #write Python objects here.
# #For connection Rules.
# get_component()
#
# al.ConnectionRuleXMLWriter
#
# ConnectionRule(
# name=element.get('MF2GC'),
# propertyrecieveport=blocks[""],
# parameters=blocks["Parameter"],
# constant=blocks["Constant"],
# alias=blocks["Alias"],
# select=blocks["Select"]
# )
#
# Select(
# mask=blocks["mask"],
# number=blocks["number"],#Does the appropriate object get expanded here
# preference=blocks["preference"],
# was_selecteds=blocks["was_selected"],
# number_selected=blocks["number_selected"],
# random_variables=blocks["random_variables"],
# select=blocks["select"],
# repeat_whiles=blocks["repeat_while"])
# )
#
pass

0 comments on commit 9f19028

Please sign in to comment.