Class implementing a TestProgram object representing the simulation to run.
Parameters: |
|
---|
Example1:
p1 = UniformParameter('x', 'x', min=-2, max=2)
p2 = UniformParameter('y', 'y', min=-2, max=2)
prog = TestProgram('./rosen_prog.py', desc='Rosenbrock Function')
# or, the equivalent using template strings
prog = TestProgram(exe='./rosen_prog.py --x=$x --y=$y',
desc='Rosenbrock Function')
Example2:
# Using newdir and infiles. Will run each job in a new directory
# with a copy of all the infiles.
prog = TestProgram('PM2', newdir=True, desc='MPM Scaling',
infiles=['pm2geometry', 'pm2input', 'pmgrid_geom.nc',
'pmpart_geom.nc'])
Example3:
# Using newdir and paramsByFile
# In this case, all parameters to rosen_prog.py located in the same directory
# as this script will be passed in the file named input_params.txt
# located in a subdirectory of the control script's directory. Ie., for the
# example below, the file structure is the following (assuming this script
# is named rosen.py contained in a directory called Rosen)
# Rosen
# |_ rosen.py
# |_ rosen_prog.py
# |_ Run 1
# |__ input_params.txt
# |_ Run 2
# |__ input_params.txt
# .
# .
# .
#
# input_params.txt contains 3 columns, separated by whitespace.
# The first column is the parameter name, the second is the parameter value,
# the third is the parameter description.
#
# Rosen_prog then reads the parameters from the file name passed to it in the
# --paramsFile argument. The contents of input_params.txt can be loaded using numpy's loadtxt
# with record-data type.
prog = TestProgram(exe='python ../rosen_prog.py --paramsFile=input_params.txt',
newdir=True, paramsByFile=True, desc='Rosenbrock Function')
Example4:
# Instead of running an executable or python script directly, can call a python function
# instead. This results in much faster execution if the test program is a python scripty
# since the overhead of starting a new python interpreter is eliminated. Note this can
# only be used with InteractiveHostMP.
#
# The equivalent of example 3 is given below. Note that rosen_prog must have a function
# named 'run' with the signature
# def run(args=None, jobinfo=None)
# The 'run' function must ALWAYS return the jobinfo argument on every possible exit path of
# the function.
# The argument 'args' is the same string as would be passed when using exe (see example1) and
# is given by func_args of the TestProgram constructor. 'args' can be directly parsed by
# argparse or optparse.
import rosen_prog
prog=TestProgram(func=rosen_prog.run, func_args='--paramsFile=input_params.txt',
newdir=True, paramsByFile=True desc='Rosenbrock Function')