# HG changeset patch
# User siwaa
# Date 1717514281 0
# Node ID f895e266b37afe1e5d9d6df32bc3163bc3823d65
planemo upload for repository https://forgemia.inra.fr/nathalie.rousse/use/-/tree/gama/GAMA/galaxy-tools commit 67d85c013c62c16392b4796af86836b1334f2eef
diff -r 000000000000 -r f895e266b37a Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Makefile Tue Jun 04 15:18:01 2024 +0000
@@ -0,0 +1,21 @@
+# assuming you have locally installed
+# - planemo
+# - singularity
+# - galaxy, the one from siwaa for instance
+#
+# assuming you have a token to get container
+# on the registry (see the job_conf.xml)
+# the following target enable to test the tools
+
+
+serveGAMA: ~/DEVS/galaxy
+ planemo serve --no_cleanup --galaxy_root ~/DEVS/galaxy \
+ --job_config_file ./job_conf.xml \
+ gama_tool.xml
+
+testGAMA: ~/DEVS/galaxy
+ planemo test \
+ --galaxy_root ~/DEVS/galaxy \
+ --job_config_file ./job_conf.xml \
+ --no_cleanup \
+ essai1.xml
diff -r 000000000000 -r f895e266b37a README.md
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/README.md Tue Jun 04 15:18:01 2024 +0000
@@ -0,0 +1,188 @@
+# Galaxy tools for GAMA platform
+
+Desc
+====
+
+The **gama_tool.xml** tool runs a **GAMA Python client**
+interacting with **gama-server (Headless server)**
+concerning a **"Predator Prey" agent-based simulation**.
+It relies on the **gama.simg** container.
+
+See also :
+[containers](../containers) from where container gama.simg comes ;
+[use-containers](../use-containers) ;
+[../../README.md](../../README.md)
+
+The **gama_tool.xml** tool case has been written **from an existing example**
+(*same example as in [use-containers](../use-containers)*) :
+
+ - example code of https://github.com/gitrdm/gama-client-python
+ project
+ - URL : https://github.com/gitrdm/gama-client-python?tab=readme-ov-file#example-code
+ - more : see [../../README.md](../../README.md)
+
+The **gama_tool.xml** tool case is based on :
+
+ - A **"Predator Prey" agent-based model** of the **GAMA platform**.
+ - A **Python program** (*MY_sequential_example.py*) interacting with
+ the GAMA platform in headless mode, as a GAMA Python client to :
+ - **drive the experiment** : initialization, parameters settings,
+ running, pausing, running some more steps, stop.
+ - **observe the experiment** : getting information values such as :
+ cycle, nb_preys/nb_preys_init...
+
+Sources
+=======
+
+The reused existing files have been copied
+at **[src/originals](./src/originals)** folder so :
+
+ - **sequential_example.py**
+ from gama-client-python/examples/sequential_example.py :
+
+ ```
+ # examples
+ cd src/originals
+ mkdir TMP; cd TMP
+ git clone https://github.com/gitrdm/gama-client-python.git
+ cd ..
+ cp -fr TMP/gama-client-python/examples .
+ rm -fr TMP
+ ```
+
+ - **predatorPrey.gaml** and **gama-headless.sh** from gama-platform/headless
+ (gama-platform/headless/samples/predatorPrey/predatorPrey.gaml,
+ gama-platform/headless/gama-headless.sh)
+ by gama.simg :
+
+ ```
+ # headless
+ gama_SIMGPATH=../../../containers/gama.simg
+ cd src/originals
+ mkdir OPT
+ singularity exec --bind ./OPT:/OPT $gama_SIMGPATH bash -c "cp -fr /opt/gama-platform /OPT/."
+ cp -fr OPT/gama-platform/headless headless
+ rm -fr OPT
+ ```
+
+Galaxy tool Inputs / Outputs
+============================
+
+**[gama_tool.xml](./gama_tool.xml) Inputs** :
+
+ - **nb_preys_init** (integer)
+ - **nb_predators_init** (integer)
+ - **nb_more_steps** (integer)
+
+**[gama_tool.xml](./gama_tool.xml) Outputs** :
+
+ - **results .txt file** produced while running the simulator
+ (cf 'reflex save_result' into MY_predatorPrey.gaml).
+ - **run_server .txt file** : gama-server screen display capture
+ - **run_client .txt file** : gama-client screen display capture
+
+Galaxy tool Code
+================
+
+The Galaxy tool **[src](./src) folder** contains :
+
+ - **[MY_sequential_example.py](./src/MY_sequential_example.py)** :
+ **Python code**
+
+ - created from [src/originals/examples/sequential_example.py](./src/originals/examples/sequential_example.py)
+ - modification : variables values for gama-server
+ (*MY_SERVER_URL, MY_SERVER_PORT, GAML_FILE_PATH_ON_SERVER*),
+ for experiment (*EXPERIMENT_NAME, MY_EXP_INIT_PARAMETERS*).
+ - modification : added some "print"
+
+ - **[MY_predatorPrey.gaml](./src/MY_predatorPrey.gaml)** :
+ **"Predator Prey" agent-based simulator** file
+
+ - created from [src/originals/headless/samples/predatorPrey/predatorPrey.gaml](./src/originals/headless/samples/predatorPrey/predatorPrey.gaml)
+ - modification : added **'reflex save_result'** to save some results data
+ into results.txt file.
+
+ - **[cmd_gama_headless.sh](./src/cmd_gama_headless.sh)** :
+ **commands file** (Shell script)
+ launching GAMA Headless gama-server *(by calling MY_gama-headless.sh)*
+
+ - **[cmd_python_client.sh](./src/cmd_python_client.sh)** :
+ **commands file** (Shell script)
+ launching Python program MY_sequential_example.py
+
+ - **[MY_gama-headless.sh](./src/MY_gama-headless.sh)** :
+
+ - created from [src/originals/headless/gama-headless.sh](./src/originals/headless/gama-headless.sh)
+ - modify : setting **java.io.tmpdir** property
+ (```-Djava.io.tmpdir=$MY_TEMP_DIR```),
+ because of gama_tool.xml running error :
+ ```
+ javax.imageio.IIOException: Can't create cache file!
+ at java.desktop/javax.imageio.ImageIO.createImageInputStream(ImageIO.java:361)
+ ....
+ Caused by: java.nio.file.FileSystemException: /tmp/imageio10268746820164254686.tmp: Read-only file system
+ ....
+ SLF4J: No SLF4J providers were found.
+ SLF4J: Defaulting to no-operation (NOP) logger implementation
+ SLF4J: See http://www.slf4j.org/codes.html#noProviders for further details.
+ ```
+
+ *Default temporary directory for Linux is /tmp. The JVM automatically
+ sets the temporary directory path as a system property. It can be
+ changed by setting the java.io.tmpdir property to the desired
+ path when starting the JVM.*
+
+Local run by 'planemo serve'
+============================
+
+**Installs** :
+
+ - Install Singularity : singularity version 3.8.5
+
+ - Install Galaxy code :
+ ```
+ cd ~/DEVS
+ git clone https://github.com/galaxyproject/galaxy.git
+ ```
+
+ Note : Galaxy requiring at least singularity 3.7
+ (cf singularity exec : --no-mount option)
+
+ - Install Planemo into a Python virtualenv :
+ ```
+ pip3 install --upgrade pip wheel setuptools virtualenv
+ python3 -m venv _venv_planemo
+ source _venv_planemo/bin/activate
+
+ python3 -m pip install planemo
+ ```
+
+**Use** :
+
+ ```
+ source _fab/_venv_planemo/bin/activate
+ ```
+
+ - Survey :
+ ```
+ htop
+ ```
+
+ - Check tool syntax :
+ ```
+ planemo lint --report_level all --fail_level error gama_tool.xml
+ ```
+
+ - Run tool :
+ ```
+ make serveGAMA
+ ```
+
+ => http://127.0.0.1:9090
+
+Use those Galaxy tools
+======================
+
+See [use-tools](../use-tools).
+
+
diff -r 000000000000 -r f895e266b37a gama_tool.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gama_tool.xml Tue Jun 04 15:18:01 2024 +0000
@@ -0,0 +1,88 @@
+
+
+ tool for GAMA Platform
+
+
+
+
+ oras://registry.forgemia.inra.fr/nathalie.rousse/use/gama:d01c3645810b3e5bf1b21170fd24d21fe1f831ec
+
+
+
+
+
+ run_server.txt & sleep 20 && /bin/bash cmd_python_client.sh $nb_preys_init $nb_predators_init $nb_more_steps > run_client.txt;
+ cp run_server.txt ${run_server_txt};
+ cp run_client.txt ${run_client_txt};
+ cp gama-platform/headless/samples/predatorPrey/results.txt ${results_txt};
+ ]]>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff -r 000000000000 -r f895e266b37a job_conf.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/job_conf.xml Tue Jun 04 15:18:01 2024 +0000
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
+ true
+
+ true
+
+
+
+
+
diff -r 000000000000 -r f895e266b37a src/MY_gama-headless.sh
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/MY_gama-headless.sh Tue Jun 04 15:18:01 2024 +0000
@@ -0,0 +1,69 @@
+#!/bin/bash
+
+javaVersion=$(java -version 2>&1 | head -n 1 | cut -d "\"" -f 2)
+# Check if good Java version before everything
+if [[ ${javaVersion:2} == 17 ]]; then
+ echo "You should use Java 17 to run GAMA"
+ echo "Found you using version : $javaVersion"
+ exit 1
+fi
+
+memory="0"
+
+for arg do
+ shift
+ case $arg in
+ -m)
+ memory="${1}"
+ shift
+ ;;
+ *)
+ set -- "$@" "$arg"
+ ;;
+ esac
+done
+
+if [[ $memory == "0" ]]; then
+ memory=$(grep Xmx "$( dirname $( realpath "${BASH_SOURCE[0]}" ) )"/../Gama.ini || echo "-Xmx4096m")
+else
+ memory=-Xmx$memory
+fi
+
+workspaceCreate=0
+case "$@" in
+ *-help*|*-version*|*-validate*|*-test*|*-xml*|*-batch*|*-write-xmi*|*-socket*)
+ workspaceCreate=1
+ ;;
+esac
+
+
+echo "******************************************************************"
+echo "* GAMA version 1.9.1 *"
+echo "* http://gama-platform.org *"
+echo "* (c) 2007-2023 UMI 209 UMMISCO IRD/SU & Partners *"
+echo "******************************************************************"
+passWork=.workspace
+# w/ output folder
+if [ $workspaceCreate -eq 0 ]; then
+ # create output folder if not existing
+ if [ ! -d "${@: -1}" ]; then
+ mkdir ${@: -1}
+ fi
+ # create workspace in output folder
+ passWork=${@: -1}/.workspace$(find ${@: -1} -name ".workspace*" | wc -l)
+ mkdir -p $passWork
+
+# w/o output folder
+else
+ # create workspace in current folder
+ passWork=.workspace$(find ./ -maxdepth 1 -name ".workspace*" | wc -l)
+fi
+
+#if ! java -cp "$( dirname $( realpath "${BASH_SOURCE[0]}" ) )"/../plugins/org.eclipse.equinox.launcher*.jar -Xms512m $memory -Djava.awt.headless=true org.eclipse.core.launcher.Main -configuration "$( dirname $( realpath "${BASH_SOURCE[0]}" ) )"/configuration -application msi.gama.headless.product -data $passWork "$@"; then
+MY_TEMP_DIR=.
+if ! java -cp "$( dirname $( realpath "${BASH_SOURCE[0]}" ) )"/../plugins/org.eclipse.equinox.launcher*.jar -Xms512m $memory -Djava.io.tmpdir=$MY_TEMP_DIR -Djava.awt.headless=true org.eclipse.core.launcher.Main -configuration "$( dirname $( realpath "${BASH_SOURCE[0]}" ) )"/configuration -application msi.gama.headless.product -data $passWork "$@"; then
+ echo "Error in you command, here's the log :"
+ cat $passWork/.metadata/.log
+ exit 1
+fi
+
diff -r 000000000000 -r f895e266b37a src/MY_predatorPrey.gaml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/MY_predatorPrey.gaml Tue Jun 04 15:18:01 2024 +0000
@@ -0,0 +1,195 @@
+/**
+* Name: Breeding of prey and predator agents
+* Author:
+* Description: 6th part of the tutorial : Predator Prey
+* Tags: reproduce, myself, self
+*/
+model prey_predator
+
+global {
+ int nb_preys_init <- 200;
+ int nb_predators_init <- 20;
+ float prey_max_energy <- 1.0;
+ float prey_max_transfer <- 0.1;
+ float prey_energy_consum <- 0.05;
+ float predator_max_energy <- 1.0;
+ float predator_energy_transfer <- 0.5;
+ float predator_energy_consum <- 0.02;
+ float prey_proba_reproduce <- 0.01;
+ int prey_nb_max_offsprings <- 5;
+ float prey_energy_reproduce <- 0.5;
+ float predator_proba_reproduce <- 0.01;
+ int predator_nb_max_offsprings <- 3;
+ float predator_energy_reproduce <- 0.5;
+ int nb_preys -> {length(prey)};
+ int nb_predators -> {length(predator)};
+ bool is_batch <- false;
+
+ init {
+ create prey number: nb_preys_init;
+ create predator number: nb_predators_init;
+ write(self);
+ }
+
+ reflex stop_simulation when: ((nb_preys = 0) or (nb_predators = 0)) and !is_batch {
+ do pause;
+ }
+}
+
+species generic_species {
+ float size <- 1.0;
+ rgb color;
+ float max_energy;
+ float max_transfer;
+ float energy_consum;
+ float proba_reproduce;
+ int nb_max_offsprings;
+ float energy_reproduce;
+ vegetation_cell my_cell <- one_of(vegetation_cell);
+ float energy <- rnd(max_energy) update: energy - energy_consum max: max_energy;
+
+ init {
+ location <- my_cell.location;
+ }
+
+ reflex basic_move {
+ my_cell <- one_of(my_cell.neighbors2);
+ location <- my_cell.location;
+ }
+
+ reflex eat {
+ energy <- energy + energy_from_eat();
+ }
+
+ reflex die when: energy <= 0 {
+ do die;
+ }
+
+ reflex reproduce when: (energy >= energy_reproduce) and (flip(proba_reproduce)) {
+ int nb_offsprings <- rnd(1, nb_max_offsprings);
+ create species(self) number: nb_offsprings {
+ my_cell <- myself.my_cell;
+ location <- my_cell.location;
+ energy <- myself.energy / nb_offsprings;
+ }
+
+ energy <- energy / nb_offsprings;
+ }
+
+ float energy_from_eat {
+ return 0.0;
+ }
+
+ aspect base {
+ draw circle(size) color: color;
+ }
+
+
+
+
+ reflex save_result when: (nb_preys > 0) and (nb_predators > 0){
+ save ("cycle: "+ cycle + "; nbPreys: " + nb_preys
+ + "; minEnergyPreys: " + (prey min_of each.energy)
+ + "; maxSizePreys: " + (prey max_of each.energy)
+ + "; nbPredators: " + nb_predators
+ + "; minEnergyPredators: " + (predator min_of each.energy)
+ + "; maxSizePredators: " + (predator max_of each.energy))
+ to: "results.txt" type: "text" rewrite: (cycle = 0) ? true : false;
+ }
+
+
+
+
+}
+
+species prey parent: generic_species {
+ rgb color <- #blue;
+ float max_energy <- prey_max_energy;
+ float max_transfer <- prey_max_transfer;
+ float energy_consum <- prey_energy_consum;
+ float proba_reproduce <- prey_proba_reproduce;
+ int nb_max_offsprings <- prey_nb_max_offsprings;
+ float energy_reproduce <- prey_energy_reproduce;
+
+ float energy_from_eat {
+ float energy_transfer <- 0.0;
+ if(my_cell.food > 0) {
+ energy_transfer <- min([max_transfer, my_cell.food]);
+ my_cell.food <- my_cell.food - energy_transfer;
+ }
+ return energy_transfer;
+ }
+}
+
+species predator parent: generic_species {
+ rgb color <- #red;
+ float max_energy <- predator_max_energy;
+ float energy_transfer <- predator_energy_transfer;
+ float energy_consum <- predator_energy_consum;
+ float proba_reproduce <- predator_proba_reproduce;
+ int nb_max_offsprings <- predator_nb_max_offsprings;
+ float energy_reproduce <- predator_energy_reproduce;
+
+ float energy_from_eat {
+ list reachable_preys <- prey inside (my_cell);
+ if(! empty(reachable_preys)) {
+ ask one_of (reachable_preys) {
+ do die;
+ }
+ return energy_transfer;
+ }
+ return 0.0;
+ }
+}
+
+grid vegetation_cell width: 50 height: 50 neighbors: 4 {
+ float max_food <- 1.0;
+ float food_prod <- rnd(0.01);
+ float food <- rnd(1.0) max: max_food update: food + food_prod;
+ rgb color <- rgb(int(255 * (1 - food)), 255, int(255 * (1 - food))) update: rgb(int(255 * (1 - food)), 255, int(255 * (1 - food)));
+ list neighbors2 <- (self neighbors_at 2);
+}
+
+experiment prey_predator type: gui {
+ parameter "Initial number of preys: " var: nb_preys_init min: 0 max: 1000 category: "Prey";
+ parameter "Prey max energy: " var: prey_max_energy category: "Prey";
+ parameter "Prey max transfer: " var: prey_max_transfer category: "Prey";
+ parameter "Prey energy consumption: " var: prey_energy_consum category: "Prey";
+ parameter "Initial number of predators: " var: nb_predators_init min: 0 max: 200 category: "Predator";
+ parameter "Predator max energy: " var: predator_max_energy category: "Predator";
+ parameter "Predator energy transfer: " var: predator_energy_transfer category: "Predator";
+ parameter "Predator energy consumption: " var: predator_energy_consum category: "Predator";
+ parameter 'Prey probability reproduce: ' var: prey_proba_reproduce category: 'Prey';
+ parameter 'Prey nb max offsprings: ' var: prey_nb_max_offsprings category: 'Prey';
+ parameter 'Prey energy reproduce: ' var: prey_energy_reproduce category: 'Prey';
+ parameter 'Predator probability reproduce: ' var: predator_proba_reproduce category: 'Predator';
+ parameter 'Predator nb max offsprings: ' var: predator_nb_max_offsprings category: 'Predator';
+ parameter 'Predator energy reproduce: ' var: predator_energy_reproduce category: 'Predator';
+
+ output {
+ display main_display {
+ grid vegetation_cell border: #black;
+ species prey aspect: base;
+ species predator aspect: base;
+ }
+
+ monitor "Number of preys" value: nb_preys;
+ monitor "Number of predators" value: nb_predators;
+ }
+}
+
+experiment Optimization type: batch repeat: 2 keep_seed: true until: ( time > 200 ) {
+ parameter "Predator energy reproduce:" var: predator_energy_reproduce min: 0.25 max: 1.0 step: 0.25;
+ parameter "Batch mode:" var: is_batch <- true;
+
+ method tabu maximize: nb_preys + nb_predators iter_max: 10 tabu_list_size: 3;
+
+
+ reflex save_results_explo {
+ ask simulations {
+ save [int(self),prey_max_transfer,prey_energy_reproduce,predator_energy_transfer,predator_energy_reproduce,self.nb_predators,self.nb_preys]
+ to: "results.csv" format:csv rewrite: (int(self) = 0) ? true : false header: true;
+ }
+ }
+}
+
diff -r 000000000000 -r f895e266b37a src/MY_sequential_example.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/MY_sequential_example.py Tue Jun 04 15:18:01 2024 +0000
@@ -0,0 +1,213 @@
+import asyncio
+from asyncio import Future
+from typing import Dict
+
+from gama_client.base_client import GamaBaseClient
+from gama_client.command_types import CommandTypes
+from gama_client.message_types import MessageTypes
+
+import pprint # _PRINT_
+import argparse
+
+nb_preys_init = 100 # default
+nb_predators_init = 10 # default
+nb_more_steps = 5 # default
+
+experiment_future: Future
+play_future: Future
+pause_future: Future
+expression_future: Future
+step_future: Future
+stop_future: Future
+
+
+async def message_handler(message: Dict):
+ print("received", message)
+ if "command" in message:
+ if message["command"]["type"] == CommandTypes.Load.value:
+ experiment_future.set_result(message)
+ elif message["command"]["type"] == CommandTypes.Play.value:
+ play_future.set_result(message)
+ elif message["command"]["type"] == CommandTypes.Pause.value:
+ pause_future.set_result(message)
+ elif message["command"]["type"] == CommandTypes.Expression.value:
+ expression_future.set_result(message)
+ elif message["command"]["type"] == CommandTypes.Step.value:
+ step_future.set_result(message)
+ elif message["command"]["type"] == CommandTypes.Stop.value:
+ stop_future.set_result(message)
+
+
+async def main():
+
+ global experiment_future
+ global play_future
+ global pause_future
+ global expression_future
+ global step_future
+ global stop_future
+
+ # Experiment and Gama-server constants
+
+ MY_SERVER_URL = "localhost"
+
+ MY_SERVER_PORT = 8000
+
+ GAML_FILE_PATH_ON_SERVER = "gama-platform/headless/samples/predatorPrey/MY_predatorPrey.gaml"
+
+ EXPERIMENT_NAME = "prey_predator"
+
+ MY_EXP_INIT_PARAMETERS = [{"type": "int", "name": "nb_preys_init",
+ "value": nb_preys_init},
+ {"type": "int", "name": "nb_predators_init",
+ "value": nb_predators_init}]
+
+ print("[MY_sequential_example.py Setting]",
+ " MY_SERVER_URL:", MY_SERVER_URL,
+ ", MY_SERVER_PORT:", MY_SERVER_PORT,
+ ", GAML_FILE_PATH_ON_SERVER: ", GAML_FILE_PATH_ON_SERVER,
+ ", EXPERIMENT_NAME: ", EXPERIMENT_NAME,
+ ", MY_EXP_INIT_PARAMETERS: ", MY_EXP_INIT_PARAMETERS)
+
+ client = GamaBaseClient(MY_SERVER_URL, MY_SERVER_PORT, message_handler)
+
+ print("connecting to Gama server")
+ await client.connect()
+
+ print("initialize a gaml model")
+ experiment_future = asyncio.get_running_loop().create_future()
+ #await client.load(GAML_FILE_PATH_ON_SERVER, EXPERIMENT_NAME, True, True, True, MY_EXP_INIT_PARAMETERS) # error
+ await client.load(file_path=GAML_FILE_PATH_ON_SERVER,
+ experiment_name=EXPERIMENT_NAME,
+ console=True, status=True, dialog=True, runtime=True,
+ parameters=MY_EXP_INIT_PARAMETERS)
+
+ gama_response = await experiment_future
+ print("*********************") # _PRINT_
+ print("gama_response.keys():", gama_response.keys())
+ print("gama_response:")
+ pprint.pprint(gama_response)
+ print("*********************")
+
+ try:
+ experiment_id = gama_response["content"]
+ except Exception as e:
+ print("error while initializing", gama_response, e)
+ return
+
+ print("initialization successful, running the model")
+ play_future = asyncio.get_running_loop().create_future()
+ await client.play(experiment_id)
+ gama_response = await play_future
+ if gama_response["type"] != MessageTypes.CommandExecutedSuccessfully.value:
+ print("error while trying to run the experiment", gama_response)
+ return
+ print("*********************") # _PRINT_
+ print("gama_response.keys():", gama_response.keys())
+ print("gama_response:")
+ pprint.pprint(gama_response)
+ print("*********************")
+
+ print("model running, waiting a bit")
+ await asyncio.sleep(2)
+
+ print("pausing the model")
+ pause_future = asyncio.get_running_loop().create_future()
+ await client.pause(experiment_id)
+ gama_response = await pause_future
+ if gama_response["type"] != MessageTypes.CommandExecutedSuccessfully.value:
+ print("Unable to pause the experiment", gama_response)
+ return
+ print("*********************") # _PRINT_
+ print("gama_response.keys():", gama_response.keys())
+ print("gama_response:")
+ pprint.pprint(gama_response)
+ print("*********************")
+
+ expression_future = asyncio.get_running_loop().create_future()
+ await client.expression(experiment_id, r"cycle")
+ gama_response = await expression_future
+ print("asking simulation the value of: cycle=", gama_response["content"])
+ print("*********************") # _PRINT_
+ print("gama_response.keys():", gama_response.keys())
+ print("gama_response:")
+ pprint.pprint(gama_response)
+ print("*********************")
+
+ expression_future = asyncio.get_running_loop().create_future()
+ await client.expression(experiment_id, r"nb_preys/nb_preys_init")
+ gama_response = await expression_future
+ print("asking simulation the value of: nb_preys/nb_preys_init=", gama_response["content"])
+ print("*********************") # _PRINT_
+ print("gama_response.keys():", gama_response.keys())
+ print("gama_response:")
+ pprint.pprint(gama_response)
+ print("*********************")
+
+ print("asking gama to run ",nb_more_steps," more steps of the experiment")
+ step_future = asyncio.get_running_loop().create_future()
+ await client.step(experiment_id, nb_more_steps, True)
+ #await client.step(experiment_id, 10, True)
+ gama_response = await step_future
+ if gama_response["type"] != MessageTypes.CommandExecutedSuccessfully.value:
+ print("Unable to execute 10 new steps in the experiment", gama_response)
+ return
+ print("*********************") # _PRINT_
+ print("gama_response.keys():", gama_response.keys())
+ print("gama_response:")
+ pprint.pprint(gama_response)
+ print("*********************")
+
+ expression_future = asyncio.get_running_loop().create_future()
+ await client.expression(experiment_id, r"cycle")
+ gama_response = await expression_future
+ print("asking simulation the value of: cycle=", gama_response["content"])
+ print("*********************") # _PRINT_
+ print("gama_response.keys():", gama_response.keys())
+ print("gama_response:")
+ pprint.pprint(gama_response)
+ print("*********************")
+
+ print("killing the simulation")
+ stop_future = asyncio.get_running_loop().create_future()
+ await client.stop(experiment_id)
+ gama_response = await stop_future
+ if gama_response["type"] != MessageTypes.CommandExecutedSuccessfully.value:
+ print("Unable to stop the experiment", gama_response)
+ return
+ print("*********************") # _PRINT_
+ print("gama_response.keys():", gama_response.keys())
+ print("gama_response:")
+ pprint.pprint(gama_response)
+ print("*********************")
+
+ # Added
+ print("killing gama-server")
+ exit_future = asyncio.get_running_loop().create_future()
+ await client.exit()
+ # no response
+ print("*********************") # _PRINT_
+ print("Command exit() done")
+ print("*********************")
+
+
+if __name__ == "__main__":
+
+ parser = argparse.ArgumentParser()
+ parser.add_argument("-nb_preys_init", type=int, help="nb_preys_init")
+ parser.add_argument("-nb_predators_init", type=int, help="nb_predators_init")
+ parser.add_argument("-nb_more_steps", type=int, help="nb_more_steps")
+ args = parser.parse_args()
+ if (args.nb_preys_init is not None) and (args.nb_preys_init != 'None') :
+ nb_preys_init = args.nb_preys_init
+ if (args.nb_predators_init is not None) and (args.nb_predators_init != 'None') :
+ nb_predators_init = args.nb_predators_init
+ if (args.nb_more_steps is not None) and (args.nb_more_steps != 'None') :
+ nb_more_steps = args.nb_more_steps
+
+ print("[MY_sequential_example.py Parameters]",
+ " nb_preys_init (for MY_predatorPrey.gaml) :", nb_preys_init,
+ " nb_predators_init (for MY_predatorPrey.gaml) :", nb_predators_init,
+ ", nb_more_steps (for MY_sequential_example.py) :", nb_more_steps)
+
+ asyncio.run(main())
diff -r 000000000000 -r f895e266b37a src/cmd_gama_headless.sh
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/cmd_gama_headless.sh Tue Jun 04 15:18:01 2024 +0000
@@ -0,0 +1,6 @@
+#!/bin/bash
+
+# Launch GAMA Headless gama-server
+
+gama-platform/headless/MY_gama-headless.sh -v -socket 8000
+
diff -r 000000000000 -r f895e266b37a src/cmd_python_client.sh
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/cmd_python_client.sh Tue Jun 04 15:18:01 2024 +0000
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+# Launch Python program MY_sequential_example.py
+
+VALUE_nb_preys_init=$1
+VALUE_nb_predators_init=$2
+VALUE_nb_more_steps=$3
+
+python3 MY_sequential_example.py -nb_preys_init $VALUE_nb_preys_init -nb_predators_init $VALUE_nb_predators_init -nb_more_steps $VALUE_nb_more_steps
+