Skip to content

Commit a6cf760

Browse files
authored
Improve tests consistency for convergence on GitHub Actions (#450)
* rebase smt 2.0 * improve EGO tests consistency for convergence on GitHub Actions * Update test_ego.py
1 parent 431d47d commit a6cf760

File tree

2 files changed

+24
-43
lines changed

2 files changed

+24
-43
lines changed

smt/applications/tests/test_ego.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,13 @@ def test_rosenbrock_2D(self):
115115
criterion = "LCB" #'EI' or 'SBO' or 'LCB'
116116
random_state = 42
117117
design_space = DesignSpace(xlimits, seed=random_state)
118-
119118
xdoe = FullFactorial(xlimits=xlimits)(10)
120119
ego = EGO(
120+
n_start=30,
121121
xdoe=xdoe,
122122
n_iter=n_iter,
123123
criterion=criterion,
124-
surrogate=KRG(design_space=design_space, print_global=False),
124+
surrogate=KRG(design_space=design_space, n_start=25, print_global=False),
125125
random_state=random_state,
126126
)
127127

@@ -156,7 +156,8 @@ def test_rosenbrock_2D_parallel(self):
156156
fun = Rosenbrock(ndim=2)
157157
xlimits = fun.xlimits
158158
criterion = "LCB" #'EI' or 'SBO' or 'LCB'
159-
design_space = DesignSpace(xlimits)
159+
random_state = 42
160+
design_space = DesignSpace(xlimits, seed=random_state)
160161

161162
xdoe = FullFactorial(xlimits=xlimits)(10)
162163
qEI = "KB"
@@ -168,7 +169,7 @@ def test_rosenbrock_2D_parallel(self):
168169
n_parallel=n_parallel,
169170
qEI=qEI,
170171
evaluator=ParallelEvaluator(),
171-
random_state=42,
172+
random_state=random_state,
172173
)
173174

174175
x_opt, y_opt, _, _, _ = ego.optimize(fun=fun)
@@ -244,8 +245,7 @@ def test_branin_2D_mixed_parallel(self):
244245
],
245246
seed=random_state,
246247
)
247-
sm = KRG(design_space=design_space, print_global=False)
248-
248+
sm = KRG(design_space=design_space, print_global=False, n_start=25)
249249
mixint = MixedIntegerContext(design_space)
250250
sampling = mixint.build_sampling_method(FullFactorial)
251251
xdoe = sampling(10)
@@ -256,6 +256,7 @@ def test_branin_2D_mixed_parallel(self):
256256
criterion=criterion,
257257
n_parallel=n_parallel,
258258
qEI=qEI,
259+
n_start=30,
259260
evaluator=ParallelEvaluator(),
260261
surrogate=sm,
261262
random_state=random_state,
@@ -275,11 +276,13 @@ def test_branin_2D_mixed(self):
275276
n_iter = 20
276277
fun = Branin(ndim=2)
277278
xlimits = fun.xlimits
279+
random_state = 42
278280
design_space = DesignSpace(
279281
[
280282
IntegerVariable(*xlimits[0]),
281283
FloatVariable(*xlimits[1]),
282-
]
284+
],
285+
seed=random_state,
283286
)
284287
criterion = "EI" #'EI' or 'SBO' or 'LCB'
285288

@@ -293,7 +296,7 @@ def test_branin_2D_mixed(self):
293296
criterion=criterion,
294297
surrogate=sm,
295298
enable_tunneling=False,
296-
random_state=42,
299+
random_state=random_state,
297300
)
298301

299302
x_opt, y_opt, _, _, _ = ego.optimize(fun=fun)
@@ -414,10 +417,12 @@ def test_ego_mixed_integer_gower_distance(self):
414417

