Skip to content

Fix degenerate dataframe handling - #965

Open
Henrik-KM wants to merge 9 commits into
emdgroup:patch/0.15.3from
Henrik-KM:bug/guard-unmeasured-targets
Open

Henrik-KM wants to merge 9 commits into
emdgroup:patch/0.15.3from
Henrik-KM:bug/guard-unmeasured-targets

Conversation

@Henrik-KM

Copy link
Copy Markdown

Fixes #938.

The composite surrogate checks each modeled quantity for training observations before fitting any component. The resulting IncompleteMeasurementsError names the quantities that need data. Discrete parameter transformations also retain their encoded columns when the input has zero rows, which preserves the computational schema of the hybrid input in the report.

With BoTorch 0.18.1, the reproducer reached the outcome standardizer with no observations. Inspecting the same input showed that the discrete transform had dropped the categorical columns. The two regression tests cover the error and the schema independently.

Verification

  • 170 tests passed and 25 were skipped in the partial-measurement, search-space, surrogate, and campaign suites. On Windows I allowed BoTorch's optional C++ compilation warning so the tests could use its Python fallback.
  • Changed-file pre-commit hooks and the Python 3.10 Pyrefly check passed.
  • Mypy reported the same RDKit stub syntax error on this branch and on the upstream base commit.

OpenAI Codex prepared, implemented, and tested this change.

@CLAassistant

CLAassistant commented Nov 19, 2026 •

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ AdrianSosic
❌ Henrik-KM
You have signed the CLA already but the status is still pending? Let us recheck it.

@AdrianSosic
AdrianSosic force-pushed the bug/guard-unmeasured-targets branch from 20e4e61 to 20dc639 Compare November 20, 2026 10:54
@AdrianSosic
AdrianSosic changed the base branch from main to patch/0.15.3 November 20, 2026 10:55
@AdrianSosic AdrianSosic changed the title Report unmeasured targets before fitting multi-target surrogates Fix degenerate dataframe handling Nov 20, 2026
@AdrianSosic
AdrianSosic force-pushed the bug/guard-unmeasured-targets branch from 725cdc4 to 20dc639 Compare November 20, 2026 10:58
@AdrianSosic

Copy link
Copy Markdown
Collaborator

Hi @Henrik-KM, thanks for the fix! I've adjusted things a little bit and could release this as 0.15.3 shortly, but we still need the CLA. Could you quickly sign it, perhaps?

Comment thread tests/test_surrogate.py
Comment on lines +188 to +191
with patch.object(GaussianProcessSurrogate, "_fit") as fit:
with pytest.raises(IncompatibleSurrogateError, match="single-output"):
GaussianProcessSurrogate().fit(searchspace, objective, measurements)
fit.assert_not_called()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reads a bit weird as you literally call a function called fit and then have fit.assert_not_called. Can we maybe rename the fit to internal_fit or similar?

Comment thread baybe/surrogates/base.py

# Validate multi-target compatibility
if objective.is_multi_output and not self.supports_multi_output:
if objective._is_multi_model:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we specify in the docstring of this class that this is a Surrogate for single outputs? The docstring reads very general which is confusing.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And it is also extra weird that there still is the support_multi_output attribute that a child could simply set to True, even though this is not possible. Or am I misunderstanding something here?

Comment thread baybe/surrogates/base.py
if df.empty:
raise IncompleteMeasurementsError(
"Each modeled quantity requires at least one complete measurement. "
f"No complete measurements are available for '{name}'."

@Scienfitz Scienfitz Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for DesirabilityObjective(pre_transform=True) this would say "there is not compelte measurement avaialble for desirability" which imo is not optimal. The specific target names should be emtnioned

Comment thread baybe/surrogates/base.py

# Validate multi-target compatibility
if objective.is_multi_output and not self.supports_multi_output:
if objective._is_multi_model:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is fishy

supports_multi_output declares a property of the surrogate class. Dropping and not self.supports_multi_output means fit now ignores that property, while _autoreplicate still relies on it. A surrogate declaring multi-output support would not be wrapped and would then always be rejected here. That no current surrogate sets the flag doesn't make the check correct.

Overall this PR makes way more incisions than I'd expect, the gut feelings ays the fix to this issue should be much simpler and not touch so many things...

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Targets without measurements in multi-target cases

5 participants