|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
Running an Experiment with
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Setting | Default Value | Description |
|---|---|---|
FunctionName | (none) | The name of the gsmatlab-compliant function that performs a simulation run. Must take three parameters, in this order: (1) a data structure mapping parameter names to parameter values; (2) the run number, passed as an integer literal; and (3) the seed for the random number generator, passed as an integer literal. A return value, if present, will be ignored. |
MatlabSearchPath | (none) | Search path that enables Matlab or Octave to call your function, i.e., the directory where your run_model.m file resides. Search paths are added using the built-in Matlab/Octave function addpath. You can provide multiple directories using the format <setting name="MatlabSearchPath">[search paths]</setting>, one search path per line. |
MatlabExecutablePath | "/usr/local/bin/matlab" | The full path to the Matlab or Octave executable in your environment. |
MatlabOptions | "-nodisplay" | Options to pass to the Matlab/Octave executable. Note that Octave does not understand "-nodisplay", so you will need to override it with "" (or something else Octave understands). You can provide multiple options to be loaded using the format <setting name="MatlabOptionsOptions">[options]</setting>, one option per line. |
gsmatlabTo run your experiment, follow the instructions described in Running An Experiment above, but be sure to use the gsmatlab command:
gsmatlab -d /path/to/experiment.xml
will perform a dry run, without actually executing your script so you can verify that output directories match your expectations, and
gsmatlab /path/to/experiment.xml
will perform an actual run. What gsmatlab will actually do is start running an instance of Matlab or Octave, e.g., by running
/usr/local/bin/matlab -nodisplay
and then sending it a series of commands that add the search path, construct a parameters data structure, and finally run your model, in that order. For our example, one of the runs might send these commands to Matlab:
addpath('/path/to/modeldir');
params.alpha = 0.5;
params.beta = 0.3;
params.gamma = 0.4;
params.nu = 0.09;
run_model(params, 15, 459410224);
Again, remember that because there are many possible ways to generate random numbers, gsmatlab will not initialize the random number generator for you: you must do this yourself in your script.
gsr)GridSweeper supports running experiments based on scripts written in R via the gsr tool. Most R users tend to perform parameter sweeps by writing nested loops to sweep over different parameter values. To produce a script that works with gsr, you typically just need to remove your outer loops and wrap your script in a function following the right format.
To be used with gsr, an R script needs to contain a function that takes three parameters, in this order:
gsr will not automatically seed the R random number generator for you: because you may want to use a different generator than the default, you need to call set.seed yourself.
The process is best illustrated with a simple example. The following is a gsr-compliant script that uses parameters to generate a series of random numbers that are written into a file appropriately tagged with the run number:
run_model = function(params, run_number, random_seed)
{
# Initialize standard random number generator
set.seed(random_seed);
# Redirect output to an output file
sink(sprintf("output.%d.txt", run_number))
# Print out parameter values
cat(sprintf("alpha=%f\n", params$alpha))
cat(sprintf("beta=%f\n", params$beta))
cat(sprintf("gamma=%f\n", params$gamma))
cat(sprintf("nu=%f\n", params$nu))
# Print 100 U(0,1) random numbers multiplied by the parameter values
for(i in 1:100)
{
cat(sprintf("%e\n", runif(1) * params$alpha
* params$beta * params$gamma * params$nu));
}
# Restore output to console
sink();
}
Once you have a script properly formatted to accept input from gsr, you can write a control file for your experiment, as described in detail in Getting Started with GridSweeper. An experiment file that uses all the gsr options will look something like this:
<?xml version="1.0" encoding="UTF-8"?>
<experiment name="huge-experiment" numRuns="16">
<setting key="ResultsDirectory" value="/path/to/gs-results"/>
<setting key="EmailAddress" value="ed@example.com"/>
<!-- gsr settings-->
<setting key="FunctionName" value="run_model"/>
<setting key="RExecutablePath" value="/usr/local/bin/R"/>
<setting key="RInputFile" value="/path/to/inputfile.R"/>
<setting key="ROptions" value="--vanilla"/>
<abbrev param="alpha" abbrev="a"/>
<abbrev param="beta" abbrev="b"/>
<abbrev param="gamma" abbrev="g"/>
<abbrev param="nu" abbrev="n"/>
<value param="alpha" value="0.5"/>
<value param="beta" value="0.3"/>
<value param="gamma" value="0.1"/>
<value param="nu" value="0.04"/>
<list param="nu">
<item value="0.05"/>
<item value="0.06"/>
<item value="0.09"/>
</list>
<range param="gamma" start="0.1" end="0.5" increment="0.1" />
</experiment>
Settings specific to gsr experiment files are as follows:
| Setting | Default Value | Description |
|---|---|---|
FunctionName | (none) | The name of the gsr-compliant function that performs a simulation run. Must take three parameters, in this order: (1) a named list mapping parameter names to parameter values; (2) the run number, passed as an integer literal; and (3) the seed for the random number generator, passed as an integer literal. A return value, if present, will be ignored. |
RInputFile | (none) | File to load into R containing the definition of your function. Files are loaded using the standard source R command. You can provide multiple files to be loaded using the format <setting name="RInputFile">[input files]</setting>, one file per line. |
RExecutablePath | "/usr/local/bin/R" | The full path to the R executable in your environment. |
ROptions | "--vanilla" | Options to pass to the R executable. You can provide multiple options to be loaded using the format <setting name="ROptions">[options]</setting>, one option per line. |
gsrTo run your experiment, follow the instructions described in Running An Experiment above, but be sure to use the gsr command:
gsr -d /path/to/experiment.xml
will perform a dry run, without actually executing your script so you can verify that output directories match your expectations, and
gsr /path/to/experiment.xml
will perform an actual run. What gsr will actually do is start running an instance of R, e.g., by running
/usr/local/bin/R --vanilla
and then sending it a series of commands that load the input file, construct a list of parameter values, and finally run your model, in that order. For our example, one of the runs might send these commands to R:
source("/path/to/inputfile.R")
params = list()
params$alpha = 0.5
params$beta = 0.3
params$gamma = 0.4
params$nu = 0.09
run_model(params, 15, 459410224)
Again, remember that gsr will not initialize the random number generator for you: you must do this yourself in your script using, e.g., set.seed.
gsnetlogo)GridSweeper can run distributed batches of NetLogo models, typically with zero or very little modification of the model. Experiment XML files for NetLogo models are run using the gsnetlogo tool, which handles converting parameter settings and random seeds to NetLogo's native format.
NOTE: NetLogo has a built-in mechanism for performing parameter sweeps on a single machine, called BehaviorSpace. In fact, gsnetlogo controls NetLogo by generating BehaviorSpace-compatible XML for each run of the model. However, as of version 1.0, gsnetlogo does not parse user-created BehaviorSpace experiments from the .nlogo model file. This is planned for the future.
As long as your NetLogo model has parameters set up in the normal way, and can be controlled via standard setup and go commands, it should work unmodified with gsnetlogo. For example, here is an example model that comes with NetLogo 4.0.4:

