Skip to content

Fix constrained minimization dispatch errors - #42714

Open
cxzhong wants to merge 1 commit into
sagemath:developfrom
cxzhong:codex/fix-minimize-constrained-dispatch
Open

Fix constrained minimization dispatch errors#42714
cxzhong wants to merge 1 commit into
sagemath:developfrom
cxzhong:codex/fix-minimize-constrained-dispatch

Conversation

@cxzhong

@cxzhong cxzhong commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Fixes #42711.

The dispatch logic in minimize_constrained previously selected TNC for every
algorithm name other than the exact string l-bfgs-b, indexed an empty
constraint list, and left the result uninitialized for unsupported constraint
shapes and ordinary callable objects.

This pull request:

  • validates the two documented algorithm names and reports unknown values;
  • treats an empty constraint list as unconstrained bounds for TNC and L-BFGS-B;
  • accepts partial functions, bound methods, callable instances, and builtins;
  • reports invalid constraint specifications with a descriptive TypeError;
  • preserves the historical symbolic-constraint representation and bounds
    dispatch compatibility.

The doctests cover both bound solvers, symbolic and Python objectives,
arbitrary callable constraints, invalid inputs, and heterogeneous interval
sequences accepted by SciPy.

📝 Checklist

  • The title is concise and informative.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation and checked the documentation preview.

⌛ Dependencies

None.

@github-actions

Copy link
Copy Markdown

Documentation preview for this PR (built with commit 32e36ef; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

minimize_constrained: unvalidated algorithm silently selects a different solver; IndexError/UnboundLocalError leak from the dispatch block

1 participant