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

No Clear API for ReverseConstraintFunction for Conic Constraints #283

Open
andrewrosemberg opened this issue Mar 22, 2025 · 1 comment
Open
Labels
bug Something isn't working enhancement New feature or request

Comments

@andrewrosemberg
Copy link
Collaborator

The following errors and it is not clear how to correctly fetch the ReverseConstraintFunction perturbations for conic constraints:

model = JuMP.Model(() -> DiffOpt.diff_optimizer(SCS.Optimizer))
set_silent(model)

x = @variable(model)
y = @variable(model)
t = @variable(model)

ceq = @constraint(model, -1.0t == -1.0)

cnon = @constraint(model, 1.0y >= 1 / 2)
csoc = @constraint(model, [1.0t, 1.0x, 1.0y] in MOI.SecondOrderCone(3))

@objective(model, Min, 1.0x)

optimize!(model)

MOI.set(
      model,
      DiffOpt.ReverseVariablePrimal(),
      y,
      1.0
  )

  DiffOpt.reverse_differentiate!(model)

JuMP.coefficient(MOI.get(model, DiffOpt.ReverseConstraintFunction(), cnon), y)

Errors with:

ERROR: MethodError: no method matching coefficient(::DiffOpt.MatrixVectorAffineFunction{…}, ::MathOptInterface.VariableIndex)

Closest candidates are:
  coefficient(::DiffOpt.MatrixScalarQuadraticFunction, ::MathOptInterface.VariableIndex)
   @ DiffOpt ~/Workspace/DiffOpt.jl/src/utils.jl:228
  coefficient(::DiffOpt.MatrixScalarQuadraticFunction, ::MathOptInterface.VariableIndex, ::MathOptInterface.VariableIndex)
   @ DiffOpt ~/Workspace/DiffOpt.jl/src/jump_moi_overloads.jl:198
  coefficient(::GenericQuadExpr{C, V}, ::V, ::V) where {C, V}
   @ JuMP ~/.julia/packages/JuMP/xlp0s/src/quad_expr.jl:220
  ...

Stacktrace:
 [1] coefficient(func::DiffOpt.IndexMappedFunction{…}, vi::MathOptInterface.VariableIndex)
   @ DiffOpt ~/Workspace/DiffOpt.jl/src/jump_moi_overloads.jl:247
 [2] coefficient(func::DiffOpt.IndexMappedFunction{DiffOpt.IndexMappedFunction{…}}, vi::MathOptInterface.VariableIndex)
   @ DiffOpt ~/Workspace/DiffOpt.jl/src/jump_moi_overloads.jl:247
 [3] coefficient(func::DiffOpt.MOItoJuMP{DiffOpt.IndexMappedFunction{DiffOpt.IndexMappedFunction{…}}}, var_ref::VariableRef)
   @ DiffOpt ~/Workspace/DiffOpt.jl/src/jump_moi_overloads.jl:297
 [4] top-level scope
@andrewrosemberg andrewrosemberg added bug Something isn't working enhancement New feature or request labels Mar 22, 2025
@joaquimg
Copy link
Member

@blegat did you think about it at some point?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Development

No branches or pull requests

2 participants