gama-platform / gama.old

Main repository for developing the 1.x versions of GAMA
GNU General Public License v3.0
304 stars 99 forks source link

Headless: float number in the XML, precision error and among facet #3006

Closed benoitgaudou closed 3 years ago

benoitgaudou commented 4 years ago

Describe the bug Please consider the following model:

model TestHeadless

global {
    float float_among <- 0.5;
    float float_min_max <- 0.5;
    float float_no_constraint <- 0.5;

    init {
        write  "-----------------------------";
        write sample(float_among);
        write sample(float_no_constraint);
        write sample(float_min_max);
        write  '=============================';
    }
}

experiment shortExplo_GridV1 type: gui {
    parameter "float among" var: float_among init: 0.5 among: [0.01, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.99];
    parameter "float no contraint" var: float_no_constraint init: 0.5;
    parameter "float min max" var: float_min_max init: 0.5 min: 0.0 max: 1.0 step: 0.01;
}

The experiment shortExplo_GridV1 will run in headless using the following XML file:

<Experiment_plan>
    <Simulation experiment="shortExplo_GridV1" finalStep="30" id="0" seed="0" sourcePath="./TestHeadless.gaml">
        <Parameters>
            <Parameter type="FLOAT" value="0.1" var="float_among"/>
            <Parameter type="FLOAT" value="0.1" var="float_no_constraint"/>         
            <Parameter type="FLOAT" value="0.6" var="float_min_max"/>           
        </Parameters>
        <Outputs/>
    </Simulation>
    <Simulation experiment="shortExplo_GridV1" finalStep="30" id="1" seed="1" sourcePath="./TestHeadless.gaml">
        <Parameters>
            <Parameter type="FLOAT" value="0.3" var="float_among"/>
            <Parameter type="FLOAT" value="0.3" var="float_no_constraint"/>         
            <Parameter type="FLOAT" value="0.75" var="float_min_max"/>
        </Parameters>
        <Outputs/>
    </Simulation>
</Experiment_plan>

To Reproduce Steps to reproduce the behavior:

  1. Locate these 2 files in the headless folder of GAMA
  2. Run the xml with headless mode: sh ./gama-headless.sh -m 6000m TestHeadless.xml toto

We get the following results:

Creation of shortExplo_GridV10
-----------------------------
float_among -: 0.01
float_no_constraint -: 0.10000000149011612
float_min_max -: 0.6000000238418579
=============================
Creation of shortExplo_GridV10
...-----------------------------
.float_among -: 0.01
float_no_constraint -: 0.30000001192092896
float_min_max -: 0.75
.=============================

This shows that there is some conversions in the number taken in the XML to GAMA as for float_no_constraint the values given in the XML file are: 0.1 and 0.3, and the variable receives the values: 0.10000000149011612 and 0.30000001192092896.

The main issue here is when the parameter is defined with the among facet ( as it is the case for float_among): the values given in the XML are in the range of possible values. But with the approximation error, it becomes out of the possible values, and thus the parameter receives the first value of the possible values.

Expected behavior No precision error is expected.

Desktop (please complete the following information):

AlexisDrogoul commented 4 years ago

Actually, this is a problem that goes beyond the headless part of GAMA and concerns the use of among with floating point values (I guess we could reproduce the same problem in the GUI). The conversion problem you describe is normal, AFAIK, maybe a bit exacerbated by the use of Float instead of Double in headless (why ? I don't know). However, the fact that it is not found in the list of possible values (among) is a real issue, which should lead us to find a new way to check whether or not a value is "inside" a list of float values.

AlexisDrogoul commented 4 years ago

Have you been able to test the changes introduced in https://github.com/gama-platform/gama/commit/507895f615e71bfd0ce64431fc7117466fc0a8ed ?

AlexisDrogoul commented 3 years ago

The fix should be tested. It seems to work on my side.

RoiArthurB commented 3 years ago

Tested and fixed with the gaml exemple :)

bash ./headless/gama-headless.sh ./test.xml ./output
******************************************************************
* GAMA version 1.8.2                                             *
* http://gama-platform.org                                       *
* (c) 2007-2021 UMI 209 UMMISCO IRD/SU & Partners                *
******************************************************************
> GAMA: version 1.8.2                         loading on____ linux 5.12.19-1-MANJARO, x86_64, JDK 15.0.2
> JAI : ImageIO extensions                    loaded for____ jpg||tiff|bmp|gif|arx|tf8|TF8|png|ppm|jp2|tif|TIF|asc|TIFF|btf|BTF|pgm|wbmp|jpeg|pbm
> GAMA: msi.gama.core                         loaded in_____ 1226ms
> GAMA: ummisco.gaml.extensions.maths         loaded in_____ 15ms
> GAMA: irit.gaml.extensions.database         loaded in_____ 13ms
> GAMA: ummisco.gaml.extensions.stats         loaded in_____ 19ms
> GAMA: ummisco.gama.java2d                   loaded in_____ 1ms
> GAMA: msi.gama.headless                     loaded in_____ 3ms
> GAMA: msi.gaml.extensions.fipa              loaded in_____ 14ms
> GAMA: espacedev.gaml.extensions.genstar     loaded in_____ 3ms
> GAMA: miat.gaml.extension.pedestrian        loaded in_____ 23ms
> GAMA: ummisco.gama.network                  loaded in_____ 6ms
> GAMA: ummisco.gama.serialize                loaded in_____ 5ms
> GAMA: ummisco.gama.opengl                   loaded in_____ 8ms
> GAMA: native Bullet library                 loaded in_____ 13ms
> GAMA: simtools.gaml.extensions.physics      loaded in_____ 28ms
> GAMA: simtools.gaml.extensions.traffic      loaded in_____ 40ms
> GAMA: msi.gaml.architecture.simplebdi       loaded in_____ 76ms
> GAMA: msi.gama.lang.gaml                    loaded in_____ 15ms
> GAMA: all plugins                           loaded in_____ 1537ms
GAMA configuring and loading...
> GAMA: GAML artefacts                        built in______ 214ms
Number of cpus used:1 (available: 8)

$ cat ./output/console-outputs-0.txt
/tmp/test.gaml model is being compiled...
-----------------------------
float_among -: 0.1
float_no_constraint -: 0.1
float_min_max -: 0.6
=============================
..............................Simulation duration 6ms    

$ cat ./output/console-outputs-1.txt
/tmp/test.gaml model is being compiled...
-----------------------------
float_among -: 0.3
float_no_constraint -: 0.3
float_min_max -: 0.75
=============================
..............................Simulation duration 5ms