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

Error DiffOpt.forward_differentiate! from PSD Conic JuMP problems #285

Open
andrewrosemberg opened this issue Mar 25, 2025 · 0 comments
Open
Labels
bug Something isn't working

Comments

@andrewrosemberg
Copy link
Collaborator

andrewrosemberg commented Mar 25, 2025

Consider the conic problem:

model = Model(() -> DiffOpt.diff_optimizer(SCS.Optimizer))
@variable(model, x[1:7])
@test num_variables(model) == 7
c1 = @constraint(model, -sum(x[i] for i in 1:6) + 10  0)
c2 = [
    @constraint(model, x[i]  0)
    for i in 1:6
]
α = 0.8
δ = 0.9
c3 = @constraint(
    model,
    LinearAlgebra.Symmetric(hcat(
        [((δ/2)*x[1] + α*x[2] + δ*x[3] +/4)*x[4] +/8)*x[5] - 1.0*x[7])   # a11
        ((-/(2*√2)))*x[1] -/4)*x[2] -/(8*√2))*x[5])],
        [((-/(2*√2)))*x[1] -/4)*x[2] -/(8*√2))*x[5])
        ((δ/2)*x[1] +- α)*x[2] + 0.0*x[3] +/8)*x[5] +/4)*x[6] - x[7])])
    ) in PSDCone()
)
@objective(model, Max, x[7])
optimize!(model)

Setting the objective sensitivity:

MOI.set(
    model,
    DiffOpt.ForwardObjectiveFunction(),
   sum(x)
)

or conic constraint sensitivity

MOI.set.(
    model,
    DiffOpt.ForwardConstraintFunction(),
    c3,
    sum(x) + 1,
)

Errors when differentiating:

> DiffOpt.forward_differentiate!(model)
ERROR: MethodError: no method matching throw_set_error_fallback(::MathOptInterface.Bridges.LazyBridgeOptimizer{…}, ::DiffOpt.ObjectiveFunctionAttribute{…}, ::MathOptInterface.Bridges.Objective.FunctionConversionBridge{…}, ::MathOptInterface.ScalarAffineFunction{…})

Closest candidates are:
  throw_set_error_fallback(::MathOptInterface.ModelLike, ::Union{MathOptInterface.AbstractModelAttribute, MathOptInterface.AbstractOptimizerAttribute}, ::Any; error_if_supported)
   @ MathOptInterface ~/.julia/packages/MathOptInterface/jGuEH/src/attributes.jl:580
  throw_set_error_fallback(::MathOptInterface.ModelLike, ::MathOptInterface.ConstraintFunction, ::MathOptInterface.ConstraintIndex{F, S}, ::F; error_if_supported) where {F<:MathOptInterface.AbstractFunction, S}
   @ MathOptInterface ~/.julia/packages/MathOptInterface/jGuEH/src/attributes.jl:1896
  throw_set_error_fallback(::MathOptInterface.ModelLike, ::MathOptInterface.ConstraintFunction, ::MathOptInterface.ConstraintIndex, ::MathOptInterface.AbstractFunction; kwargs...)
   @ MathOptInterface ~/.julia/packages/MathOptInterface/jGuEH/src/attributes.jl:1908
  ...

Stacktrace:
 [1] set(::MathOptInterface.Bridges.LazyBridgeOptimizer{…}, ::DiffOpt.ObjectiveFunctionAttribute{…}, ::MathOptInterface.Bridges.Objective.FunctionConversionBridge{…}, ::MathOptInterface.ScalarAffineFunction{…})
   @ MathOptInterface ~/.julia/packages/MathOptInterface/jGuEH/src/attributes.jl:553
 [2] set(b::MathOptInterface.Bridges.LazyBridgeOptimizer{…}, attr::DiffOpt.ObjectiveFunctionAttribute{…}, value::MathOptInterface.ScalarAffineFunction{…})
   @ DiffOpt ~/Workspace/DiffOpt.jl/src/copy_dual.jl:51
 [3] set(b::MathOptInterface.Bridges.LazyBridgeOptimizer{…}, attr::DiffOpt.ForwardObjectiveFunction, value::MathOptInterface.ScalarAffineFunction{…})
   @ DiffOpt ~/Workspace/DiffOpt.jl/src/copy_dual.jl:71
 [4] forward_differentiate!(model::DiffOpt.Optimizer{MathOptInterface.Utilities.CachingOptimizer{…}})
   @ DiffOpt ~/Workspace/DiffOpt.jl/src/moi_wrapper.jl:564
 [5] forward_differentiate!
   @ ~/Workspace/DiffOpt.jl/src/jump_moi_overloads.jl:393 [inlined]
 [6] forward_differentiate!(model::MathOptInterface.Utilities.CachingOptimizer{…})
   @ DiffOpt ~/Workspace/DiffOpt.jl/src/jump_moi_overloads.jl:378
 [7] forward_differentiate!(model::Model)
   @ DiffOpt ~/Workspace/DiffOpt.jl/src/jump_moi_overloads.jl:363
 [8] top-level scope
   @ REPL[24]:1
Some type information was truncated. Use `show(err)` to see complete types.
@andrewrosemberg andrewrosemberg added the bug Something isn't working label Mar 25, 2025
@andrewrosemberg andrewrosemberg changed the title Error DiffOpt.forward_differentiate! from Conic JuMP problems Error DiffOpt.forward_differentiate! from PSD Conic JuMP problems Mar 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

1 participant