gama-platform / gama

Main repository for developing the 2024+ versions of GAMA
https://gama-platform.org
GNU General Public License v3.0
12 stars 5 forks source link

[GS] Unable to retrieve batch experiments when running headless server #152

Open lesquoyb opened 3 months ago

lesquoyb commented 3 months ago

Describe the bug When running gama server from a console and trying to execute an experiment of type batch, gama returns UnableToExecuteRequest: 'Unable to find the experiment or simulation'. Changing the experiment type to gui solves the issue.

In addition there seem to be no problem when running a batch experiment with gama-server started from the GUI.

I have no error message in the console or in eclipse when running from git but a user reported that he has the following error message for batch experiments since 1.9.3:

java.lang.ClassCastException: class msi.gama.kernel.experiment.BatchAgent cannot be cast to class msi.gama.kernel.simulation.SimulationAgent (msi.gama.kernel.experiment.BatchAgent and msi.gama.kernel.simulation.SimulationAgent are in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @63b78115)
    at gaml.additions.core.GamlAdditions.lambda$161(GamlAdditions.java:243)
    at msi.gaml.compilation.GamaHelper.run(GamaHelper.java:73)
    at msi.gaml.compilation.IGamaHelper.run(IGamaHelper.java:49)
    at msi.gaml.variables.Variable.value(Variable.java:840)
    at msi.gaml.variables.Variable.value(Variable.java:834)
    at msi.gaml.variables.Variable.getInitialValue(Variable.java:889)
    at msi.gama.kernel.experiment.ExperimentAgent$ExperimentAgentScope.getGlobalVarValue(ExperimentAgent.java:1042)
    at msi.gaml.expressions.variables.GlobalVariableExpression._value(GlobalVariableExpression.java:95)
    at msi.gaml.expressions.AbstractExpression.value(AbstractExpression.java:87)
    at msi.gaml.expressions.operators.BinaryOperator._value(BinaryOperator.java:148)
    at msi.gaml.expressions.AbstractExpression.value(AbstractExpression.java:87)
    at msi.gaml.expressions.operators.BinaryOperator._value(BinaryOperator.java:148)
    at msi.gaml.expressions.AbstractExpression.value(AbstractExpression.java:87)
    at msi.gama.headless.server.GamaServerExperimentController$MyRunnable.run(GamaServerExperimentController.java:83)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.lang.Thread.run(Thread.java:833)

Additional context Could it be related to the last minute fix we brought to headless legacy at the coding camp that was also related to the type of the experiment ? (can't find any issue about it, so I guess it's just in one of the very first commits of this repo or the very last of gama.old)

cvaraujo commented 3 months ago

Complementing the description with some infos to reproduce the bug using GAMA_1.9.3_Linux_with_JDK.zip. I'm using Julia to make the requests and my Gui experiment is defined as:

