diff --git a/moptipyapps/dynamic_control/objective.py b/moptipyapps/dynamic_control/objective.py index a77bed05..ca703f8e 100644 --- a/moptipyapps/dynamic_control/objective.py +++ b/moptipyapps/dynamic_control/objective.py @@ -198,10 +198,13 @@ def evaluate(self, x: np.ndarray) -> float: np.copy(start.flatten()) # <--- This should make no sense... ode = run_ode( start, equations, controller, x, controller_dim, steps, time) - results[i] = j_from_ode(ode, state_dim, state_dims_in_j, gamma) + results[i] = z = j_from_ode(ode, state_dim, state_dims_in_j, gamma) + if not (0.0 <= z <= 1e100): + return 1e200 if collector is not None: collector(diff_from_ode(ode, state_dim)) - return self.sum_up_results(results) + z = self.sum_up_results(results) + return z if 0.0 <= z <= 1e100 else 1e200 def sum_up_results(self, results: np.ndarray) -> float: """ diff --git a/tests/dynamic_control/test_experiment_raw.py b/tests/dynamic_control/test_experiment_raw.py index 2783a610..dc67f86e 100644 --- a/tests/dynamic_control/test_experiment_raw.py +++ b/tests/dynamic_control/test_experiment_raw.py @@ -58,9 +58,10 @@ def test_experiment_raw(random: Generator = default_rng()) -> None: :param random: a randomizer """ - n_runs: Final[int] = int(random.integers(1, 5)) + n_runs: Final[int] = 1 er: list[EndResult] = [] insts: list[Callable[[], Instance]] = __make_instances() + insts = [insts[random.integers(len(insts))]] with TempDir.create() as use_dir: er.clear() diff --git a/tests/dynamic_control/test_experiment_surrogate.py b/tests/dynamic_control/test_experiment_surrogate.py index a7b362ad..b822e506 100644 --- a/tests/dynamic_control/test_experiment_surrogate.py +++ b/tests/dynamic_control/test_experiment_surrogate.py @@ -1,6 +1,6 @@ """A test for the surrogate experiment of the dynamic control problem.""" -from typing import Callable, cast +from typing import Callable, Final, cast from moptipy.api.execution import Execution from moptipy.api.experiment import run_experiment @@ -66,6 +66,7 @@ def test_experiment_surrogate(random: Generator = default_rng()) -> None: :param random: a randomizer """ + n_runs: Final[int] = 1 er: list[EndResult] = [] insts: list[Callable[[], SystemModel]] = list(__make_instances(random)) insts = [insts[random.integers(len(insts))]] @@ -75,8 +76,8 @@ def test_experiment_surrogate(random: Generator = default_rng()) -> None: run_experiment(base_dir=use_dir, instances=insts, setups=[__cmaes], - n_runs=1, + n_runs=n_runs, perform_warmup=False, perform_pre_warmup=False) EndResult.from_logs(use_dir, er.append) - assert len(er) == len(insts) + assert len(er) == (len(insts) * n_runs) diff --git a/tests/dynamic_control/test_objective.py b/tests/dynamic_control/test_objective.py index f26dccd9..eb512bf2 100644 --- a/tests/dynamic_control/test_objective.py +++ b/tests/dynamic_control/test_objective.py @@ -10,12 +10,6 @@ from moptipyapps.dynamic_control.controllers.ann import anns from moptipyapps.dynamic_control.controllers.cubic import cubic from moptipyapps.dynamic_control.controllers.linear import linear -from moptipyapps.dynamic_control.controllers.min_ann import min_anns -from moptipyapps.dynamic_control.controllers.partially_linear import ( - partially_linear, -) -from moptipyapps.dynamic_control.controllers.peaks import peaks -from moptipyapps.dynamic_control.controllers.predefined import predefined from moptipyapps.dynamic_control.controllers.quadratic import quadratic from moptipyapps.dynamic_control.instance import Instance from moptipyapps.dynamic_control.objective import ( @@ -23,11 +17,8 @@ FigureOfMeritLE, ) from moptipyapps.dynamic_control.system import System -from moptipyapps.dynamic_control.systems.lorenz import LORENZ_4, LORENZ_111 -from moptipyapps.dynamic_control.systems.stuart_landau import ( - STUART_LANDAU_4, - STUART_LANDAU_111, -) +from moptipyapps.dynamic_control.systems.lorenz import LORENZ_4 +from moptipyapps.dynamic_control.systems.stuart_landau import STUART_LANDAU_4 def __objective_test(fc: Callable[[Instance, bool], FigureOfMerit], @@ -63,8 +54,7 @@ def __objective_tests(fc: Callable[[Instance, bool], FigureOfMerit], :param fc: the figure of merit :param random: the generator """ - for orig_system in (STUART_LANDAU_111, LORENZ_111, STUART_LANDAU_4, - LORENZ_4): + for orig_system in (STUART_LANDAU_4, LORENZ_4): system = System(orig_system.name, orig_system.state_dims, orig_system.control_dims, orig_system.state_dim_mod, @@ -78,10 +68,6 @@ def __objective_tests(fc: Callable[[Instance, bool], FigureOfMerit], controllers = [linear(system), quadratic(system), cubic(system)] controllers.extend(anns(system)) - controllers.extend(min_anns(system)) - controllers.extend(partially_linear(system)) - controllers.extend(predefined(system)) - controllers.extend(peaks(system)) for c in controllers: __objective_test(fc, Instance(system, c))