-
Notifications
You must be signed in to change notification settings - Fork 151
Open
Description
I've encountered this issue when running the tests of my package ConicQKD, which started to hang when I switched from ForwardDiff 0.10 to 1.0.
It was a lot of work to reduce it to a minimum working example. Apparently the problem appears when you try to compute the Hessian of a function of a complex matrix that sets several elements to zero and asks for its eigenvalues. If I just ask for the eigenvalues without setting anything to zero then it's fine. Real matrices work without any problems, even when setting elements to zero.
To reproduce, call test_hessian(ComplexF64)
. You can also check the real case test_hessian(Float64)
, it works fine.
using LinearAlgebra
import ForwardDiff
import GenericLinearAlgebra.eigen
import Random
function test_hessian(::Type{T}) where {T}
Random.seed!(1)
d = 3
function barrier(point)
d2 = div(d, 2)
M = mat(point, T)
M[1:d2, d2+1:end] .= 0
return sum(eigvals(Hermitian(M)))
end
x = randn(T, d, d)
point = rvec(x * x')
fd_hess = ForwardDiff.hessian(barrier, point)
return fd_hess
end
function rvec(M::AbstractMatrix{T}) where {T}
if T <: Real
return vec(M)
else
return [real(vec(M)); imag(vec(M))]
end
end
function mat(v::AbstractVector, ::Type{T}) where {T}
if T <: Real
n = isqrt(length(v))
return reshape(v, n, n)
else
l2 = div(length(v), 2)
n = isqrt(l2)
return reshape(v[1:l2] + im*v[l2+1:end], n, n)
end
end
Metadata
Metadata
Assignees
Labels
No labels