DiffOpt.jl
DiffOpt.jl copied to clipboard
Bridging error (?)
model = DiffOpt.conic_diff_model(SCS.Optimizer)
set_silent(model)
@variable(model, x)
@variable(model, p in Parameter(1.0))
@constraint(model, con, [-p*x 0; 0 x] in PSDCone())
optimize!(model)
julia> optimize!(model)
ERROR: MathOptInterface.SetAttributeNotAllowed{MathOptInterface.ConstraintFunction}:
## Cause
Setting attribute MathOptInterface.ConstraintFunction() cannot be performed because:
Bridge of type `SquareBridge` does not support setting a value for the attribute `MathOptInterface.ConstraintFunction()`. 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.
## Fixing this error
An `MOI.NotAllowedError` error occurs when you have tried to do something that
is not implemented by the solver.
The most common way to fix this error is to wrap the optimizer in a
`MOI.Utilities.CachingOptimizer`.
For example, if you are using `JuMP.Model` or `JuMP.set_optimizer`, do:
model = JuMP.Model(optimizer; with_cache_type = Float64)
model = JuMP.GenericModel{T}(optimizer; with_cache_type = T)
JuMP.set_optimizer(model, optimizer; with_cache_type = Float64)
Similarly, if you are using `MOI.instantiate`, do:
model = MOI.instantiate(optimizer; with_cache_type = Float64)
Stacktrace:
[1] set(model::MathOptInterface.Bridges.LazyBridgeOptimizer{…}, attr::MathOptInterface.ConstraintFunction, bridge::MathOptInterface.Bridges.Constraint.SquareBridge{…}, ::MathOptInterface.VectorAffineFunction{…})
@ MathOptInterface.Bridges C:\JG\Julia\packages\MathOptInterface\vK6dk\src\Bridges\bridge.jl:184
[2] (::MathOptInterface.Bridges.var"#3#4"{…})(bridge::MathOptInterface.Bridges.Constraint.SquareBridge{…})
@ MathOptInterface.Bridges C:\JG\Julia\packages\MathOptInterface\vK6dk\src\Bridges\bridge_optimizer.jl:324
[3] (::MathOptInterface.Bridges.var"#1#2"{…})()
@ MathOptInterface.Bridges C:\JG\Julia\packages\MathOptInterface\vK6dk\src\Bridges\bridge_optimizer.jl:309
[4] call_in_context(map::MathOptInterface.Bridges.Variable.Map, bridge_index::Int64, f::MathOptInterface.Bridges.var"#1#2"{…})
@ MathOptInterface.Bridges.Variable C:\JG\Julia\packages\MathOptInterface\vK6dk\src\Bridges\Variable\map.jl:621
[5] call_in_context
@ C:\JG\Julia\packages\MathOptInterface\vK6dk\src\Bridges\Variable\map.jl:652 [inlined]
[6] call_in_context
@ C:\JG\Julia\packages\MathOptInterface\vK6dk\src\Bridges\bridge_optimizer.jl:306 [inlined]
[7] call_in_context
@ C:\JG\Julia\packages\MathOptInterface\vK6dk\src\Bridges\bridge_optimizer.jl:321 [inlined]
[8] _set_substituted(b::MathOptInterface.Bridges.LazyBridgeOptimizer{…}, attr::MathOptInterface.ConstraintFunction, ci::MathOptInterface.ConstraintIndex{…}, value::MathOptInterface.VectorAffineFunction{…})
@ MathOptInterface.Bridges C:\JG\Julia\packages\MathOptInterface\vK6dk\src\Bridges\bridge_optimizer.jl:1431
[9] set(b::MathOptInterface.Bridges.LazyBridgeOptimizer{…}, attr::MathOptInterface.ConstraintFunction, ci::MathOptInterface.ConstraintIndex{…}, func::MathOptInterface.VectorAffineFunction{…})
@ MathOptInterface.Bridges C:\JG\Julia\packages\MathOptInterface\vK6dk\src\Bridges\bridge_optimizer.jl:1407
[10] _update_vector_quadratic_constraints!(model::ParametricOptInterface.Optimizer{…}, vector_quadratic_constraint_cache_inner::MathOptInterface.Utilities.DoubleDicts.DoubleDictInner{…})
@ ParametricOptInterface C:\JG\Julia\packages\ParametricOptInterface\X6CpI\src\update_parameters.jl:417
[11] _update_vector_quadratic_constraints!(model::ParametricOptInterface.Optimizer{…})
@ ParametricOptInterface C:\JG\Julia\packages\ParametricOptInterface\X6CpI\src\update_parameters.jl:324
[12] update_parameters!(model::ParametricOptInterface.Optimizer{Float64, MathOptInterface.Bridges.LazyBridgeOptimizer{…}})
@ ParametricOptInterface C:\JG\Julia\packages\ParametricOptInterface\X6CpI\src\update_parameters.jl:314
[13] optimize!(model::ParametricOptInterface.Optimizer{Float64, MathOptInterface.Bridges.LazyBridgeOptimizer{…}})
@ ParametricOptInterface C:\JG\Julia\packages\ParametricOptInterface\X6CpI\src\MOI_wrapper.jl:1922
[14] optimize!
@ C:\JG\Julia\packages\MathOptInterface\vK6dk\src\MathOptInterface.jl:122 [inlined]
[15] optimize!(m::MathOptInterface.Utilities.CachingOptimizer{…})
@ MathOptInterface.Utilities C:\JG\Julia\packages\MathOptInterface\vK6dk\src\Utilities\cachingoptimizer.jl:370
[16] optimize!(model::DiffOpt.Optimizer{MathOptInterface.Utilities.CachingOptimizer{…}})
@ DiffOpt C:\JG\Julia\dev\DiffOpt\src\moi_wrapper.jl:501
[17] optimize!(model::Model; ignore_optimize_hook::Bool, _differentiation_backend::MathOptInterface.Nonlinear.SparseReverseMode, kwargs::@Kwargs{})
@ JuMP C:\JG\Julia\packages\JuMP\Ue9wj\src\optimizer_interface.jl:609
[18] optimize!(model::Model)
@ JuMP C:\JG\Julia\packages\JuMP\Ue9wj\src\optimizer_interface.jl:560
[19] top-level scope
@ REPL[30]:1
Some type information was truncated. Use `show(err)` to see complete types.
We could add support for it in this bridge but many other bridges don't support it. So we should maybe add a cache, it could be an option of POI. Why is it updating the value of the parameter ? The code doesn't seem to change the value of the parameter.
Thats a good point. We are probably calling the update always in this case, we chould check if the parameter was changed before calling the update.
This would partially solve the issue indeed, as the above code would work.
Yes and in case we have this error, we should just tell the user to use the option that adds a cache