Parametric Scans
It is often useful to create a series of "parametric" runs where simulations are carried out over a range of input parameters of interest. It can be a challenge to organize these. This difficulty can be further compounded because it is difficult to carry out multiple runs within a single generation cycle of the code. (This is because many internal parameters are set during the generation of the run and these must all be (re)set consistently to repeat the run taking into account whatever has varied. It is not recommended that users attempt to do this.)
Fortunately, the Warp runcounter package include tools to make it more straightforward to run a single script while varying parameters. Within a run script.py, include:
from runcounter import *
i = runcounter()
Then the index i will be incremented by unity with each execution of script.py calling runcounter(). The counter i can be used within script.py to vary a parameter of interest, for example
top.ibeam = 0.1 + 0.01*i
to increment the current by 0.01 A each successive run starting from 0.1 A on the first execution of script.py. Various options detailed in doc(runcounter) can be used to set properties of the counter, such as starting value and increment. The run index is stored in a text file "script_runcounter", where "script" is the runid. This file can be deleted to reset the counter or modified to control index on the subsequent simulation. The latter can be useful to repeat a particular run.
Note that cgm output of each execution of script.py will be stored in script.xxx.cgm with xxx incremented by unity each run starting from 000 on the first execution. Correspondence of these run output files to the parameter varied must be known for the runs to be useful.
The runcounter package also has a function accumulatedata() which can be used to accumulate the data from each of the runs. The data is saved in PWpickle file and can be accessed for post processing.
runcounter() also supports multidimensional parameter scans. For example,
i1, i2 = runcounter(ensambles=[10])
gives two run counters i1 and i2. i1 will vary from 0 to 9 and i2 will be incremented every 10th run.
Sometimes it can be useful to write a shell script or python script to execute the parametric runs. To do this using python (loading Warp if relevant functionality is desired), the Warp run is executed using the following lines.
import os # This is not needed if Warp is loaded in python
os.system('python script.py')
Here, os.system('str') executes the command 'str' in a subshell. Note that python execution is not blocked until the command is complete.
An alternative way to carry out parametric scans is to use a stream editor such as "sed" within a shell script, or some other means, to edit and then execute the run script script.py. Details of such procedures will depend method used to edit the file. It is not recommended to do the scans this way unless a complicated pattern is needed that can not be generated by runcounter.