In this model, all the slider parameters—altruistic-probability, selfish-probability, etc.—can be controlled by gsnetlogo automatically; they are modified in a GridSweeper experiment XML file normally. If you want to output data once per tick using the standard NetLogo output format used by BehaviorSpace, you need not make any modifications at all.
If you perform custom output to data files, you will need a way to receive the run number from GridSweeper. This is done by setting up an extra parameter—called whatever you like, say run-number—and then instructing GridSweeper to use that parameter to set the run number in the experiment XML file, as described in the next section.
Experiment control files for NetLogo models are largely as described in detail in Getting Started with GridSweeper, with several additional settings to tell GridSweeper how to talk to NetLogo.
An experiment file that uses all the gsnetlogo options will look something like this:
<?xml version="1.0" encoding="UTF-8"?>
<experiment name="huge-experiment" numRuns="16">
<setting key="ResultsDirectory" value="/path/to/gs-results"/>
<setting key="EmailAddress" value="ed@example.com"/>
<!-- gsnetlogo settings-->
<setting key="Model" value="/path/to/model.nlogo"/>
<setting key="NetLogoJarPath" value="/path/to/NetLogo.jar"/>
<setting key="JavaPath" value="/usr/bin/java"/>
<setting key="JavaOptions">
-server
-Xmx1024M
</setting>
<setting key="RunNumberVariable" value="run-number"/>
<setting key="Metrics"
%susceptible
%infected
</setting>
<setting key="OutputFormat" value="Table"/>
<setting key="RunMetricsEveryStep" value="true"/>
<setting key="Setup" value="setup"/>
<setting key="Go" value="go"/>
<setting key="Final" value="final"/>
<setting key="ExitCondition" value="%infected = 0"/>
<setting key="TimeLimit" value="1000"/>
<abbrev param="alpha" abbrev="a"/>
<abbrev param="beta" abbrev="b"/>
<abbrev param="gamma" abbrev="g"/>
<abbrev param="nu" abbrev="n"/>
<value param="alpha" value="0.5"/>
<value param="beta" value="0.3"/>
<value param="gamma" value="0.1"/>
<value param="nu" value="0.04"/>
<list param="nu">
<item value="0.05"/>
<item value="0.06"/>
<item value="0.09"/>
</list>
<range param="gamma" start="0.1" end="0.5" increment="0.1" />
</experiment>
Settings specific to gsnetlogo experiment files are as follows:
| Setting | Default Value | Description |
|---|---|---|
Model | (none) | The full path to the .nlogo model file. |
NetLogoJarPath | (none) | The full path to the NetLogo.jar file. If you are unsure where this is, ask your system administrator. |
JavaPath | "/usr/bin/java" | The full path to the Java executable. If you are unsure where this is, ask your system administrator or type which java at the command line to see where the default installation resides on your system. |
JavaOptions | "-server", "-Xmx1024M" | Command-line options to pass to the Java runtime. The default options are the ones recommended by the NetLogo team. To provide multiple options, use the format <setting key="JavaOptions">[options]</setting>, with one option on each line. |
RunNumberVariable | (none) | If provided, a variable used by GridSweeper to set the run number so your model can properly name custom output files. |
Metrics | (none) | A list of metrics—typically variables that your code updates each tick—to be automatically outputted to an output file. To provide multiple metrics, use the format <setting key="Metrics">[metrics]</setting>, with one metric on each line. |
OutputFormat | "Table" | The NetLogo standard output format to write metrics and other run data to, either "None", "Table", "Spreadsheet", or "Both" (case-sensitive). Output data will be written to table.[run-number].csv and/or spreadsheet.[run-number].csv. |
RunMetricsEveryStep | "true" | Whether to output metrics every timestep, or just at the end of the run. Must be "true" or "false". |
Setup | "setup" | NetLogo commands to set up the run. Multiple commands can be provided in the format <setting key="Setup">[commands]</setting>, one command per line. |
Go | "go" | NetLogo commands to cause the model to advance a tick. Multiple commands are allowed, as with Setup. |
Final | (none) | NetLogo commands to perform when the model has finished. Multiple commands are allowed, as with Setup. |
ExitCondition | (none) | A conditional statement that when true will cause the model to finish. |
TimeLimit | (none) | The maximum number of ticks to run the model for. |
gsnetlogoTo run your experiment, follow the instructions described in Running An Experiment above, but be sure to use the gsnetlogo command:
gsnetlogo -d /path/to/experiment.xml
will perform a dry run, without actually executing your model so you can verify that output directories match your expectations, and
gsnetlogo /path/to/experiment.xml
will perform an actual run.
When a run is executed, what actually happens is that GridSweeper generates a BehaviorSpace XML file, .gsnetlogo.[run-number].xml, in the working directory, and then runs a separate Java process for NetLogo, e.g., via:
/usr/bin/java -server -Xmx1024M -cp /path/to/NetLogo.jar org.nlogo.headless.HeadlessWorkspace --model /path/to/model.nlogo --setup-file .gsnetlogo.15.xml --table table.15.csv
NetLogo then runs the model in headless mode, generating output files as requested.
The GridSweeper tools (gsdrone, gsmatlab, etc.) support, in addition to running an experiment from the command line, flexible command-line options to create and modify parameter sweeps. To see full details about how to do this, you can view the manpage online or at the command line with
man gsdrone
GridSweeper installation is fairly straightforward: if you have the right system, download the package, unzip it in a convenient location, and perform a small bit of configuration.
GridSweeper is known to require the following:
python and mail
NOTE: GridSweeper has been tested primarily in a Linux environment using Sun Grid Engine 6.2u5. If you have success or issues on other platforms, please email gridsweeper@umich.edu with comments. Also see the Troubleshooting section in this manual.
First, download the GridSweeper 1.0 installation from the GridSweeper main page, and unzip it, e.g.,
unzip gridsweeper-1.0
First, you need to make sure GridSweeper can link against the DRMAA library (drmaa.jar). With Sun Grid Engine, drmaa.jar is located in the lib subdirectory of the SGE root.
The easiest way to do this is to add a symbolic link to drmaa.jar in the GridSweeper lib directory:
ln -s /path/to/sge/lib/drmaa.jar /path/to/gridsweeper/lib/drmaa.jar
If the JAVA_HOME environment variable is set, GridSweeper will use that version of Java. Otherwise, it will use the Java installation accessed via the command java at the shell prompt—that is, whatever comes up when you type which java. The same JAVA_HOME will be used on execution hosts. If you want to use a different Java configuration, set the JAVA_HOME environment variable. For more customization, you can modify gridsweeper/scripts/gsweep and gridsweeper/scripts/gsrunner via the JAVA and JAVA_OPTIONS variables at the top of these two files.
Finally, you will need to add the gridsweeper/scripts directory to your system search path, and add gridsweeper/man to your system manpage path, or instruct users to add them individually. E.g., a user might have to modify her .bash_profile like so:
export PATH=$PATH:/path/to/gridsweeper/scripts export MANPATH=$MANPATH:/path/to/gridsweeper/man
That's it. Now users should be able to use gsdrone, gsmatlab, gsr, and gsnetlogo scripts to submit experiments to the grid.
In GridSweeper, a software object called an adapter translates the parameter sweeps set up by the user into a format the desired model can understand, and actually runs the model itself. Built-in adapter classes provide support for Drone-style command-line programs, Matlab and R scripts, and NetLogo models.
Additional adapters can be installed in the plugins directory inside the GridSweeper installation directory, either in JAR files or as raw Java classes in a package directory hierarchy rooted in plugins.
If you are familiar with Java programming, it is fairly straightforward to implement a custom adapter. First, configure your programming environment to link against the gridsweeper/lib/gridsweeper.jar, and then create a class that implements the gridsweeper.adapter.Adapter interface.
Custom adapter classes must implement the run method defined in the interface as well as a single constructor, that takes an instance of gridsweeper.util.Settings as a parameter:
import gridsweeper.adapter.*;
import gridsweeper.util.*;
import java.io.*;
public class SampleAdapter implements Adapter
{
// Instance variables to store settings here
public SampleAdapter(Settings settings) throws AdapterException
{
// Load settings from the Settings object
}
public RunResults run(ParameterMap parameterMap, int runNumber,
int numRuns, int rngSeed, OutputStream stdout, OutputStream stderr)
throws AdapterException
{
// Run the model using the provided parameters, etc., passing
// output and error to the appropriate output streams if desired
}
}
The best way to get going is to look at the sample adapter provided in the GridSweeper source code (gridsweeper.example.SampleAdapter) as well as the source code for the built-in adapters in the gridsweeper.adapter package.
Once the adapter is completed, package it into a .jar file and place it in the gridsweeper/plugins folder. Users can now use your adapter by specifying it in experiment XML files:
<setting name="Adapter" value="my.adapter.ClassName"/>
and then running GridSweeper using the built-in gsweep tool:
gsweep /path/to/experiment.xml
To make things a bit easier, you can also write a script that sets the adapter, which is how the gsdrone, gsmatlab, etc. scripts work, so the user can just type
custom-script experiment.xml
without worrying about Java class names in their experiment file.
For example, if you add your script into /path/to/gridsweeper/scripts, it could look like this:
#!/bin/sh
ABSPATH=`python -c "import os; print os.path.abspath(\"$0\")"`
BINPATH=`dirname $ABSPATH`
GRIDSWEEPER_ROOT=`dirname $BINPATH`
ADAPTER="my.adapter.ClassName"
${GRIDSWEEPER_ROOT}/scripts/gsweep -a ${ADAPTER} "$@"
The experiment file format described here is used for both input and output files. Experiment files are written in XML with a simple set of elements. At the top level is the <experiment> element:
<?xml version="1.0" encoding="UTF-8"?> <experiment name="My Experiment" numRuns="10" firstSeedRow="0" seedCol="0" gridConfig="-q anotherqueue"> <!-- ... --> </experiment>
All attributes of the <experiment> element are optional. The name attribute is used to name experiment directories in the filesystem and in naming strings submitted to the grid. The numRuns attribute specifies how many runs with different random seeds should be completed for each case.
The attributes firstSeedRow and seedCol identify the starting seed location in a virtual table of random seeds that is used to extract the sequence of random seeds that will be assigned to runs. See Random Seed Generation for more information.
The gridConfig attribute passes along a configuration string to the underlying grid system. The format of this string is system-dependent. In Sun Grid Engine, for example, this string can contain the same options that would be passed to qsub, such as to specify a queue. Terminology note: gridConfig corresponds to the "native specification" in the DRMAA standard.
Elements that may appear within <experiment> are described below.
<setting>The <experiment> element will typically contain one or more <setting> elements, which look like this:
<setting key="key" value="value"/>
Values may also be assigned as multi-line XML content between start and end tags:
<setting key="key> value </setting>
See the earlier sections on using GridSweeper for a description of available settings.
<value>The <value> element is used to assign single values to parameters. It takes the form
<value param="param" value="value"/>
Parameter values can be any string; special XML entities must be properly escaped.
<list>The <list> element is used to define a list sweep for a particular parameter. It can contain <item> elements and <range> elements to specify parameter values, as shown here:
<list param="param"> <item value="0.1"/> <item value="0.3"/> <range start="0.5" end="1.0" increment="0.1"/> <!-- ... --> </list>
<range>The <range> element is used to define a range list sweep for a particular parameter. In addition to the parameter name, it supports and requires three attributes, for the start value, end value, and increment:
<range param="param" start="0.0" end="1.0" increment="0.1"/>
If provided as a child of a <list> element, the param attribute is optional, and a conflicting name will result in an error.
<multiplicative>The <multiplicative> tag is used to define a multiplicative combination sweep. This tag is strictly a container:
<multiplicative> <range param="param1" start="0.0" end="1.0" increment="0.1"/> <range param="param2" start="0" end="100" increment="5"/> </multiplicative>
<parallel>The <parallel> tag is used to define a parallel combination sweep. This is also just a container, whose children must all generate the exact same number of cases, six each in this example:
<parallel>
<range param="param1"
start="0.0" end="1.0" increment="0.2"/>
<range param="param2"
start="0" end="100" increment="20"/>
<list param="param3">
<item value="25"/>
<item value="399"/>
<item value="4096"/>
<item value="33333"/>
<item value="1677216"/>
<item value="10000000"/>
</list>
</parallel>
Case files are also written out as XML. The format is very simple, consisting of a single <case> element that in turn contains a number of <value> and <run> elements.
The <case> element includes a single attribute, name, which is intended for human readability only and is constructed by GridSweeper from the experiment name, the parameter settings, and the date. For example:
<case name="echo - r=0.4-s=0.9 (2007-07-20, 16-29-39)"> <!-- ... --> </case>
The <value> elements are the same as in experiment XML files, and are the only type of parameter specification allowed in case XML files. They specify the parameter name with the param attribute, and the value with the value attribute, as in:
<value param="r" value="0.4"/>
Each <run> element includes two attributes, number and rngSeed:
<run number="1" rngSeed="1986201165"/>
Here is a complete example of a case file:
<?xml version="1.0" encoding="UTF-8"?> <case name="echo - r=0.4-s=0.9 (2007-07-20, 16-29-39)"> <value param="r" value="0.4"/> <value param="s" value="0.9"/> <run number="0" rngSeed="526374054"/> <run number="1" rngSeed="1986201165"/> <run number="2" rngSeed="1585196345"/> <run number="3" rngSeed="1619001183"/> <run number="4" rngSeed="2137463870"/> <run number="5" rngSeed="549727158"/> <run number="6" rngSeed="1322681018"/> <run number="7" rngSeed="296371489"/> <run number="8" rngSeed="1066118686"/> <run number="9" rngSeed="1141036221"/> </case>
Random seeds are generated using the RandomSeedGenerator class from the CERN Colt scientific computing library, whose sole purpose is to decorrelate seeds from any uniform random number generator. Seeds are selected deterministically, in sequence from one of two columns, 0 or 1, in a virtual seed table. The range of rows is 0 to 2^32^ - 1. The firstSeedRow and seedCol attributes in experiment XML can be used to specify a starting point in the table; if are missing, they are chosen at random. Unless you are trying to reproduce a prior experiment, there is no reason to specify these attributes, but they will appear in the experiment file generated in the experiment results directory. You can read more in the RandomSeedGenerator API documentation.
GridSweeper has not been tested in many environments, so you may run into quirks specific to your configuration. If you are having trouble getting things set up, or if you had to perform a special workaround for your system, please send comments to gridsweeper@umich.edu.
First, make sure your installation meets the listed system requirements. If you're sure it does, make sure that you can submit single jobs using the native submission system for your grid (e.g., qsub). Check the shared filesystem: is GridSweeper creating output directories before jobs run, and are those output directories visible to all execution agents at job runtime? Check individual output directories, and make sure that files called .gsweep_in.[run-number] are being created.
Make sure that your jobs are working properly when run manually one at a time. Check your debugging output in stderr.[run-number] and stdout.[run-number]. Also check GridSweeper's debugging output in .gsweep_err.[run-number]. If all jobs are returning the same error, try submitting a single run using your grid's native submission system to see if the fault lies with GridSweeper or the underlying system.
qsub option)Actually, you can. As of version 1.0.1, you can use the gridConfig experiment attribute to pass along a string to the underlying grid system, like so:
<?xml version="1.0" encoding="UTF-8"?> <experiment name="My Experiment" numRuns="10" gridConfig="-q anotherqueue"> <!-- ... --> </experiment>
In Sun Grid Engine, this string takes the same form as command-line options passed to qsub. Other grid systems are likely to work similarly, but what gridConfig actually does may vary.
Terminology note: in the DRMAA specification, this string is referred to as a "native specification."
Make sure that it is possible to send emails on your system using the standard Unix mail command (Sendmail). If you have a unique system configuration, it may be possible to modify gridsweeper/scripts/gsmail to work with your mail system.
If you are having another issue, or if you have had to deal with one, please send an email to gridsweeper@umich.edu and let us know. We will add additional notes here as they arise.
JAVA_HOME environment variable is used to determine which Java to use. The same copy of Java is always used on submit hosts and execution hosts.
.gsweep_in, .gsweep_err, and .gsweep_out are deleted unless errors occur, or the -t or --keep-temp-files command-line option is specified.
notification_email.txt in the output directory), and are thus accessible even email delivery has not been configured properly.
Introduced gridConfig attribute to enable grid system-specific options (e.g., qsub command-line options).
First generally available version.
|
CSCS Home |
Research |
Education |
Positions |
People |
Events |
Online Resources |
Contact Info |
Giving |
SiteMap
© 2005 Center for the Study of Complex Systems |