Skip to content
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
6 changes: 5 additions & 1 deletion src/NonLinearProgram/nlp_utilities.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Copyright (c) 2025: Andrew Rosemberg and contributors
# Copyright (c) 2020: Akshay Sharma and contributors
#
# Use of this source code is governed by an MIT-style license that can be found
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.

#=
The code in this file related to calculating hessians and jacobians is based on the
JuMP Tutorial for Querying Hessians:
Expand Down
5 changes: 5 additions & 0 deletions src/copy_dual.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Copyright (c) 2020: Akshay Sharma and contributors
#
# Use of this source code is governed by an MIT-style license that can be found
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.

"""
struct ObjectiveFunctionAttribute{A,F} <: MOI.AbstractModelAttribute
attr::A
Expand Down
5 changes: 5 additions & 0 deletions src/jump_wrapper.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Copyright (c) 2020: Akshay Sharma and contributors
#
# Use of this source code is governed by an MIT-style license that can be found
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.

"""
diff_model(optimizer_constructor; with_bridge_type = Float64, with_cache_type = Float64, with_outer_cache = true)

Expand Down
5 changes: 5 additions & 0 deletions test/bridges.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Copyright (c) 2020: Akshay Sharma and contributors
#
# Use of this source code is governed by an MIT-style license that can be found
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.

module TestBridges

using Test
Expand Down
15 changes: 10 additions & 5 deletions test/nlp_program.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Copyright (c) 2020: Akshay Sharma and contributors
#
# Use of this source code is governed by an MIT-style license that can be found
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.

module TestNLPProgram

using DiffOpt
Expand Down Expand Up @@ -46,7 +51,7 @@ function analytic_jacobian(x, p)
g_1_J = [
2.0 * x[1], # ∂g_1/∂x_1
0.0, # ∂g_1/∂x_2
-1.0, # ∂g_1/∂p_1
-1.0, # ∂g_1/∂p_1
0.0, # ∂g_1/∂p_2
0.0, # ∂g_1/∂p_3
]
Expand Down Expand Up @@ -161,12 +166,12 @@ function test_analytical_simple(; P = 2) # Number of parameters
# Compute derivatives
DiffOpt.forward_differentiate!(m)

# test Objective Sensitivity wrt parameters
# test Objective Sensitivity wrt parameters
df_dp = MOI.get(m, DiffOpt.ForwardObjectiveValue())
@test isapprox(df_dp, dot(dual.(con), Δp); atol = 1e-4)
@test all(isapprox.(dual.(ParameterRef.(p)), dual.(con); atol = 1e-8))

# Test sensitivities
# Test sensitivities
@test_throws ErrorException MOI.get(
m.moi_backend.optimizer.model.diff.model,
DiffOpt.ForwardConstraintDual(),
Expand Down Expand Up @@ -320,7 +325,7 @@ function test_analytical_simple(; P = 2) # Number of parameters
end
end

# f(x, p) = 0
# f(x, p) = 0
# x = g(p)
# ∂x/∂p = ∂g/∂p

Expand Down Expand Up @@ -945,7 +950,7 @@ end
=#
################################################

# For ease of testing, we will define a simple situation
# For ease of testing, we will define a simple situation
# where the Jacobian matrix of the KKT becomes needs inertia correction
# minimize x1 + x2
# x1 + 2x2 ≥ 1
Expand Down
9 changes: 7 additions & 2 deletions test/vno_bridge.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Copyright (c) 2020: Akshay Sharma and contributors
#
# Use of this source code is governed by an MIT-style license that can be found
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.

module TestVNOBridge

using DiffOpt
Expand Down Expand Up @@ -193,7 +198,7 @@ end

function test_VectorNonlinearOracle_multivariate()
# Multivariate test: 2 inputs, 2 outputs
# Constraint: [x1^2 + x2^2; x1 * x2] in [-Inf, 1] x [0, Inf]
# Constraint: [x1^2 + x2^2; x1 * x2] in [-Inf, 1] x [0, Inf]
# (i.e., x1^2+x2^2 <= 1, x1*x2 >= 0)
model = DiffOpt.nonlinear_diff_model(Ipopt.Optimizer)
set_silent(model)
Expand Down Expand Up @@ -265,7 +270,7 @@ function test_VectorNonlinearOracle_multivariate()
@test value(x[1]) ≈ p_val[1] atol = 1e-6
@test value(x[2]) ≈ p_val[2] atol = 1e-6

# Reverse-mode: dx/dp = I (identity), so with seed [1.0, 1.0] on x,
# Reverse-mode: dx/dp = I (identity), so with seed [1.0, 1.0] on x,
# sensitivity on p should be [1.0, 1.0]
DiffOpt.empty_input_sensitivities!(model)
DiffOpt.set_reverse_variable(model, x[1], 1.0)
Expand Down
Loading