Skip to content

Commit

Permalink
Cleanup Discrete Optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanDeHoop committed Dec 16, 2024
1 parent d03a3b7 commit 87066ec
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
42 changes: 27 additions & 15 deletions tests/everest/test_discrete.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import pytest

from ert.run_models.everest_run_model import EverestRunModel
from everest.config import EverestConfig
from everest.config.input_constraint_config import InputConstraintConfig
from everest.config import (
ControlConfig,
EverestConfig,
InputConstraintConfig,
InstallJobConfig,
OptimizationConfig,
)


@pytest.mark.integration_test
Expand All @@ -11,22 +16,29 @@ def test_discrete_optimizer(
):
# Arrange
config = EverestConfig.load_file("config_minimal.yml")
config.controls[0].min = 0
config.controls[0].max = 10
config.controls[0].control_type = "integer"
config.controls[0].initial_guess = 0
config.controls[0].variables.pop()
config.controls = [
ControlConfig(
name="point",
type="generic_control",
min=0,
max=10,
control_type="integer",
initial_guess=0,
variables=[{"name": "x"}, {"name": "y"}],
)
]
config.input_constraints = [
InputConstraintConfig(weights={"point.x": 1.0, "point.y": 1.0}, upper_bound=10)
]
config.optimization.backend = "scipy"
config.optimization.algorithm = "differential_evolution"
config.optimization.max_function_evaluations = 4
config.optimization.parallel = False
config.optimization.backend_options = {"seed": 9}
config.install_jobs[0].name = "discrete"
config.install_jobs[0].source = "jobs/DISCRETE"
config.forward_model[0] = "discrete --point-file point.json --out distance"
config.optimization = OptimizationConfig(
backend="scipy",
algorithm="differential_evolution",
max_function_evaluations=4,
parallel=False,
backend_options={"seed": 9},
)
config.install_jobs = [InstallJobConfig(name="discrete", source="jobs/DISCRETE")]
config.forward_model = ["discrete --point-file point.json --out distance"]

# Act
run_model = EverestRunModel.create(config)
Expand Down
4 changes: 3 additions & 1 deletion tests/everest/test_objective_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
def test_objective_type(
copy_math_func_test_data_to_tmp, evaluator_server_config_generator
):
# Arrange
config = EverestConfig.load_file("config_minimal.yml")
config.objective_functions = [
ObjectiveFunctionConfig(name="distance", weight=1.0),
Expand All @@ -16,11 +17,12 @@ def test_objective_type(
),
]

# Act
run_model = EverestRunModel.create(config)
evaluator_server_config = evaluator_server_config_generator(run_model)
run_model.run_experiment(evaluator_server_config)

# Check resulting points
# Assert
x0, x1, x2 = (run_model.result.controls["point_" + p] for p in ["x", "y", "z"])
assert x0 == pytest.approx(0.5, abs=0.025)
assert x1 == pytest.approx(0.5, abs=0.025)
Expand Down

0 comments on commit 87066ec

Please sign in to comment.