def write_and_compile_nmodl(component): build_dir = os.path.join(BUILD_DIR, component.name.replace('-', '_')) clear_and_recreate_dir(build_dir) if not component.is_flat(): component = flatten(component) ComponentModifier.close_all_reduce_ports(component=component) print ' -- Writing Component to .mod' modfilename = os.path.join(build_dir, component.name + '.mod').replace('-', '_') write_nmodldirect(component=component, mod_filename=modfilename, weight_variables={}) compile_nmodl(build_dir)
from nineml.abstraction_layer.testing_utils import TestableComponent from nineml.abstraction_layer.flattening import flatten #from nineml.abstraction_layer.flattening import ComponentFlattener from nineml.abstraction_layer.component_modifiers import ComponentModifier from nineml.utility import LocationMgr #from nineml.abstraction_layer.visitors import RenameSymbol LocationMgr.StdAppendToPath() comp_data = TestableComponent('nestequivalent_iaf_cond_exp') # Build the component: component = comp_data() component = flatten(component) component.backsub_all() ComponentModifier.close_all_reduce_ports(component=component) # Copy the descriptive strings: component.short_description = comp_data.metadata.short_description component.long_description = comp_data.metadata.long_description # Get the initial regime. If this component comes from an flattened component, # then we should look up the new regime from the locations in the old # components, hence the nedd for this code: initial_regime = comp_data.metadata.initial_regime if component.was_flattened(): new_regime = component.flattener.get_new_regime(initial_regime) initial_regime = new_regime.name from nestbuilder import NestFileBuilder nfb = NestFileBuilder(
# Remove and recreate the old test-dir: if os.path.exists(test_dir): shutil.rmtree(test_dir) os.makedirs(output_dir) # generate NMODL files for model in models: # run the example script, saving the XML to file tc = TestableComponent(model) component = tc() #ComponentModifier.close_all_reduce_ports(component) ComponentModifier.remap_port_to_parameter(component, 'Isyn') nineml2nmodl.write_nmodldirect(component=component, mod_filename='%s/%s.mod'%(test_dir, model) ) # run nrnivmodl p = Popen("nrnivmodl", shell=True, stdout=None, stderr=None, cwd=output_dir) result = p.wait() assert result == 0, "nrnivmodl failed" # run test scripts cwd = os.getcwd() os.chdir(output_dir)
def t4(): print 'Loading Forth XML File (iaf-2coba-Model)' print '----------------------------------------' component = readers.XMLReader.read_component( Join(tenml_dir, 'iaf_2coba.10ml'), component_name='iaf') writers.XMLWriter.write(component, '/tmp/nineml_toxml4.xml', ) model = readers.XMLReader.read_component(Join(tenml_dir, 'iaf_2coba.10ml')) from nineml.abstraction_layer.flattening import flatten from nineml.abstraction_layer.component_modifiers import ComponentModifier flatcomponent = flatten(model, componentname='iaf_2coba') ComponentModifier.close_analog_port(component=flatcomponent, port_name='iaf_iSyn', value='0') writers.XMLWriter.write(flatcomponent, '/tmp/nineml_out_iaf_2coba.9ml') import pyNN.neuron as sim from pyNN.utility import init_logging init_logging(None, debug=True) sim.setup(timestep=0.1, min_delay=0.1) print 'Attempting to simulate From Model:' print '----------------------------------' celltype_cls = pyNNml.nineml_celltype_from_model( name="iaf_2coba", nineml_model=flatcomponent, synapse_components=[ pyNNml.CoBaSyn(namespace='cobaExcit', weight_connector='q'), pyNNml.CoBaSyn(namespace='cobaInhib', weight_connector='q'), ] ) parameters = { 'iaf.cm': 1.0, 'iaf.gl': 50.0, 'iaf.taurefrac': 5.0, 'iaf.vrest': -65.0, 'iaf.vreset': -65.0, 'iaf.vthresh': -50.0, 'cobaExcit.tau': 2.0, 'cobaInhib.tau': 5.0, 'cobaExcit.vrev': 0.0, 'cobaInhib.vrev': -70.0, } parameters = ComponentFlattener.flatten_namespace_dict(parameters) cells = sim.Population(1, celltype_cls, parameters) cells.initialize('iaf_V', parameters['iaf_vrest']) cells.initialize('tspike', -1e99) # neuron not refractory at start cells.initialize('regime', 1002) # temporary hack input = sim.Population(2, sim.SpikeSourcePoisson, {'rate': 100}) connector = sim.OneToOneConnector(weights=1.0, delays=0.5) conn = [sim.Projection(input[0:1], cells, connector, target='cobaExcit'), sim.Projection(input[1:2], cells, connector, target='cobaInhib')] cells._record('iaf_V') cells._record('cobaExcit_g') cells._record('cobaInhib_g') cells._record('cobaExcit_I') cells._record('cobaInhib_I') cells.record() sim.run(100.0) cells.recorders['iaf_V'].write("Results/nineml_neuron.V", filter=[cells[0]]) cells.recorders['cobaExcit_g'].write("Results/nineml_neuron.g_exc", filter=[cells[0]]) cells.recorders['cobaInhib_g'].write("Results/nineml_neuron.g_inh", filter=[cells[0]]) cells.recorders['cobaExcit_I'].write("Results/nineml_neuron.g_exc", filter=[cells[0]]) cells.recorders['cobaInhib_I'].write("Results/nineml_neuron.g_inh", filter=[cells[0]]) t = cells.recorders['iaf_V'].get()[:, 1] v = cells.recorders['iaf_V'].get()[:, 2] gInh = cells.recorders['cobaInhib_g'].get()[:, 2] gExc = cells.recorders['cobaExcit_g'].get()[:, 2] IInh = cells.recorders['cobaInhib_I'].get()[:, 2] IExc = cells.recorders['cobaExcit_I'].get()[:, 2] import pylab pylab.subplot(311) pylab.ylabel('Voltage') pylab.plot(t, v) pylab.subplot(312) pylab.ylabel('Conductance') pylab.plot(t, gInh) pylab.plot(t, gExc) pylab.subplot(313) pylab.ylabel('Current') pylab.plot(t, IInh) pylab.plot(t, IExc) pylab.suptitle("From Tree-Model Pathway") pylab.show() sim.end()
from nineml.abstraction_layer.flattening import flatten #from nineml.abstraction_layer.flattening import ComponentFlattener from nineml.abstraction_layer.component_modifiers import ComponentModifier from nineml.utility import LocationMgr #from nineml.abstraction_layer.visitors import RenameSymbol LocationMgr.StdAppendToPath() comp_data = TestableComponent('nestequivalent_iaf_cond_exp') # Build the component: component = comp_data() component = flatten( component ) component.backsub_all() ComponentModifier.close_all_reduce_ports(component=component) # Copy the descriptive strings: component.short_description = comp_data.metadata.short_description component.long_description = comp_data.metadata.long_description # Get the initial regime. If this component comes from an flattened component, # then we should look up the new regime from the locations in the old # components, hence the nedd for this code: initial_regime = comp_data.metadata.initial_regime if component.was_flattened(): new_regime = component.flattener.get_new_regime(initial_regime) initial_regime = new_regime.name