def test_xml_roundtrip(self): delay = 1.5 # (ms) global delay for all neurons in the group J = 0.1 # (mV) EPSP size Jeff = 24.0 * J # (nA) synaptic weight g = 5.0 # relative strength of inhibitory synapses # eta = 2.0 # nu_ext / nu_thresh Je = Jeff # excitatory weights Ji = -g * Je # inhibitory weights theta = 20.0 # firing thresholds tau = 20.0 # membrane time constant tau_syn = 0.5 # synapse time constant input_rate = 50.0 # mean input spiking rate neuron_parameters = nineml.PropertySet(tau=(tau, ms), theta=(theta, mV), tau_rp=(2.0, ms), Vreset=(10.0, mV), R=(1.5, Mohm)) psr_parameters = nineml.PropertySet(tau_syn=(tau_syn, ms)) neuron_initial_values = { "V": (0.0, mV), # todo: use random distr. "t_rpend": (0.0, ms) } synapse_initial_values = {"A": (0.0, nA), "B": (0.0, nA)} celltype = nineml.SpikingNodeType("nrn", path.join(self.xml_dir, 'BrunelIaF.xml'), neuron_parameters, initial_values=neuron_initial_values) ext_stim = nineml.SpikingNodeType("stim", path.join(self.xml_dir, "Poisson.xml"), nineml.PropertySet(rate=(input_rate, Hz)), initial_values={"t_next": (0.5, ms)}) psr = nineml.SynapseType("syn", path.join(self.xml_dir, "AlphaPSR.xml"), psr_parameters, initial_values=synapse_initial_values) p1 = nineml.Population("Exc", 1, celltype, positions=None) p2 = nineml.Population("Inh", 1, celltype, positions=None) inpt = nineml.Population("Ext", 1, ext_stim, positions=None) all_to_all = nineml.ConnectionRule( "AllToAll", path.join(self.xml_dir, "AllToAll.xml")) static_exc = nineml.ConnectionType("ExcitatoryPlasticity", path.join(self.xml_dir, "StaticConnection.xml"), initial_values={"weight": (Je, nA)}) static_inh = nineml.ConnectionType("InhibitoryPlasticity", path.join(self.xml_dir, "StaticConnection.xml"), initial_values={"weight": (Ji, nA)}) exc_prj = nineml.Projection( "Excitation", inpt, p1, connectivity=all_to_all, response=psr, plasticity=static_exc, port_connections=[ nineml.PortConnection("plasticity", "response", "weight", "q"), nineml.PortConnection("response", "destination", "Isyn", "Isyn") ], delay=(delay, ms)) inh_prj = nineml.Projection( "Inhibition", inpt, p2, connectivity=all_to_all, response=psr, plasticity=static_inh, port_connections=[ nineml.PortConnection("plasticity", "response", "weight", "q"), nineml.PortConnection("response", "destination", "Isyn", "Isyn") ], delay=(delay, ms)) model = nineml.Network("Three-neuron network with alpha synapses") model.add(inpt, p1, p2) model.add(exc_prj, inh_prj) model.write(self.tmp_xml_file) loaded_model = nineml.Network.read(self.tmp_xml_file) self.assertEqual(loaded_model, model) os.remove(self.tmp_xml_file)
def spiking_node_to_nineml(self, label): return nineml.SpikingNodeType( name="neuron type for population %s" % label, definition=nineml.Definition(self.spiking_mechanism_definition_url), parameters=build_parameter_set(self.spiking_mechanism_parameters))
'upperBound': (-60.0, "dimensionless") }) exc_cell_parameters = nineml.ParameterSet(C=(1.0, "nF"), gL=(tau_distr, "nS"), t_ref=(5.0, "ms"), theta=(-50.0, "mV"), vL=(-65.0, "mV"), V_reset=(reset_distr, "mV")) inh_cell_parameters = nineml.ParameterSet(gL=(20.0, "nS"), V_reset=(-60.0, "mV")) inh_cell_parameters.complete(exc_cell_parameters) exc_celltype = nineml.SpikingNodeType("Excitatory neuron type", catalog + "neurons/leaky_iaf.xml", exc_cell_parameters) inh_celltype = nineml.SpikingNodeType("Inhibitory neuron type", catalog + "neurons/leaky_iaf.xml", inh_cell_parameters) grid2D = nineml.Structure( "2D grid", catalog + "networkstructures/2Dgrid.xml", { 'fillOrder': ("sequential", None), 'aspectRatioXY': (1.0, "dimensionless"), 'dx': (1.0, u"µm"), 'dy': (1.0, u"µm"), 'x0': (0.0, u"µm"), 'y0': (0.0, u"µm") })
def build_model(g, eta): """ Build a NineML representation of the Brunel (2000) network model. Arguments: g: relative strength of inhibitory synapses eta: nu_ext / nu_thresh Returns: a nineml user layer Model object """ order = 1000 # scales the size of the network Ne = 4 * order # number of excitatory neurons Ni = 1 * order # number of inhibitory neurons epsilon = 0.1 # connection probability Ce = int(epsilon * Ne) # number of excitatory synapses per neuron Ci = int(epsilon * Ni) # number of inhibitory synapses per neuron Cext = Ce # effective number of external synapses per neuron delay = 1.5 # (ms) global delay for all neurons in the group J = 0.1 # (mV) EPSP size Jeff = 24.0 * J # (nA) synaptic weight Je = Jeff # excitatory weights Ji = -g * Je # inhibitory weights Jext = Je # external weights theta = 20.0 # firing thresholds tau = 20.0 # membrane time constant tau_syn = 0.1 # synapse time constant #nu_thresh = theta / (Je * Ce * tau * exp(1.0) * tau_syn) # threshold rate nu_thresh = theta / (J * Ce * tau) nu_ext = eta * nu_thresh # external rate per synapse input_rate = 1000.0 * nu_ext * Cext # mean input spiking rate neuron_parameters = nineml.PropertySet(tau=(tau, ms), theta=(theta, mV), tau_rp=(2.0, ms), Vreset=(10.0, mV), R=(1.5, Mohm)) # units?? psr_parameters = nineml.PropertySet(tau_syn=(tau_syn, ms)) #v_init = nineml.RandomDistribution("uniform(rest,threshold)", # "catalog/randomdistributions/uniform_distribution.xml", # hack - this file doesn't exist # {'lowerBound': (0.0, "dimensionless"), # 'upperBound': (theta, "dimensionless")}) v_init = 0.0 neuron_initial_values = {"V": (v_init, mV), "t_rpend": (0.0, ms)} synapse_initial_values = {"A": (0.0, nA), "B": (0.0, nA)} celltype = nineml.SpikingNodeType("nrn", "BrunelIaF.xml", neuron_parameters, initial_values=neuron_initial_values) #tpoisson_init = nineml.RandomDistribution("exponential(beta)", # "catalog/randomdistributions/exponential_distribution.xml", # {"beta": (1000.0/input_rate, "dimensionless")}) tpoisson_init = 5.0 ext_stim = nineml.SpikingNodeType( "stim", "Poisson.xml", nineml.PropertySet(rate=(input_rate, Hz)), initial_values={"t_next": (tpoisson_init, ms)}) psr = nineml.SynapseType("syn", "AlphaPSR.xml", psr_parameters, initial_values=synapse_initial_values) exc_cells = nineml.Population("Exc", Ne, celltype, positions=None) inh_cells = nineml.Population("Inh", Ni, celltype, positions=None) external = nineml.Population("Ext", Ne + Ni, ext_stim, positions=None) all_cells = nineml.Selection("All neurons", nineml.Concatenate(exc_cells, inh_cells)) one_to_one = nineml.ConnectionRule("OneToOne", "OneToOne.xml") random_exc = nineml.ConnectionRule("RandomExc", "RandomFanIn.xml", {"number": (Ce, unitless)}) random_inh = nineml.ConnectionRule("RandomInh", "RandomFanIn.xml", {"number": (Ci, unitless)}) static_ext = nineml.ConnectionType("ExternalPlasticity", "StaticConnection.xml", initial_values={"weight": (Jext, nA)}) static_exc = nineml.ConnectionType("ExcitatoryPlasticity", "StaticConnection.xml", initial_values={"weight": (Je, nA)}) static_inh = nineml.ConnectionType("InhibitoryPlasticity", "StaticConnection.xml", initial_values={"weight": (Ji, nA)}) input_prj = nineml.Projection( "External", external, all_cells, connectivity=one_to_one, response=psr, plasticity=static_ext, port_connections=[ nineml.PortConnection("plasticity", "response", "weight", "q"), nineml.PortConnection("response", "destination", "Isyn", "Isyn") ], delay=(delay, ms)) exc_prj = nineml.Projection( "Excitation", exc_cells, all_cells, connectivity=random_exc, response=psr, plasticity=static_exc, port_connections=[ nineml.PortConnection("plasticity", "response", "weight", "q"), nineml.PortConnection("response", "destination", "Isyn", "Isyn") ], delay=(delay, ms)) inh_prj = nineml.Projection( "Inhibition", inh_cells, all_cells, connectivity=random_inh, response=psr, plasticity=static_inh, port_connections=[ nineml.PortConnection("plasticity", "response", "weight", "q"), nineml.PortConnection("response", "destination", "Isyn", "Isyn") ], delay=(delay, ms)) network = nineml.Network("BrunelCaseC") network.add(exc_cells, inh_cells, external, all_cells) network.add(input_prj, exc_prj, inh_prj) #model = nineml.Model("Brunel (2000) network with alpha synapses") #model.add_group(network) #return model return network
# encoding: utf-8 import nineml.user_layer as nineml catalog = "http://svn.incf.org/svn/nineml/trunk/catalog/" cell_parameters = { "membraneCapacitance": (1.0, "nF"), "membraneTimeConstant": (20.0, "ms"), "refractoryTime": (5.0, "ms"), "threshold": (-50.0, "mV"), "restingPotential": (-65.0, "mV"), "resetPotential": (-70.0, "mV"), } exc_celltype = nineml.SpikingNodeType(name="Excitatory neuron type", definition=catalog + "neurons/IaF_tau.xml", parameters=cell_parameters) inh_celltype = nineml.SpikingNodeType(name="Inhibitory neuron type", definition=catalog + "neurons/IaF_tau.xml", parameters=cell_parameters) inner_grid = nineml.Structure(name="neuronal grid with 1 micron spacing", definition=catalog + "networkstructures/2Dgrid.xml", parameters={ 'fillOrder': ("sequential", None), 'aspectRatioXY': (1.0, "dimensionless"), 'dx': (1.0, u"µm"), 'dy': (1.0, u"µm"),
input_rate = 50.0 # mean input spiking rate neuron_parameters = nineml.PropertySet(tau=(tau, ms), theta=(theta, mV), tau_rp=(2.0, ms), Vreset=(10.0, mV), R=(1.5, Mohm)) psr_parameters = nineml.PropertySet(tau_syn=(tau_syn, ms)) neuron_initial_values = { "V": (0.0, mV), # todo: use random distr. "t_rpend": (0.0, ms) } synapse_initial_values = {"A": (0.0, nA), "B": (0.0, nA)} celltype = nineml.SpikingNodeType("nrn", "BrunelIaF.xml", neuron_parameters, initial_values=neuron_initial_values) ext_stim = nineml.SpikingNodeType("stim", "Poisson.xml", nineml.PropertySet(rate=(input_rate, Hz)), initial_values={"t_next": (0.5, ms)}) psr = nineml.SynapseType("syn", "AlphaPSR.xml", psr_parameters, initial_values=synapse_initial_values) p1 = nineml.Population("Exc", 1, celltype, positions=None) p2 = nineml.Population("Inh", 1, celltype, positions=None) input = nineml.Population("Ext", 1, ext_stim, positions=None) all_to_all = nineml.ConnectionRule("AllToAll", "AllToAll.xml")
def test_9ml_al(test_ref, AL_file_ref, instance_name, params, dur, dt): import nineml.user_layer as UL file_name = test_ref + ".xml" '''file_al_9ml = test_ref+"_AL.9ml"''' file_ul_9ml = test_ref + "_UL.9ml" print "Testing LEMS export..." al_def_dir = "../../lib9ml/python/examples/AL" sys.path.append(al_def_dir) exec("from %s import *" % AL_file_ref) my_cell_comp = c1 ''' To handle Abigail's models...''' if my_cell_comp.name.lower() != AL_file_ref.lower(): print my_cell_comp.name + " is not " + AL_file_ref + "..." try: my_cell_comp = leaky_iaf except NameError: print "Going with the flow..." print "Loaded abstraction layer definition: %s from file %s/%s.py" % ( my_cell_comp.name, al_def_dir, AL_file_ref) components_9ml = [] components_9ml.append(my_cell_comp) catalog = "../../catalog/" network = UL.Group("Network1") model = UL.Model( "Simple 9ML example model (based on %s AL definition) to run on LEMS" % AL_file_ref) model.add_group(network) al_definition_name = my_cell_comp.name comp_instance = UL.SpikingNodeType(instance_name, al_definition_name, params) model.add_component(comp_instance) unstructured = UL.Structure("Unstructured", catalog + "networkstructures/Unstructured.xml") cellPop = UL.Population("CellsA", 1, comp_instance, UL.PositionList(structure=unstructured)) network.add(cellPop) model.write(file_ul_9ml) lems_file = open(file_name, 'w') lems = LEMS() lems.read_9ml(components_9ml, model) lems.gen_sim_with_def_plots(lems.networks.values()[0].id, 200, 0.01) lems.write(lems_file) lems_file.close() print "Saved file to %s" % file_name run_in_lems = True if run_in_lems: os.system("java -jar lems-0.6.1.jar " + file_name)