Skip to content

Add support for dual_ftol_rel parameter in NLopt #949

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 24, 2025

Conversation

ChrisRackauckas
Copy link
Member

Summary

Fixes #922 - This PR adds support for the dual_ftol_rel parameter in OptimizationNLopt, which is used by MMA/CCSA algorithms to control the dual optimization subproblem tolerance.

Problem

When trying to use the dual_ftol_rel parameter with NLopt solvers like LD_CCSAQ, users would get an error:

sol = solve(prob, NLopt.LD_CCSAQ(), xtol_rel = 1e-7, dual_ftol_rel = 1e-7)
# ERROR: UndefVarError: `dual_ftol_rel\!` not defined

This happened because the code was trying to call NLopt.dual_ftol_rel\!() which doesn't exist. The dual_ftol_rel is not a direct setter function but a named parameter in NLopt.

Solution

Added special handling for dual_ftol_rel in the __map_optimizer_args\! function:

  • Check if the keyword argument is dual_ftol_rel
  • If yes, use NLopt.nlopt_set_param(opt, "dual_ftol_rel", value) instead of the generic eval approach
  • Otherwise, continue with the existing behavior

Why this matters

From the NLopt documentation:

Because this subsidiary solve requires no evaluations of the user's objective function, it is typically fast enough that it can be solved to high precision without worrying too much about the details. However, in high-dimensional problems you may notice that MMA/CCSA is taking a long time between optimization steps, in which case you may want to increase dual_ftol_rel or make other changes.

This parameter is particularly important for users working with high-dimensional optimization problems using MMA or CCSA algorithms.

Testing

Verified that:

  • The parameter can now be set without errors
  • The fix uses the correct NLopt API (nlopt_set_param)
  • Backward compatibility is maintained for all other parameters

🤖 Generated with Claude Code

Fixes #922 - Added handling for the dual_ftol_rel parameter which is
used by MMA/CCSA algorithms in NLopt to control the dual optimization
subproblem tolerance.

Previously, passing dual_ftol_rel would throw:
```
ERROR: UndefVarError: `dual_ftol_rel\!` not defined
```

Now the parameter is properly handled using NLopt.nlopt_set_param()
since it's not a direct setter function but a named parameter.

Changes:
- Added special case handling for dual_ftol_rel in __map_optimizer_args\!
- Uses NLopt.nlopt_set_param(opt, "dual_ftol_rel", value) instead of
  trying to call a non-existent dual_ftol_rel\! function

This enables users to control the dual problem tolerance for faster
convergence in high-dimensional problems with CCSA/MMA algorithms.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@ChrisRackauckas
Copy link
Member Author

Needs a test.

ChrisRackauckas and others added 2 commits July 24, 2025 06:27
- Test that dual_ftol_rel can be passed without UndefVarError
- Test with both NLopt.Opt and direct algorithm interfaces
- Verify it works combined with other solver options

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@ChrisRackauckas ChrisRackauckas merged commit 21f1bea into master Jul 24, 2025
24 of 29 checks passed
@ChrisRackauckas ChrisRackauckas deleted the fix-nlopt-dual-ftol-rel branch July 24, 2025 13:07
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.

Adding dual_ftol_rel keyword for NLopt
1 participant