Skip to content

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

Closed

Description

@JoeyTan21

Bug description

When params is a 1d numpy array and no constraints or scaling are used, get_converter takes a fast path (_get_fast_path_converter in src/optimagic/parameters/conversion.py). That fast path calls bounds.lower.astype(float) and bounds.upper.astype(float) directly instead of going through get_internal_bounds. As a result, om.Bounds with a list or tuple as lower or upper fails with AttributeError. The deprecated lower_bounds=[...] argument fails the same way, because it is converted into Bounds(lower=list).

The same bounds work as soon as the problem leaves the fast path, for example with scaling=True, because the slow path processes bounds through get_internal_bounds. The fast path also skips the lower > upper check and the conversion of all-infinite bounds to None that get_internal_bounds performs.

To Reproduce

import numpy as np
import optimagic as om

params = np.array([1.0, 2.0, 3.0])

om.minimize(lambda x: x @ x, params, algorithm="scipy_lbfgsb",
            bounds=om.Bounds(lower=[0.5, 0.5, 0.5]))
# AttributeError: 'list' object has no attribute 'astype'

om.minimize(lambda x: x @ x, params, algorithm="scipy_lbfgsb",
            bounds=om.Bounds(lower=[0.5, 0.5, 0.5]), scaling=True)
# works, params = [0.5, 0.5, 0.5]

Expected behavior

Bounds that work on the slow path should also work on the fast path. Calling get_internal_bounds(params=params, bounds=bounds) in _get_fast_path_converter would do this. It already has its own fast path for 1d array bounds, so the behavior for array bounds stays the same. I have a small patch with a regression test in tests/optimagic/parameters/test_conversion.py and can open a PR if that is welcome.

System

  • OS: macOS 15
  • Version: optimagic main at 2b1eea8 (0.5.5.dev17), Python 3.12

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

Activity

  1. timmens commented on Oct 30, 2026

    @timmens
    Member

    Hi @JoeyTan21, thanks for the very clear and thorough report! We'd be happy to receive a PR with your fix if you want to contribute.

    I found another bug in get_internal_bounds while looking into this and opened #729 to fix it, so you don't need to take care of that. Feel free to open your PR in the meantime!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions