-
Notifications
You must be signed in to change notification settings - Fork 13
Using Lua to Generate Params
Note: this page describes features in the develop branch.
It is possible to use a Lua program as a params file. This page describes the procedures for building with Lua support and running PetaVision from a Lua program.
#Enabling Lua support.
Lua support in PetaVision requires Lua version 5.2 or later. In Ubuntu, the necessary files can be installed using
sudo apt-get install liblua5.2-dev
Then, when running CMake, set the cache variable PV_USE_LUA to ON.
#Running PetaVision with a Lua program
If the params file (-p option) has the extension .lua
, PetaVision will interpret it as a Lua program. Otherwise, it
is treated as an ordinary params file.
The program must create a Lua string variable called paramsFileString
. PetaVision will exit with an error if there is
no such Lua variable. The paramsFileString is then parsed the same way as the contents of an ordinary params file would be.
Anything printed to io.output is ignored by PetaVision.
#PVModule
The file parameterWrapper/PVModule.lua
contains functions convenient for generating the paramsFileString from a table. The
most useful function in this module is createParamsFileString
. Each entry in the table corresponds to a parameter group, where the key is the group name, and the value is a table listing the parameters and their values. The group keyword is stored as an extra entry in the table with key groupType
.
For example, consider the following Lua program:
package.path = package.path .. ";" .. "/path/to/OpenPV/paramaterWrapper/?.lua"
local pv = require "PVModule"
local params = {
column = {
groupType = "HyPerCol";
startTime = 0;
stopTime = 10;
dt = 1;
nx = 32;
ny = 32;
};
input = {
groupType = "ImagePvp";
nxScale = 1;
nyScale = 1;
nf = 3;
inputPath = "input/sampleImage.pvp";
};
}
paramsFileString = pv.createParamsFileString(params)
io.write(paramsFileString)
might generate the string
debugParsing = true;
HyPerCol "column" = {
startTime = 0;
ny = 32;
stopTime = 0;
nx = 32;
dt = 1;
}
ImagePvp "input" = {
nf = 3;
nxScale = 1;
nyScale = 1;
};
Because of the way Lua stores tables, the order of parameters within a group is not deterministic. Since, PetaVision does not have any requirements on the order of parameters, this is not an issue. For the sake of brevity, only two groups are presented. The HyPerCol column always comes first, but otherwise the order of groups is not deterministic. Again, this is not an issue because PetaVision only requires the HyPerCol to be first.
From the standpoint of running this Lua program from within PetaVision, the io.write command at the end has no effect on the state of PetaVision; it is the contents of paramsFileString that matters. The io.write command is included as a way to see the result, to aid in debugging.
When running PetaVision, either with or without the dry-run flag -n
, PetaVision creates two files recording the parameters used in the run. One is an ordinary params file, and the other is a Lua program. The file name of the ordinary params file is given in the HyPerCol parameter printParamsFilename
. The file name of the Lua program is the same except that .lua
is appended.
The .lua file can therefore be used as the params file of a future PetaVision run.