Closed araujoms closed 8 months ago
The issue is that we shouldn't wrap in Hermitian
something that's not Hermitian
^^
julia> B = MA._mult_upper(im, m)
2×2 Matrix{GenericAffExpr{ComplexF64, VariableRef}}:
real(m[1,1]) im real(m[1,2]) im - imag(m[1,2])
real(m[1,2]) im + imag(m[1,2]) real(m[2,2]) im
julia> h = Hermitian(B, :U)
2×2 Hermitian{GenericAffExpr{ComplexF64, VariableRef}, Matrix{GenericAffExpr{ComplexF64, VariableRef}}}:
-real(m[1,1]) im real(m[1,2]) im - imag(m[1,2])
-real(m[1,2]) im - imag(m[1,2]) -real(m[2,2]) im
julia> h.data
2×2 Matrix{GenericAffExpr{ComplexF64, VariableRef}}:
real(m[1,1]) im real(m[1,2]) im - imag(m[1,2])
real(m[1,2]) im + imag(m[1,2]) real(m[2,2]) im
That's weird. Shouldn't Hermitian(B)
return instead
2×2 Hermitian{GenericAffExpr{ComplexF64, VariableRef}, Matrix{GenericAffExpr{ComplexF64, VariableRef}}}:
0.0 real(m[1,2]) im - imag(m[1,2])
-real(m[1,2]) im - imag(m[1,2]) 0.0
Yes, looks like another bug, it calls LinearAlgebra.hermitian(h.data[1, 1], :U)
which doesn't seem to do the right thing see https://github.com/jump-dev/JuMP.jl/issues/3692
With #265, we now get:
julia> using JuMP
julia> model = Model();
julia> @variable(model, m[1:2,1:2] in HermitianPSDCone());
julia> im*m
2×2 Matrix{GenericAffExpr{ComplexF64, VariableRef}}:
real(m[1,1]) im real(m[1,2]) im - imag(m[1,2])
real(m[1,2]) im + imag(m[1,2]) real(m[2,2]) im
Wait, please, don't close the issue! What about getting a new dispatch so that a Hermitian matrix multiplied by a real variable stays Hermitian? It is the only reason I was even testing this stuff.
What about getting a new dispatch so that a Hermitian matrix multiplied by a real variable stays Hermitian?
I'll open a separate issue.
Great, thanks.
The algebra with complex numbers and Symmetric or Hermitian matrices doesn't work as it should. First of all, multiplying a complex number by a Hermitian matrix gives an incorrect result wrapped in Hermitian:
Also, if I create a real variable and multiply it by a Symmetric or Hermitian matrix, I get the correct result, but it's no longer wrapped in Symmetric or Hermitian:
(Of course, Symmetric matrices multiplied by complex variables should still be Symmetric, but I don't think this will ever matter.)