From 4331330fd6760ccbd3062a0710970f4ddbdbd877 Mon Sep 17 00:00:00 2001 From: Vaibhav Dixit Date: Tue, 13 Aug 2024 23:11:13 -0400 Subject: [PATCH 1/3] Add fg and fgh fields to OptimizationFunction --- src/scimlfunctions.jl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/scimlfunctions.jl b/src/scimlfunctions.jl index a88e4445b..4c6cc733e 100644 --- a/src/scimlfunctions.jl +++ b/src/scimlfunctions.jl @@ -1897,13 +1897,15 @@ For more details on this argument, see the ODEFunction documentation. The fields of the OptimizationFunction type directly match the names of the inputs. """ -struct OptimizationFunction{iip, AD, F, G, H, HV, C, CJ, CJV, CVJ, CH, HP, CJP, CHP, O, +struct OptimizationFunction{iip, AD, F, G, FG, H, FGH, HV, C, CJ, CJV, CVJ, CH, HP, CJP, CHP, O, EX, CEX, SYS, LH, LHP, HCV, CJCV, CHCV, LHCV} <: AbstractOptimizationFunction{iip} f::F adtype::AD grad::G + fg::FG hess::H + fgh::FGH hv::HV cons::C cons_j::CJ @@ -1934,8 +1936,8 @@ struct MultiObjectiveOptimizationFunction{iip, AD, F, J, H, HV, C, CJ, CJV, CVJ, AbstractOptimizationFunction{iip} f::F adtype::AD - jac::J # Replacing grad with jac for the Jacobian - hess::Vector{H} # Hess will be a vector of type H + jac::J + hess::H hv::HV cons::C cons_j::CJ From a4f515450b9774c914e4c42bbedb087ba008aa89 Mon Sep 17 00:00:00 2001 From: Vaibhav Kumar Dixit Date: Tue, 13 Aug 2024 23:31:55 -0400 Subject: [PATCH 2/3] Update src/scimlfunctions.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/scimlfunctions.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/scimlfunctions.jl b/src/scimlfunctions.jl index 4c6cc733e..2ad1922da 100644 --- a/src/scimlfunctions.jl +++ b/src/scimlfunctions.jl @@ -1897,7 +1897,8 @@ For more details on this argument, see the ODEFunction documentation. The fields of the OptimizationFunction type directly match the names of the inputs. """ -struct OptimizationFunction{iip, AD, F, G, FG, H, FGH, HV, C, CJ, CJV, CVJ, CH, HP, CJP, CHP, O, +struct OptimizationFunction{ + iip, AD, F, G, FG, H, FGH, HV, C, CJ, CJV, CVJ, CH, HP, CJP, CHP, O, EX, CEX, SYS, LH, LHP, HCV, CJCV, CHCV, LHCV} <: AbstractOptimizationFunction{iip} f::F From 99546fc2f95523e5d74dcede118e68e8580c4daf Mon Sep 17 00:00:00 2001 From: Vaibhav Dixit Date: Wed, 14 Aug 2024 11:50:21 -0400 Subject: [PATCH 3/3] update constructors and bump version --- Project.toml | 2 +- src/interpolation.jl | 2 +- src/problems/optimization_problems.jl | 8 ++++++-- src/scimlfunctions.jl | 19 ++++++++++++------- src/utils.jl | 1 - 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/Project.toml b/Project.toml index 2588f8120..9c2b38cd7 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "SciMLBase" uuid = "0bca4576-84f4-4d90-8ffe-ffa030f20462" authors = ["Chris Rackauckas and contributors"] -version = "2.48.1" +version = "2.49.0" [deps] ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" diff --git a/src/interpolation.jl b/src/interpolation.jl index 11a74748b..4b08e4eb5 100644 --- a/src/interpolation.jl +++ b/src/interpolation.jl @@ -616,6 +616,6 @@ Returns a copy of the interpolation stripped of its function, to accommodate ser If the interpolation object has no function, returns the interpolation object as is. """ strip_interpolation(id::AbstractDiffEqInterpolation) = id -strip_interpolation(id::HermiteInterpolation) = id +strip_interpolation(id::HermiteInterpolation) = id strip_interpolation(id::LinearInterpolation) = id strip_interpolation(id::ConstantInterpolation) = id diff --git a/src/problems/optimization_problems.jl b/src/problems/optimization_problems.jl index a23f2b8cb..c9dd315df 100644 --- a/src/problems/optimization_problems.jl +++ b/src/problems/optimization_problems.jl @@ -103,7 +103,9 @@ struct OptimizationProblem{iip, F, uType, P, LB, UB, I, LC, UC, S, K} <: ucons::UC sense::S kwargs::K - @add_kwonly function OptimizationProblem{iip}(f::Union{OptimizationFunction{iip}, MultiObjectiveOptimizationFunction{iip}}, u0, + @add_kwonly function OptimizationProblem{iip}( + f::Union{OptimizationFunction{iip}, MultiObjectiveOptimizationFunction{iip}}, + u0, p = NullParameters(); lb = nothing, ub = nothing, int = nothing, lcons = nothing, ucons = nothing, @@ -119,7 +121,9 @@ struct OptimizationProblem{iip, F, uType, P, LB, UB, I, LC, UC, S, K} <: end end -function OptimizationProblem(f::Union{OptimizationFunction, MultiObjectiveOptimizationFunction}, args...; kwargs...) +function OptimizationProblem( + f::Union{OptimizationFunction, MultiObjectiveOptimizationFunction}, + args...; kwargs...) OptimizationProblem{isinplace(f)}(f, args...; kwargs...) end function OptimizationProblem(f, args...; kwargs...) diff --git a/src/scimlfunctions.jl b/src/scimlfunctions.jl index 2ad1922da..076cfc3bc 100644 --- a/src/scimlfunctions.jl +++ b/src/scimlfunctions.jl @@ -1932,7 +1932,8 @@ end $(TYPEDEF) """ -struct MultiObjectiveOptimizationFunction{iip, AD, F, J, H, HV, C, CJ, CJV, CVJ, CH, HP, CJP, CHP, O, +struct MultiObjectiveOptimizationFunction{ + iip, AD, F, J, H, HV, C, CJ, CJV, CVJ, CH, HP, CJP, CHP, O, EX, CEX, SYS, LH, LHP, HCV, CJCV, CHCV, LHCV} <: AbstractOptimizationFunction{iip} f::F @@ -3812,7 +3813,7 @@ struct NoAD <: AbstractADType end OptimizationFunction(args...; kwargs...) = OptimizationFunction{true}(args...; kwargs...) function OptimizationFunction{iip}(f, adtype::AbstractADType = NoAD(); - grad = nothing, hess = nothing, hv = nothing, + grad = nothing, fg = nothing, hess = nothing, hv = nothing, fgh = nothing, cons = nothing, cons_j = nothing, cons_jvp = nothing, cons_vjp = nothing, cons_h = nothing, hess_prototype = nothing, @@ -3834,8 +3835,9 @@ function OptimizationFunction{iip}(f, adtype::AbstractADType = NoAD(); lag_hess_colorvec = nothing) where {iip} isinplace(f, 2; has_two_dispatches = false, isoptimization = true) sys = sys_or_symbolcache(sys, syms, paramsyms) - OptimizationFunction{iip, typeof(adtype), typeof(f), typeof(grad), typeof(hess), - typeof(hv), + OptimizationFunction{ + iip, typeof(adtype), typeof(f), typeof(grad), typeof(fg), typeof(hess), + typeof(fgh), typeof(hv), typeof(cons), typeof(cons_j), typeof(cons_jvp), typeof(cons_vjp), typeof(cons_h), typeof(hess_prototype), @@ -3845,7 +3847,7 @@ function OptimizationFunction{iip}(f, adtype::AbstractADType = NoAD(); typeof(lag_hess_prototype), typeof(hess_colorvec), typeof(cons_jac_colorvec), typeof(cons_hess_colorvec), typeof(lag_hess_colorvec) - }(f, adtype, grad, hess, + }(f, adtype, grad, fg, hess, fgh, hv, cons, cons_j, cons_jvp, cons_vjp, cons_h, hess_prototype, cons_jac_prototype, @@ -3858,7 +3860,9 @@ end (f::MultiObjectiveOptimizationFunction)(args...) = f.f(args...) # Convenience constructor -MultiObjectiveOptimizationFunction(args...; kwargs...) = MultiObjectiveOptimizationFunction{true}(args...; kwargs...) +function MultiObjectiveOptimizationFunction(args...; kwargs...) + MultiObjectiveOptimizationFunction{true}(args...; kwargs...) +end # Constructor with keyword arguments function MultiObjectiveOptimizationFunction{iip}(f, adtype::AbstractADType = NoAD(); @@ -3884,7 +3888,8 @@ function MultiObjectiveOptimizationFunction{iip}(f, adtype::AbstractADType = NoA lag_hess_colorvec = nothing) where {iip} isinplace(f, 2; has_two_dispatches = false, isoptimization = true) sys = sys_or_symbolcache(sys, syms, paramsyms) - MultiObjectiveOptimizationFunction{iip, typeof(adtype), typeof(f), typeof(jac), typeof(hess), + MultiObjectiveOptimizationFunction{ + iip, typeof(adtype), typeof(f), typeof(jac), typeof(hess), typeof(hv), typeof(cons), typeof(cons_j), typeof(cons_jvp), typeof(cons_vjp), typeof(cons_h), diff --git a/src/utils.jl b/src/utils.jl index aca5d24da..a12a9b9f0 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -537,4 +537,3 @@ the arity of a function is computed with `numargs` See also: `prepare_initial_state`. """ prepare_function(f) = f -