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

Max min to dev #84

Open
wants to merge 23 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a56eb93
minval maxval extension for TVB Rateml
DeLaVlag Jan 6, 2023
b35a54e
Merge pull request #71 from DeLaVlag/master
pgleeson Jan 17, 2023
9b15fae
Make minval/maxval optional
pgleeson Jan 17, 2023
f171ed4
Merge branch 'development' into experimental
pgleeson Jan 27, 2023
4a9b717
Fixes for arg order
pgleeson Jan 27, 2023
4d72ceb
Merge branch 'development' into experimental
pgleeson May 11, 2023
470bcfb
To v0.6.3; make sure case without condition serialises correctly
pgleeson May 11, 2023
49070b7
Remove print..
pgleeson May 11, 2023
6ddc733
Test on macos
pgleeson Jun 14, 2023
b2184ce
Fix script for masos
pgleeson Jun 16, 2023
2cc800e
Merge branch 'experimental' of github.com:LEMS/pylems into experimental
pgleeson Jun 16, 2023
3437c68
Merge branch 'chore/remove-setup.py' into experimental
pgleeson Jun 16, 2023
1529015
To v0.6.3
pgleeson Jun 16, 2023
9052a1e
Merge branch 'development' into experimental
pgleeson Jun 16, 2023
0eb3d1f
Merge pull request #74 from LEMS/development
pgleeson Sep 11, 2023
446b65e
Retesting max/min impl - still need to write max/min to XML
pgleeson Sep 19, 2023
e58aecf
Merge branch 'development' into experimental
pgleeson Feb 20, 2024
f19ab2d
Better closing of files
pgleeson Feb 20, 2024
533dbf3
Merge branch 'development' into experimental
pgleeson Aug 7, 2024
c6a67e1
Update pylems examples to formatted version from lems repo
pgleeson Aug 19, 2024
908403b
Merge branch 'development' into experimental
pgleeson Aug 19, 2024
50f2fc7
Merge branch 'development' into experimental
pgleeson Sep 24, 2024
8a7ae01
Merge pull request #90 from LEMS/development
pgleeson Dec 19, 2024
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
11 changes: 8 additions & 3 deletions ci/run-apitest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@
#
# Run api tests on GitHub actions

python examples/apitest.py
python examples/apitest2.py
python examples/loadtest.py
cd examples
python apitest.py
python apitest2.py
python apitest3.py
python loadtest.py
python apitest_maxmin.py
cd ..


# Update NeuroML2 path for CI
if [ "$CI" = "true" ]; then
Expand Down
35 changes: 35 additions & 0 deletions examples/apitest_maxmin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#! /usr/bin/python

import lems.api as lems

model = lems.Model()

#model.add(lems.Include("maxmin.xml"))

model.add(lems.Dimension("voltage", m=1, l=3, t=-3, i=-1))
model.add(lems.Dimension("time", t=1))
model.add(lems.Dimension("capacitance", m=-1, l=-2, t=4, i=2))

model.add(lems.Unit("milliVolt", "mV", "voltage", -3))
model.add(lems.Unit("milliSecond", "ms", "time", -3))
model.add(lems.Unit("microFarad", "uF", "capacitance", -12))

iaf1 = lems.ComponentType("iaf1")
model.add(iaf1)

iaf1.add(lems.Parameter("threshold", "voltage", minval=-44, maxval=55))
iaf1.add(lems.Parameter("reset", "voltage"))


fn = "maxmin.xml"
model.export_to_file(fn)

print("----------------------------------------------")
print(open(fn, "r").read())
print("----------------------------------------------")

print("Written generated LEMS to %s" % fn)

from lems.base.util import validate_lems

validate_lems(fn)
13 changes: 13 additions & 0 deletions examples/maxmin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" ?>
<Lems xmlns="http://www.neuroml.org/lems/0.7.6" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.neuroml.org/lems/0.7.6 https://raw.githubusercontent.com/LEMS/LEMS/development/Schemas/LEMS/LEMS_v0.7.6.xsd">
<Dimension name="voltage" m="1" l="3" t="-3" i="-1"/>
<Dimension name="time" t="1"/>
<Dimension name="capacitance" m="-1" l="-2" t="4" i="2"/>
<Unit symbol="mV" dimension="voltage" power="-3" scale="1.0"/>
<Unit symbol="ms" dimension="time" power="-3" scale="1.0"/>
<Unit symbol="uF" dimension="capacitance" power="-12" scale="1.0"/>
<ComponentType name="iaf1" description="">
<Parameter name="threshold" dimension="voltage"/>
<Parameter name="reset" dimension="voltage"/>
</ComponentType>
</Lems>
20 changes: 18 additions & 2 deletions lems/model/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Parameter(LEMSBase):
Stores a parameter declaration.
"""

def __init__(self, name, dimension, description=""):
def __init__(self, name, dimension, minval=None, maxval=None, description=""):
"""
Constructor.