experiment headless_dengue_propagation type: batch keep_seed: true until: (cycle >= max_cycles or end_simulation) repeat: 30 {
    parameter "Type of execution" var: run_batch category: "bool" init: true;
    parameter "SQLite" var: sqlite_ds category: "string";
    parameter "Max cycles" var: max_cycles category: "int" init: 1;
    parameter "Execution id" var: execution_id category: "int" init: 1;
    parameter "Save" var: save_states category: "bool" init: false;
}
  1. I'm starting the gama server without set memory or CPUs: ./gama-headless.sh -socket 6868

  2. Message exchange occurs as follows in Julia (I've omitted the parameters to simplify the visualization):

Sent: Dict{String, Any}("until" => "end_simulation = true", "parameters" => Any[...], "status" => true, "model" => "models/dengue_propagation.gaml", "experiment" => "headless_dengue_propagation", "type" => "load")
Received: Dict{String, Any}("content" => "775369427", "type" => "ConnectionSuccessful")
Received: Dict{String, Any}("content" => "{\"message\": \" Batch ready. Click run to begin.\"}", "exp_id" => "7246", "type" => "SimulationStatusInform")

Sent: Dict{String, Any}("sync" => true, "exp_id" => "7246", "type" => "play")
Received: Dict{String, Any}("content" => "7246", "command" => Dict{String, Any}("until" => "end_simulation = true", "parameters" => Any[...], "status" => true, "model" => "models/dengue_propagation.gaml", "experiment" => "headless_dengue_propagation", "type" => "load"), "type" => "CommandExecutedSuccessfully")
Received: Dict{String, Any}("content" => "Unable to find the experiment or simulation", "command" => Dict{String, Any}("sync" => true, "exp_id" => "7246", "type" => "play"), "type" => "UnableToExecuteRequest")

And the messages in the server are:

models/dengue_propagation.gaml model is being compiled...

after the load command, and

java.lang.ClassCastException: class msi.gama.kernel.experiment.BatchAgent cannot be cast to class msi.gama.kernel.simulation.SimulationAgent (msi.gama.kernel.experiment.BatchAgent and msi.gama.kernel.simulation.SimulationAgent are in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @3ffb439f)
    at gaml.additions.core.GamlAdditions.lambda$161(GamlAdditions.java:243)
    at msi.gaml.compilation.GamaHelper.run(GamaHelper.java:73)
    at msi.gaml.compilation.IGamaHelper.run(IGamaHelper.java:49)
    at msi.gaml.variables.Variable.value(Variable.java:840)
    at msi.gaml.variables.Variable.value(Variable.java:834)
    at msi.gaml.variables.Variable.getInitialValue(Variable.java:889)
    at msi.gama.kernel.experiment.ExperimentAgent$ExperimentAgentScope.getGlobalVarValue(ExperimentAgent.java:1042)
    at msi.gaml.expressions.variables.GlobalVariableExpression._value(GlobalVariableExpression.java:95)
    at msi.gaml.expressions.AbstractExpression.value(AbstractExpression.java:87)
    at msi.gaml.expressions.operators.BinaryOperator._value(BinaryOperator.java:148)
    at msi.gaml.expressions.AbstractExpression.value(AbstractExpression.java:87)
    at msi.gaml.expressions.operators.BinaryOperator._value(BinaryOperator.java:148)
    at msi.gaml.expressions.AbstractExpression.value(AbstractExpression.java:87)
    at msi.gama.headless.server.GamaServerExperimentController$MyRunnable.run(GamaServerExperimentController.java:83)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.lang.Thread.run(Thread.java:833)

After the Play command.

I don't think my Gama model will help much, since it has more than 1k lines and is quite messy for some tests with Database and other things.

lesquoyb commented 2 months ago

I narrowed it down, here is a basic example model where it happens:

model test

experiment simulation type: batch until:cycle=100;

The problem is that when cycle is evaluated, its scope is a BatchAgent but it is expected to be a SimulationAgent. Here is the stack trace I have:

java.lang.ClassCastException: class gama.core.kernel.experiment.BatchAgent cannot be cast to class gama.core.kernel.simulation.SimulationAgent (gama.core.kernel.experiment.BatchAgent and gama.core.kernel.simulation.SimulationAgent are in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @56ca9154)
    at gaml.additions.core.GamlAdditions.lambda$152(GamlAdditions.java:235)
    at gama.gaml.compilation.GamaHelper.run(GamaHelper.java:75)
    at gama.gaml.compilation.IGamaHelper.run(IGamaHelper.java:51)
    at gama.gaml.variables.Variable.value(Variable.java:822)
    at gama.gaml.variables.Variable.value(Variable.java:816)
    at gama.gaml.variables.Variable.getInitialValue(Variable.java:871)
    at gama.core.kernel.experiment.ExperimentAgent$ExperimentAgentScope.getGlobalVarValue(ExperimentAgent.java:1100)
    at gama.gaml.expressions.variables.GlobalVariableExpression._value(GlobalVariableExpression.java:95)
    at gama.gaml.expressions.AbstractExpression.value(AbstractExpression.java:87)
    at gama.gaml.expressions.operators.BinaryOperator._value(BinaryOperator.java:148)
    at gama.gaml.expressions.AbstractExpression.value(AbstractExpression.java:87)
    at gama.headless.server.GamaServerExperimentController$MyRunnable.run(GamaServerExperimentController.java:83)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.lang.Thread.run(Thread.java:842)

I find it weird that this only appeared in 1.9.3 as both classes are not directly link and probably haven't been for a long time, and what is especially weird is that it doesn't happen in pure gui mode nor in server-mode with the gui of gama. @AlexisDrogoul do you have an idea of what could have happened ? maybe some changes when porting the server mode in gui ?

lesquoyb commented 3 weeks ago

Turns out it was a mix between gama-server problems and batch problems. Once both #186 and #226 are merged into the main branch it should be working again