Skip to content

HeadlessLegacy

RoiArthurB edited this page Sep 11, 2023 · 17 revisions

Headless Legacy

Getting started

This headless mode is the Legacy one. So, if you are already familiar with headless from version 1.8.1 or older, nothing changed.

This mode relies on writing an explicit simulation plan in XML file. Those simulations, mostly for legacy reason, have to be of type gui (which is pretty counterintuitive, but this type let you set the parameter value to each simulation independently), but you don't have to write it explicitly as it's the default type for an experiment.

You can generate a first XML file corresponding to an existing experiment with the following command:

./gama-headless.sh -xml experimentName /path/to/inputFile.gaml /path/to/outputFile.xml
  • with:
    • -xml: the flag asking the headless to generate a XML file well-formatted for our experiment
    • experimentName: the name of the experiment you want to run in headless
    • /path/to/inputFile.gaml: the path (relative or absolute) to your GAML file containing the experiment you want to run
    • /path/to/outputFile.xml: the path (relative or absolute) to the generated XML file

You can see more in details the content of the generated XML file (applied on the model Predator Prey) in the Experiment Input File part.

Once you finished preparing your XML file, you can run it with a command similar to the following one:

./gama-headless.sh /path/to/file.xml /path/to/generated/outputFolder
  • with:
    • /path/to/file.xml: the path (relative or absolute) to the XML file containing the full exploration plan to run by the headless
    • /path/to/generated/outputFolder: the path (relative or absolute) which will be generated by GAMA and hold every output files (variables, snapshots, and console messages)

You can see result output folder in the Simulation Output part

Experiment Input File

The XML input file contains for example (you can find it next to the file gama-headless.sh at the path samples/predatorPrey.xml:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Experiment_plan>
	<Simulation experiment="prey_predatorExp" finalStep="1000" id="0" seed="1.0" sourcePath="./samples/predatorPrey/predatorPrey.gaml">
		<Parameters>
			<Parameter name="Nb Preys: " type="INT" value="200" var="nb_preys_init"/>
			<Parameter name="Prey max energy: " type="FLOAT" value="1.0" var="prey_max_energy"/>
			<Parameter name="Prey max transfert: " type="FLOAT" value="0.1" var="prey_max_transfert"/>
			<Parameter name="Prey energy consumption: " type="FLOAT" value="0.05" var="prey_energy_consum"/>
			<Parameter name="Nb predators: " type="INT" value="20" var="nb_predators_init"/>
			<Parameter name="Predator max energy: " type="FLOAT" value="1.0" var="predator_max_energy"/>
			<Parameter name="Predator energy transfert: " type="FLOAT" value="0.5" var="predator_energy_transfert"/>
			<Parameter name="Predator energy consumption: " type="FLOAT" value="0.02" var="predator_energy_consum"/>
		</Parameters>
		<Outputs>
			<Output framerate="1" id="0" name="Number of preys"/>
			<Output framerate="1" id="1" name="Number of predators"/>
			<Output framerate="1" id="2" name="main_display"/>
		</Outputs>
	</Simulation>
</Experiment_plan>

NB: Several simulations can be determined in one experiment plan. These simulations are run in parallel according to the number of allocated cores.

Simulation

<Simulation experiment="prey_predatorExp" finalStep="1000" id="0" seed="1.0" sourcePath="./samples/predatorPrey/predatorPrey.gaml">
  • with:
    • experiment (required): determines which experiment should be run on the model. This experiment should exist, otherwise, the headless mode will exit.
    • finalStep (required): determines the number of simulation steps you want to run.
    • id (required): permits to prefix output files for experiment plans with huge simulations.
    • seed (optional): permits to set the seed value of the simulation.
    • sourcePath (required): contains the relative or absolute path to read the gaml model.
    • until (optional): defines a stop condition in GAML. It can be combined with the finalStep facet (in this case a simulation will finish when the stop condition is fulfilled or when the final step is reached).

Parameters

One line per parameter you want to specify a value to:

<Parameter name="Nb Preys: " type="INT" value="200" var="nb_preys_init"/>
  • with:
    • name: name of the parameter in the gaml model
    • type (required): type of the parameter (INT, FLOAT, BOOLEAN, STRING)
    • value (required): the chosen value
    • var: name of the parameter variable in the gaml model

NB: You need to set at least one of the attributes name or var in your Parameter tag)

