In this section we will describe the usage of PCSIM by using a more realistic example. We will implement the model defined as ``Benchmark 3: Conductance based HH network'' in Simulation of networks of spiking neurons: A review of tools and strategies. This network is composed of Hudgkin and Huxly type neurons coupled by conductance based synapses. Furthermore we will learn how to perform a distributed simulation with PCSIM .
The full source code of this example is available as examples/example1.py
from pypcsim import * import random import numpy as N
nNeurons = 4000; # number of neurons minDelay = 1e-3; # minimum synapse delay [sec] ConnP = 0.02; # connectivity probability Frac_EXC = 0.8; # fraction of excitatory neurons Tsim = 0.1; # duration of the simulation [sec] DTsim = 1e-4; # simulation time step [sec] nRecordNeurons = 25; # number of neurons to plot the spikes from Tinp = 50e-3; # length of the initial stimulus [sec] nInputNeurons = 10 ; # number of neurons which provide initial input (for a time span of Tinp) inpConnP = 0.01 ; # connectivity from input neurons to network neurons inputFiringRate = 80; # firing rate of the input neurons during the initial input [spikes/sec]
SimParameter, DistributedSingleThreadNetwork
sp = SimParameter( dt=Time.sec( DTsim ) , minDelay = Time.sec(minDelay), simulationRNGSeed = 345678, constructionRNGSeed = 349871 ); net = DistributedSingleThreadNetwork( sp )
SimObjectVariationFactory HHNeuronTraubMiles91 UniformDistribution
exz_nrn_model = SimObjectVariationFactory( HHNeuronTraubMiles91( ) ) exz_nrn_model.set( "Vresting", UniformDistribution( -50e-3, -48e-3) ) exz_nrn_model.set( "Cm", UniformDistribution( 1.5e-10, 2.5e-10 ) ) inh_nrn_model = SimObjectVariationFactory( HHNeuronTraubMiles91( ) ); inh_nrn_model.set( "Vresting", UniformDistribution( -55e-3, -50e-3) ) inh_nrn_model.set( "Cm", UniformDistribution( 2.2e-10, 2.7e-10 ) ) num_exz = int( nNeurons * Frac_EXC ) num_inh = nNeurons - num_exz exz_nrn = net.create( exz_nrn_model, num_exz ); inh_nrn = net.create( inh_nrn_model, num_inh ); all_nrn = list(exz_nrn) + list(inh_nrn);
exz_syn = SimObjectVariationFactory( StaticCondExpSynapse( W=2e-9, tau= 5e-3, delay=1e-3, Erev = 0 ) ) exz_syn.set( "tau", UniformDistribution( 4e-3, 6e-3 ) ) inh_syn = SimObjectVariationFactory( StaticCondExpSynapse( W=33e-9, tau=10e-3, delay=1e-3, Erev = -80e-3 ) ) inh_syn.set( "tau", UniformDistribution( 9e-3, 13e-3 ) )
n_exz_syn = net.connect( exz_nrn, all_nrn, exz_syn, RandomConnections( conn_prob = ConnP ) )[0] n_inh_syn = net.connect( inh_nrn, all_nrn, inh_syn, RandomConnections( conn_prob = ConnP ) )[0]
Create input neurons for the initial stimulus and connect them to random neurons in circuit
SpikingInputNeuron StaticCondExpSynapse
inp_nrn = [ net.add( SpikingInputNeuron( [ random.uniform(0,Tinp) for x in range( int(inputFiringRate*Tinp) ) ] ) ) for i in range(nInputNeurons) ] inp_syn = StaticCondExpSynapse( W=6e-9, tau=5e-3, delay=1e-3, Erev = 0 ) net.connect( inp_nrn, all_nrn, inp_syn, RandomConnections( conn_prob = inpConnP ) )
SpikeTimeRecorder AnalogRecorder
spike_rec = range( len(all_nrn) ) for i in range( len(all_nrn) ): spike_rec[i] = net.create( SpikeTimeRecorder(), SimEngine.ID(0,0) ) net.connect( all_nrn[i], spike_rec[i] , Time.ms(1) )
rec_nrn = random.sample( all_nrn, nRecordNeurons ); vm_rec = range( nRecordNeurons ) for i in range( nRecordNeurons ): vm_rec[i] = net.create( AnalogRecorder(), SimEngine.ID(0,0) ) net.connect( rec_nrn[i], 'Vm', vm_rec[i], 0, Time.ms(1) )
net.reset(); net.simulate( Tsim )