Skip to content

Process bounds via get_internal_bounds on the converter fast path - #730

Merged
timmens merged 3 commits into
optimagic-dev:mainfrom
JoeyTan21:fix/fast-path-sequence-bounds
Nov 4, 2026
Merged

timmens merged 3 commits into
optimagic-dev:mainfrom
JoeyTan21:fix/fast-path-sequence-bounds

Conversation

@JoeyTan21

Copy link
Copy Markdown
Contributor

Closes #725

What problem do you want to solve?

When params is a 1d numpy array and there are no constraints and no scaling, get_converter takes a fast path that calls astype(float) directly on bounds.lower and bounds.upper. So bounds given as a list or tuple (including the deprecated lower_bounds=[...]) raise AttributeError. The same bounds work fine once scaling is turned on, because that goes through the slow path.

The fix makes the fast path call get_internal_bounds, the same function the slow path uses. It already has a quick branch for array bounds, so array input behaves the same as before. As a side effect, the fast path now also gets the lower > upper check.

I added a parametrized test in test_conversion.py for list, tuple and np.ndarray bounds. The list and tuple cases fail on main and pass with this change. test_conversion.py and test_bounds.py pass locally (41 passed), and ruff is clean.

Thanks @timmens for the quick reply. #729 only touches bounds.py, so it doesn't conflict with this.

AI use

I used Claude Code to help find the bug, write the reproducer, and draft the fix and test. I reviewed every line of the diff, and I ran the reproducer and the tests myself before and after the change.

Todo

Disclosure: found, reproduced and the draft fix tested locally with the help of an AI coding agent (Claude Code); reviewed before filing.

When params is a 1d numpy array and no constraints or scaling are used,
get_converter took a fast path that called .astype(float) directly on
bounds.lower and bounds.upper. Bounds given as a list or tuple therefore
raised AttributeError, while the same bounds worked on the slow path.

Delegate to get_internal_bounds, which already has its own fast path for
1d array bounds and handles other pytrees, so both paths behave the same.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
src/optimagic/parameters/conversion.py 96.70% <100.00%> (-0.14%) ⬇️
tests/optimagic/parameters/test_conversion.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@timmens

timmens commented Nov 2, 2026

Copy link
Copy Markdown
Member

Thanks for the excellent PR! The fix looks good, and the tests make the intended behavior clear.

While reviewing, I noticed that the existing test uses fast_case (test_get_converter_fast_case), whereas the codebase generally uses fast_path. It would be great if you could rename both the existing test and the new test to use fast_path for consistency and merge main into your branch?

@JoeyTan21

Copy link
Copy Markdown
Contributor Author

Renamed both tests to fast_path and merged main, thanks!

@timmens timmens 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.

Thanks again, approved!

(The failing RTD check is unrelated to your change, and will be fixed in a subsequent PR.)

@timmens
timmens merged commit abef180 into optimagic-dev:main Nov 4, 2026
19 of 20 checks passed
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.

Bounds given as a list or tuple raise AttributeError when params is a numpy array

2 participants