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

Scalarize bridge error #2363

Closed
joaquimg opened this issue Dec 18, 2023 · 2 comments · Fixed by #2365
Closed

Scalarize bridge error #2363

joaquimg opened this issue Dec 18, 2023 · 2 comments · Fixed by #2365

Comments

@joaquimg
Copy link
Member

@blegat this is the scalarize error I mentioned in jump-dev/ParametricOptInterface.jl#143

The code:

function scalarize_bridge_error()
    model = direct_model(DiffOpt.diff_optimizer(SCS.Optimizer))
    set_silent(model)
    @variable(model, x)
    # @variable(model, p in MOI.Parameter(3.0))
    p = 3.0
    @constraint(model, cons, [x - 3 * p] in MOI.Zeros(1))

    # it works it this is uncommented
    # @constraint(model, fake_soc, [0, 0, 0] in SecondOrderCone())

    @objective(model, Min, 2x)
    optimize!(model)

    MOI.set(model, DiffOpt.ForwardConstraintFunction(), cons,
        MOI.VectorAffineFunction{Float64}(MOI.VectorOfVariables([x]))
    )
    DiffOpt.forward_differentiate!(model) # ERROR

    return
end

the error:

ERROR: MathOptInterface.UnsupportedAttribute{DiffOpt.ForwardConstraintFunction}: Attribute DiffOpt.ForwardConstraintFunction() is not supported by the model: Bridge of type `ScalarizeBridge` does not support setting a value for the attribute `DiffOpt.ForwardConstraintFunction()`. If you encountered this error unexpectedly, it probably means your model has been reformulated using the bridge, and you are attempting to query an attribute that we haven't implemented yet for this bridge. Please open an issue at https://github.com/jump-dev/MathOptInterface.jl/issues/new and provide a reproducible example explaining what you were trying to do.
Stacktrace:
  [1] set(model::MathOptInterface.Bridges.LazyBridgeOptimizer{DiffOpt.QuadraticProgram.Model}, attr::DiffOpt.ForwardConstraintFunction, bridge::MathOptInterface.Bridges.Constraint.ScalarizeBridge{Float64, MathOptInterface.ScalarAffineFunction{Float64}, MathOptInterface.EqualTo{Float64}}, #unused#::MathOptInterface.VectorAffineFunction{Float64})
    @ MathOptInterface.Bridges C:\JG\Julia\packages\MathOptInterface\IiXiU\src\Bridges\bridge.jl:182
@blegat
Copy link
Member

blegat commented Dec 19, 2023

With jump-dev/DiffOpt.jl#253, this is becoming an MOI bug

@blegat blegat transferred this issue from jump-dev/DiffOpt.jl Dec 19, 2023
@blegat
Copy link
Member

blegat commented Dec 19, 2023

using JuMP, SCS
function fallback_error()
    model = Model(SCS.Optimizer)
    @variable(model, x, start = 1)
    @objective(model, Min, x)
    optimize!(model)
    set_start_values(model)
    optimize!(model)
    return
end

gives

ERROR: MethodError: no method matching throw_set_error_fallback(::MathOptInterface.Bridges.LazyBridgeOptimizer{MathOptInterface.Utilities.CachingOptimizer{SCS.Optimizer, MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}}, ::MathOptInterface.Bridges.Objective.SlackBridgePrimalDualStart, ::MathOptInterface.Bridges.Objective.FunctionConversionBridge{Float64, MathOptInterface.ScalarAffineFunction{Float64}, MathOptInterface.VariableIndex}, ::Nothing)

Closest candidates are:
  throw_set_error_fallback(::MathOptInterface.ModelLike, ::Union{MathOptInterface.AbstractModelAttribute, MathOptInterface.AbstractOptimizerAttribute}, ::Any; error_if_supported)
   @ MathOptInterface ~/.julia/dev/MathOptInterface/src/attributes.jl:577
  throw_set_error_fallback(::MathOptInterface.ModelLike, ::Union{MathOptInterface.AbstractConstraintAttribute, MathOptInterface.AbstractVariableAttribute}, ::Union{MathOptInterface.VariableIndex, MathOptInterface.ConstraintIndex}, ::Any; error_if_supported)
   @ MathOptInterface ~/.julia/dev/MathOptInterface/src/attributes.jl:590
  throw_set_error_fallback(::MathOptInterface.ModelLike, ::MathOptInterface.Bridges.Objective.SlackBridgePrimalDualStart, ::Nothing)
   @ MathOptInterface ~/.julia/dev/MathOptInterface/src/Bridges/Objective/bridges/slack.jl:191
  ...

Stacktrace:
 [1] set(::MathOptInterface.Bridges.LazyBridgeOptimizer{MathOptInterface.Utilities.CachingOptimizer{SCS.Optimizer, MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}}, ::MathOptInterface.Bridges.Objective.SlackBridgePrimalDualStart, ::MathOptInterface.Bridges.Objective.FunctionConversionBridge{Float64, MathOptInterface.ScalarAffineFunction{Float64}, MathOptInterface.VariableIndex}, ::Nothing)
   @ MathOptInterface ~/.julia/dev/MathOptInterface/src/attributes.jl:550
 [2] set(b::MathOptInterface.Bridges.LazyBridgeOptimizer{MathOptInterface.Utilities.CachingOptimizer{SCS.Optimizer, MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}}, attr::MathOptInterface.Bridges.Objective.SlackBridgePrimalDualStart, #unused#::Nothing)
   @ MathOptInterface.Bridges.Objective ~/.julia/dev/MathOptInterface/src/Bridges/Objective/bridges/slack.jl:248

What's a bit weird is that if I remove the first optimize! not error is thrown. Maybe because the attribute is passed before the ObjectiveFunction which is a separate issue that should also be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants