From 8084faa8fc4dd15b082a9e1982940ddeac8c92bc Mon Sep 17 00:00:00 2001 From: Vaibhav Dixit Date: Wed, 2 Oct 2024 14:02:02 -0400 Subject: [PATCH 1/5] Move iterator checking here and make symbolics stuff extension --- Project.toml | 11 +-- ext/OptimizationMLDataDevicesExt.jl | 8 ++ ext/OptimizationMLUtilsExt.jl | 8 ++ ext/OptimizationSymbolicAnalysisExt.jl | 103 ++++++++++++++++++++++ src/OptimizationBase.jl | 1 + src/cache.jl | 117 ++++--------------------- src/symify.jl | 6 ++ 7 files changed, 149 insertions(+), 105 deletions(-) create mode 100644 ext/OptimizationMLDataDevicesExt.jl create mode 100644 ext/OptimizationMLUtilsExt.jl create mode 100644 ext/OptimizationSymbolicAnalysisExt.jl create mode 100644 src/symify.jl diff --git a/Project.toml b/Project.toml index 3deeafb..363f936 100644 --- a/Project.toml +++ b/Project.toml @@ -17,24 +17,27 @@ SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" SparseConnectivityTracer = "9f842d2f-2579-4b1d-911e-f412cf18a3f5" SparseMatrixColorings = "0a514795-09f3-496d-8182-132a7b665d35" -SymbolicAnalysis = "4297ee4d-0239-47d8-ba5d-195ecdf594fe" -SymbolicIndexingInterface = "2efcf032-c050-4f8e-a9bb-153293bab1f5" -Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7" [weakdeps] Enzyme = "7da242da-08ed-463a-9acd-ee780be4f1d9" FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41" ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" +MLDataDevices = "7e8f7934-dd98-4c1a-8fe8-92b47a384d40" +MLUtils = "f1d291b0-491e-4a28-83b9-f70985020b54" ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78" ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267" +SymbolicAnalysis = "4297ee4d-0239-47d8-ba5d-195ecdf594fe" Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f" [extensions] OptimizationEnzymeExt = "Enzyme" OptimizationFiniteDiffExt = "FiniteDiff" OptimizationForwardDiffExt = "ForwardDiff" +OptimizationMLDataDevicesExt = "MLDataDevices" +OptimizationMLUtilsExt = "MLUtils" OptimizationMTKExt = "ModelingToolkit" OptimizationReverseDiffExt = "ReverseDiff" +OptimizationSymbolicAnalysisExt = "SymbolicAnalysis" OptimizationZygoteExt = "Zygote" [compat] @@ -56,8 +59,6 @@ SciMLBase = "2" SparseConnectivityTracer = "0.6" SparseMatrixColorings = "0.4" SymbolicAnalysis = "0.3" -SymbolicIndexingInterface = "0.3" -Symbolics = "5.12, 6" Zygote = "0.6.67" julia = "1.10" diff --git a/ext/OptimizationMLDataDevicesExt.jl b/ext/OptimizationMLDataDevicesExt.jl new file mode 100644 index 0000000..ae8d510 --- /dev/null +++ b/ext/OptimizationMLDataDevicesExt.jl @@ -0,0 +1,8 @@ +module OptimizationMLDataDevicesExt + +using MLDataDevices +using OptimizationBase + +OptimizationBase.isa_dataiterator(::DeviceIterator) = true + +end diff --git a/ext/OptimizationMLUtilsExt.jl b/ext/OptimizationMLUtilsExt.jl new file mode 100644 index 0000000..5178831 --- /dev/null +++ b/ext/OptimizationMLUtilsExt.jl @@ -0,0 +1,8 @@ +module OptimizationMLUtilsExt + +using MLUtils +using OptimizationBase + +OptimizationBase.isa_dataiterator(::MLUtils.DataLoader) = true + +end diff --git a/ext/OptimizationSymbolicAnalysisExt.jl b/ext/OptimizationSymbolicAnalysisExt.jl new file mode 100644 index 0000000..6db8475 --- /dev/null +++ b/ext/OptimizationSymbolicAnalysisExt.jl @@ -0,0 +1,103 @@ +module OptimizationSymbolicAnalysisExt + +using OptimizationBase, SciMLBase, SymbolicAnalysis, SymbolicAnalysis.Symbolics + +function OptimizationBase.symify_cache(f::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}, prob) where {iip, AD, F, G, FG, H, FGH, HV, C, CJ, CJV, CVJ, CH, HP, CJP, CHP, O, EX <: Nothing, CEX <: Nothing, SYS, LH, LHP, HCV, CJCV, CHCV, LHCV} + try + vars = if prob.u0 isa Matrix + @variables X[1:size(prob.u0, 1), 1:size(prob.u0, 2)] + else + ArrayInterface.restructure( + prob.u0, [variable(:x, i) for i in eachindex(prob.u0)]) + end + params = if prob.p isa SciMLBase.NullParameters + [] + elseif prob.p isa MTK.MTKParameters + [variable(:α, i) for i in eachindex(vcat(p...))] + else + ArrayInterface.restructure(p, [variable(:α, i) for i in eachindex(p)]) + end + + if prob.u0 isa Matrix + vars = vars[1] + end + + obj_expr = f.f(vars, params) + + if SciMLBase.isinplace(prob) && !isnothing(prob.f.cons) + lhs = Array{Symbolics.Num}(undef, num_cons) + f.cons(lhs, vars) + cons = Union{Equation, Inequality}[] + + if !isnothing(prob.lcons) + for i in 1:num_cons + if !isinf(prob.lcons[i]) + if prob.lcons[i] != prob.ucons[i] + push!(cons, prob.lcons[i] ≲ lhs[i]) + else + push!(cons, lhs[i] ~ prob.ucons[i]) + end + end + end + end + + if !isnothing(prob.ucons) + for i in 1:num_cons + if !isinf(prob.ucons[i]) && prob.lcons[i] != prob.ucons[i] + push!(cons, lhs[i] ≲ prob.ucons[i]) + end + end + end + if (isnothing(prob.lcons) || all(isinf, prob.lcons)) && + (isnothing(prob.ucons) || all(isinf, prob.ucons)) + throw(ArgumentError("Constraints passed have no proper bounds defined. + Ensure you pass equal bounds (the scalar that the constraint should evaluate to) for equality constraints + or pass the lower and upper bounds for inequality constraints.")) + end + cons_expr = lhs + elseif !isnothing(prob.f.cons) + cons_expr = f.cons(vars, params) + else + cons_expr = nothing + end + catch err + throw(ArgumentError("Automatic symbolic expression generation with failed with error: $err. + Try by setting `structural_analysis = false` instead if the solver doesn't require symbolic expressions.")) + end + return obj_expr, cons_expr +end + +function analysis(obj_expr, cons_expr) + if obj_expr !== nothing + obj_expr = obj_expr |> Symbolics.unwrap + if manifold === nothing + obj_res = analyze(obj_expr) + else + obj_res = analyze(obj_expr, manifold) + end + @info "Objective Euclidean curvature: $(obj_res.curvature)" + if obj_res.gcurvature !== nothing + @info "Objective Geodesic curvature: $(obj_res.gcurvature)" + end + end + + if cons_expr !== nothing + cons_expr = cons_expr .|> Symbolics.unwrap + if manifold === nothing + cons_res = analyze.(cons_expr) + else + cons_res = analyze.(cons_expr, Ref(manifold)) + end + for i in 1:num_cons + @info "Constraints Euclidean curvature: $(cons_res[i].curvature)" + + if cons_res[i].gcurvature !== nothing + @info "Constraints Geodesic curvature: $(cons_res[i].gcurvature)" + end + end + end + + return obj_res, cons_res +end + +end \ No newline at end of file diff --git a/src/OptimizationBase.jl b/src/OptimizationBase.jl index 8a1c3e4..7c914d8 100644 --- a/src/OptimizationBase.jl +++ b/src/OptimizationBase.jl @@ -31,6 +31,7 @@ Base.iterate(::NullData, i = 1) = nothing Base.length(::NullData) = 0 include("adtypes.jl") +include("symify.jl") include("cache.jl") include("OptimizationDIExt.jl") include("OptimizationDISparseExt.jl") diff --git a/src/cache.jl b/src/cache.jl index e7722f5..e44f524 100644 --- a/src/cache.jl +++ b/src/cache.jl @@ -1,5 +1,7 @@ import Symbolics: ≲, ~ +isa_dataiterator(data) = false + struct AnalysisResults objective::Union{Nothing, AnalysisResult} constraints::Union{Nothing, Vector{AnalysisResult}} @@ -32,8 +34,17 @@ function OptimizationCache(prob::SciMLBase.OptimizationProblem, opt; structural_analysis = false, manifold = nothing, kwargs...) - reinit_cache = OptimizationBase.ReInitCache(prob.u0, prob.p) + + if isa_dataiterator(prob.p) + reinit_cache = OptimizationBase.ReInitCache(prob.u0, iterate(prob.p)[1]) + reinit_cache_passedon = OptimizationBase.ReInitCache(prob.u0, prob.p) + else + reinit_cache = OptimizationBase.ReInitCache(prob.u0, iterate(prob.p)[1]) + reinit_cache_passedon = reinit_cache + end + num_cons = prob.ucons === nothing ? 0 : length(prob.ucons) + f = OptimizationBase.instantiate_function( prob.f, reinit_cache, prob.f.adtype, num_cons; g = SciMLBase.requiresgradient(opt), h = SciMLBase.requireshessian(opt), @@ -41,113 +52,19 @@ function OptimizationCache(prob::SciMLBase.OptimizationProblem, opt; fgh = SciMLBase.allowsfgh(opt), cons_j = SciMLBase.requiresconsjac(opt), cons_h = SciMLBase.requiresconshess(opt), cons_vjp = SciMLBase.allowsconsjvp(opt), cons_jvp = SciMLBase.allowsconsjvp(opt), lag_h = SciMLBase.requireslagh(opt)) - if (f.sys === nothing || - f.sys isa SymbolicIndexingInterface.SymbolCache{Nothing, Nothing, Nothing}) && - structural_analysis + if structural_analysis + obj_expr, cons_expr = symify_cache(f, prob) try - vars = if prob.u0 isa Matrix - @variables X[1:size(prob.u0, 1), 1:size(prob.u0, 2)] - else - ArrayInterface.restructure( - prob.u0, [variable(:x, i) for i in eachindex(prob.u0)]) - end - params = if prob.p isa SciMLBase.NullParameters - [] - elseif prob.p isa MTK.MTKParameters - [variable(:α, i) for i in eachindex(vcat(p...))] - else - ArrayInterface.restructure(p, [variable(:α, i) for i in eachindex(p)]) - end - - if prob.u0 isa Matrix - vars = vars[1] - end - - obj_expr = f.f(vars, params) - - if SciMLBase.isinplace(prob) && !isnothing(prob.f.cons) - lhs = Array{Symbolics.Num}(undef, num_cons) - f.cons(lhs, vars) - cons = Union{Equation, Inequality}[] - - if !isnothing(prob.lcons) - for i in 1:num_cons - if !isinf(prob.lcons[i]) - if prob.lcons[i] != prob.ucons[i] - push!(cons, prob.lcons[i] ≲ lhs[i]) - else - push!(cons, lhs[i] ~ prob.ucons[i]) - end - end - end - end - - if !isnothing(prob.ucons) - for i in 1:num_cons - if !isinf(prob.ucons[i]) && prob.lcons[i] != prob.ucons[i] - push!(cons, lhs[i] ≲ prob.ucons[i]) - end - end - end - if (isnothing(prob.lcons) || all(isinf, prob.lcons)) && - (isnothing(prob.ucons) || all(isinf, prob.ucons)) - throw(ArgumentError("Constraints passed have no proper bounds defined. - Ensure you pass equal bounds (the scalar that the constraint should evaluate to) for equality constraints - or pass the lower and upper bounds for inequality constraints.")) - end - cons_expr = lhs - elseif !isnothing(prob.f.cons) - cons_expr = f.cons(vars, params) - else - cons_expr = nothing - end + obj_res, cons_res = analysis(obj_expr, cons_expr) catch err - throw(ArgumentError("Automatic symbolic expression generation with failed with error: $err. - Try by setting `structural_analysis = false` instead if the solver doesn't require symbolic expressions.")) - end - else - sys = f.sys isa SymbolicIndexingInterface.SymbolCache{Nothing, Nothing, Nothing} ? - nothing : f.sys - obj_expr = f.expr - cons_expr = f.cons_expr === nothing ? nothing : getfield.(f.cons_expr, Ref(:lhs)) - end - - if obj_expr !== nothing && structural_analysis - obj_expr = obj_expr |> Symbolics.unwrap - if manifold === nothing - obj_res = analyze(obj_expr) - else - obj_res = analyze(obj_expr, manifold) - end - - @info "Objective Euclidean curvature: $(obj_res.curvature)" - - if obj_res.gcurvature !== nothing - @info "Objective Geodesic curvature: $(obj_res.gcurvature)" + throw("Structural analysis requires SymbolicAnalysis.jl to be loaded, either add `using SymbolicAnalysis` to your script or set `structural_analysis = false`.") end else obj_res = nothing - end - - if cons_expr !== nothing && structural_analysis - cons_expr = cons_expr .|> Symbolics.unwrap - if manifold === nothing - cons_res = analyze.(cons_expr) - else - cons_res = analyze.(cons_expr, Ref(manifold)) - end - for i in 1:num_cons - @info "Constraints Euclidean curvature: $(cons_res[i].curvature)" - - if cons_res[i].gcurvature !== nothing - @info "Constraints Geodesic curvature: $(cons_res[i].gcurvature)" - end - end - else cons_res = nothing end - return OptimizationCache(f, reinit_cache, prob.lb, prob.ub, prob.lcons, + return OptimizationCache(f, reinit_cache_passedon, prob.lb, prob.ub, prob.lcons, prob.ucons, prob.sense, opt, progress, callback, manifold, AnalysisResults(obj_res, cons_res), merge((; maxiters, maxtime, abstol, reltol), diff --git a/src/symify.jl b/src/symify.jl new file mode 100644 index 0000000..1cf9673 --- /dev/null +++ b/src/symify.jl @@ -0,0 +1,6 @@ +function symify_cache(f::OptimizationFunction, prob) + obj_expr = f.expr + cons_expr = f.cons_expr === nothing ? nothing : getfield.(f.cons_expr, Ref(:lhs)) + + return obj_expr, cons_expr +end From 8ad24f881a89f8bd19cd390d1d3ccced868bd080 Mon Sep 17 00:00:00 2001 From: Vaibhav Dixit Date: Wed, 2 Oct 2024 14:40:10 -0400 Subject: [PATCH 2/5] fixup --- ext/OptimizationSymbolicAnalysisExt.jl | 2 ++ src/OptimizationBase.jl | 5 ----- src/cache.jl | 10 ++++------ 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/ext/OptimizationSymbolicAnalysisExt.jl b/ext/OptimizationSymbolicAnalysisExt.jl index 6db8475..8ca9e7f 100644 --- a/ext/OptimizationSymbolicAnalysisExt.jl +++ b/ext/OptimizationSymbolicAnalysisExt.jl @@ -1,6 +1,8 @@ module OptimizationSymbolicAnalysisExt using OptimizationBase, SciMLBase, SymbolicAnalysis, SymbolicAnalysis.Symbolics +using SymbolicAnalysis: AnalysisResult +import Symbolics: variable, Equation, Inequality, unwrap, @variables function OptimizationBase.symify_cache(f::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}, prob) where {iip, AD, F, G, FG, H, FGH, HV, C, CJ, CJV, CVJ, CH, HP, CJP, CHP, O, EX <: Nothing, CEX <: Nothing, SYS, LH, LHP, HCV, CJCV, CHCV, LHCV} try diff --git a/src/OptimizationBase.jl b/src/OptimizationBase.jl index 7c914d8..875fd90 100644 --- a/src/OptimizationBase.jl +++ b/src/OptimizationBase.jl @@ -9,11 +9,6 @@ if !isdefined(Base, :get_extension) end using ArrayInterface, Base.Iterators, SparseArrays, LinearAlgebra -using SymbolicIndexingInterface -using SymbolicAnalysis -using SymbolicAnalysis: AnalysisResult -import Symbolics -import Symbolics: variable, Equation, Inequality, unwrap, @variables import SciMLBase: OptimizationProblem, OptimizationFunction, ObjSense, MaxSense, MinSense, OptimizationStats diff --git a/src/cache.jl b/src/cache.jl index e44f524..bf80e31 100644 --- a/src/cache.jl +++ b/src/cache.jl @@ -1,10 +1,8 @@ -import Symbolics: ≲, ~ - isa_dataiterator(data) = false -struct AnalysisResults - objective::Union{Nothing, AnalysisResult} - constraints::Union{Nothing, Vector{AnalysisResult}} +struct AnalysisResults{O, C} + objective::O + constraints::C end struct OptimizationCache{F, RC, LB, UB, LC, UC, S, O, P, C, M} <: @@ -39,7 +37,7 @@ function OptimizationCache(prob::SciMLBase.OptimizationProblem, opt; reinit_cache = OptimizationBase.ReInitCache(prob.u0, iterate(prob.p)[1]) reinit_cache_passedon = OptimizationBase.ReInitCache(prob.u0, prob.p) else - reinit_cache = OptimizationBase.ReInitCache(prob.u0, iterate(prob.p)[1]) + reinit_cache = OptimizationBase.ReInitCache(prob.u0, prob.p) reinit_cache_passedon = reinit_cache end From 4bda49ab44056ecfa21e8d51b3c189a011908b68 Mon Sep 17 00:00:00 2001 From: Vaibhav Dixit Date: Wed, 2 Oct 2024 16:12:21 -0400 Subject: [PATCH 3/5] format --- ext/OptimizationSymbolicAnalysisExt.jl | 8 ++++++-- src/cache.jl | 1 - 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ext/OptimizationSymbolicAnalysisExt.jl b/ext/OptimizationSymbolicAnalysisExt.jl index 8ca9e7f..82364d8 100644 --- a/ext/OptimizationSymbolicAnalysisExt.jl +++ b/ext/OptimizationSymbolicAnalysisExt.jl @@ -4,7 +4,11 @@ using OptimizationBase, SciMLBase, SymbolicAnalysis, SymbolicAnalysis.Symbolics using SymbolicAnalysis: AnalysisResult import Symbolics: variable, Equation, Inequality, unwrap, @variables -function OptimizationBase.symify_cache(f::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}, prob) where {iip, AD, F, G, FG, H, FGH, HV, C, CJ, CJV, CVJ, CH, HP, CJP, CHP, O, EX <: Nothing, CEX <: Nothing, SYS, LH, LHP, HCV, CJCV, CHCV, LHCV} +function OptimizationBase.symify_cache( + f::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}, + prob) where {iip, AD, F, G, FG, H, FGH, HV, C, CJ, CJV, CVJ, CH, HP, CJP, CHP, O, + EX <: Nothing, CEX <: Nothing, SYS, LH, LHP, HCV, CJCV, CHCV, LHCV} try vars = if prob.u0 isa Matrix @variables X[1:size(prob.u0, 1), 1:size(prob.u0, 2)] @@ -102,4 +106,4 @@ function analysis(obj_expr, cons_expr) return obj_res, cons_res end -end \ No newline at end of file +end diff --git a/src/cache.jl b/src/cache.jl index bf80e31..fb3d867 100644 --- a/src/cache.jl +++ b/src/cache.jl @@ -32,7 +32,6 @@ function OptimizationCache(prob::SciMLBase.OptimizationProblem, opt; structural_analysis = false, manifold = nothing, kwargs...) - if isa_dataiterator(prob.p) reinit_cache = OptimizationBase.ReInitCache(prob.u0, iterate(prob.p)[1]) reinit_cache_passedon = OptimizationBase.ReInitCache(prob.u0, prob.p) From e5e854305c905ada0fcba38284795ec531007574 Mon Sep 17 00:00:00 2001 From: Vaibhav Dixit Date: Wed, 2 Oct 2024 18:24:17 -0400 Subject: [PATCH 4/5] S to A for sparsity pattern --- ext/OptimizationZygoteExt.jl | 8 ++++---- src/OptimizationDISparseExt.jl | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/ext/OptimizationZygoteExt.jl b/ext/OptimizationZygoteExt.jl index 899b231..230dcd4 100644 --- a/ext/OptimizationZygoteExt.jl +++ b/ext/OptimizationZygoteExt.jl @@ -332,7 +332,7 @@ function OptimizationBase.instantiate_function( function hess(res, θ) hessian!(f.f, res, prep_hess, soadtype, θ, Constant(p)) end - hess_sparsity = prep_hess.coloring_result.S + hess_sparsity = prep_hess.coloring_result.A hess_colors = prep_hess.coloring_result.color if p !== SciMLBase.NullParameters() && p !== nothing @@ -415,7 +415,7 @@ function OptimizationBase.instantiate_function( J = vec(J) end end - cons_jac_prototype = prep_jac.coloring_result.S + cons_jac_prototype = prep_jac.coloring_result.A cons_jac_colorvec = prep_jac.coloring_result.color elseif cons !== nothing && cons_j == true cons_j! = (J, θ) -> f.cons_j(J, θ, p) @@ -455,7 +455,7 @@ function OptimizationBase.instantiate_function( prep_cons_hess = [prepare_hessian(cons_oop, soadtype, x, Constant(i)) for i in 1:num_cons] colores = getfield.(prep_cons_hess, :coloring_result) - conshess_sparsity = getfield.(colores, :S) + conshess_sparsity = getfield.(colores, :A) conshess_colors = getfield.(colores, :color) function cons_h!(H, θ) for i in 1:num_cons @@ -474,7 +474,7 @@ function OptimizationBase.instantiate_function( lag_extras = prepare_hessian( lagrangian, soadtype, x, Constant(one(eltype(x))), Constant(ones(eltype(x), num_cons)), Constant(p)) - lag_hess_prototype = lag_extras.coloring_result.S + lag_hess_prototype = lag_extras.coloring_result.A lag_hess_colors = lag_extras.coloring_result.color function lag_h!(H::AbstractMatrix, θ, σ, λ) diff --git a/src/OptimizationDISparseExt.jl b/src/OptimizationDISparseExt.jl index 128f545..e05bae1 100644 --- a/src/OptimizationDISparseExt.jl +++ b/src/OptimizationDISparseExt.jl @@ -65,7 +65,7 @@ function instantiate_function( function hess(res, θ) hessian!(f.f, res, prep_hess, soadtype, θ, Constant(p)) end - hess_sparsity = prep_hess.coloring_result.S + hess_sparsity = prep_hess.coloring_result.A hess_colors = prep_hess.coloring_result.color if p !== SciMLBase.NullParameters() && p !== nothing @@ -147,7 +147,7 @@ function instantiate_function( J = vec(J) end end - cons_jac_prototype = prep_jac.coloring_result.S + cons_jac_prototype = prep_jac.coloring_result.A cons_jac_colorvec = prep_jac.coloring_result.color elseif cons_j === true && f.cons !== nothing cons_j! = (J, θ) -> f.cons_j(J, θ, p) @@ -185,7 +185,7 @@ function instantiate_function( prep_cons_hess = [prepare_hessian(cons_oop, soadtype, x, Constant(i)) for i in 1:num_cons] colores = getfield.(prep_cons_hess, :coloring_result) - conshess_sparsity = getfield.(colores, :S) + conshess_sparsity = getfield.(colores, :A) conshess_colors = getfield.(colores, :color) function cons_h!(H, θ) for i in 1:num_cons @@ -204,7 +204,7 @@ function instantiate_function( lag_prep = prepare_hessian( lagrangian, soadtype, x, Constant(one(eltype(x))), Constant(ones(eltype(x), num_cons)), Constant(p)) - lag_hess_prototype = lag_prep.coloring_result.S + lag_hess_prototype = lag_prep.coloring_result.A lag_hess_colors = lag_prep.coloring_result.color function lag_h!(H::AbstractMatrix, θ, σ, λ) @@ -357,7 +357,7 @@ function instantiate_function( function hess(θ) hessian(f.f, prep_hess, soadtype, θ, Constant(p)) end - hess_sparsity = prep_hess.coloring_result.S + hess_sparsity = prep_hess.coloring_result.A hess_colors = prep_hess.coloring_result.color if p !== SciMLBase.NullParameters() && p !== nothing @@ -410,7 +410,7 @@ function instantiate_function( end return J end - cons_jac_prototype = prep_jac.coloring_result.S + cons_jac_prototype = prep_jac.coloring_result.A cons_jac_colorvec = prep_jac.coloring_result.color elseif cons_j === true && f.cons !== nothing cons_j! = (θ) -> f.cons_j(θ, p) @@ -459,7 +459,7 @@ function instantiate_function( return H end colores = getfield.(prep_cons_hess, :coloring_result) - conshess_sparsity = getfield.(colores, :S) + conshess_sparsity = getfield.(colores, :A) conshess_colors = getfield.(colores, :color) elseif cons_h == true && f.cons !== nothing cons_h! = (res, θ) -> f.cons_h(res, θ, p) @@ -482,7 +482,7 @@ function instantiate_function( return hess end end - lag_hess_prototype = lag_prep.coloring_result.S + lag_hess_prototype = lag_prep.coloring_result.A lag_hess_colors = lag_prep.coloring_result.color if p !== SciMLBase.NullParameters() && p !== nothing From a25ebfb0b54a7e3fc12186560b095c3fd36896b3 Mon Sep 17 00:00:00 2001 From: Vaibhav Kumar Dixit Date: Wed, 2 Oct 2024 19:28:32 -0400 Subject: [PATCH 5/5] Update Project.toml --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 363f936..dab75fd 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "OptimizationBase" uuid = "bca83a33-5cc9-4baa-983d-23429ab6bcbb" authors = ["Vaibhav Dixit and contributors"] -version = "2.1.0" +version = "2.2.0" [deps] ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"