Coder Social home page Coder Social logo

tclose / nineml-python Goto Github PK

View Code? Open in Web Editor NEW

This project forked from incf/nineml-python

0.0 2.0 1.0 13.54 MB

A Python library for reading, parsing, validating and writing the 9ML (http://nineml.net) object model

License: Other

Python 100.00%

nineml-python's Introduction

NineML Python Library

Unit Test Status Unit Test Coverage Documentation Status

NineML (9ML) is a language for describing the dynamics and connectivity of neuronal network simulations (http://nineml.net). The language is defined as an object model, described in the NineML specification (http://nineml.net/specification).

The NineML Python Library (9ML-Python) is a software library written in Python, which maps the NineML object model onto Python classes for convenient creation, manipulation and validation of NineML models, as well as handling their serialization to and from XML, JSON, YAML, and HDF5.

Installation

HDF5

To add support to read/write HDF5 serializations you must first install the HDF5 library.

On macOS it can be installed using Homebrew

$ brew install hdf5

On Ubuntu/Debian it can be installed via the libhdf5-serial-dev (serial) libhdf5-openmpi-dev/ (parallel with Open MPI), or libhdf5-mpich-dev (parallel with MPICH) packages.

Pip

9ML-Python can be installed using pip from the cloned/downloaded repo directory

$ pip install -r requirements.txt .

which, will also install the prerequisites packages sympy, lxml, and h5py if they are not already installed.

If you have not installed the HDF5 library in the previous step (and you don't plan to use HDF5 serialization), you can avoid having to install h5py by installing sympy, pyyaml and lxml separately (pyaml_ and lxml are also optional if you don't require XML or YAML support).

NB: As of 12/10/2016 Sympy v1.0 has a bug in its ccode printer, which is used by 9ML-python to write expressions within MathInline elements. This bug has been fixed in the development branch so please either use sympy >= 1.0dev or the earlier version e.g. 0.7.6.1. If you need to use the latest version of Sympy for a different project see virtualenv.

Relation to the NineML Specification

The layout of the Python modules and classes in 9ML-Python relates closely to the structure of the `NineML specification v1.0`_. However, there are notable exceptions where 9ML-Python uses names and relationships that are planned to be changed in v2.0 of the specification (9ML-Python will be backwards compatible), such as the renaming of ComponentClass elements to separate Dynamics, ConnectionRule and RandomDistribution elements (see INCF/nineml-spec#94). A full list of changes planned for NineML v2.0 can be found at https://github.com/INCF/nineml/milestone/3. When serializing 9ML models the v1.0 syntax is used unless the version=2.0 keyword argument is used.

In addition to classes that directly correspond to the 9ML object model, a range of shorthand notations ("syntactic sugar") exist to make writing 9ML models by hand more convenient (see the nineml.sugar module). These notations are frequently demonstrated in the examples directory of the repository.

NineML Catalog

The NineML Catalog (http://github.com/INCF/NineMLCatalog) contains a collection of validated NineML models that can be loaded and maninpulated with nineml-python. If you create a model that you believe will be of wider use to the computational neuroscience community please consider contributing to the catalog via a pull request.

Links

copyright:Copyright 20011-2017 by the nineml-python team, see AUTHORS.
license:BSD 3, see LICENSE for details.

nineml-python's People

Contributors

tclose avatar apdavison avatar

Watchers

 avatar  avatar

Forkers

daisukemiyamoto

nineml-python's Issues

Add unit tests

Before opening pull request we need unittests for

  • All multi-dynamics accessors
  • Local event-port connections with delay
  • Reference connectivity generators (should be moved to
  • Assign roles method in port_connections

Python Component Class -> jinja2 template -> NMODL ( test_rt_kin branch) (from russel)

I am raising this issue while still fresh in memory:

The file test_rt_comparison.py can otherwise generate NMODL code in the test_rt_kin branch, when the appropriate lines are commented out, but they they should not ultimately be commented.

To recreate this bug there must be no jinja2 syntax errors, that is why we did not see it when I tried to demonstrate this bug previously (as there were jinja2 errors).

If you execute
/pype9/test/unittests$ python test_rt_comparison.py

But and by omitting the following comments, the syntax errors stated below will result.

line 198: of file: /pype9/cells/code_gen/base.py

Class BaseCodeGenerator(object):
verbose=verbose, **kwargs)
# Write the timestamp of the 9ML file used to generate the source
# files

  •        with open(nineml_mod_time_path, 'w') as f:
    
  •            f.write(nineml_mod_time)
    
  •        #with open(nineml_mod_time_path, 'w') as f:
    
  •        #    f.write(nineml_mod_time)
     if compile_source:
         # Clean existing compile & install directories from previous builds
         self.clean_compile_dir(compile_dir)
    

....................................

Output:

TypeError Traceback (most recent call last)
/usr/lib/python2.7/dist-packages/IPython/utils/py3compat.pyc in execfile(fname, *where)
202 else:
203 filename = fname
--> 204 builtin.execfile(filename, *where)

/home/russell/git/pype9/test/unittests/test_rt_comparison.py in ()
159
160 test = TestKinetics()
--> 161 test.test_kinetics_roundtrip()
162
163

/home/russell/git/pype9/test/unittests/test_rt_comparison.py in test_kinetics_roundtrip(self)
39 self.code_generator.generate(
40 component, name='Golgi_SK2_regenerated', build_dir=os.getcwd(),
---> 41 build_mode='force', verbose=True)
42
43

/usr/local/lib/python2.7/dist-packages/pype9/cells/code_gen/base.py in generate(self, component, name, saved_name, initial_state, install_dir, build_dir, build_mode, verbose, **kwargs)
196 # files
197 with open(nineml_mod_time_path, 'w') as f:
--> 198 f.write(nineml_mod_time)
199 if compile_source:
200 # Clean existing compile & install directories from previous builds

TypeError: expected a character buffer object

Missing 'RandomVariable' attribute in OnCondition block attribute error (Dynamics, Transitions, OnCondition).

lib9ml/test/unit/nineml_test/abstraction_layer/component$ python connectionrule_test.py

NineMLRuntimeError Traceback (most recent call last)
/usr/lib/python2.7/dist-packages/IPython/utils/py3compat.pyc in execfile(fname, *where)
202 else:
203 filename = fname
--> 204 builtin.execfile(filename, *where)

/home/russell/git/lib9ml/test/unit/nineml_test/abstraction_layer/component/connectionrule_test.py in ()
45 c4 = nineml.read("/home/russell/git/lib9ml/test/xml/connectionrules/RandomFanIn.xml")
46 c5 = nineml.read("/home/russell/git/lib9ml/test/xml/neurons/HodgkinHuxleyClass.xml")
---> 47 xml = c5.items()
48 ConnectionRule.from_xml(xml, Document())
49 c5.to_xml()

/usr/local/lib/python2.7/dist-packages/nineml/document.pyc in items(self)
117
118 def items(self):
--> 119 return list(self.iteritems())
120
121 @Property

/usr/local/lib/python2.7/dist-packages/nineml/document.pyc in iteritems(self)
113 for k, v in super(Document, self).iteritems():
114 if isinstance(v, self._Unloaded):
--> 115 v = self._load_elem_from_xml(v)
116 yield k, v
117

/usr/local/lib/python2.7/dist-packages/nineml/document.pyc in _load_elem_from_xml(self, unloaded)
171 for u in self._loading)))
172 self._loading.append(unloaded)
--> 173 elem = unloaded.cls.from_xml(unloaded.xml, self)
174 assert self._loading[-1] is unloaded
175 self._loading.pop()

/usr/local/lib/python2.7/dist-packages/nineml/abstraction/dynamics/base.pyc in from_xml(cls, element, document, *_kwargs)
696 @classmethod
697 def from_xml(cls, element, document, *_kwargs): # @unusedvariable
--> 698 return DynamicsXMLLoader(document).load_dynamics(element)
699
700

/usr/local/lib/python2.7/dist-packages/nineml/annotations.pyc in annotate_from_xml(cls, element, _args, *_kwargs)
62 kwargs['validate_dimensions'] = (
63 annotations[NINEML][VALIDATE_DIMENSIONS] == 'True')
---> 64 nineml_object = from_xml(cls, element, _args, *_kwargs)
65 nineml_object.annotations.update(annotations.iteritems())
66 return nineml_object

/usr/local/lib/python2.7/dist-packages/nineml/abstraction/dynamics/visitors/xml.py in load_dynamics(self, element, **kwargs)
38 'Constant')
39
---> 40 blocks = self._load_blocks(element, block_names=block_names)
41
42 try:

