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

Support for skew symmetric variables #2147

Closed
wants to merge 0 commits into from

Conversation

frederikgeth
Copy link

@frederikgeth frederikgeth commented Feb 1, 2020

This is an attempt to support skew symmetric variables (#2146).

Note that the return type (affine expression) is different from the input type (variable ref) here.

Keen to hear your feedback!

Closes #2146

@codecov
Copy link

codecov bot commented Feb 1, 2020

Codecov Report

Merging #2147 into master will increase coverage by 0.03%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2147      +/-   ##
==========================================
+ Coverage   91.42%   91.46%   +0.03%     
==========================================
  Files          42       42              
  Lines        4105     4122      +17     
==========================================
+ Hits         3753     3770      +17     
  Misses        352      352
Impacted Files Coverage Δ
src/sd.jl 95.08% <100%> (+1.9%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dd68f81...c5f0a68. Read the comment docs.

src/sd.jl Outdated
side_dimension::Int
end
function reshape_vector(vectorized_form::Vector{T}, shape::SkewSymmetricMatrixShape) where T
matrix = Matrix{Base.promote_type(T, _MA.promote_operation(-, T), _MA.promote_operation(zero, T))}(undef, shape.side_dimension, shape.side_dimension)
Copy link
Member

@blegat blegat Feb 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks 80-char limit, see JuMP style guide

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Member

@blegat blegat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks ! Could you add a subsection documenting this in https://www.juliaopt.org/JuMP.jl/dev/variables/#Variables-constrained-on-creation-1 ?

@frederikgeth
Copy link
Author

Thanks, @blegat , I will update the pr and add the docs tomorrow

@frederikgeth
Copy link
Author

So tests fail for test_variable_skewsymmetric({JuMPExtension.MyModel}) for 3x3 matrices. This is the error:

  Got exception outside of a @test
  DimensionMismatch("arrays could not be broadcast to a common size; got a dimension with lengths 6 and 3")
  Stacktrace:
   [1] add_variable(::Main.JuMPExtension.MyModel, ::VariablesConstrainedOnCreation{MathOptInterface.Reals,SkewSymmetricMatrixShape,ScalarVariable{Float64,Float64,Float64,Float64}}, ::Array{String,2}) at ./broadcast.jl:490

Not sure where to go with this?

test/variable.jl Outdated
@test x[1, 2] == -x[2, 1]
@test iszero(x[1, 1])
@test iszero(x[2, 2])
@test model[:x] === x
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add test for the number of variables actually added to the inner model

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how to access those?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/sd.jl Outdated
n = _square_side(_error, variables)
set = MOI.Reals(div(n^2 - n, 2))
shape = SkewSymmetricMatrixShape(n)
return VariablesConstrainedOnCreation(vectorize(variables, SkewSymmetricMatrixShape(n)), set, shape)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, you will ignore variables outside the upper triangle, add a TODO for throwing error in case the user set something that does not suit the skew symmetry like we do in _vectorize_variables

@martincornejo
Copy link

Any updates on this PR? This feature could be convenient for me

@odow
Copy link
Member

odow commented Dec 15, 2020

Moved to #2416

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

Successfully merging this pull request may close these issues.

Support for skew-symmetric matrix variables
4 participants