Faculty, staff and students...
Computer Lab, seminar listings, contact information...
Events, seminars, and academic deadlines...
Find documents and people...
More detail on the latest CSCS news...

  • Comments?
    email webmaster


  • UM-ExpTools-4


    NOTE: This page under construction

    The directory /appl/swarm2.2x-um/UM-ExpTools4 contains tools for running Swarm (version 2.2x) application experiments, and in particular, the UM-ExpTools4 library includes two classes, RParameters and RParameter, which are useful for all model implementations. (/appl/swarm2.1.1-um/UM-ExpTools4 is a version that runs with Swarm version 2.1.1 and earlier.) See the Readme.txt file in that directory for instructions on how to obtain and make the latest version. There are also instructions on how to download the latest version here.

    These objects can be used as part of a Swarm application to provide easy ways to:

    • processing of command line arguments, in GUI or Batch mode.
    • processing of parameters from an input-file
    • a pre-built set of parameters, including a RNG seed, report file name, output directory, inputfile, and run number.
    • automatic writing of parameters to the head of the report file (or other user opened files) in a format ready for re-reading, so that runs can be replicated.
    • utility macros and methods for RNG access, parameter access, etc.
    The page describes:

    For an example of one way to use these objects and tools, see UM-HeatbugsPlus, and see an example of using heatbugsPlus with drone.


    The RParameters interface

    -(void) setProgVersion: (char *) version;
    -(void) setProgName: (char *) progname;
    -(char *) getProgVersion;
    -(char *) getProgName;
    Set/set the program version and name (written to report file).
    -(void) startReportFile
    -(void) endReportFile
    startReportFile opens a file with a path/name that is assembled from the values of outputDirName/reportFileName.reportFileNameSuffix . It then writes the program name, version, start date/time to the top of the file, along with all the parameter values in a format that can be read back in via the -IF= parameter (as processed by the xxx method). The FILE pointer is accessible via the getReportFILE method for other methods to append to it as the run proceeds. Just before the program ends (e.g., in main.m) call endReportFile to close it up properly.
    -(void) startRNG;
    Start the RNG objects, using the value of the seed parameter. Thus this should be called after runtime parameters (and gui-settable, if running in gui mode) have been processed, and it should be called just before starting the report file
    -(char *) setStartDateTime
    -(char *) getStartTime
    -(char *) getStartDate
    setStartDateTime stores the time of run start, from the system clock. This should be done once, near the start of the program (e.g., just before starting the report file). The get-methods return pointers to char buffer with time/date of run start.
    -(FILE *) getReportFILE;
    -(char *) getReportFileName;
    -(char *) getReportFileNameSuffix
    Methods to get the FILE pointer to the report file, as well as the base name and the suffix for the report file name.
    -(unsigned) getReportFrequency
    This should be used in Model-stepReport method to specify how often information is written to the report file.
    -(int) getValueOfParameter: (char *) name inBuff: (char *) buff
    -(double) getDoublePar: (char *) name
    -(unsigned) getUnsignedPar: (char *) name
    -(float) getFloatPar: (char *) name
    -(BOOL) getBoolPar: (char *) name
    -(int) getIntPar: (char *) name
    -(char *) getStringPar: (char *) name
    Main methods for accessing values of parameters. The first puts a string version of the parameter value in a supplied buffer. The rest return the value of a parameter of a particular type...its up to the user to call the method with the proper type for the given parameter.
    -(FILE *) openOutputFile: (char *) name How: (char *) how
    -(void) writeParameterHeaderTo: (FILE *) F
    -(void) writeStartDataMarkerTo: (FILE *) F
    Methods useful for opening auxilliary output files (i.e., besides the basic report file). openOutputFile opens the file in directory specified by outputDirName parameter (but not with the reportFileNameSuffix). The other methods write header information just as it is found in the basic report file.
    +createBegin: (id) zone
    -createEnd
    create the RParameters object.
    -(char *) getOutputDirName
    -(unsigned) getStopT
    -(unsigned) getSeed
    -(char *) getInputFileName
    -(id) getParList
    -(id) getModel
    Standard get-methods to get values for these various instance variables.
    -(unsigned) getRDebug
    Get value of the rDebug instance variable. This can be set to values > 0 to control what debug information is written by the Debug macros (see below).
    -(int) processCmdLineArgC:(int)argc ArgV:(char **)argv
    -(int) readInputFile
    These methods are used to process user-specified parameters, typically (but not only in) batch mode runs. The former processes command line arguments, and the latter reads parameters from an input file. Command line arguments -h and -batchmode are ignored. The -IF=filename parameter causes it to try to read parameters from filename, using the readInputFile method. The format of the parameters in the input file should look just like the top of a report file produced by the startReport method. All other command line arguments are assumed to be the names of model parameters (or their aliases); any that are not cause an error return and message to stderr.
    -(double) getSampleWithMean: (double) mean withVariance: (double) var withMin: (double) mn withMax: (double) mx
    Method to return normal variate with given mean, variance, maximum and minimum values. See the macros (below) for many more ways to access random variates.
    -(void) help
    -(int) printParametersOn: (FILE *) f
    Methods used to print help messages, e.g., when application run with -h parameter..
    -(void) writeHostNameIn: (char *) buff
    Write hostname and date/time into a buffer. Used by endReport for its last line.
    -(void) setstopT
    -(char *) getAliasFor: (char *) parName
    -(char *) getNameFor: (char *) parAlias
    -(char *) isPar: (char *) name
    -getParFor: (char *) name
    -(int) setParameter: (char *) cmd // parName=parValue
    -(int) setParameterName: (char *) name ToValue: (char *) value
    -(id) getValueOfParameter: (char *) name
    Various low level methods generally not used by user applications.


    The RParameters macros and subroutines

    This section describes some macros and subroutines intended to make life a little easier and programs a little cleaner. The first set of macros are to make obtaining random variates easier (and also to buffer applications from changes in the underlying swarm random library). A second set of macros and subroutines are for accessing values of parameters in the RParameters object (or subclasses thereof). There are also a few macros (and functions) for other typical tasks (eg checking to see if a string is an ascii representation of an integer) and for producing debugging messages that can be turned on and off with the rDebug (-D) parameter.

    Note well: To use these macros, you must of course #import the RParameters interface (or subclasses of it). Furthermore, some of these macros depend on having a variable declared literally "parameters" which points to the applications Parameters object which is a subclass of RParameters. That is, those macros attempt to send messages to an object pointed to by a variable called parameters.

    The random variate macros:

    extern id uniformUR, uniformIR, uniformDR, normalDR, gammaDR, logNormalDR;
    getUniformU(mn,mx)
    getUniformI(mn,mx)
    getUniformD(mn,mx)
    getNormalD(mean,var)
    getLogNormalD(mean,var)
    Call these to get random variates of the various types described. These send messagest to the distribution objects specified on the extern line.
    getNormalDPRepeatUntilInRange(mean,var,mn,mx)
    This keeps trying to get a normal variate with mean and max as described, but requiring it in [mn,mx].

    Subroutines for getting the values of parameters:

    These subroutines can be used anywhere in a program (but you do need to import the Parameters.h file for your Parameters object). Note the case of these (small "r" to start)!

    retDPar("Name")
    retIPar("Name")
    retSPar("Name")
    retUPar("Name")
    retFPar("Name")
    retBPar("Name")
    These return value of parameter of specified type, where D=doublePar, I=intPar, S=stringPar, U=unsignedPar, F=floatPar and B=boolPar. Its the callers responsibility to be sure the parameter Name is of the specified type. The value returned is of the specified type.

    The macros for getting values of parameters:

    Note all these macros for getting values of parameters depend on having in scope a variable named "parameters" which points to the user's RParameters instance.

    RetDPar("Name")
    RetIPar("Name")
    RetSPar("Name")
    RetUPar("Name")
    RetFPar("Name")
    RetBPar("Name")
    Return value of parameter of specified type, where D=doublePar, I=intPar, S=stringPar, U=unsignedPar, F=floatPar and B=boolPar. Its the callers responsibility to be sure the parameter Name is of the specified type. The value returned is of the specified type. These depend on having a variable "parameters" in scope.
    getDPar("Name")
    getIPar("Name")
    getSPar("Name")
    getUPar("Name")
    getFPar("Name")
    getBPar("Name")
    Aliases which do the same as the analogous RetXPar macros describe above.
    RetDParFrom(p,"Name")
    RetIParFrom(p,"Name")
    RetSParFrom(p,"Name")
    RetUParFrom(p,"Name")
    RetFParFrom(p,"Name")
    RetBParFrom(p,"Name")
    These macros are analogous to those above, except the take a first argument which is a pointer (id) to the Parameters object which has the parameters.
    #define FTC(t) (*(id *)(&t))
    This is useful for getting values of various types back from perform-calls to execute methods. Need more notes here...
    extern unsigned int *GlobalRDebug;
    #define DMSG(N,S) if(*GlobalRDebug >= N) fprintf S;
    This macro can be used to conditionally print debugging messages, under the control of the built-in parameter rDebug (-D). A typical call to this would look like
    DMSG(3,(stderr,"A message with one double value %d .\n",dd));
    This would print out that message with D parameter is greater than or equal to 3, on stderr, substituting the value of dd in the message.
    BOOL IsInt( char *s );
    BOOL IsUInt( char *s );
    BOOL IsFloat( char *s );
    int SameString( char *s1, char *s2, int KeepCase );
    char *stripUI ( char *buff, unsigned int *v );
    char *stripFloat ( char *buff, float *v );
    #define max(a,b)
    #define min(a,b)
    Some utility functions and macros.

    How to use RParameters in your Swarm application

    This section describes one way to use the RParameters object. The basic steps necessary to use RParameters in this way are roughly as follows (assuming you have a Swarm application that has a top structure that approximates that of the basic heatbugs application):

    
    0. Make your Makefile look like the one in
       /appl/swarmXXX-um/UM-HeatbugsPlus
       (XXX=2.1.1 for version 2.1.1 of Swarm and UM-HeatbugsPlus.) 
       In particular, it links in the ExpTools4 library,
       and it tells make to include the path to the *.h files 
       from ExpTools on the compile commands.
    
    1. Define a Parameters object in your application,
       a subclass of RParameters.  
       This will hold instance variables for all parameters
       you want to be settable on the command line or via the GUI.
    
       The super class provides the following parameters:
        reportFileName (RFN) = report
           file to which report will be written    
        reportFileNameSuffix (RN) = 
           appended to reportFileName, after a dot (.)
        reportFrequency (RF) = 1
           frequency averages will be written to report
        outputDirName (OD) = .
           directory into which report will be written.
           default is the directory in which heatbugsPlus is run.
           NOTE: the directory must exist.
        stopT (T) = 4
           number of steps to run in batchmode.
        seed (S) = 0
           RNG seed.  Default (0) means generate a new one
           from clock time and process number.
        inputFileName (IF) = rparameters.in
           file from which parameters were read.
           (this is ignore when in an input file!)
        rDebug (D) = 0
           sets rDebug flag (not currenlty used...could be used
           to control debugging messages).
    
    2. To your Parameters.h interface definition,
       add your model-specific instance variables.
       Note you don't have to add specific methods to get/set them.
    
    3. In the Parameters+createBegin method, assign initial values,
       and build a probe for the variables if you plan to use a GUI.
    
    4. In the Parameters-initParameters object, create and add 
       a Parameter object for each of your new parameters.
       Bascially you specify:
       - Name: this must match the instance variable name!
       - Alias: some short version of the name.
            You will be able to use this on command lines, eg.
       - The parameter type: unsignedPar, doublePar, intPar,
            floatPar, stringPar, boolPar.
       See the /appl/swarmXXX-um/UM-HeatbugsPlus/Parameters.m file for
       examples of how to do this 
       (where XXX is, e.g., 2.1.1, for that version of Swarm).
    
    3. Link your Parameters object (its best if you name
       it "parameters") to your Observer, Batch and Model objects.
       This can be done when you create the Parameters object,
       as shown in the HeatbugsPlus example program.
    
    4. Modify main.m and buildObjects methods so the
       argc and argv can get passed to the RParameters
       processComdLineArgC:Argv method, which you need
       to send to your Parameters object.
       You also need to import RParametersArgs.h and pass it to
       the initialization function like this:
          initSwarmArguments(argc, argv, [RParametersArgs class] );
       (Again, see HeatbugsPlus).
       Also send a message to the parameters object to
       tell it the name and version of your program.
       (This gets printed in the report file, eg.)
    
    


    Other Classes in the UM-ExpTools-4 Library

    This section describes some other classes that are included in the UM-ExpTools-4 library. To use each class, import the appropriate interface file.

    NOTE: As of Swarm 2.2x, the Swarm libraries provide all the functionality (and more) previous provided by these classes, e.g., the Averager provides moving averages and moving standard deviations. So as of UM-ExpTools4 for Swarm-2.2x, these are no longer in the UM-ExpTools4 library.

    The RAverager Class

    This is a simple subclass of the Swarm Averager object (see the Analysis library). It adds one method, getStd, to those provided by the base class.

    -getStd
    Returns the standard deviation associated with the mean.

    The RunningAverage Class

    Documentation to be provided...

    The Shuffler Class

    Documentation to be provided...


    The RParameter interface

    The RParameter object and methods are not intended to be used directly in user applications. Instead, they are used by the RParameters object. But for completeness, the RParameter interface is described here.

    -(void) setParameters: (id) p;
    -setParName: (char *) name Aka: (char *) A
            Type: (ParameterType) type;
    -setLB: (double) db;
    -setUB: (double) db;
    -createEnd;
    
    -(char *) getParName;
    -(char *) getParAlias;
    
    -setDesc: (char *) desc;
    
    -setsetFn: (SEL) aSel;
    -(SEL) getsetFn;