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

Add support for {Hermitian,Symmetric} in Zeros constraint #3281

Merged
merged 7 commits into from
Mar 15, 2023

Conversation

odow
Copy link
Member

@odow odow commented Mar 12, 2023

"vector-valued set. Did you mean to use the broadcasting syntax " *
"`.==` instead?",
),
@constraint(model, X == A),
Copy link
Member Author

Choose a reason for hiding this comment

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

We recently added (#3273) support for vector == vector. But it is less clear what to do for matrix == matrix.

It gets lowered to X - A in Zeros(), but X - A is a matrix, and Zeros() is a vector-valued set, which triggers this error.

Copy link
Member

Choose a reason for hiding this comment

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

We could make the equality case work.
The inequality, it's better that it's an error since the user most probably forgot PSDCone()

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it wouldn't even be possible to support inequalities, as JuMP cannot know whether the user wants PSDCone() or HermitianPSDCone().

In any case, I concur, allowing inequalities leads to ambiguities. Maybe the user has a symmetric matrix, but wants to constrain it to be elementwise nonnegative.

There's also a bug that always happens with YALMIP: the user has a matrix they think is Hermitian but it's actually not because of numerical noise. Then the user writes >= 0 thinking it's constraining it to be PSD, but YALMIP instead interprets that as elementwise non-negativity.

Copy link
Member

Choose a reason for hiding this comment

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

There's also a bug that always happens with YALMIP: the user has a matrix they think is Hermitian but it's actually not because of numerical noise. Then the user writes >= 0 thinking it's constraining it to be PSD, but YALMIP instead interprets that as elementwise non-negativity.

Indeed, we want to avoid that, an error asking the user to be explicit about it is better than trying to save a few keystrokes

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's merge this and see how we go re-feedback. The non-symmetric case X .== Y is pretty easy to type, and there's a nice error message.

The specialized support for symmetric and hermitian is more useful because of the redundant constraints.

Agree on inequalities.

Copy link
Member

Choose a reason for hiding this comment

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

The case of equalities is not so clear-cut because the user intention is not ambiguous. If JuMP interprets == as .== in the non-symmetric case the result will be a slowdown, not a bug (assuming the user thought the matrix was Hermitian).

I would just change the error message to say "Please declare your matrix as Symmetric or Hermitian if it is the case. Otherwise use .=="

We can't really do that since JuMP is a general purpose solver so having equality between matrices is completely fine and it's weird to talk about Symmetric or Hermitian matrices outside the context of SDP.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough, but the error message seems to imply that == is never supported for matrices, which is not the case.

Copy link
Member

Choose a reason for hiding this comment

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

Good point, JuMP.Zeros is indeed not a vector-valued set (since it works with scalars, Symmetric and Hermitian). "Equality between $(typeof(matrix)). Use .== for elementwise inequality or wrap the matrix in Symmetric or Hermitian) for equality between matrices of such special structure"

Copy link
Contributor

Choose a reason for hiding this comment

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

Perfect, thanks.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated the docs and the error message.

@codecov
Copy link

codecov bot commented Mar 12, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (f38bfce) 98.11% compared to head (c7bbaba) 98.11%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3281   +/-   ##
=======================================
  Coverage   98.11%   98.11%           
=======================================
  Files          34       34           
  Lines        4714     4732   +18     
=======================================
+ Hits         4625     4643   +18     
  Misses         89       89           
Impacted Files Coverage Δ
src/print.jl 99.73% <ø> (ø)
src/sd.jl 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

src/sd.jl Outdated Show resolved Hide resolved
src/sd.jl Outdated Show resolved Hide resolved
src/sd.jl Outdated Show resolved Hide resolved
@blegat
Copy link
Member

blegat commented Mar 14, 2023

@araujoms
Copy link
Contributor

One should also update the complex tutorial to use the new syntax and mention that it's more efficient.

@odow odow merged commit 59cfe78 into master Mar 15, 2023
@odow odow deleted the od/add-matrix-in-set branch March 15, 2023 19:02
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.

3 participants