Expand Down Expand Up @@ -63,6 +63,14 @@ def __init__(self, name, dimension, description=""):

:type: str """

self.minval = minval
""" Minimum value of this parameter.
:type: str """

self.maxval = maxval
""" Maximum value of this parameter.
:type: str """

def toxml(self):
"""
Exports this object into a LEMS XML object
Expand Down Expand Up @@ -332,7 +340,7 @@ class Exposure(LEMSBase):
Stores a exposure specification.
"""

def __init__(self, name, dimension, description=""):
def __init__(self, name, dimension, minval=None, maxval=None, description=""):
"""
Constructor.

Expand All @@ -344,6 +352,14 @@ def __init__(self, name, dimension, description=""):

:type: str """

self.minval = minval
""" Minimum value of this parameter.
:type: str """

self.maxval = maxval
""" Maximum value of this parameter.
:type: str """

self.dimension = dimension
""" Physical dimension of the exposure.

Expand Down
14 changes: 11 additions & 3 deletions lems/model/dynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class StateVariable(LEMSBase):
Store the specification of a state variable.
"""

def __init__(self, name, dimension, exposure=None):
def __init__(self, name, dimension, minval=None, maxval=None, exposure=None):
"""
Constructor.

Expand All @@ -28,6 +28,14 @@ def __init__(self, name, dimension, exposure=None):

:type: str """

self.minval = minval
""" Minimum value of this parameter.
:type: str """

self.maxval = maxval
""" Maximum value of this parameter.
:type: str """

self.dimension = dimension
""" Dimension of the state variable.

Expand Down Expand Up @@ -185,9 +193,9 @@ def toxml(self):
"""
Exports this object into a LEMS XML object
"""

cond = ' condition="{0}"'.format(self.condition) if self.condition is not None else ''
return (
'<Case condition="{0}" value="{1}"'.format(self.condition, self.value)
'<Case{0} value="{1}"'.format(cond, self.value)
+ "/>"
)

Expand Down
36 changes: 33 additions & 3 deletions lems/parser/LEMS.py
Original file line number Diff line number Diff line change
Expand Up @@ -998,14 +998,24 @@ def parse_exposure(self, node):
except:
self.raise_error("<Exposure> must specify a name")

if "minval" in node.lattrib:
minval = node.lattrib["minval"]
else:
minval = 0.0

if "maxval" in node.lattrib:
maxval = node.lattrib["maxval"]
else:
maxval = 0.0

try:
dimension = node.lattrib["dimension"]
except:
self.raise_error("Exposure '{0}' must specify a dimension", name)

description = node.lattrib.get("description", "")

self.current_component_type.add_exposure(Exposure(name, dimension, description))
self.current_component_type.add_exposure(Exposure(name, dimension, minval, maxval, description))

def parse_fixed(self, node):
"""
Expand Down Expand Up @@ -1298,13 +1308,23 @@ def parse_parameter(self, node):
except:
self.raise_error("<Parameter> must specify a name")

if "minval" in node.lattrib:
minval = node.lattrib["minval"]
else:
minval = 0.0

if "maxval" in node.lattrib:
maxval = node.lattrib["maxval"]
else:
maxval = 0.0

try:
dimension = node.lattrib["dimension"]
except:
self.raise_error("Parameter '{0}' has no dimension", name)

description = node.lattrib.get("description", "")
parameter = Parameter(name, dimension, description)
parameter = Parameter(name, dimension, minval, maxval, description)

self.current_component_type.add_parameter(parameter)

Expand Down Expand Up @@ -1650,6 +1670,16 @@ def parse_state_variable(self, node):
else:
self.raise_error("<StateVariable> must specify a name")

if "minval" in node.lattrib:
minval = node.lattrib["minval"]
else:
minval = 0.0

if "maxval" in node.lattrib:
maxval = node.lattrib["maxval"]
else:
maxval = 0.0

if "dimension" in node.lattrib:
dimension = node.lattrib["dimension"]
else:
Expand All @@ -1660,7 +1690,7 @@ def parse_state_variable(self, node):
else:
exposure = None

self.current_regime.add_state_variable(StateVariable(name, dimension, exposure))
self.current_regime.add_state_variable(StateVariable(name, dimension, minval, maxval, exposure))

def parse_structure(self, node):
"""
Expand Down
Loading