Skip to content
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

call cons_vjp if available #811

Merged
merged 3 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, cons_vjp = 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, x, w)

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
Loading