DOELibrary: the seed of the library should be used by default
By default, successive executions of the same OptimizationProblem
with the same DOELibrary
using a pseudo-random algorithm should give two series of evalautions. For that, the DOELibrary
and its subclasses PyDOE
and OpenTURNS
offer a seed
initialized to 0; at each execution, this seed is incremented before being used to set the random number generator, unless the execution option seed
is not None
. Similarly, when the DOELibrary.execute
is called by a DOEScenario
, the latter passes the execution option seed
based on the same mechanisme (the DOEScenario
has a seed initialized to 0 and incremented at each execution of the DOEscenario
).
Thus, when the user does not set the seed
in the algo_options
from a DOEScenario
, the seed
of the DOELibrary
is incremented as expected and passes to the random number generator.
BUT when the user does not set the seed
in the options of the DOELibrary
, even if the seed
of the DOELibrary
increments as expected, the seed passed to the random number generator remains equal to 1. The reason is that the default option of seed
is not None
but 1.
We could fix this bug by changing the default value of the seed
in DOELibrary._get_options
. Warning: it will also be necessary to update the JSON file.
Reproducer
from gemseo.algos.design_space import DesignSpace
from gemseo.algos.opt_problem import OptimizationProblem
from gemseo.api import execute_algo
from gemseo.core.mdofunctions.mdo_function import MDOFunction
design_space = DesignSpace()
design_space.add_variable("x", l_b=0.0, u_b=1.0, value=0.5)
problem = OptimizationProblem(design_space)
problem.objective = MDOFunction(lambda x: x, "obj")
execute_algo(problem, "OT_MONTE_CARLO", algo_type="doe", n_samples=2)
problem.reset(
database=False,
design_space=False,
function_calls=False,
preprocessing=False,
)
execute_algo(problem, "OT_MONTE_CARLO", algo_type="doe", n_samples=2)
assert len(problem.database.get_func_history("obj")) == 2 # expected: 2+2=4