diff --git a/examples/one_neuron_example.py b/examples/one_neuron_example.py new file mode 100644 index 00000000..23362dbb --- /dev/null +++ b/examples/one_neuron_example.py @@ -0,0 +1,87 @@ +# encoding: utf-8 +""" +A conversion to PyNN of the "One neuron example" from the NEST examples gallery. + +See: https://nest-simulator.readthedocs.io/en/stable/auto_examples/one_neuron.html + + +Usage: one_neuron_example.py [-h] [--plot-figure] [--debug DEBUG] simulator + +positional arguments: + simulator neuron, nest, brian or another backend simulator + +optional arguments: + -h, --help show this help message and exit + --plot-figure plot the simulation results to a file + --debug DEBUG print debugging information +""" + +from pyNN.utility import get_simulator, init_logging, normalized_filename +from pyNN.utility.plotting import Figure, Panel + +sim, options = get_simulator(("--plot-figure", "Plot the simulation results to a file.", {"action": "store_true"}), + ("--debug", "Print debugging information.")) + + +if options.debug: + init_logging(None, debug=True) + +# === Define parameters ======================================================== + +cell_params = { + "v_rest": -70.0, # (mV) + "v_reset": -70.0, # (mV) + "cm": 0.250, # (nF) + "tau_m": 10, # (ms) + "tau_refrac": 2, # (ms) + "tau_syn_E": 2, # (ms) + "tau_syn_I": 2, # (ms) + "v_thresh": -55.0, # (mV) + "i_offset": 0.376, # (nA) +} + +# === Build the network ======================================================== + +sim.setup(timestep=0.1) # (ms) + +cell_type = sim.IF_curr_alpha(**cell_params) +neuron = sim.Population(1, cell_type, initial_values={"v": -70.0}, label="Simulation result") +neuron.record("v") + + +# === Run simulation =========================================================== + +sim.run(1000.0) + +data_v = neuron.get_data().segments[0].filter(name="v")[0] + +if options.plot_figure: + from neo import AsciiSignalIO + from quantities import kHz + + reference_data = AsciiSignalIO( + "one_neuron_example_reference_data.txt", sampling_rate=1 * kHz + ).read_block() + + figure_filename = normalized_filename( + "Results", "one_neuron_example", "png", options.simulator, sim.num_processes() + ) + Figure( + Panel( + reference_data.segments[0].analogsignals[0], + data_v[:, 0], + xticks=True, + yticks=True, + xlabel="Time (in ms)", + ylabel="Membrane Potential (mV)", + line_properties=[{"lw": 3}, {"lw": 1}], + data_labels=["Reference data", "Simulation result"] + ), + title="One Neuron", + annotations=f"One Neuron Example using PyNN (simulator: {options.simulator})", + ).save(figure_filename) + print(figure_filename) + +# === Clean up and quit ======================================================== + +sim.end() diff --git a/examples/one_neuron_example_reference_data.txt b/examples/one_neuron_example_reference_data.txt new file mode 100644 index 00000000..93ebf239 --- /dev/null +++ b/examples/one_neuron_example_reference_data.txt @@ -0,0 +1,1000 @@ +-7.0e+01 +-6.856875476726082752e+01 +-6.727371052629284520e+01 +-6.610190603905303419e+01 +-6.504161349237601542e+01 +-6.408222112207801047e+01 +-6.321412700685415587e+01 +-6.242864296902280330e+01 +-6.171790762032301814e+01 +-6.107480768249861569e+01 +-6.049290679521849512e+01 +-5.996638109881912015e+01 +-5.948996094715952410e+01 +-5.905887816723155481e+01 +-5.866881833768177046e+01 +-5.831587760863239112e+01 +-5.799652363063962213e+01 +-5.770756020175313239e+01 +-5.744609527885266687e+01 +-5.720951203310843169e+01 +-5.699544265987865543e+01 +-5.680174468092484830e+01 +-5.662647950176950218e+01 +-5.646789300959096636e+01 +-5.632439801747276675e+01 +-5.619455837930344444e+01 +-5.607707461634358737e+01 +-5.597077091160583961e+01 +-5.587458334188328024e+01 +-5.578754922964836993e+01 +-5.570879750825267962e+01 +-5.563754000399912059e+01 +-5.557306354783463576e+01 +-5.551472283771465754e+01 +-5.546193398020330534e+01 +-5.541416864667166919e+01 +-5.537094878560728262e+01 +-5.533184183811390255e+01 +-5.529645640871672896e+01 +-5.526443834814489264e+01 +-5.523546720888656125e+01 +-5.520925303804248330e+01 +-5.518553347537998377e+01 +-5.516407112754349384e+01 +-5.514465119214214184e+01 +-5.512707930793516198e+01 +-5.511117960959928297e+01 +-5.509679296760950251e+01 +-5.508377539561725200e+01 +-5.507199660938669439e+01 +-5.506133872286623898e+01 +-5.505169506834535298e+01 +-5.504296912888823812e+01 +-5.503507357235992714e+01 +-5.502792937737689272e+01 +-5.502146504243449954e+01 +-5.501561587029590328e+01 +-5.501032332048036722e+01 +-5.500553442337045595e+01 +-5.500120125007428129e+01 +-7.000000000000000000e+01 +-7.000000000000000000e+01 +-6.898320305138545905e+01 +-6.764871884160960747e+01 +-6.644122759482627316e+01 +-6.534864433278580975e+01 +-6.436003411497182469e+01 +-6.346550259804104144e+01 +-6.265609700990960107e+01 +-6.192371654740087195e+01 +-6.126103130068449332e+01 +-6.066140889307511941e+01 +-6.011884810197735618e+01 +-5.962791879663289762e+01 +-5.918370759154683469e+01 +-5.878176867167412212e+01 +-5.841807929720832959e+01 +-5.808899954264958865e+01 +-5.779123586720675121e+01 +-5.752180815193415953e+01 +-5.727801987369957715e+01 +-5.705743111747436558e+01 +-5.685783415684378639e+01 +-5.667723135833898596e+01 +-5.651381518844982565e+01 +-5.636595012322200660e+01 +-5.623215627938353833e+01 +-5.611109460317562991e+01 +-5.600155346865256689e+01 +-5.590243655132199052e+01 +-5.581275185576090081e+01 +-5.573160178739206572e+01 +-5.565817416905577630e+01 +-5.559173411246782592e+01 +-5.553161666321062739e+01 +-5.547722014564583048e+01 +-5.542800014114235552e+01 +-5.538346403935171480e+01 +-5.534316610799807989e+01 +-5.530670303183987357e+01 +-5.527370987615522324e+01 +-5.524385643435267923e+01 +-5.521684392315256673e+01 +-5.519240199226359778e+01 +-5.517028601862620008e+01 +-5.515027465814279140e+01 +-5.513216763039159929e+01 +-5.511578371415290434e+01 +-5.510095893368616515e+01 +-5.508754491760569039e+01 +-5.507540741392993766e+01 +-5.506442494644257835e+01 +-5.505448759891764610e+01 +-5.504549591504105877e+01 +-5.503735990301836978e+01 +-5.502999813490666270e+01 +-5.502333693165627437e+01 +-5.501730962570618289e+01 +-5.501185589375259610e+01 +-5.500692115301304597e+01 +-5.500245601494358993e+01 +-7.000000000000000000e+01 +-7.000000000000000000e+01 +-6.941027316485093479e+01 +-6.803514786039804108e+01 +-6.679088303044096619e+01 +-6.566502565434964822e+01 +-6.464630777309044163e+01 +-6.372453371570480840e+01 +-6.289047805760745291e+01 +-6.213579328943635716e+01 +-6.145292627237336092e+01 +-6.083504264379216409e+01 +-6.027595841666006038e+01 +-5.977007808811721645e+01 +-5.931233863780332882e+01 +-5.889815885544810925e+01 +-5.852339349057911733e+01 +-5.818429176546175086e+01 +-5.787745983605501721e+01 +-5.759982682527963505e+01 +-5.734861408864809107e+01 +-5.712130740465665468e+01 +-5.691563181161152585e+01 +-5.672952883904756050e+01 +-5.656113590586396356e+01 +-5.640876767898662081e+01 +-5.627089920598820072e+01 +-5.614615065285175888e+01 +-5.603327349412805347e+01 +-5.593113801727325551e+01 +-5.583872201610609665e+01 +-5.575510056022478977e+01 +-5.567943673799275217e+01 +-5.561097328044557742e+01 +-5.554902498228877050e+01 +-5.549297184413285322e+01 +-5.544225286733102820e+01 +-5.539636043931624698e+01 +-5.535483525324394805e+01 +-5.531726171109482948e+01 +-5.528326376423014921e+01 +-5.525250114977059468e+01 +-5.522466598513096869e+01 +-5.519947968662785343e+01 +-5.517669018132040293e+01 +-5.515606938417969474e+01 +-5.513741091533705685e+01 +-5.512052803456498395e+01 +-5.510525177231816230e+01 +-5.509142923862951591e+01 +-5.507892209293595442e+01 +-5.506760515951960855e+01 +-5.505736517470707270e+01 +-5.504809965328855981e+01 +-5.503971586281148376e+01 +-5.503212989548285350e+01 +-5.502526582839190894e+01 +-5.501905496364811654e+01 +-5.501343514082957142e+01 +-5.500835011486061887e+01 +-5.500374899309222343e+01 +-7.000000000000000000e+01 +-7.000000000000000000e+01 +-6.985034949958749451e+01 +-6.843334539485978496e+01 +-6.715118705939161714e+01 +-6.599104222161331279e+01 +-6.494129976205024946e+01 +-6.399145350533648013e+01 +-6.313199707088048029e+01 +-6.235432872981292007e+01 +-6.165066531599303801e+01 +-6.101396432946588533e+01 +-6.043785345275571785e+01 +-5.991656677457085323e+01 +-5.944488708262551313e+01 +-5.901809364802569746e+01 +-5.863191497862769808e+01 +-5.828248606850905134e+01 +-5.796630971569017277e+01 +-5.768022152096151700e+01 +-5.742135821751266889e+01 +-5.718712901439575802e+01 +-5.697518966701883159e+01 +-5.678341901515806001e+01 +-5.660989775367329457e+01 +-5.645288922345707050e+01 +-5.631082203036660871e+01 +-5.618227431818301909e+01 +-5.606595953819638112e+01 +-5.596071357299386051e+01 +-5.586548308558130316e+01 +-5.577931497723262311e+01 +-5.570134684855735685e+01 +-5.563079836831773406e+01 +-5.556696346361135852e+01 +-5.550920325325625981e+01 +-5.545693965365334321e+01 +-5.540964959313137683e+01 +-5.536685977686991578e+01 +-5.532814195000565860e+01 +-5.529310861151383705e+01 +-5.526140913596772464e+01 +-5.523272626436148158e+01 +-5.520677292887543786e+01 +-5.518328937980481896e+01 +-5.516204058589744363e+01 +-5.514281388208191714e+01 +-5.512541684104412809e+01 +-5.510967534735003426e+01 +-5.509543185483984473e+01 +-5.508254380985309950e+01 +-5.507088222450376946e+01 +-5.506033038572607552e+01 +-5.505078268717093692e+01 +-5.504214357226211263e+01 +-5.503432657783390169e+01 +-5.502725346877867452e+01 +-5.502085345504366387e+01 +-5.501506248314027658e+01 +-5.500982259507529903e+01 +-5.500508134828778850e+01 +-5.500079129078629592e+01 +-7.000000000000000000e+01 +-7.000000000000000000e+01 +-6.884366984965500080e+01 +-6.752246397962552749e+01 +-6.632698747149410679e+01 +-6.524527559455383141e+01 +-6.426650221276436525e+01 +-6.338087143314364624e+01 +-6.257951956517847236e+01 +-6.185442641003056252e+01 +-6.119833499169098445e+01 +-6.060467892672505741e+01 +-6.006751670569988732e+01 +-5.958147222856101877e+01 +-5.914168099881604235e+01 +-5.874374143801874482e+01 +-5.838367083329254825e+01 +-5.805786547700144951e+01 +-5.776306459963272744e+01 +-5.749631773491967834e+01 +-5.725495519058353722e+01 +-5.703656132915583044e+01 +-5.683895039146668182e+01 +-5.666014462083236936e+01 +-5.649835446900168279e+01 +-5.635196068575556438e+01 +-5.621949811290663490e+01 +-5.609964102050359713e+01 +-5.599118983848034503e+01 +-5.589305915095547306e+01 +-5.580426683302538038e+01 +-5.572392422132807610e+01 +-5.565122722000162980e+01 +-5.558544825302244874e+01 +-5.552592898237993779e+01 +-5.547207371920838170e+01 +-5.542334346193257488e+01 +-5.537925050175891784e+01 +-5.533935354152181674e+01 +-5.530325327903339883e+01 +-5.527058841073295525e+01 +-5.524103201563949739e+01 +-5.521428828341667838e+01 +-5.519008955380354564e+01 +-5.516819363778064655e+01 +-5.514838139366095504e+01 +-5.513045453384619066e+01 +-5.511423364029791117e+01 +-5.509955636886144958e+01 +-5.508627582447106619e+01 +-5.507425909097476335e+01 +-5.506338590086473772e+01 +-5.505354743159977460e+01 +-5.504464521647263098e+01 +-5.503659015912219132e+01 +-5.502930164182708950e+01 +-5.502270671865647955e+01 +-5.501673938540263009e+01 +-5.501133991898866782e+01 +-5.500645427973988433e+01 +-5.500203357053655395e+01 +-7.000000000000000000e+01 +-7.000000000000000000e+01 +-6.926649054449073617e+01 +-6.790504796543287114e+01 +-6.667316377739392408e+01 +-6.555850886936944732e+01 +-6.454992740039146781e+01 +-6.363732514812252106e+01 +-6.281156848248568281e+01 +-6.206439295322486061e+01 +-6.138832057650884622e+01 +-6.077658499275570136e+01 +-6.022306374663178019e+01 +-5.972221701146096962e+01 +-5.926903214477727033e+01 +-5.885897352011421191e+01 +-5.848793713293072472e+01 +-5.815220952635421980e+01 +-5.784843062565614247e+01 +-5.757356010949469294e+01 +-5.732484698135696277e+01 +-5.709980203666116694e+01 +-5.689617294996057950e+01 +-5.671192173291339600e+01 +-5.654520433741043917e+01 +-5.639435219972186530e+01 +-5.625785554095053698e+01 +-5.613434825665734706e+01 +-5.602259424442886626e+01 +-5.592147503254888363e+01 +-5.582997858595757634e+01 +-5.574718917746442770e+01 +-5.567227822284276328e+01 +-5.560449598808028782e+01 +-5.554316408578910824e+01 +-5.548766868567671651e+01 +-5.543745437112614383e+01 +-5.539201858039976401e+01 +-5.535090657683247883e+01 +-5.531370689767437909e+01 +-5.528004723603319093e+01 +-5.524959071470181726e+01 +-5.522203251457797535e+01 +-5.519709682393220618e+01 +-5.517453407799133913e+01 +-5.515411846121040895e+01 +-5.513564564723473893e+01 +-5.511893075393314234e+01 +-5.510380649303536416e+01 +-5.509012149585493034e+01 +-5.507773879834034858e+01 +-5.506653447029293602e+01 +-5.505639637503169581e+01 +-5.504722304709170544e+01 +-5.503892267672368632e+01 +-5.503141219103114423e+01 +-5.502461642254891672e+01 +-5.501846735694188339e+01 +-5.501290345229467960e+01 +-5.500786902317950933e+01 +-5.500331368333765170e+01 +-7.000000000000000000e+01 +-7.000000000000000000e+01 +-6.970218804653360678e+01 +-6.829928336822604251e+01 +-6.702988272135567627e+01 +-6.588128151758830597e+01 +-6.484198417001844916e+01 +-6.390158904147172336e+01 +-6.305068434142390288e+01 +-6.228075392963797441e+01 +-6.158409208377022992e+01 +-6.095372637791109582e+01 +-6.038334790020310550e+01 +-5.986724811113052169e+01 +-5.940026171053717974e+01 +-5.897771494156639704e+01 +-5.859537881413143623e+01 +-5.824942677976131478e+01 +-5.793639643421757057e+01 +-5.765315486458885630e+01 +-5.739686729404557042e+01 +-5.716496871044046912e+01 +-5.695513819480503059e+01 +-5.676527569281230967e+01 +-5.659348099672737220e+01 +-5.643803472748960104e+01 +-5.629738112658917260e+01 +-5.617011248551297342e+01 +-5.605495505692464064e+01 +-5.595075630657310484e+01 +-5.585647337834245718e+01 +-5.577116265699736175e+01 +-5.569397032416468107e+01 +-5.562412381303218467e+01 +-5.556092407624024077e+01 +-5.550373858958086259e+01 +-5.545199502148285831e+01 +-5.540517550492509713e+01 +-5.536281145444927887e+01 +-5.532447887639919770e+01 +-5.528979412544968852e+01 +-5.525841006495532781e+01 +-5.523001259269011598e+01 +-5.520431749720692238e+01 +-5.518106761335371857e+01 +-5.516003024847834979e+01 +-5.514099485356224051e+01 +-5.512377091597505796e+01 +-5.510818605276025295e+01 +-5.509408428536852398e+01 +-5.508132447857204994e+01 +-5.506977892793569396e+01 +-5.505933208170809223e+01 +-5.504987938434088335e+01 +-5.504132623006167080e+01 +-5.503358701602759595e+01 +-5.502658428558338244e+01 +-5.502024795304903648e+01 +-5.501451460227884382e+01 +-5.500932685197125238e+01 +-5.500463278137750933e+01 +-5.500038541066138720e+01 +-7.000000000000000000e+01 +-7.000000000000000000e+01 +-6.870552502647927895e+01 +-6.739746537450817243e+01 +-6.621388405638161601e+01 +-6.514293539245240083e+01 +-6.417390096853361570e+01 +-6.329708236240698938e+01 +-6.250370407875347922e+01 +-6.178582572104663484e+01 +-6.113626252139528106e+01 +-6.054851343297157484e+01 +-6.001669606534927937e+01 +-5.953548781156323599e+01 +-5.910007257766987721e+01 +-5.870609258166029321e+01 +-5.834960473931316471e+01 +-5.802704120048257153e+01 +-5.773517364085456194e+01 +-5.747108095179229537e+01 +-5.723212000489901641e+01 +-5.701589919870068002e+01 +-5.682025452269452614e+01 +-5.664322789920463208e+01 +-5.648304758628241018e+01 +-5.633811044551767822e+01 +-5.620696589729060122e+01 +-5.608830140288332444e+01 +-5.598092932815129785e+01 +-5.588377505728161054e+01 +-5.579586623767671227e+01 +-5.571632304832282756e+01 +-5.564434939424551629e+01 +-5.557922493892358773e+01 +-5.552029789491908929e+01 +-5.546697850056957435e+01 +-5.541873311745511188e+01 +-5.537507888956567115e+01 +-5.533557891071583157e+01 +-5.529983785184086997e+01 +-5.526749800441058369e+01 +-5.523823570036207542e+01 +-5.521175807272104663e+01 +-5.518780012449062156e+01 +-5.516612207647236232e+01 +-5.514650696747546021e+01 +-5.512875848289621672e+01 +-5.511269898993547400e+01 +-5.509816775978991643e+01 +-5.508501935902411617e+01 +-5.507312219402389530e+01 +-5.506235719396314465e+01 +-5.505261661910301996e+01 +-5.504380298249639480e+01 +-5.503582807430574775e+01 +-5.502861207896945217e+01 +-5.502208277638079892e+01 +-5.501617481908490959e+01 +-5.501082907825942669e+01 +-5.500599205193341135e+01 +-5.500161532952159860e+01 +-7.000000000000000000e+01 +-7.000000000000000000e+01 +-6.912413858510710440e+01 +-6.777624258605182206e+01 +-6.655661585048564177e+01 +-6.545305194410831007e+01 +-6.445450602842416288e+01 +-6.355098432028617594e+01 +-6.273344407075515505e+01 +-6.199370306222903793e+01 +-6.132435771805894120e+01 +-6.071870900506569058e+01 +-6.017069538736406997e+01 +-5.967483216047438788e+01 +-5.922615655855655348e+01 +-5.882017808538148529e+01 +-5.845283357193557805e+01 +-5.812044651085950875e+01 +-5.781969026072687257e+01 +-5.754755475189868008e+01 +-5.730131636073468115e+01 +-5.707851065065251817e+01 +-5.687690770721810907e+01 +-5.669448982041246410e+01 +-5.652943129071167050e+01 +-5.638008015687238839e+01 +-5.624494166254851280e+01 +-5.612266329626723405e+01 +-5.601202125503962037e+01 +-5.591190819612900498e+01 +-5.582132215439263234e+01 +-5.573935651427780158e+01 +-5.566519093610863678e+01 +-5.559808314585090017e+01 +-5.553736150618399137e+01 +-5.548241829452886975e+01 +-5.543270362075625002e+01 +-5.538771992370134001e+01 +-5.534701699140445186e+01 +-5.531018745523844871e+01 +-5.527686271282654218e+01 +-5.524670923894584007e+01 +-5.521942524749480441e+01 +-5.519473767111653473e+01 +-5.517239942824885901e+01 +-5.515218695024901052e+01 +-5.513389794384352172e+01 +-5.511734936650913141e+01 +-5.510237559452171752e+01 +-5.508882676533836786e+01 +-5.507656727772268823e+01 +-5.506547443460208058e+01 +-5.505543721507415000e+01 +-5.504635516327223854e+01 +-5.503813738296932456e+01 +-5.503070162785805053e+01 +-5.502397347840202002e+01 +-5.501788559702006154e+01 +-5.501237705414910550e+01 +-5.500739271844060596e+01 +-5.500288270498750620e+01 +-7.000000000000000000e+01 +-7.000000000000000000e+01 +-6.955550082456956318e+01 +-6.816655528104524819e+01 +-6.690978538165013845e+01 +-6.577261295081616765e+01 +-6.474365678463868790e+01 +-6.381261874396246725e+01 +-6.297018068714373840e+01 +-6.220791121095664522e+01 +-6.151818126627589578e+01 +-6.089408780398888155e+01 +-6.032938468695998324e+01 +-5.981842017659069199e+01 +-5.935608036832013568e+01 +-5.893773800994935641e+01 +-5.855920619054607812e+01 +-5.821669643643274838e+01 +-5.790678079486872321e+01 +-5.762635752594696470e+01 +-5.737262005933860110e+01 +-5.714302890519370237e+01 +-5.693528623807333844e+01 +-5.674731289954024049e+01 +-5.657722758924235507e+01 +-5.642332803622657877e+01 +-5.628407396203888879e+01 +-5.615807166509991077e+01 +-5.604406007207104778e+01 +-5.594089811660864342e+01 +-5.584755331918849919e+01 +-5.576309145370376541e+01 +-5.568666719741606386e+01 +-5.561751567068138513e+01 +-5.555494478177752171e+01 +-5.549832830021754404e+01 +-5.544709958922452131e+01 +-5.540074593464029817e+01 +-5.535880341350976863e+01 +-5.532085225098410319e+01 +-5.528651261907292280e+01 +-5.525544083519810101e+01 +-5.522732592250303441e+01 +-5.520188649749172782e+01 +-5.517886795384816878e+01 +-5.515803991425079289e+01 +-5.513919392467875014e+01 +-5.512214136813405219e+01 +-5.510671157689922950e+01 +-5.509275012443748665e+01 +-5.508011727983996764e+01 +-5.506868660935190007e+01 +-5.505834371098105606e+01 +-5.504898506952417137e+01 +-5.504051702055200224e+01 +-5.503285481298421900e+01 +-5.502592176087213716e+01 +-5.501964847589992758e+01 +-5.501397217292307573e+01 +-5.500883604159350426e+01 +-5.500418867778256526e+01 +-7.000000000000000000e+01 +-7.000000000000000000e+01 +-7.000000000000000000e+01 +-6.856875476726082752e+01 +-6.727371052629284520e+01 +-6.610190603905303419e+01 +-6.504161349237601542e+01 +-6.408222112207801047e+01 +-6.321412700685415587e+01 +-6.242864296902280330e+01 +-6.171790762032301814e+01 +-6.107480768249861569e+01 +-6.049290679521849512e+01 +-5.996638109881912015e+01 +-5.948996094715952410e+01 +-5.905887816723155481e+01 +-5.866881833768177046e+01 +-5.831587760863239112e+01 +-5.799652363063962213e+01 +-5.770756020175313239e+01 +-5.744609527885266687e+01 +-5.720951203310843169e+01 +-5.699544265987865543e+01 +-5.680174468092484830e+01 +-5.662647950176950218e+01 +-5.646789300959096636e+01 +-5.632439801747276675e+01 +-5.619455837930344444e+01 +-5.607707461634358737e+01 +-5.597077091160583961e+01 +-5.587458334188328024e+01 +-5.578754922964836993e+01 +-5.570879750825267962e+01 +-5.563754000399912059e+01 +-5.557306354783463576e+01 +-5.551472283771465754e+01 +-5.546193398020330534e+01 +-5.541416864667166919e+01 +-5.537094878560728262e+01 +-5.533184183811390255e+01 +-5.529645640871672896e+01 +-5.526443834814489264e+01 +-5.523546720888656125e+01 +-5.520925303804248330e+01 +-5.518553347537998377e+01 +-5.516407112754349384e+01 +-5.514465119214214184e+01 +-5.512707930793516198e+01 +-5.511117960959928297e+01 +-5.509679296760950251e+01 +-5.508377539561725200e+01 +-5.507199660938669439e+01 +-5.506133872286623898e+01 +-5.505169506834535298e+01 +-5.504296912888823812e+01 +-5.503507357235992714e+01 +-5.502792937737689272e+01 +-5.502146504243449954e+01 +-5.501561587029590328e+01 +-5.501032332048036722e+01 +-5.500553442337045595e+01 +-5.500120125007428129e+01 +-7.000000000000000000e+01 +-7.000000000000000000e+01 +-6.898320305138545905e+01 +-6.764871884160960747e+01 +-6.644122759482627316e+01 +-6.534864433278580975e+01 +-6.436003411497182469e+01 +-6.346550259804104144e+01 +-6.265609700990960107e+01 +-6.192371654740087195e+01 +-6.126103130068449332e+01 +-6.066140889307511941e+01 +-6.011884810197735618e+01 +-5.962791879663289762e+01 +-5.918370759154683469e+01 +-5.878176867167412212e+01 +-5.841807929720832959e+01 +-5.808899954264958865e+01 +-5.779123586720675121e+01 +-5.752180815193415953e+01 +-5.727801987369957715e+01 +-5.705743111747436558e+01 +-5.685783415684378639e+01 +-5.667723135833898596e+01 +-5.651381518844982565e+01 +-5.636595012322200660e+01 +-5.623215627938353833e+01 +-5.611109460317562991e+01 +-5.600155346865256689e+01 +-5.590243655132199052e+01 +-5.581275185576090081e+01 +-5.573160178739206572e+01 +-5.565817416905577630e+01 +-5.559173411246782592e+01 +-5.553161666321062739e+01 +-5.547722014564583048e+01 +-5.542800014114235552e+01 +-5.538346403935171480e+01 +-5.534316610799807989e+01 +-5.530670303183987357e+01 +-5.527370987615522324e+01 +-5.524385643435267923e+01 +-5.521684392315256673e+01 +-5.519240199226359778e+01 +-5.517028601862620008e+01 +-5.515027465814279140e+01 +-5.513216763039159929e+01 +-5.511578371415290434e+01 +-5.510095893368616515e+01 +-5.508754491760569039e+01 +-5.507540741392993766e+01 +-5.506442494644257835e+01 +-5.505448759891764610e+01 +-5.504549591504105877e+01 +-5.503735990301836978e+01 +-5.502999813490666270e+01 +-5.502333693165627437e+01 +-5.501730962570618289e+01 +-5.501185589375259610e+01 +-5.500692115301304597e+01 +-5.500245601494358993e+01 +-7.000000000000000000e+01 +-7.000000000000000000e+01 +-6.941027316485093479e+01 +-6.803514786039804108e+01 +-6.679088303044096619e+01 +-6.566502565434964822e+01 +-6.464630777309044163e+01 +-6.372453371570480840e+01 +-6.289047805760745291e+01 +-6.213579328943635716e+01 +-6.145292627237336092e+01 +-6.083504264379216409e+01 +-6.027595841666006038e+01 +-5.977007808811721645e+01 +-5.931233863780332882e+01 +-5.889815885544810925e+01 +-5.852339349057911733e+01 +-5.818429176546175086e+01 +-5.787745983605501721e+01 +-5.759982682527963505e+01 +-5.734861408864809107e+01 +-5.712130740465665468e+01 +-5.691563181161152585e+01 +-5.672952883904756050e+01 +-5.656113590586396356e+01 +-5.640876767898662081e+01 +-5.627089920598820072e+01 +-5.614615065285175888e+01 +-5.603327349412805347e+01 +-5.593113801727325551e+01 +-5.583872201610609665e+01 +-5.575510056022478977e+01 +-5.567943673799275217e+01 +-5.561097328044557742e+01 +-5.554902498228877050e+01 +-5.549297184413285322e+01 +-5.544225286733102820e+01 +-5.539636043931624698e+01 +-5.535483525324394805e+01 +-5.531726171109482948e+01 +-5.528326376423014921e+01 +-5.525250114977059468e+01 +-5.522466598513096869e+01 +-5.519947968662785343e+01 +-5.517669018132040293e+01 +-5.515606938417969474e+01 +-5.513741091533705685e+01 +-5.512052803456498395e+01 +-5.510525177231816230e+01 +-5.509142923862951591e+01 +-5.507892209293595442e+01 +-5.506760515951960855e+01 +-5.505736517470707270e+01 +-5.504809965328855981e+01 +-5.503971586281148376e+01 +-5.503212989548285350e+01 +-5.502526582839190894e+01 +-5.501905496364811654e+01 +-5.501343514082957142e+01 +-5.500835011486061887e+01 +-5.500374899309222343e+01 +-7.000000000000000000e+01 +-7.000000000000000000e+01 +-6.985034949958749451e+01 +-6.843334539485978496e+01 +-6.715118705939161714e+01 +-6.599104222161331279e+01 +-6.494129976205024946e+01 +-6.399145350533648013e+01 +-6.313199707088048029e+01 +-6.235432872981292007e+01 +-6.165066531599303801e+01 +-6.101396432946588533e+01 +-6.043785345275571785e+01 +-5.991656677457085323e+01 +-5.944488708262551313e+01 +-5.901809364802569746e+01 +-5.863191497862769808e+01 +-5.828248606850905134e+01 +-5.796630971569017277e+01 +-5.768022152096151700e+01 +-5.742135821751266889e+01 +-5.718712901439575802e+01 +-5.697518966701883159e+01 +-5.678341901515806001e+01 +-5.660989775367329457e+01 +-5.645288922345707050e+01 +-5.631082203036660871e+01 +-5.618227431818301909e+01 +-5.606595953819638112e+01 +-5.596071357299386051e+01 +-5.586548308558130316e+01 +-5.577931497723262311e+01 +-5.570134684855735685e+01 +-5.563079836831773406e+01 +-5.556696346361135852e+01 +-5.550920325325625981e+01 +-5.545693965365334321e+01 +-5.540964959313137683e+01 +-5.536685977686991578e+01 +-5.532814195000565860e+01 +-5.529310861151383705e+01 +-5.526140913596772464e+01 +-5.523272626436148158e+01 +-5.520677292887543786e+01 +-5.518328937980481896e+01 +-5.516204058589744363e+01 +-5.514281388208191714e+01 +-5.512541684104412809e+01 +-5.510967534735003426e+01 +-5.509543185483984473e+01 +-5.508254380985309950e+01 +-5.507088222450376946e+01 +-5.506033038572607552e+01 +-5.505078268717093692e+01 +-5.504214357226211263e+01 +-5.503432657783390169e+01 +-5.502725346877867452e+01 +-5.502085345504366387e+01 +-5.501506248314027658e+01 +-5.500982259507529903e+01 +-5.500508134828778850e+01 +-5.500079129078629592e+01 +-7.000000000000000000e+01 +-7.000000000000000000e+01 +-6.884366984965500080e+01 +-6.752246397962552749e+01 +-6.632698747149410679e+01 +-6.524527559455383141e+01 +-6.426650221276436525e+01 +-6.338087143314364624e+01 +-6.257951956517847236e+01 +-6.185442641003056252e+01 +-6.119833499169098445e+01 +-6.060467892672505741e+01 +-6.006751670569988732e+01 +-5.958147222856101877e+01 +-5.914168099881604235e+01 +-5.874374143801874482e+01 +-5.838367083329254825e+01 +-5.805786547700144951e+01 +-5.776306459963272744e+01 +-5.749631773491967834e+01 +-5.725495519058353722e+01 +-5.703656132915583044e+01 +-5.683895039146668182e+01 +-5.666014462083236936e+01 +-5.649835446900168279e+01 +-5.635196068575556438e+01 +-5.621949811290663490e+01 +-5.609964102050359713e+01 +-5.599118983848034503e+01 +-5.589305915095547306e+01 +-5.580426683302538038e+01 +-5.572392422132807610e+01 +-5.565122722000162980e+01 +-5.558544825302244874e+01 +-5.552592898237993779e+01 +-5.547207371920838170e+01 +-5.542334346193257488e+01 +-5.537925050175891784e+01 +-5.533935354152181674e+01 +-5.530325327903339883e+01 +-5.527058841073295525e+01 +-5.524103201563949739e+01 +-5.521428828341667838e+01 +-5.519008955380354564e+01 +-5.516819363778064655e+01 +-5.514838139366095504e+01 +-5.513045453384619066e+01 +-5.511423364029791117e+01 +-5.509955636886144958e+01 +-5.508627582447106619e+01 +-5.507425909097476335e+01 +-5.506338590086473772e+01 +-5.505354743159977460e+01 +-5.504464521647263098e+01 +-5.503659015912219132e+01 +-5.502930164182708950e+01 +-5.502270671865647955e+01 +-5.501673938540263009e+01 +-5.501133991898866782e+01 +-5.500645427973988433e+01 +-5.500203357053655395e+01 +-7.000000000000000000e+01 +-7.000000000000000000e+01 +-6.926649054449073617e+01 +-6.790504796543287114e+01 +-6.667316377739392408e+01 +-6.555850886936944732e+01 +-6.454992740039146781e+01 +-6.363732514812252106e+01 +-6.281156848248568281e+01 +-6.206439295322486061e+01 +-6.138832057650884622e+01 +-6.077658499275570136e+01 +-6.022306374663178019e+01 +-5.972221701146096962e+01 +-5.926903214477727033e+01 +-5.885897352011421191e+01 +-5.848793713293072472e+01 +-5.815220952635421980e+01 +-5.784843062565614247e+01 +-5.757356010949469294e+01 +-5.732484698135696277e+01 +-5.709980203666116694e+01 +-5.689617294996057950e+01 +-5.671192173291339600e+01 +-5.654520433741043917e+01 +-5.639435219972186530e+01 +-5.625785554095053698e+01 +-5.613434825665734706e+01 +-5.602259424442886626e+01 +-5.592147503254888363e+01 +-5.582997858595757634e+01 +-5.574718917746442770e+01 +-5.567227822284276328e+01 +-5.560449598808028782e+01 +-5.554316408578910824e+01 +-5.548766868567671651e+01 +-5.543745437112614383e+01 +-5.539201858039976401e+01 +-5.535090657683247883e+01 +-5.531370689767437909e+01 +-5.528004723603319093e+01 +-5.524959071470181726e+01 +-5.522203251457797535e+01 +-5.519709682393220618e+01 +-5.517453407799133913e+01 +-5.515411846121040895e+01 +-5.513564564723473893e+01 +-5.511893075393314234e+01 +-5.510380649303536416e+01 +-5.509012149585493034e+01 +-5.507773879834034858e+01 +-5.506653447029293602e+01 +-5.505639637503169581e+01 +-5.504722304709170544e+01 +-5.503892267672368632e+01 +-5.503141219103114423e+01 +-5.502461642254891672e+01 +-5.501846735694188339e+01 +-5.501290345229467960e+01 +-5.500786902317950933e+01 +-5.500331368333765170e+01 +-7.000000000000000000e+01 +-7.000000000000000000e+01 +-6.970218804653360678e+01 +-6.829928336822604251e+01 +-6.702988272135567627e+01 +-6.588128151758830597e+01 +-6.484198417001844916e+01 +-6.390158904147172336e+01 +-6.305068434142390288e+01 +-6.228075392963797441e+01 +-6.158409208377022992e+01 +-6.095372637791109582e+01 +-6.038334790020310550e+01 +-5.986724811113052169e+01 +-5.940026171053717974e+01 +-5.897771494156639704e+01 +-5.859537881413143623e+01 +-5.824942677976131478e+01 +-5.793639643421757057e+01 +-5.765315486458885630e+01 +-5.739686729404557042e+01 diff --git a/examples/one_neuron_noise_example.py b/examples/one_neuron_noise_example.py new file mode 100644 index 00000000..8c694fcf --- /dev/null +++ b/examples/one_neuron_noise_example.py @@ -0,0 +1,98 @@ +# encoding: utf-8 +""" +A conversion to PyNN of the "One neuron with noise" example from the NEST examples gallery. + +See: https://nest-simulator.readthedocs.io/en/stable/auto_examples/one_neuron_with_noise.html + + +Usage: one_neuron_noise_example.py [-h] [--plot-figure] [--debug DEBUG] simulator + +positional arguments: + simulator neuron, nest, brian or another backend simulator + +optional arguments: + -h, --help show this help message and exit + --plot-figure plot the simulation results to a file + --debug DEBUG print debugging information +""" + +from pyNN.utility import get_simulator, init_logging, normalized_filename +from pyNN.utility.plotting import Figure, Panel + +sim, options = get_simulator(("--plot-figure", "Plot the simulation results to a file.", {"action": "store_true"}), + ("--debug", "Print debugging information.")) + + +if options.debug: + init_logging(None, debug=True) + +# === Define parameters ======================================================== + +cell_params = { + "v_rest": -70.0, # (mV) + "v_reset": -70.0, # (mV) + "cm": 0.250, # (nF) + "tau_m": 10, # (ms) + "tau_refrac": 2, # (ms) + "tau_syn_E": 2, # (ms) + "tau_syn_I": 2, # (ms) + "v_thresh": -55.0, # (mV) + "i_offset": 0, # (nA) +} + +# === Build the network ======================================================== + +sim.setup(timestep=0.01) # (ms) + +cell_type = sim.IF_curr_alpha(**cell_params) + +neuron = sim.Population(1, cell_type, initial_values={"v": -70}, label="Neuron") +neuron.record(["v", "spikes"]) + +poisson_noise_generators = sim.Population(2, sim.SpikeSourcePoisson(rate=[80000, 15000])) +poisson_noise_generators.record("spikes") + +prjs = [ + sim.Projection( + poisson_noise_generators[0:1], + neuron, + sim.AllToAllConnector(), + sim.StaticSynapse(weight=0.0012, delay=1), + receptor_type="excitatory", + ), + sim.Projection( + poisson_noise_generators[1:2], + neuron, + sim.AllToAllConnector(), + sim.StaticSynapse(weight=-0.001, delay=1), + receptor_type="inhibitory", + ), +] + +# === Run simulation =========================================================== + +sim.run(1000) + +data_v = neuron.get_data().segments[0].filter(name="v")[0] +data_spikes = neuron.get_data().segments[0].spiketrains + +if options.plot_figure: + figure_filename = normalized_filename( + "Results", "one_neuron_noise_example", "png", options.simulator + ) + Figure( + Panel( + data_v[:, 0], + xlabel="Time (in ms)", + ylabel="Membrane Potential", + xticks=True, + yticks=True, + ), + title="One neuron with noise", + annotations=f"One neuron with noise example using PyNN (simulator: {options.simulator})", + ).save(figure_filename) + print(figure_filename) + +# === Clean up and quit ======================================================== + +sim.end() diff --git a/examples/two_neuron_example.py b/examples/two_neuron_example.py new file mode 100644 index 00000000..fe5296f4 --- /dev/null +++ b/examples/two_neuron_example.py @@ -0,0 +1,79 @@ +""" +A conversion to PyNN of the "Two neuron example" from the NEST examples gallery. + +See: https://nest-simulator.readthedocs.io/en/stable/auto_examples/twoneurons.html + +Usage: two_neuron_example.py [-h] [--plot-figure] [--debug DEBUG] simulator + +positional arguments: + simulator neuron, nest, brian or another backend simulator + +optional arguments: + -h, --help show this help message and exit + --plot-figure plot the simulation results to a file + --debug DEBUG print debugging information + +""" + +from pyNN.utility import get_simulator, init_logging, normalized_filename +from pyNN.utility.plotting import Figure, Panel + +sim, options = get_simulator(("--plot-figure", "Plot the simulation results to a file.", {"action": "store_true"}), + ("--debug", "Print debugging information.")) + +if options.debug: + init_logging(None, debug=True) + +# === Define parameters ======================================================== + +cell_params = { + "v_rest": -70.0, # (mV) + "v_reset": -70.0, # (mV) + "cm": 0.250, # (nF) + "tau_m": 10, # (ms) + "tau_refrac": 2, # (ms) + "tau_syn_E": 2, # (ms) + "tau_syn_I": 2, # (ms) + "v_thresh": -55.0, # (mV) + "i_offset": 0, # (nA) +} + +# === Build the network ======================================================== + +sim.setup(timestep=0.1) # (ms) + +cell_type = sim.IF_curr_alpha(**cell_params) +neurons = sim.Population(2, cell_type, initial_values={"v": -70}, label="Neurons") +neurons[0:1].set(i_offset=0.376) +neurons.record("v") + +syn = sim.StaticSynapse(weight=0.02, delay=1.0) +projection1 = sim.Projection(neurons[0:1], neurons[1:2], sim.AllToAllConnector(), syn) + +# === Run simulation =========================================================== + +sim.run(1000) + +data = neurons.get_data().segments[0].filter(name="v")[0] + +if options.plot_figure: + figure_filename = normalized_filename( + "Results", "two_neuron_example", "png", options.simulator + ) + + Figure( + Panel( + data, + xticks=True, + yticks=True, + xlabel="Time (in ms)", + ylabel="Membrane Potential (in mV)", + ), + title="Two neurons", + annotations=f"Two neuron example using PyNN (simulator: {options.simulator})", + ).save(figure_filename) + print(figure_filename) + +# === Clean up and quit ======================================================== + +sim.end()