Skip to content

Fix native float output from parameter untransform - #6869

Merged
c-bata merged 1 commit into
optuna:masterfrom
yen-0:fix/botorch-native-scalars-clean
Sep 30, 2026
Merged

c-bata merged 1 commit into
optuna:masterfrom
yen-0:fix/botorch-native-scalars-clean

Conversation

@yen-0

@yen-0 yen-0 commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

Motivation

_SearchSpaceTransform.untransform() is expected to return native Python scalar values. This matters for sampler conformance checks and for consumers that reject NumPy scalar types, even though NumPy scalars usually behave like Python numbers in arithmetic and comparisons.

However, the linear, non-stepped float branch still contained:

param = min(trans_param, np.nextafter(d.high, d.high - 1))

When the upper-bound clamp is selected, np.nextafter() supplies a NumPy scalar and min() returns it unchanged. The result can therefore be a numpy.float64 instead of a Python float.

Description of the changes

The branch now explicitly converts the result:

param = float(min(trans_param, np.nextafter(d.high, d.high - 1)))

This preserves the numerical behavior while making the output type
consistent with the other numerical branches:

# Logarithmic float
param = float(np.clip(param, d.low, np.nextafter(d.high, d.high - 1)))

# Stepped float
param = float(np.clip(...))

# Linear non-stepped float
param = float(min(trans_param, np.nextafter(d.high, d.high - 1)))

Checklist

  • I used an LLM while working on this PR.

@not522 not522 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@not522 not522 added the code-fix Change that does not change the behavior, such as code refactoring. label Sep 25, 2026
@not522

not522 commented Sep 28, 2026

Copy link
Copy Markdown
Member

@c-bata Could you review this PR?

@c-bata c-bata added this to the v5.1.0 milestone Sep 30, 2026
@c-bata
c-bata merged commit e292b1c into optuna:master Sep 30, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code-fix Change that does not change the behavior, such as code refactoring.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants