-
Notifications
You must be signed in to change notification settings - Fork 14
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
[WIP] Integrate with POI to improve UX #262
base: master
Are you sure you want to change the base?
Conversation
Last commit is an attempt to solve the error raised by: using JuMP, DiffOpt, HiGHS
b = [1.0, 2.0]
m = Model(
() -> DiffOpt.diff_optimizer(
HiGHS.Optimizer;
with_parametric_opt_interface = true,
),
)
@variable(m, x[1:2] >= 0)
@variable(m, c[1:2] in MOI.Parameter.(b))
@constraint(m, con, x <= c)
@objective(m, Max, sum(x))
optimize!(m)
MOI.set(m, DiffOpt.ReverseVariablePrimal(), m[:x][1], 1.0)
DiffOpt.reverse_differentiate!(m) which is:
|
this still fails using JuMP, DiffOpt, SCS, LinearAlgebra
num_A = 2
##### SecondOrderCone #####
_x_hat = rand(num_A)
μ = rand(num_A) * 10
Σ_12 = rand(num_A, num_A)
Σ = Σ_12 * Σ_12' + 0.1 * I
γ = 1.0
model = direct_model(
DiffOpt.diff_optimizer(
SCS.Optimizer;
with_parametric_opt_interface = true,
),
)
# model = direct_model(POI.Optimizer(DiffOpt.diff_optimizer(SCS.Optimizer)))
set_silent(model)
@variable(model, x[1:num_A])
@variable(model, x_hat[1:num_A] in MOI.Parameter.(_x_hat))
@variable(model, norm_2)
# (x - x_hat)^T Σ^-1 (x - x_hat) <= γ
@constraint(
model,
(x - μ)' * inv(Σ) * (x - μ) <= γ,
)
# norm_2 >= ||x - x_hat||_2
@constraint(model, [norm_2; x - x_hat] in SecondOrderCone())
@objective(model, Min, norm_2)
optimize!(model)
# MOI.set.(model, POI.ForwardParameter(), x_hat, ones(num_A))
MOI.set.(model, DiffOpt.ForwardConstraintSet(), ParameterRef.(x_hat), 1)
DiffOpt.forward_differentiate!(model) # ERROR with:
if we switch to @objective(model, Min, 3*norm_2) it works. so it looks like a VariableIndex typed objective. Found a MWE: model = Model(
() -> DiffOpt.diff_optimizer(
SCS.Optimizer;
with_parametric_opt_interface = true,
),
)
MOI.set(model, DiffOpt.ModelConstructor(), DiffOpt.ConicProgram.Model)
set_silent(model)
@variable(model, x)
@variable(model, p in Parameter(3.0))
@constraint(model, cons, x >= 3 * p)
@objective(model, Min, x)
optimize!(model)
DiffOpt.set_forward_parameter(model, p, 1)
DiffOpt.forward_differentiate!(model) the issue is conic backend + VariabelIndex objective
|
@blegat, Looking at So the error might be where the bridge is being triggered? if I add:
the error goes away, but I am not sure if this is correct. |
Maybe we need to start reviving #253 otherwise we'll spend time on a fix that will need to be updated once we merge it |
Agreed! |
Let me know if rebasing on master fixed the error |
Add multiple improvements to DiffOpt leading to a massive UX improvement.
with_parametric_opt_interface = true
using Prepare integration with DiffOpt ParametricOptInterface.jl#161method
(maybe switch tomodel_constructor
)empty_input_sensitivities!
About the integration with POI:
with_parametric_opt_interface
is false by default, for now. I want to make it true.(Forward/Reverse)ConstraintSet
forMOI.Parameters
is supported (ObjectiveFunction
andConstraintFunction
are not supported)ConstraintSet
only woks forMOI.Parameters
. We can addEqualTo
etc in a future PR.TODO:
set_forward_parameter
,set_forward
or onlyMOI. ...
. The first two make total sense for JuMP users, the MOI method will remain in the code for MOI users and extensions. I am strongly in favor of a JuMP-like method.