Skip to content

Commit dde8083

Browse files
author
Elwardi
committed
fix: remaining specialization computation only in --no-opt mode, and at the end of the opt run
1 parent 292eabf commit dde8083

3 files changed

Lines changed: 31 additions & 2 deletions

File tree

src/foambo/api_server.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2231,6 +2231,14 @@ def get_specialization_cost():
22312231
if hasattr(_state, '_specialization_cache') and _state._specialization_cache:
22322232
return SafeJSONResponse(content=_state._specialization_cache)
22332233

2234+
# Heavy GP simulation — only run in --no-opt dashboard mode.
2235+
# During an active optimization, this would compete with trial scheduling.
2236+
if not getattr(_state, 'no_opt', False):
2237+
return SafeJSONResponse(content={
2238+
"estimates": {},
2239+
"error": "Specialization cost is only computed in --no-opt mode",
2240+
})
2241+
22342242
import numpy as np
22352243
raw_cfg = _state.raw_cfg
22362244
if not raw_cfg or not raw_cfg.get("robust_optimization"):
@@ -3188,7 +3196,7 @@ def get_trial_visualization(trial_index: int):
31883196
# Server lifecycle
31893197

31903198
def start_api_server(client, raw_cfg, orch_cfg, host: str = "127.0.0.1",
3191-
port: int = 8098) -> threading.Thread | None:
3199+
port: int = 8098, no_opt: bool = False) -> threading.Thread | None:
31923200
"""Start the API server in a background daemon thread.
31933201
31943202
Args:
@@ -3208,6 +3216,7 @@ def start_api_server(client, raw_cfg, orch_cfg, host: str = "127.0.0.1",
32083216
_state.client = client
32093217
_state.raw_cfg = raw_cfg
32103218
_state.orch_cfg = orch_cfg
3219+
_state.no_opt = no_opt
32113220
_state.start_time = time.time()
32123221
_state.last_callback = time.time()
32133222

src/foambo/optimize.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,7 @@ def _warm_fit(self, *a, state_dict=None, refit=True, **kw):
10291029
plain_cfg = OmegaConf.to_container(cfg, resolve=True) if hasattr(cfg, '_metadata') else cfg
10301030
thread = start_api_server(
10311031
client=client, raw_cfg=plain_cfg, orch_cfg=orch_cfg,
1032-
host=orch_cfg.api_host, port=orch_cfg.api_port,
1032+
host=orch_cfg.api_host, port=orch_cfg.api_port, no_opt=True,
10331033
)
10341034
if thread is None:
10351035
log.error("API server failed to start")

src/foambo/robustness.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,19 @@ def _construct_botorch_acquisition(self, botorch_acqf_class, botorch_acqf_option
187187
if issubclass(botorch_acqf_class, qLogNoisyExpectedHypervolumeImprovement):
188188
botorch_acqf_class = qLogNoisyExpectedImprovement
189189
log.debug("MARS: swapped acqf to qLogNoisyExpectedImprovement")
190+
# Temporarily clear outcome_constraints for the parent construction:
191+
# with MARS scalarization, the constraint transforms produce shape
192+
# mismatches in prune_inferior_points.
193+
_saved_oc = self._outcome_constraints
194+
self._outcome_constraints = None
195+
try:
196+
return super()._construct_botorch_acquisition(
197+
botorch_acqf_class=botorch_acqf_class,
198+
botorch_acqf_options=botorch_acqf_options,
199+
model=model,
200+
)
201+
finally:
202+
self._outcome_constraints = _saved_oc
190203
return super()._construct_botorch_acquisition(
191204
botorch_acqf_class=botorch_acqf_class,
192205
botorch_acqf_options=botorch_acqf_options,
@@ -203,6 +216,13 @@ def get_botorch_objective_and_transform(self, botorch_acqf_class, model,
203216
if is_moo:
204217
from botorch.acquisition.logei import qLogNoisyExpectedImprovement
205218
botorch_acqf_class = qLogNoisyExpectedImprovement
219+
# MARS + constraint transforms produce shape mismatches in
220+
# prune_inferior_points. Drop constraints for MARS — the
221+
# GP-learned posterior already accounts for constraint violations
222+
# via the training data.
223+
if outcome_constraints is not None:
224+
log.debug("MARS: dropping outcome_constraints to avoid shape mismatch")
225+
outcome_constraints = None
206226

207227
from ax.generators.torch.utils import get_botorch_objective_and_transform as _get_obj
208228
objective, posterior_transform = _get_obj(

0 commit comments

Comments
 (0)