You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add solve interface to OptimizationBase from SciMLBase.jl
This commit adds the missing solve.jl file to lib/OptimizationBase and
implements the top-level solve interface functionality from SciMLBase.jl
(lines 36-248), including:
**New solve.jl functionality:**
- IncompatibleOptimizerError and OptimizerMissingError exception types
- _check_opt_alg function for comprehensive algorithm compatibility checking
- Base dispatch functions: supports_opt_cache_interface, __solve, __init
- Proper error handling with informative messages for missing optimizers
**Algorithm validation for:**
- Bounds compatibility (allowsbounds/requiresbounds)
- Constraint handling (allowsconstraints/requiresconstraints)
- Gradient/Hessian requirements (requiresgradient/requireshessian)
- Constraint Jacobian/Hessian requirements (requiresconsjac/requiresconshess)
- Callback support (allowscallback)
**Modified OptimizationBase.jl:**
- Added include("solve.jl")
- Added exports: IncompatibleOptimizerError, OptimizerMissingError, _check_opt_alg, supports_opt_cache_interface
This provides the foundation for moving optimization-specific functionality
from SciMLBase.jl into the optimization ecosystem where it belongs.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
throw(IncompatibleOptimizerError("The algorithm $(typeof(alg)) does not support box constraints. Either remove the `lb` or `ub` bounds passed to `OptimizationProblem` or use a different algorithm."))
throw(IncompatibleOptimizerError("The algorithm $(typeof(alg)) requires box constraints. Either pass `lb` and `ub` bounds to `OptimizationProblem` or use a different algorithm."))
throw(IncompatibleOptimizerError("The algorithm $(typeof(alg)) does not support constraints. Either remove the `cons` function passed to `OptimizationFunction` or use a different algorithm."))
throw(IncompatibleOptimizerError("The algorithm $(typeof(alg)) does not support callbacks, remove the `callback` keyword argument from the `solve` call."))
49
+
SciMLBase.requiresgradient(alg) &&
50
+
!(prob.f isa SciMLBase.AbstractOptimizationFunction) &&
51
+
throw(IncompatibleOptimizerError("The algorithm $(typeof(alg)) requires gradients, hence use `OptimizationFunction` to generate them with an automatic differentiation backend e.g. `OptimizationFunction(f, AutoForwardDiff())` or pass it in with `grad` kwarg."))
52
+
SciMLBase.requireshessian(alg) &&
53
+
!(prob.f isa SciMLBase.AbstractOptimizationFunction) &&
54
+
throw(IncompatibleOptimizerError("The algorithm $(typeof(alg)) requires hessians, hence use `OptimizationFunction` to generate them with an automatic differentiation backend e.g. `OptimizationFunction(f, AutoFiniteDiff(); kwargs...)` or pass them in with `hess` kwarg."))
55
+
SciMLBase.requiresconsjac(alg) &&
56
+
!(prob.f isa SciMLBase.AbstractOptimizationFunction) &&
57
+
throw(IncompatibleOptimizerError("The algorithm $(typeof(alg)) requires constraint jacobians, hence use `OptimizationFunction` to generate them with an automatic differentiation backend e.g. `OptimizationFunction(f, AutoFiniteDiff(); kwargs...)` or pass them in with `cons` kwarg."))
58
+
SciMLBase.requiresconshess(alg) &&
59
+
!(prob.f isa SciMLBase.AbstractOptimizationFunction) &&
60
+
throw(IncompatibleOptimizerError("The algorithm $(typeof(alg)) requires constraint hessians, hence use `OptimizationFunction` to generate them with an automatic differentiation backend e.g. `OptimizationFunction(f, AutoFiniteDiff(), AutoFiniteDiff(hess=true); kwargs...)` or pass them in with `cons` kwarg."))
61
+
return
62
+
end
63
+
64
+
# Base solver dispatch functions (these will be extended by specific solver packages)
0 commit comments