Skip to content

Commit

Permalink
call cons_vjp if available
Browse files Browse the repository at this point in the history
  • Loading branch information
baggepinnen committed Aug 26, 2024
1 parent 0f222b6 commit f870457
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
2 changes: 2 additions & 0 deletions lib/OptimizationMOI/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ authors = ["Vaibhav Dixit <[email protected]> and contributors"]
version = "0.4.2"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
Optimization = "7f7a1694-90dd-40f0-9382-eb1efda571ba"
Expand All @@ -19,6 +20,7 @@ HiGHS = "1"
Ipopt = "1"
Ipopt_jll = "300.1400"
Juniper = "0.9"
LinearAlgebra = "1"
MathOptInterface = "1"
ModelingToolkit = "9"
NLopt = "1"
Expand Down
1 change: 1 addition & 0 deletions lib/OptimizationMOI/src/OptimizationMOI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import ModelingToolkit: parameters, unknowns, varmap_to_vars, mergedefaults, toe
import ModelingToolkit
const MTK = ModelingToolkit
using Symbolics
using LinearAlgebra

const MOI = MathOptInterface

Expand Down
30 changes: 18 additions & 12 deletions lib/OptimizationMOI/src/nlp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function MOIOptimizationNLPCache(prob::OptimizationProblem,

num_cons = prob.ucons === nothing ? 0 : length(prob.ucons)
f = Optimization.instantiate_function(prob.f, reinit_cache, prob.f.adtype, num_cons;
g = true, h = true, cons_j = true, lag_h = true)
g = true, h = false, cons_j = true, lag_h = true)
T = eltype(prob.u0)
n = length(prob.u0)

Expand Down Expand Up @@ -297,17 +297,23 @@ end
# return
# end

# function MOI.eval_constraint_jacobian_transpose_product(
# evaluator::Evaluator,
# y,
# x,
# w,
# )
# start = time()
# MOI.eval_constraint_jacobian_transpose_product(evaluator.backend, y, x, w)
# evaluator.eval_constraint_jacobian_timer += time() - start
# return
# end
function MOI.eval_constraint_jacobian_transpose_product(
evaluator::MOIOptimizationNLPEvaluator,
y,
x,
w,
)
if evaluator.f.cons_vjp !== nothing
evaluator.f.cons_vjp(y, w, x)

elseif evaluator.f.cons_j !== nothing
J = evaluator.J
evaluator.f.cons_j(J, x)
mul!(y, J', w)
return
end
error("Thou shalt provide the v'J of the constraint jacobian, not doing so is associated with great misfortune and also no ice cream for you.")
end

function MOI.hessian_lagrangian_structure(evaluator::MOIOptimizationNLPEvaluator)
lagh = evaluator.f.lag_h !== nothing
Expand Down

0 comments on commit f870457

Please sign in to comment.