Outputs

One line per output value you want to retrieve. Outputs can be the name of monitors or displays defined in the 'output' section of experiments, or the names of attributes defined in the experiment or the model itself (in the 'global' section).

    ... with the name of a monitor defined in the 'output' section of the experiment...
    <Output framerate="1" id="1" name="Number of predators"/>
    ... with the name of a (built-in) variable defined in the experiment itself...
    <Output framerate="1" id="2" name="main_display"/>
  • with:
    • framerate (required): the frequency of the monitoring (each step, every 2 steps, every 100 steps...).
    • id (optional): permits to prefix output files for simulation with huge outputs
    • name (required): name of the output in the 'output'/'permanent' section in the experiment or name of the experiment/model attribute to retrieve
    • output_path (optional): change the output directory where snapshot images are saved (for display output only!)

NB: the lower the framerate value is, the longer the experiment.

NB2: if the chosen output is a display, an image is produced and the output file contains the path to access this image

Output Directory

During headless experiments, a directory is created with the following structure:

Outputed-directory-path/
out
├── console-outputs-0.txt
├── simulation-outputs0.xml
└── snapshot
    ├── main_display0-0.png
    ├── main_display0-1.png
    ├── main_display0-2.png
    ├── main_display0-3.png
    ├── main_display0-4.png
    └── ...
  • with:
    • console-outputs-<simulationId>.xml: containing every message written in GAMA's console
    • simulation-outputs<simulationId>.xml: containing variables' results in a XML format
    • snapshot: containing the snapshots (i.e. screenshots of gui displays) produced during the simulation

Simulation Output

A file named simulation-output.xml is created with the following contents when the experiment runs.

<?xml version="1.0" encoding="UTF-8"?>
<Simulation id="0" >
	<Step id='0' >
		<Variable name='main_display' value='main_display2-0.png'/>
		<Variable name='number_of_preys' value='613'/>
		<Variable name='number_of_predators' value='51'/>
                <Variable name='duration' value='6' />
	</Step>
	<Step id='1' >
		<Variable name='main_display' value='main_display2-0.png'/>
		<Variable name='number_of_preys' value='624'/>
		<Variable name='number_of_predators' value='51'/>
                <Variable name='duration' value='5' />
	</Step>
        <Step id='2'>

...
  • With:
    • <Simulation id="0" >: tag containing results of the simulation. The id is set one set in the input file, in the heading part
    • <Step id='0' >: one block per step done containing the value of outputs variables. The id corresponds to the step number
      • <Variable /> with:
        • name: name of the output
        • value: the current value of the model variable at the given step.

NB: The value of an output is repeated according to the framerate defined in the input experiment file.

NB2: The value of an output display gives the relative path to the generated image saved in '.png' format.

Calling GAMA headless legacy on Windows

The example below assumes that your GAMA application is in folder D:\software\ and your project (model) file is in folder D:\my_models\ The data structure of the example model as in following. The example models can be found in the GAMA headless folder (GAMA_1.9.2_Windows_with_JDK\headless\samples\predatorPrey)

predatorPrey
├── includes
└── models
    ├── ...
    └── predatorPrey.gaml

In the predatorPrey model, we have a GUI experiment named prey_predator

Windows PowerShell

  • You can open Windows PowerShell, change your directory to the headless folder and run gama-headless command:
cd D:\software\GAMA_1.9.2_Windows_with_JDK\headless\
.\gama-headless.bat -xml prey_predator D:\my_models\predatorPrey\models\predatorPrey.gaml D:\my_models\predatorPrey\models\predatorPrey.xml
.\gama-headless.bat D:\my_models\predatorPrey\models\predatorPrey.xml D:\my_models\predatorPrey\results

Command Prompt

  • You can open Command Prompt, change your directory to the headless folder D:\software\GAMA_1.9.2_Windows_with_JDK\headless\ then run the commands:
gama-headless.bat -xml prey_predator D:\my_models\predatorPrey\models\predatorPrey.gaml D:\my_models\predatorPrey\models\predatorPrey.xml
gama-headless.bat D:\my_models\predatorPrey\models\predatorPrey.xml D:\my_models\predatorPrey\results