415418
criterion = "EI" #'EI' or 'SBO' or 'LCB'
416419
ego = EGO(
420+
n_start=30,
417421
n_iter=n_iter,
418422
criterion=criterion,
419423
xdoe=xdoe,
420424
surrogate=KRG(
425+
n_start=25,
421426
design_space=design_space,
422427
categorical_kernel=MixIntKernelType.GOWER,
423428
print_global=False,
@@ -431,6 +436,8 @@ def test_ego_mixed_integer_gower_distance(self):
431436

432437
@unittest.skipIf(int(os.getenv("RUN_SLOW", 0)) < 1, "too slow")
433438
def test_ego_mixed_integer_hierarchical_NN(self):
439+
random_state = 42
440+
434441
def f_neu(x1, x2, x3, x4):
435442
if x4 == 0:
436443
return 2 * x1 + x2 - 0.5 * x3
@@ -652,6 +659,7 @@ def f_hv(X):
652659
raise ValueError
653660
return np.array(y)
654661

662+
random_state = 0
655663
ds = DesignSpace(
656664
[
657665
CategoricalVariable(values=[0, 1, 2, 3]), # meta
@@ -665,7 +673,8 @@ def f_hv(X):
665673
IntegerVariable(0, 2),
666674
IntegerVariable(0, 2),
667675
IntegerVariable(0, 2),
668-
]
676+
],
677+
seed=random_state,
669678
)
670679

671680
# x4 is acting if meta == 1, 3
@@ -678,7 +687,6 @@ def f_hv(X):
678687
ds.declare_decreed_var(decreed_var=8, meta_var=0, meta_value=[0, 1])
679688

680689
n_doe = 25
681-
random_state = 0
682690
ds.seed = random_state
683691
Xt, x_is_active = ds.sample_valid_x(n_doe)
684692

@@ -712,20 +720,22 @@ def f_hv(X):
712720

713721
def test_ego_mixed_integer_homo_gaussian(self):
714722
n_iter = 15
723+
random_state = 42
715724
design_space = DesignSpace(
716725
[
717726
FloatVariable(-5, 5),
718727
CategoricalVariable(["blue", "red", "green"]),
719728
CategoricalVariable(["large", "small"]),
720729
IntegerVariable(0, 2),
721-
]
730+
],
731+
seed=random_state,
722732
)
723733
n_doe = 5
724734
sampling = MixedIntegerSamplingMethod(
725735
LHS,
726736
design_space,
727737
criterion="ese",
728-
random_state=42,
738+
random_state=random_state,
729739
output_in_folded_space=True,
730740
)
731741
xdoe = sampling(n_doe)
@@ -741,7 +751,7 @@ def test_ego_mixed_integer_homo_gaussian(self):
741751
print_global=False,
742752
),
743753
enable_tunneling=False,
744-
random_state=42,
754+
random_state=random_state,
745755
)
746756
_, y_opt, _, _, _ = ego.optimize(fun=TestEGO.function_test_mixed_integer)
747757

@@ -783,7 +793,7 @@ def test_ego_mixed_integer_homo_gaussian_pls(self):
783793
xdoe=xdoe,
784794
surrogate=sm,
785795
enable_tunneling=False,
786-
random_state=42,
796+
random_state=random_state,
787797
)
788798
_, y_opt, _, _, _ = ego.optimize(fun=TestEGO.function_test_mixed_integer)
789799

@@ -798,7 +808,6 @@ def test_ydoe_option(self):
798808
design_space = DesignSpace(xlimits, seed=random_state)
799809
xdoe = FullFactorial(xlimits=xlimits)(10)
800810
ydoe = fun(xdoe)
801-
802811
ego = EGO(
803812
xdoe=xdoe,
804813
ydoe=ydoe,

smt/applications/tests/test_mixed_integer.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -34,34 +34,6 @@
3434

3535

3636
class TestMixedInteger(unittest.TestCase):
37-
def test_krg_mixed_3D_INT(self):
38-
design_space = DesignSpace(
39-
[
40-
FloatVariable(-10, 10),
41-
CategoricalVariable(["blue", "red", "green"]),
42-
IntegerVariable(-10, 10),
43-
]
44-
)
45-
46-
mixint = MixedIntegerContext(design_space)
47-
48-
sm = mixint.build_kriging_model(KRG(print_prediction=False))
49-
sampling = mixint.build_sampling_method(LHS, criterion="m")
50-
51-
fun = Sphere(ndim=3)
52-
xt = sampling(20)
53-
yt = fun(xt)
54-
sm.set_training_values(xt, yt)
55-
sm.train()
56-
57-
eq_check = True
58-
for i in range(xt.shape[0]):
59-
if abs(float(xt[i, :][2]) - int(float(xt[i, :][2]))) > 10e-8:
60-
eq_check = False
61-
if not (xt[i, :][1] == 0 or xt[i, :][1] == 1 or xt[i, :][1] == 2):
62-
eq_check = False
63-
self.assertTrue(eq_check)
64-
6537
def test_krg_mixed_3D(self):
6638
design_space = DesignSpace(
6739
[

0 commit comments

Comments
 (0)