/usr/local/lib/python2.7/dist-packages/nineml/abstraction/componentclass/visitors/xml.pyc in _load_blocks(self, element, block_names)
120 raise NineMLRuntimeError(err)
121 try:
--> 122 loaded_objects[tag].append(self.tag_to_loader[tag](self, t))
123 except KeyError, e:
124 raise NineMLRuntimeError(

/usr/local/lib/python2.7/dist-packages/nineml/annotations.pyc in annotate_from_xml(cls, element, _args, *_kwargs)
62 kwargs['validate_dimensions'] = (
63 annotations[NINEML][VALIDATE_DIMENSIONS] == 'True')
---> 64 nineml_object = from_xml(cls, element, _args, *_kwargs)
65 nineml_object.annotations.update(annotations.iteritems())
66 return nineml_object

/usr/local/lib/python2.7/dist-packages/nineml/abstraction/dynamics/visitors/xml.py in load_regime(self, element, **kwargs)
88 block_names = ('TimeDerivative', 'OnCondition', 'OnEvent',
89 'Alias')
---> 90 blocks = self._load_blocks(element, block_names=block_names)
91 transitions = blocks["OnEvent"] + blocks['OnCondition']
92 #

/usr/local/lib/python2.7/dist-packages/nineml/abstraction/componentclass/visitors/xml.pyc in _load_blocks(self, element, block_names)
127 ("'{}' ".format(t.attrib['name'])
128 if 'name' in t.attrib else ''), tag,
--> 129 self.document.url))
130 return loaded_objects
131

NineMLRuntimeError: Missing 'RandomVariable' attribute in OnCondition block in '/lib9ml/test/xml/neurons/HodgkinHuxleyClass.xml' document


Although the error message suggests that the problem is that the line of file: /lib9ml/test/xml/neurons/HodgkinHuxleyClass.xml

Should read:

I am unsure if the problem is in the python code base of nineml, and not the XML code.

I think the problem is that the problem is that the base dynamics object is not properly inheriting the _random_variable attribute from the classes
nineml/abstraction/dynamics/base.py is not properly inheriting the attribute from:
/dynamics/transitions.py (Transitions, and OnCondition).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.