-
-
Notifications
You must be signed in to change notification settings - Fork 393
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
Broadcasting variables constrained on creation #2148
Comments
I think if there are sets where broadcasting is not reasonable we should have at least a way to allow broadcasting for when it is useful i.e by having an extra |
I would vote for (b) as it would also resolve a common feature requested from user coming from cvx.
where here it currently fails: julia> @variable(model, x[1:10, 1:10, 1:8] in PSDCone())
ERROR: MethodError: no method matching build_variable(::JuMP.var"#_error#83"{Tuple{Symbol,Expr}}, ::Array{ScalarVariable{Float64,Float64,Float64,Float64},3}, ::PSDCone)
Closest candidates are:
build_variable(::Function, ::Array{#s92,2} where #s92<:ScalarVariable, ::PSDCone) at /home/blegat/.julia/dev/JuMP/src/sd.jl:182
build_variable(::Function, ::Array{#s92,1} where #s92<:ScalarVariable, ::AbstractVectorSet) at /home/blegat/.julia/dev/JuMP/src/sets.jl:6
build_variable(::Function, ::Array{#s92,2} where #s92<:ScalarVariable, ::SymMatrixSpace) at /home/blegat/.julia/dev/JuMP/src/sd.jl:164
...
Stacktrace:
[1] top-level scope at /home/blegat/.julia/dev/JuMP/src/macros.jl:45 The reasoning would be similar to broadcast in Base. Since PSD variables are matrices and the user want to create an
We could add a trait in case some sets want to throw a warning or error if it gets broadcasted but we can wait to see if there is a set that needs that. |
Urgh, the @variable(model, x[1:2, 1:2, 1:3, 1:3] in PSDCone()) will create 9 2x2 PSD matrices? So Does @variable(model, x[1:3, 1:4] in SecondOrderCone() create 4 SOC vectors? I guess it is a natural extension from broadcasting scalar sets over a vector. We'd just have to make it consistent for all sets and dimensions. |
@odow Yes, exactly, it's a bit odd but if we make it consistent with each set and dimension and with Julia Base broadcasting, it should not be too confusing once the user gets used to it. |
I used the example of integer sets like
The one above is only necessary if something like Here broadcasting is already implemented the same way as it is for |
Yes, this was kind of the old way to specify constrained variables. This is what is used in SumOfSquares and PolyJuMP where you can create containers of polynomials and broadcast works. |
Copied from: #2416 (comment), which has a suggestion that makes the syntax a bit clearer: We don't support @variable(model, x[2:3, 2:3] in SkewSymMatrixSpace()) because it isn't apparent you can have a symmetric But if users are forced to write @variable(model, x[1:3, 1:3] in SkewSymMatrixSpace()) why not just @variable(model, X in SkewSymMatrixSpace(3)) For anonymous variables, we could support X = @variable(model, _ in SkewSymMatrixSpace(3)) Then @variable(model, x[1:3, 1:3] in SkewSymMatrixSpace(2)) is a 3x3 matrix of 2x2 skew-symmetric matrices. It should be possible to have a deprecated way of doing this, because we can distinguish between |
Related issue: #2056 |
#3184 resolves another array-in-scalar-set issue. But I'm not convinced about changing the vector-valued sets. It seems ripe to add more confusion, rather than less. People can easily do things like X = [
@variable(model, [1:3, 1:3] in SkewSymMatrixSpace())
for i in 1:2, j in 1:2
] |
@blegat are you okay with closing this?
I'm not convinced that the syntax: @variable(model, x[1:2, 1:2, 1:3, 1:3] in PSDCone())
@variable(model, x[1:3, 1:4] in SecondOrderCone() is less confusing compared with the currently working: x = [@variable(model, [1:2, 1:2] in PSDCone()) for i in 1:3, j in 1:3]
x = [@variable(model, [1:3] in SecondOrderCone()) for i in 1:4] |
Yes, for vector set we could wait to see if there is a real need for it. But we could at least support it for abitrary scalar set. #3184 is only for |
We already supported scalar sets: #2657. A special method was needed for Closing because this seems resolved. If any future reader has a strong wish for the vector syntax |
For the record, @araujoms just requested exactly that in https://discourse.julialang.org/t/error-when-constraining-variable-to-be-hermitian-psd/95223
|
For what is worth it I no longer think this is a good idea. The JuMP version |
We have a decision to make about what to do if a user writes the following:
Should we
MOI.Integer
is a scalar-set andx
is a vector; orEither case needs a method like:
along with some tests. (If (a), the
return
replaced by a nice error message.)cc @Wikunia
The text was updated successfully, but these errors were encountered: