Startup program

From Emergent

(Redirected from startup program)
Jump to: navigation, search

A startup program is a program that controls what to do with a project when run without the gui (see nogui run). It is just a regular program that has the STARTUP_RUN flag set in the properties dialog. Setting this flag means that when a project is loaded, this program will be automatically run. This auto-running happens regardless of whether the program was started in -nogui or -gui mode, but typically the first line in the startup program is to exit if it is gui mode, because the typical use of a startup program is to run in the background (see nogui run for details).

A pre-configured startup program is available in the Program Library (prog lib) as LeabraStartup -- you can load that (do context menu on programs and select New From Lib) and modify. This program is based on the standard startup script described in detail in that link, so see that for more detailed documentation.

Contents

Making New Command Line Arguments

(See Command line switches for built-in command line switches).

A very productive way of exploring the model parameter space, especially if you have access to a cluster, is to run a bunch of different versions of a model with different parameter settings. The best way to do this is to create a startup program that reads command-line arguments to set parameters in your model. Starting with the 4.0.11 version there are special program elements that make this very straightforward.

Key Tip: the LeabraStartup program contains a tag= startup argument that you can use to indicate the specific parameterization for a given run -- the log files (and weight files if those are being saved) will automatically have this tag appended to them, so you can keep the results separate and know what they are for. For example, if you have a lrate parameter that you are manipulating, you might do something like this to run your program:

emergent -nogui -ni -p myproj.proj epochs=100 batches=10 lrate=0.01 tag=_lr01

which will create a log file as myproj_lr01.epc.dat. There is also a logdir= argument that can put these log files in a separate subdirectory, if you want.

The following program elements for creating new startup command-line arguments are found in the Program toolbox under Print/Args...

General Rules for arg_name and passing arguments on the command line

Each of the program elements has a arg_name parameter that specifies the argument name which will be used on the command line to specify the argument, and also can be used within the program to access the value that the user specified on the command line.

For example, if you enter the arg_name as "lrate" (you don't enter the quotes!) for the learning rate, then you would set this on the command line as follows:

lrate=0.01

Note that there cannot be any spaces in this string, and you must use the equals sign there (but NOT in your arg_name as you enter it), and it is case sensitive!

RegisterArgs (reg args in toolbox)

VERY IMPORTANT you MUST include only 1 instance of this item in your program code before any of the following argument setting functions. This registers any arg_name items present in the following functions, and reads their values from the command line, so that the following functions will work. It will also do taMisc::UpdateArgs, which will process any other args you might have specified before this item using taMisc::AddArgName. (both of these taMisc functions can be called by using a MiscCall program element, found in the toolbox under Misc Funs/misc())

ProgVarFmArg (var=arg in toolbox)

This sets a program variable based on a startup argument. You just provide the Program, the variable name, and the argument name, and it does all the work. If the user does not pass the argument, nothing happens. If they do, you'll see an informative message.

MemberFmArg (memb=arg in toolbox)

This sets a member of an object to the value passed on the command line argument. You provide the object, and a path to the member (use the member_lookup to conveniently select from the members) and the name of the argument.

DataColsFmArgs (data=args in toolbox)

This sets DataTable values based on arguments passed as "column_name=<value>" on the command line, where column_name is the name of a datatable column. You provide just the data table and the information for which row to set the values in (can be the current row, a row looked up by index from a variable, or a one looked up by value from a variable). This makes it very convenient to just put a bunch of parameters into a datatable and then they can all be automatically processed using this function. See also DataVarProg for a convenient program element for reading items out of the datatable into program variables.

Specific Cases

Setting Number of Units in a Layer

There is now a SetNUnits function on the Layer which does the work. The overall strategy is thus:

  • create an int variable in the startup program to hold the value the user passes (e.g., n_units)
  • assignexpr (var=) n_units = -1
  • ProgVarFmArg (var=arg) n_units
  • if(n_units > 0) // user actually set this parameter
    • network.layers.LayerName.SetNUnits(n_units); // easiest to just use script for this -- Ctrl-L lookup will help you find all the items along the way
    • network.Build() // use meth() for this
    • print var n_units -- good idea to indicate that units were actually set.
Personal tools