A Magpie script works by creating variables and operating on them with commands specific to their type. As an example, the following script imports data from a text file, trains a decision tree model on that data, and prints performance statistics.
data = new data.Dataset
data import data.csv
model = new models.regression.WekaRegression trees.REPTree
model train $data
print model training stats
Magpie currently supports several kinds of variables, which include datasets, models, statistics calculators, optimization algorithms, and crystal structure predictors. While each of these types are designed to perform different tasks and, consequently, have different available commands, they all support the following operations:
A variable is created in Magpie using the following command:
<variable name> = new <class name> <options...>
Once created, you can start using and modifying this variable by issuing commands. Commands specific to a certain type of variable (e.g. models) are, detailed in other parts of the manual. Regardless of variable type, commands all follow the same syntax:
[<output> = ] <variable name> <command...>
For reference: <>'s denote parameters in a command. If you need to pass multiple words to a single parameter, surround them with quotation marks. If a parameter is surrounded by []'s, it is optional. If the name contains '...', then you can supply multiple words for that parameter without quotation marks. Lastly, if there is a '$' in front of the parameter name, this command requires accessing another variable (e.g. a model must be trained using a dataset). To do so, supply the name of that variable with a '$' affixed to the beginning. The '$' symbols tells the command interpreter to pass the value of the corresponding variable to the command rather than text.
Values stored in a variable are accessed using the print command. Each variable type has its own printing commands, though all are accessed using the same command syntax:
print <variable name> <print command...>
The variables themselves can be saved to disk using the command:
save <variable name> <filename> [<format>]
If no format is provided, the class will be saved to disk using serialization into a machine-independent format, which can be loaded back into Magpie later by calling
<variable name> = load <path>
Outside of commands that operate on variables, a few other commands may be required for a complete script:
read <filename>
Read all commands from a certain file. Returns control to the calling script once complete.
citations [<variable names...>]
Print out suggested citations for variable objects used in this Magpie script. If
no variable types are explicitly listed, prints out citation information for all variables.
Prints a reason for this citation being suggested, along with the associated component
of that variable, and enough information to at least find the resource that should be cited.
list
Write out the names and types of all variables currently in memory
timer <start|elapsed> [<name>]
Simple timer functionality. "start" resets a timer to 0 and "elapsed" prints out how much time has elapsed. Multiple timers with different names can be stored and monitored concurrently. If no name is provided, time will be measured with respect to when Magpie was started.
evaluate $<model> $<dataset> <entries to evaluate...>
Given a model to run and dataset template to generate attributes, evaluate a series of entries.
exit
Done. Close Magpie and get on with your life.