def test_write_read_roundtrip(self): for version in (1.0, 2.0): if version == 1.0: docs = v1_safe_docs else: docs = list(instances_of_all_types['NineML'].values()) for format in format_to_serializer: # @ReservedAssignment try: ext = format_to_ext[format] except KeyError: continue # ones that can't be written to file (e.g. dict) for i, document in enumerate(docs): try: doc = document.clone() except: document.clone() raise url = os.path.join( self._tmp_dir, 'test{}v{}{}'.format(i, version, ext)) nineml.write(url, doc, format=format, version=version, indent=2) if self.print_serialized and format in self.printable: with open(url) as f: print(f.read()) reread_doc = nineml.read(url, reload=True) self.assertTrue(doc.equals(reread_doc), doc.find_mismatch(reread_doc))
def test_write_read_roundtrip(self): for version in (1.0, 2.0): if version == 1.0: docs = v1_safe_docs else: docs = list(instances_of_all_types['NineML'].values()) for format in format_to_serializer: # @ReservedAssignment try: ext = format_to_ext[format] except KeyError: continue # ones that can't be written to file (e.g. dict) for i, document in enumerate(docs): try: doc = document.clone() except: document.clone() raise url = os.path.join(self._tmp_dir, 'test{}v{}{}'.format(i, version, ext)) nineml.write(url, doc, format=format, version=version, indent=2) if self.print_serialized and format in self.printable: with open(url) as f: print(f.read()) reread_doc = nineml.read(url, reload=True) self.assertTrue(doc.equals(reread_doc), doc.find_mismatch(reread_doc))
def function(): for version in (1.0, 2.0): if version == 1.0: docs = v1_safe_docs else: docs = list(instances_of_all_types['NineML'].values()) for format in format_to_serializer: # @ReservedAssignment try: ext = format_to_ext[format] except KeyError: continue # ones that can't be written to file (e.g. dict) for i, document in enumerate(docs): doc = document.clone() url = os.path.join(_tmp_dir, 'test{}v{}{}'.format(i, version, ext)) nineml.write(url, doc, format=format, version=version, indent=2) if print_serialized and format in printable: with open(url) as f: print(f.read()) reread_doc = nineml.read(url, reload=True) # @UnusedVariable shutil.rmtree(_tmp_dir)
def test_url_resolution(self): tmp_dir = tempfile.mkdtemp() os.chdir(tmp_dir) write(self.tmp_path, dynA, dynB) reread_dynA = read('{}#dynA'.format(self.tmp_path)) self.assertEqual(dynA, reread_dynA) # Read again using document cache via Dynamics Properties dynBProps = DynamicsProperties( name='dynBProps', definition='{}#dynB'.format(os.path.join(tmp_dir, self.tmp_path)), properties={'P1': 1, 'P2': 2, 'P3': 3}) self.assertEqual(dynB, dynBProps.component_class)
def test_url_resolution(self): tmp_dir = tempfile.mkdtemp() os.chdir(tmp_dir) write(self.tmp_path, dynA, dynB) reread_dynA = read('{}#dynA'.format(self.tmp_path)) self.assertEqual(dynA, reread_dynA) # Read again using document cache via Dynamics Properties dynBProps = DynamicsProperties( name='dynBProps', definition='{}#dynB'.format(os.path.join(tmp_dir, self.tmp_path)), properties={ 'P1': 1, 'P2': 2, 'P3': 3 }) self.assertEqual(dynB, dynBProps.component_class)
def function(): for version in (1.0, 2.0): if version == 1.0: docs = v1_safe_docs else: docs = list(instances_of_all_types['NineML'].values()) for format in format_to_serializer: # @ReservedAssignment try: ext = format_to_ext[format] except KeyError: continue # ones that can't be written to file (e.g. dict) for i, document in enumerate(docs): doc = document.clone() url = os.path.join( _tmp_dir, 'test{}v{}{}'.format(i, version, ext)) nineml.write(url, doc, format=format, version=version, indent=2) if print_serialized and format in printable: with open(url) as f: print(f.read()) reread_doc = nineml.read(url, reload=True) # @UnusedVariable shutil.rmtree(_tmp_dir)
""" """ import nineml.abstraction as al from nineml.units import per_time, time, ms, per_ms model = al.Dynamics( name="Poisson", regimes=[ al.Regime( name="default", transitions=al.On("t > t_next", do=["t_next = t + one_ms * random.exponential(thousand_per_millisecond / rate)", al.OutputEvent('spikeOutput')])) ], event_ports=[al.EventSendPort('spikeOutput')], state_variables=[al.StateVariable('t_next', dimension=time)], parameters=[al.Parameter('rate', dimension=per_time)], constants=[al.Constant('thousand_per_millisecond', value=1000.0, units=per_ms), al.Constant('one_ms', value=1.0, units=ms)] ) if __name__ == "__main__": import nineml filename = __file__[0].upper() + __file__[1:].replace(".py", ".xml") nineml.write(model, filename)
import nineml.abstraction as al from nineml.units import current, A, s model = al.Dynamics( name="StaticConnection", regimes=[ al.Regime( name="default", time_derivatives=[ "dfixed_weight/dt = zero"], ) ], state_variables=[ al.StateVariable('fixed_weight', dimension=current), # TGC 4/15 what is the point of this state variable, where is it read? @IgnorePep8 ], analog_ports=[al.AnalogSendPort("fixed_weight", dimension=current)], constants=[al.Constant('zero', 0.0, A / s)], ) if __name__ == "__main__": import nineml filename = __file__[0].upper() + __file__[1:].replace(".py", ".xml") nineml.write(model, filename)
def write(self, fname, **kwargs): """ Writes the top-level NineML object to file in XML. """ nineml.write(fname, self, **kwargs)