Skip to content

Add support for transforming bounded parameters into unbounded ones - #814

Merged
ChrisRackauckas merged 8 commits into
SciML:masterfrom
JamesWrigley:bounds
Feb 15, 2026
Merged

ChrisRackauckas merged 8 commits into
SciML:masterfrom
JamesWrigley:bounds

Conversation

@JamesWrigley

Copy link
Copy Markdown
Member

This adds support for bounds for any algorithm that doesn't natively support it. As suggested in SciML/CurveFit.jl#84. I didn't use TransformVariables.jl since the transform seems like a fairly straightforward thing to implement. I did add a dependency on LogExpFunction since that has robust versions of logit and logistic, but that's already a transitive dependency through ForwardDiff so it shouldn't increase load times. PreallocationTools is likewise also a dependency of SciMLBase.

Written with a lot of help from Claude 🤖

Checklist

  • Appropriate tests were added
  • Any code changes were done in a way that does not break public API
  • All documentation related to code changes were updated
  • The new code follows the
    contributor guidelines, in particular the SciML Style Guide and
    COLPRAC.
  • Any new documentation only uses public API

@JamesWrigley
JamesWrigley force-pushed the bounds branch 3 times, most recently from bd9c7fe to 7ba62e6 Compare February 13, 2026 21:11
Comment thread test/bounds_tests.jl Resolved
@JamesWrigley

Copy link
Copy Markdown
Member Author

Applied runic in 69cb989.

# doesn't receive 0 or 1, which would give ±Inf. Only applied once to u0 before
# the initial transform — it's a no-op if u0 is already in the interval.
#
# We use sqrt(eps) (~1.5e-8 for Float64) as the relative nudge factor. Plain eps

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.

that still seems large? Is eps()^(3/4) not more reasaonable?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah that's fair, changed in 8167dcd.


function _transform_u(w::BoundedWrapper, u)
return if isnothing(w.u_cache)
_from_unbounded.(u, w.lb, w.ub)

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.

this allocates. If it's enzyme, the cache should be in the w function and be written to.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah right I didn't realize Enzyme doesn't use Dual's. Fixed in 8167dcd and added some more tests for the cache type. Do we also need to check Mooncake/ReverseDiff?

@ChrisRackauckas
ChrisRackauckas merged commit b5f79df into SciML:master Feb 15, 2026
119 checks passed
@ChrisRackauckas

Copy link
Copy Markdown
Member

It might be good to follow up with some kind of tutorial on box constraints? Since this is a feature many people ask about. But, merging as the feature seems done so let's get it out there.

@JamesWrigley
JamesWrigley deleted the bounds branch February 15, 2026 16:46
ChrisRackauckas-Claude pushed a commit to ChrisRackauckas-Claude/NonlinearSolve.jl that referenced this pull request Feb 15, 2026
Follow-up to SciML#814 — adds a Documenter.jl tutorial covering box constraints
for NonlinearProblem and NonlinearLeastSquaresProblem, including two-sided
bounds, one-sided bounds, curve fitting, and in-place formulations.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
ChrisRackauckas added a commit that referenced this pull request Feb 16, 2026
Follow-up to #814 — adds a Documenter.jl tutorial covering box constraints
for NonlinearProblem and NonlinearLeastSquaresProblem, including two-sided
bounds, one-sided bounds, curve fitting, and in-place formulations.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
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.

2 participants