Page 1 of 1

Automating tasks: batch run procedures

Posted: Wed Jun 29, 2011 1:35 pm
by ted
It is often necessary to run a series of simulations in which the values of one or more parameters (independent variables) differ from one run to the next. If these parameters do not affect the structure of the model (do not destroy, add, or move sections), the most straightforward way to run a batch of simulations is with a procedure that is executed _after_ the entire model specification has been executed, i.e. after
--all sections have been created and connected
--all artificial spiking cells have been created
--all synaptic mechanisms have been created and attached to spike sources and postsynaptic cells
--all instrumentation code has been executed. This means code that creates signal sources (for example IClamp, SEClamp) and code that takes care of signal monitoring (for example Graphs, Vector play and/or recording)
--all user interface code has been executed
--all control constants, variables, and procedures have been set up

The typical batch procedure contains one or more "for loops" that increment one or more independent variables over a range of values, followed by a run() statement--for example

Code: Select all

  batchrun(5, 50)
executes 5 simulations, each lasting 50 ms,
with soma.gnabar_hh(0.5) stepping from 0 to 0.4*default gnabar_hh
proc batchrun() { local i, tmp
  t_stop = $2
  tmp = soma.gnabar_hh(0.5)
  for i=0,$1-1 {
    soma.gnabar_hh(0.5) = tmp*i/10
hoc's iterator (see Programmer's Reference) can be useful for iterating an independent variable over a series of values that are not easily described by a simple algebraic expression. Alternatively, the independent variable's values might be passed in a Vector argument. It is often useful to call a "postprocessing procedure" immediately after run(), for the purpose of saving simulation results to a file or performing some preliminary data analysis on simulation results before saving them to a file.

If one or more of the independent variables affects the structure of your model, it may not be practical to use a hoc batchrun() procedure. Instead, it may be better to use a shell script and pass parameters via command line arguments, as described in this thread:
Automating tasks: -c "statement" and batch runs

Users who have access to parallel hardware may be able to speed up batch simulations by using "bulletin-board style parallelization." This is supported by NEURON's ParallelContext class and works well on hardware that ranges from multicore Macs and PCs to workstation clusters and massively parallel supercomputers. But that's a different story, not for this discussion thread.