Back to Documentation/Tutorial
Wrapping a binary model using template file
Goal: In this tutorial, we explore a binary model, using template file mechanism.
The model used
SimpleModel is a binary model that could be computed using command:
java -jar SimpleModel.jar config.in
The program takes one argument (config.in in the example) that contains model parameters. It computes predator / prey dynamics according to those parameters, and dumps computed trajectories into output file.
- Download SimpleModel.jar on your computer.
- Download config.in, the config file example in the same directory.
- Open a command line interface
- Go to the directory where you download files.
- Run the model with the command java -jar SimpleModel.jar config.in
- Constat that named r_K_C_n_p_20.0_15.0_20.0_30.0_12.0_data.dat file has been created in the directory.
- Check that the file contains dumped trajectories.
Now we will automate this operation using SimExplorer and scenarii defined into first step on design of experiments. You can either do this previous step or load this file.
Defining Model inputs
As you can see in the input file example, the model has two parameters :
- n: the initial cardinality of the prey group
- p: the initial cardinality of the predator group
Now, you need defining this input structure in SimExplorer:
- Open the "inputStructure" frame.
- Add input by right-clicking on "inputStructure" entry and choosing "Add a child...". It opens the "New data structure node" dialog box.
- Type the name of the input in the "Name" field for example "n"
- Choose "Double" in the "Data type" list.
- Click "OK" button.
- Using the same scenario, add the "p" input.
Input are accessible in all the "Exploration_loop" using the variable "input" (input.n, input.p).
Linking factors and inputs
Factor values are accessible using "factors" object.
- Add a processor by right clicking the "Input_generation" node and clicking the "Add a processor" entry.
It opens a dialog box in order to choose which type of processor you want.
- Pick the "GroovyProcessor" in the dialog box list and click "OK".
- In the application frame, click the just created GroovyProcessor in order to edit the groovy code in the "Editor" frame.
- Copy and Paste the following code in order to link factors and inputs.
/* Linking factors and inputs */ input.n = factors.a + 0.1 input.p = factors.b + 0.1
Defining and linking Model outputs
- Open the "outputStructure" frame.
- Add output by right-clicking on "outputStructure" entry and choosing "Add a child...".
It opens the "New data structure node" dialog box.
- Type the name of the output in the "Name" field for example "trajectory".
- Choose "Complex" in the "Data type" list.
- Check "sequence data" box to create an array of complex nodes.
The "outputStructure.trajectory" object will be used to store each state of the dynamic, step by step.
- Aggregate outputStructure by editing "output" in "Variable" frame.
- Right click on "output" variable.
- Check the "Gathered after the exploration loop" box.
- Validate by clicking "OK" button.
- Put the groovy code of the "Final_processing" as following:
import org.simexplorer.graph.Grapher g = Grapher.getInstance() g.title = "Predator Prey Dynamic" g.addSeries(output.trajectory)
Computing config file from template file
In order to repeat automatically this operation for each set of parameters, generating needed config files is accomplished using a template mechanism. It means that we define a unique template file containing patterns. Those patterns are replaced by input values during the exploration runtime, and a file is generated for each simulation.
- Download config.in.tpl file on your Desktop or any.
Into SimExplorer:
- Add a TemplateFileInputGenerator processor in the Input_generation node.
- Edit the TemplateFileInputGenerator processor.
- Select the just downloded template file config.in.tpl using browse button.
- Type r_K_C_n_p_20.0_15.0_20.0_${input.n}_${input.p}_config.in into input file field.
At runtime, this processor creates files r_K_C_n_p_20.0_15.0_20.0_${input.n}_${input.p}_config.in with ${xx} patterns replaced using xx values. Created files contain config.in.tpl content with ${xx} patterns replaced with xx values.
- Check it by running the design.
Wrapping binary model
- Add SystemExecLauncher processor in the Model_launcher node.
- Edit the SystemExecLauncher processor.
- Select your Desktop or any for the Working directory using browse button.
- Select the java 1.6 executable for the Executable path
- Type -jar SimpleModel.jar r_K_C_n_p_20.0_15.0_20.0_${input.n}_${input.p}_config.in for Arguments.
Retriving results into the contexte
You could retrieve the results by copying/pasting following snippet into a new 'GroovyProcessor into the Output_processing node.
output.n << input.n
output.p << input.p
new File("/home/dumoulin/SimExplorerSamples/" +
"r_K_C_n_p_20.0_15.0_20.0_${input.n}_${input.p}_data.dat").eachLine {
line ->
data = line.split("\t")
if (data[0] != "n"){
output.n << Double.parseDouble(data[0])
output.p << Double.parseDouble(data[1])
}
}
Retrieve the final content of the application using this file.





