• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SMTorg / smt-optim / 28718428290

04 Jul 2026 08:17PM UTC coverage: 86.103% (-0.9%) from 87.05%
28718428290

push

github

web-flow
Feat/mo acquisition functions (#15)

270 of 363 new or added lines in 5 files covered. (74.38%)

3922 of 4555 relevant lines covered (86.1%)

1.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.67
/src/tests/test_unit/test_multi_objective.py
1
import unittest
2✔
2
import numpy as np
2✔
3

4

5
from smt_optim.acquisition_functions.multi_obj import init_mpi
2✔
6

7

8
class MockModel:
2✔
9
    def __init__(self, val, var):
2✔
10
        self.val = val
2✔
11
        self.var = var
2✔
12

13
    def predict_values(self, x):
2✔
14
        return np.array([[self.val]])
2✔
15

16
    def predict_variances(self, x):
2✔
17
        return np.array([[self.var]])
2✔
18

19

20
class MockProblem:
2✔
21
    def __init__(self):
2✔
22
        self.num_obj = 2
2✔
23

24

25
class MockDataset:
2✔
26
    def __init__(self):
2✔
27
        self.points = np.array([[0.5, 0.5]])
2✔
28

29
    def export_as_dict(self):
2✔
30
        return {
2✔
31
            "obj": np.array([[0.2, 0.2], [0.8, 0.8]]),
32
            "rscv": np.array([0.0, 0.0]),
33
            "fidelity": np.array([0, 0]),
34
            "x": np.array([[0.1], [0.9]]),
35
        }
36

37

38
class MockState:
2✔
39
    def __init__(self):
2✔
40
        self.obj_models = [MockModel(0.1, 0.0), MockModel(0.1, 0.0)]
2✔
41
        self.problem = MockProblem()
2✔
42
        self.scaled_dataset = MockDataset()
2✔
43

44

45
class TestMultiObjectiveFixes(unittest.TestCase):
2✔
46
    def test_mpi_zero_variance(self):
2✔
47
        state = MockState()
2✔
48
        # Initialize MPI
49
        mpi_func = init_mpi(state)
2✔
50
        # Point to predict
51
        x_test = np.array([[0.5]])
2✔
52
        # Since variances are 0.0, MPI should return 0.0 to prevent infinite loop
53
        val = mpi_func(x_test)
2✔
54
        self.assertEqual(val, 0.0)
2✔
55

56
    def test_ei_cf_constraint_filtering(self):
2✔
57
        from smt_optim.acquisition_functions.multi_obj import init_bi_obj_ei_cf
2✔
58

59
        state = MockState()
2✔
60
        # Create a mock dataset with one feasible and one infeasible point
61
        # [0.2, 0.2] has rscv = 1.0 (infeasible)
62
        # [0.8, 0.8] has rscv = 0.0 (feasible)
63
        state.scaled_dataset.export_as_dict = lambda: {
2✔
64
            "obj": np.array([[0.2, 0.2], [0.8, 0.8]]),
65
            "rscv": np.array([1.0, 0.0]),
66
            "fidelity": np.array([0, 0]),
67
            "x": np.array([[0.1], [0.9]]),
68
        }
69

70
        # phi is just sum of objectives
71
        def mock_phi(y):
2✔
72
            return np.sum(y, axis=-1)
2✔
73

74
        kwargs = {"phi": mock_phi, "n_accuracy": 10}
2✔
75

76
        # init_bi_obj_ei_cf should find f_min = mock_phi([0.8, 0.8]) = 1.6
77
        # rather than mock_phi([0.2, 0.2]) = 0.4
78

79
        # Since I can't easily extract f_min from the closure without calling it,
80
        # I'll call it with a point. If f_min = 1.6, and predictions are 0.1, 0.1
81
        # Then phi(y) = 0.2. max(f_min - phi(y), 0) = max(1.6 - 0.2, 0) = 1.4
82
        # If f_min was 0.4, max(0.4 - 0.2, 0) = 0.2
83
        ei_cf_func = init_bi_obj_ei_cf(state, kwargs)
2✔
84

85
        val = ei_cf_func(np.array([[0.5]]))
2✔
86
        self.assertAlmostEqual(val[0][0], 1.4)
2✔
87

88

89
if __name__ == "__main__":
2✔
NEW
90
    unittest.main()
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc