5
5
# LICENSE file in the root directory of this source tree.
6
6
7
7
from itertools import product
8
- from unittest import mock
9
8
10
9
import torch
11
- from botorch .acquisition .max_value_entropy_search import qMaxValueEntropy
12
10
from botorch .acquisition .multi_objective .max_value_entropy_search import (
13
11
qLowerBoundMultiObjectiveMaxValueEntropySearch ,
14
12
qMultiObjectiveMaxValueEntropy ,
15
13
)
16
14
from botorch .acquisition .multi_objective .utils import compute_sample_box_decomposition
17
- from botorch .exceptions .errors import UnsupportedError
18
- from botorch .models .gp_regression import SingleTaskGP
19
15
from botorch .models .model_list_gp_regression import ModelListGP
20
16
from botorch .sampling .normal import SobolQMCNormalSampler
21
17
from botorch .utils .test_helpers import get_model
@@ -33,130 +29,11 @@ def dummy_sample_pareto_frontiers(model):
33
29
)
34
30
35
31
32
+ # TODO: remove all references
36
33
class TestMultiObjectiveMaxValueEntropy (BotorchTestCase ):
37
- def test_multi_objective_max_value_entropy (self ):
38
- for dtype , m in product ((torch .float , torch .double ), (2 , 3 )):
39
- torch .manual_seed (7 )
40
- # test batched model
41
- train_X = torch .rand (1 , 1 , 2 , dtype = dtype , device = self .device )
42
- train_Y = torch .rand (1 , 1 , m , dtype = dtype , device = self .device )
43
- model = SingleTaskGP (train_X , train_Y , outcome_transform = None )
44
- with self .assertRaises (NotImplementedError ):
45
- qMultiObjectiveMaxValueEntropy (
46
- model = model , sample_pareto_frontiers = dummy_sample_pareto_frontiers
47
- )
48
- # test initialization
49
- train_X = torch .rand (4 , 2 , dtype = dtype , device = self .device )
50
- train_Y = torch .rand (4 , m , dtype = dtype , device = self .device )
51
- # Models with outcome transforms aren't supported.
52
- model = SingleTaskGP (train_X , train_Y )
53
- with self .assertRaisesRegex (
54
- UnsupportedError ,
55
- "Conversion of models with outcome transforms is unsupported. "
56
- "To fix this error, explicitly pass `outcome_transform=None`." ,
57
- ):
58
- qMultiObjectiveMaxValueEntropy (
59
- model = ModelListGP (model , model ),
60
- sample_pareto_frontiers = dummy_sample_pareto_frontiers ,
61
- )
62
- # test batched MO model
63
- model = SingleTaskGP (train_X , train_Y , outcome_transform = None )
64
- mesmo = qMultiObjectiveMaxValueEntropy (
65
- model = model , sample_pareto_frontiers = dummy_sample_pareto_frontiers
66
- )
67
- self .assertEqual (mesmo .num_fantasies , 16 )
68
- # Initialize the sampler.
69
- dummy_post = model .posterior (train_X [:1 ])
70
- mesmo .get_posterior_samples (dummy_post )
71
- self .assertIsInstance (mesmo .sampler , SobolQMCNormalSampler )
72
- self .assertEqual (mesmo .sampler .sample_shape , torch .Size ([128 ]))
73
- self .assertIsInstance (mesmo .fantasies_sampler , SobolQMCNormalSampler )
74
- self .assertEqual (mesmo .posterior_max_values .shape , torch .Size ([3 , 1 , m ]))
75
- # test conversion to single-output model
76
- self .assertIs (mesmo .mo_model , model )
77
- self .assertEqual (mesmo .mo_model .num_outputs , m )
78
- self .assertIsInstance (mesmo .model , SingleTaskGP )
79
- self .assertEqual (mesmo .model .num_outputs , 1 )
80
- self .assertEqual (
81
- mesmo .model ._aug_batch_shape , mesmo .model ._input_batch_shape
82
- )
83
- # test ModelListGP
84
- model = ModelListGP (
85
- * [
86
- SingleTaskGP (train_X , train_Y [:, i : i + 1 ], outcome_transform = None )
87
- for i in range (m )
88
- ]
89
- )
90
- mock_sample_pfs = mock .Mock ()
91
- mock_sample_pfs .return_value = dummy_sample_pareto_frontiers (model = model )
92
- mesmo = qMultiObjectiveMaxValueEntropy (
93
- model = model , sample_pareto_frontiers = mock_sample_pfs
94
- )
95
- self .assertEqual (mesmo .num_fantasies , 16 )
96
- # Initialize the sampler.
97
- dummy_post = model .posterior (train_X [:1 ])
98
- mesmo .get_posterior_samples (dummy_post )
99
- self .assertIsInstance (mesmo .sampler , SobolQMCNormalSampler )
100
- self .assertEqual (mesmo .sampler .sample_shape , torch .Size ([128 ]))
101
- self .assertIsInstance (mesmo .fantasies_sampler , SobolQMCNormalSampler )
102
- self .assertEqual (mesmo .posterior_max_values .shape , torch .Size ([3 , 1 , m ]))
103
- # test conversion to batched MO model
104
- self .assertIsInstance (mesmo .mo_model , SingleTaskGP )
105
- self .assertEqual (mesmo .mo_model .num_outputs , m )
106
- self .assertIs (mesmo .mo_model , mesmo ._init_model )
107
- # test conversion to single-output model
108
- self .assertIsInstance (mesmo .model , SingleTaskGP )
109
- self .assertEqual (mesmo .model .num_outputs , 1 )
110
- self .assertEqual (
111
- mesmo .model ._aug_batch_shape , mesmo .model ._input_batch_shape
112
- )
113
- # test that we call sample_pareto_frontiers with the multi-output model
114
- mock_sample_pfs .assert_called_once_with (mesmo .mo_model )
115
- # test basic evaluation
116
- X = torch .rand (1 , 2 , device = self .device , dtype = dtype )
117
- with torch .no_grad ():
118
- vals = mesmo (X )
119
- igs = qMaxValueEntropy .forward (mesmo , X = X .view (1 , 1 , 1 , 2 ))
120
- self .assertEqual (vals .shape , torch .Size ([1 ]))
121
- self .assertTrue (torch .equal (vals , igs .sum (dim = - 1 )))
122
-
123
- # test batched evaluation
124
- X = torch .rand (4 , 1 , 2 , device = self .device , dtype = dtype )
125
- with torch .no_grad ():
126
- vals = mesmo (X )
127
- igs = qMaxValueEntropy .forward (mesmo , X = X .view (4 , 1 , 1 , 2 ))
128
- self .assertEqual (vals .shape , torch .Size ([4 ]))
129
- self .assertTrue (torch .equal (vals , igs .sum (dim = - 1 )))
130
-
131
- # test set X pending to None
132
- mesmo .set_X_pending (None )
133
- self .assertIs (mesmo .mo_model , mesmo ._init_model )
134
- fant_X = torch .cat (
135
- [
136
- train_X .expand (16 , 4 , 2 ),
137
- torch .rand (16 , 1 , 2 , device = self .device , dtype = dtype ),
138
- ],
139
- dim = 1 ,
140
- )
141
- fant_Y = torch .cat (
142
- [
143
- train_Y .expand (16 , 4 , m ),
144
- torch .rand (16 , 1 , m , device = self .device , dtype = dtype ),
145
- ],
146
- dim = 1 ,
147
- )
148
- fantasy_model = SingleTaskGP (fant_X , fant_Y , outcome_transform = None )
149
-
150
- # test with X_pending is not None
151
- with mock .patch .object (
152
- SingleTaskGP , "fantasize" , return_value = fantasy_model
153
- ) as mock_fantasize :
154
- qMultiObjectiveMaxValueEntropy (
155
- model ,
156
- dummy_sample_pareto_frontiers ,
157
- X_pending = torch .rand (1 , 2 , device = self .device , dtype = dtype ),
158
- )
159
- mock_fantasize .assert_called_once ()
34
+ def test_multi_objective_max_value_entropy (self ) -> None :
35
+ with self .assertRaisesRegex (NotImplementedError , "no longer available" ):
36
+ qMultiObjectiveMaxValueEntropy ()
160
37
161
38
162
39
class TestQLowerBoundMultiObjectiveMaxValueEntropySearch (BotorchTestCase ):
0 commit comments