repeated execution

Anything that doesn't fit elsewhere.
Post Reply
rllin

repeated execution

Post by rllin »

If I had a loop to "xopen" a file to run, do I need it to wait until it's done somehow? The issue is

Code: Select all

for i=0, num_run - 1 {
	xopen("SIE_fig2_10.hoc")
	strobj.right(wfilename, 1)
	print i*100000
}
	
The loop seems to get stuck (i*100000 stays the same) yet does go through the first two steps until the file breaks. Thanks!
ted
Site Admin
Posts: 5793
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: repeated execution

Post by ted »

Are you trying to execute a series of simulations?
rllin

Re: repeated execution

Post by rllin »

Yes, and changing some parameter between each.
ted
Site Admin
Posts: 5793
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: repeated execution

Post by ted »

Each time you xopen a file, the contents of the file may destroy previously existing variables, procedures, functions, sections, and objects. And if the file contains a template, hoc will simply refuse to continue because it will not read the same template more than once.

If the parameters you want to vary do not affect the structure of the model (do not destroy, add, or move sections), the best 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

/*
usage:
  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
    run()
  }
}
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 of your parameters 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
viewtopic.php?f=28&t=1747
rllin

Re: repeated execution

Post by rllin »

Thanks! Makes sense. I seem to have run into issues using objects inside my procedures though?

EDIT: Never mind. I was both loading and xopening the file. Thanks!



For example:

Code: Select all

// 29 June 2011 Saver



/*****************************WRITING************************/

proc save() {
	//RECORD STIM AND SPIKES
	wfilename = $1
	
	objref dataf, fullVec
	dataf = new File()
	fullVec = new Vector()
	fullVec.insrt(0, stimVec.size()/(tstop-2*buffer), rNCVec.size()/(tstop-2*buffer), IrVec.max(), tstop, stimVec, -1e99, rNCVec)
	
	fullVec.printf()
	dataf.wopen(wfilename)
	fullVec.vwrite(dataf)
	dataf.close()
	printf("saved in %s", wfilename)
}
will return

Code: Select all

/Applications/NEURON-7.2/nrn/i386/bin/nrniv.app/Contents/MacOS/nrniv: syntax error
 in saver.hoc near line 12
 	dataf = new File()
            ^
        xopen("saver.hoc")
      execute1("{xopen("saver.hoc")}")
    load_file("saver.hoc")
	0 
/Applications/NEURON-7.2/nrn/i386/bin/nrniv.app/Contents/MacOS/nrniv: syntax error
 in saver.hoc near line 13
 	fullVec = new Vector()
              ^


EDIT: Never mind. I was both loading and xopening the file. Thanks!
Post Reply