示例#1
0
    def test_roundtrip_nested(self):
        global nested_example

        model = nested_example

        f = tempfile.TemporaryFile()
        model.write(f)
        f.seek(0)

        model1 = parse(f)
        f.close()

        assert model == model1
示例#2
0
 def __init__(self, sim, nineml_model):
     """
     Instantiate a network from a 9ML file, in the specified simulator.
     """
     global random_distributions
     self.sim = sim
     if isinstance(nineml_model, basestring):
         self.nineml_model = nineml.parse(nineml_model)
     elif isinstance(nineml_model, nineml.Model):
         self.nineml_model = nineml_model
     else:
         raise TypeError("nineml_model must be a nineml.Model instance or the path to a NineML XML file.")
     self.random_distributions = {}
     self.assemblies = {}
     self.projections = {}
     _tmp = __import__(sim.__name__, globals(), locals(), ["nineml"])
     self._nineml_module = _tmp.nineml
     self._build()
示例#3
0
 def readModel(self, filename, target):
     if isinstance(target, str):
         if not moose.exists(target):
             target = moose.Neutral(target)
     elif isinstance(target, moose.NeutralArray):
         target = target._id
     elif isinstance(target, moose.Neutral):
         target = target._oid.getId()
     elif not (isinstance(target, moose.Id) or isinstance(target, moose.ObjId)):
         raise TypeError('Target must be a string or an Id or an ObjId or a moose object.')
     
     # current = moose.getCwe() - until the moose unit test bugs are fixed
     self._moose_root = target
     with open(filename) as model_file:
         model = ninemlul.parse(model_file)
         model.check()
         spiking_nodes = {}  
         projections = {}
         synapses = {}            
         for name, component in model.components.items():
             if isinstance(component, ninemlul.SpikingNodeType):
                 spiking_nodes[name] = component
         print spiking_nodes.keys()
         moose.setCwe(target)
         # We instantiate the model here. TODO: components are
         # actually prototypes, we need to make copies of them when
         # creating Groups
         for name, node in spiking_nodes.items():
             if node.definition.url == 'http://svn.incf.org/svn/nineml/trunk/catalog/neurons/IaF_tau.xml':
                 moose_object = self._create_LeakyIaF(node)
                 self._moose_to_nineml[moose_object] = node
                 self._nineml_to_moose[node] = moose_object
             elif node.definition.url == 'http://svn.incf.org/svn/nineml/trunk/catalog/neurons/Iz1.xml':
                 moose_object = self._create_IzhikevichNeuron(node)
                 self._moose_to_nineml[moose_object] = node
                 self._nineml_to_moose[node] = moose_object