Netlogo on the grid

Adapt your model for OpenMole

If you want to use your program with graphical widget and with Netlogo, we need to apply some good guidelines :

  • Implicit globals is bad, very bad, really.
    We prefer explicit globals with the globals primitive.
  • Do not use the same functions setup and go to set your program on the grid
    On the grid, the netlogo program is initialized and launchad only once, so it is useless to call a clear-all primitive at each setup. On the grid, clear-all is *not* your best friend since it erases all the globals given by OpenMOLE to your program before your run and makes crash your code .
  • Do not use directly the implicit globals created by means of a widget.
    It is only an advice, because you can access and overwrite it into openmole, but it prevents OpenMOLE from mapping explicitely its Prototypes and the Netlogo globals.

For more information about this, please read the section dedicated to the Netlogo headless codes.

Now, let’s take the initial segregation.nlogo, and transform it to use it safely with OpenMOLE :

> first define two new globals replacing implicit globals widgets (the other two already exist and store results at the end of the simulation) :
>Then change the occurencies of the implicit widget globals by the new explicit ones :
  – similar-wanted is replaced by op-similar-wanted
  – number is replaced by op-number
> let us now make work this program as it worked in the past : create a common-setup function which will be called by the new two setups (grid and local) we want to create :
You can click, it’s alive !
> Let us now create the second function to specialize our program and prepare it for the grid launching.
On the grid, you cannot click on the go button to start or stop your program, so we need to define a termination criteria like this :

Happy or unhappy turtle ? That is the question !
> Let us now add the specialized function to launch the segregation :

The complete nlogo file can be downloaded here (Netlogo 5 version) : Segregation.nlogo

The OpenMOLE part of cake

The goal of the simulation is to study the impact of the OP-SIMILAR-WANTED factor for a fixed size of population NUMBER. To do this, we would like to build a design of experiment where the OP-SIMILAR-WANTED factor takes its value from 20 to 80%. Since it is a stochastic model, we are interested in doing replications for each step and storing it in a CSV file. In this example, we will do 10 replications for each (even though it is clearly a too small sample to draw up any conclusion). Here is the workflow we intend to build:

> create some prototypes :
So we first need to define three prototypes to map later with explicit globals of our Netlogo model :
- an Integer one to increment the replications => replication ,
- an other Double one to map the OP-SIMILAR-WANTED => seuilVoisinage and
- a Double to map the total numbers OP-NUMBER of individual in our model => number.
To store our results at the end of simulation, let us create two new Prototypes :
- a Double to store the pourcent of individual similar => pSimilar,
- a Double to store the pourcent of unhappy individual at the end of simulation => pUnhappy
> build the design of experiments by defining the Sampling
So we need to repeat 10 times our experience for every step of the OP-SIMILAR-WANTED exploration.

The NetLogo model has to be supplied with the seeds for the random generator. To do this, we will use an infinite array of Integers uniformly distributed

> define a new Exploration Task, and link the Sampling with it

> add the Task on the Scene (a right click on the Scene)

>create a new NetlogoTask with the path of the .nlogo model, copy paste the given command to run the simulation, close and add it to the Scene (right click on the Scene)

In this example, cmds contains two main calls to the NetLogo methods, in this order :
a) the random-seed gets a random seed for the input prototype ${replication},
b) the run-to-grid method needs only one explicit parameter: the maximum number of step in the case where the model does not converge.
> in the next step, Let us map the other two implicit parameters (OP-SIMILAR-WANTED and OP-NUMBER) needeed to run correctly the model via the input mapping (seuilVoisinage and number Prototypes). In order to make this possible we need a Transition between the two defined Tasks ( SHIFT + CLICK on the center of Exploration Task, and drag the pointer to the input slot of the Netlogo Task (more information here) .

> re-open the Netlogo Task, and map the Prototype with the Netlogo model inputs

> when the Task is closed after the mapping, you can see an error, it’s normal, the Sampling defines values for replication and seuilVoisinage prototype, but not for the number Prototype ?

When a mapped Prototype is add in the NetlogoTask, OpenMOLE adds automatically these Prototypes as inputs of the Task. You can see that if you click on the left circle, two automatic inputs are shaded corresponding to the mapped values required by the Task. So at this point, the Task is in error because we map the number value, but we don’t give any value at this Prototype (The Exploration Task has only two output Prototypes seuilVoisinage and replication). We do not want to design a Sampling for number, so click on the icon on the right-hand side of the prototype number, and fix its value to 2000d

As you can see in the Settings panel in the Netlogo task, we use ${replication} syntax. With this notation, mapping is not automatic, so we need to add the input manually to the task, like this

> At this point,  the followifg workflow is defined on the Scene

> define now a Grid Environnement to run the workflow on the Grid (you of course need a certficate on it to access it)

If you have a slow internet connection, or if you want to test your worflow, you can also use the simple MultiThreading Environnement :

> right click on a task you want to run the task on the Grid (here we want to run the netlogoTask on the Grid (the L icon of Environnement appears on the Task) ):
> define the start point of your workflow : right click on the Exploration Eask > define as start capsule. The input slot comes from yellow to green, so we are ready to run !

> Build the workflow
> Add a display hook

> Run the workflow, now !

> As you can see we have few displays, perhaps you can add some information about simulation parameters, return to the Scene and edit the output of NetlogoTask like this …

> Re-build the workflow, and add some new values to display hooks !

> Export the results to a CSV file thanks to another usefull Hook, the “append to file hook”. Double click on the blank area, and choose a destination for csv file

> Modify the output of the Hook, and launch the Mole !

> The xml file (OpenMole 0.5 only) can be downloaded here : Segregation.xml