@@ -112,7 +112,7 @@ def function(self, x, *args, **kwargs):
112112 self ._aux_input ()
113113
114114 # check for ensmble
115- if len (x .shape ) == 1 :
115+ if len (x .shape ) == 1 :
116116 x = x [:,np .newaxis ]
117117 self .ne = self .num_models
118118 else : self .ne = x .shape [1 ]
@@ -124,22 +124,22 @@ def function(self, x, *args, **kwargs):
124124 x = self ._reorganize_multilevel_ensemble (x )
125125 x = self .scale_state (x ).squeeze ()
126126
127- if self .enX is not None :
128- self .enX = self .scale_state (self .enX )
127+ # if self.enX is not None:
128+ # self.enX = self.scale_state(self.enX)
129129
130130 # Evaluate the objective function
131131 if run_success :
132132 func_values = self .obj_func (
133133 self .pred_data ,
134134 input_dict = self .sim .input_dict ,
135135 true_order = self .sim .true_order ,
136- state = matrix_to_dict (self . enX , self .idX ),
136+ state = matrix_to_dict (x , self .idX ),
137137 ** kwargs
138138 )
139139 else :
140140 func_values = np .inf # the simulations have crashed
141141
142- if len (x .shape ) == 1 :
142+ if len (x .shape ) == 1 :
143143 self .stateF = func_values
144144 else :
145145 self .enF = func_values
@@ -258,13 +258,13 @@ def save_stateX(self, path='./', filetype='npz'):
258258 np .save (path + 'stateX.npy' , stateX )
259259
260260 def _reorganize_multilevel_ensemble (self , x ):
261- if ( ' multilevel' in self . keys_en ) and ( len ( x . shape ) > 1 ):
262- ml_ne = self . keys_en [ 'multilevel' ][ 'ml_ne' ]
263- x = ot . toggle_ml_state ( x , ml_ne )
264- return x
265- else :
266- return x
267-
261+ # Only toggle multilevel state when x is truly an ensemble (2D with >1 columns).
262+ # Treat shape (nx, 1) the same as a 1D vector.
263+ if 'multilevel' in self . keys_en :
264+ if isinstance ( x , list ) or ( x . ndim > 1 and ( x . shape [ 1 ] > 1 ) ):
265+ ml_ne = self . multilevel [ 'ml_ne' ]
266+ x = ot . toggle_ml_state ( x , ml_ne )
267+ return x
268268
269269 def _aux_input (self ):
270270 """
0 commit comments