Python Script

  • Your python script will have the following lines of code, mainly using the os package to run the native system commands
import os
os.chdir("D:\software\GAMA_1.9.2_Windows_with_JDK\headless")
os.system("gama-headless.bat -xml prey_predator D:\my_models\predatorPrey\models\predatorPrey.gaml D:\my_models\predatorPrey\models\predatorPrey.xml")
os.system("gama-headless.bat D:\my_models\predatorPrey\models\predatorPrey.xml D:\my_models\predatorPrey\results")
  1. What's new (Changelog)
  1. Installation and Launching
    1. Installation
    2. Launching GAMA
    3. Updating GAMA
    4. Installing Plugins
  2. Workspace, Projects and Models
    1. Navigating in the Workspace
    2. Changing Workspace
    3. Importing Models
  3. Editing Models
    1. GAML Editor (Generalities)
    2. GAML Editor Tools
    3. Validation of Models
  4. Running Experiments
    1. Launching Experiments
    2. Experiments User interface
    3. Controls of experiments
    4. Parameters view
    5. Inspectors and monitors
    6. Displays
    7. Batch Specific UI
    8. Errors View
  5. Running Headless
    1. Headless Batch
    2. Headless Server
    3. Headless Legacy
  6. Preferences
  7. Troubleshooting
  1. Introduction
    1. Start with GAML
    2. Organization of a Model
    3. Basic programming concepts in GAML
  2. Manipulate basic Species
  3. Global Species
    1. Regular Species
    2. Defining Actions and Behaviors
    3. Interaction between Agents
    4. Attaching Skills
    5. Inheritance
  4. Defining Advanced Species
    1. Grid Species
    2. Graph Species
    3. Mirror Species
    4. Multi-Level Architecture
  5. Defining GUI Experiment
    1. Defining Parameters
    2. Defining Displays Generalities
    3. Defining 3D Displays
    4. Defining Charts
    5. Defining Monitors and Inspectors
    6. Defining Export files
    7. Defining User Interaction
  6. Exploring Models
    1. Run Several Simulations
    2. Batch Experiments
    3. Exploration Methods
  7. Optimizing Model Section
    1. Runtime Concepts
    2. Optimizing Models
  8. Multi-Paradigm Modeling
    1. Control Architecture
    2. Defining Differential Equations
  1. Manipulate OSM Data
  2. Diffusion
  3. Using Database
  4. Using FIPA ACL
  5. Using BDI with BEN
  6. Using Driving Skill
  7. Manipulate dates
  8. Manipulate lights
  9. Using comodel
  10. Save and restore Simulations
  11. Using network
  12. Headless mode
  13. Using Headless
  14. Writing Unit Tests
  15. Ensure model's reproducibility
  16. Going further with extensions
    1. Calling R
    2. Using Graphical Editor
    3. Using Git from GAMA
  1. Built-in Species
  2. Built-in Skills
  3. Built-in Architecture
  4. Statements
  5. Data Type
  6. File Type
  7. Expressions
    1. Literals
    2. Units and Constants
    3. Pseudo Variables
    4. Variables And Attributes
    5. Operators [A-A]
    6. Operators [B-C]
    7. Operators [D-H]
    8. Operators [I-M]
    9. Operators [N-R]
    10. Operators [S-Z]
  8. Exhaustive list of GAMA Keywords
  1. Installing the GIT version
  2. Developing Extensions
    1. Developing Plugins
    2. Developing Skills
    3. Developing Statements
    4. Developing Operators
    5. Developing Types
    6. Developing Species
    7. Developing Control Architectures
    8. Index of annotations
  3. Introduction to GAMA Java API
    1. Architecture of GAMA
    2. IScope
  4. Using GAMA flags
  5. Creating a release of GAMA
  6. Documentation generation

  1. Predator Prey
  2. Road Traffic
  3. 3D Tutorial
  4. Incremental Model
  5. Luneray's flu
  6. BDI Agents

  1. Team
  2. Projects using GAMA
  3. Scientific References
  4. Training Sessions

Resources

  1. Videos
  2. Conferences
  3. Code Examples
  4. Pedagogical materials
Clone this wiki locally