gama-platform / gama

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

Cannot set rng in gaml #221

Closed lesquoyb closed 2 months ago

lesquoyb commented 3 months ago

Is your request related to a problem? Please describe. Currently it is not possible to create reliable unit tests for operators using randomness. Sure the results are reproducible if gama is setup with the same generator, but when writing unit tests you cannot know the settings of the machine that is going to execute it, so you have to force your random generator explicitly in the code. The problem is that this doesn't seem to be taken into account. Take for example this model:

experiment rng  type:test {
    test {
        seed <- 0.0327;
        list<int> l1 <- [1,2,3,4,5,6,7,8,9,10];
        write any(l1);
        write 3 among l1;
        assert true;
    }
}

with my generator being set to java by default I get consistently the value 3 and array [7,3,4], with mersenne the value 2 and [2,8,5] and with threaded, 9 and [2,5,4]. So far so good, everything works. But imagine I have a default rng set to java and I want to force the test to execute with threaded for example, I will try to add the line:

gama.pref_rng_name <- "threaded";

before setting the seed. I tried a few places, in the init of the experiment, the global, in the setup and even directly in the test, but I always end up having the same result as with the rng set in the parameters window. If I write the value of pref_rng_name during the execution of the test I can see threaded, but If I look in the experiment parameter it's still java (or whatever I set in the parameters).

Describe the improvement you'd like Setting the pref_rng_name changes the rng in the simulation. Or if it's not possible, then this variable shouldn't be settable.

lesquoyb commented 3 months ago

when it's fixed, uncomment the test on random operators in Lists.experiment

AlexisDrogoul commented 3 months ago

I do not understand why you want to set the default rng name (with gama.pref_rng_name <- "threaded";) instead of the simulation/experiment one specific one with string rng <- "java"; for instance. rng does not work ?

lesquoyb commented 3 months ago

Oh right, I didn't know rng existed, I just thought I could manipulate the one linked to the rng set in preferences. I'll check if everything works properly with that method then