ArgumentError: invalid argument #4 to LAPACK call

This problem arose using Julia 1.4.2, and I then got version 1.5.1 and the problem is still there.

If I create a matrix, then get its eigenvalues, then plot the eigenvalues, then get the eigenvalues again, I get the error:

ArgumentError: invalid argument #4 to LAPACK call

Stacktrace:
 [1] chklapackerror at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\LinearAlgebra\src\lapack.jl:36 [inlined]
 [2] geevx!(::Char, ::Char, ::Char, ::Char, ::Array{Float64,2}) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\LinearAlgebra\src\lapack.jl:2082
 [3] eigvals!(::Array{Float64,2}; permute::Bool, scale::Bool, sortby::typeof(LinearAlgebra.eigsortby)) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\LinearAlgebra\src\eigen.jl:293
 [4] eigvals! at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\LinearAlgebra\src\eigen.jl:292 [inlined]
 [5] #eigvals#73 at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\LinearAlgebra\src\eigen.jl:326 [inlined]
 [6] eigvals(::Array{Float64,2}) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\LinearAlgebra\src\eigen.jl:326
 [7] top-level scope at In[242]:1
 [8] include_string(::Function, ::Module, ::String, ::String) at .\loading.jl:1091

This was the easiest way I could reproduce the problem:

using LinearAlgebra
using Plots; pyplot();

A = [0.475 0.5 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0;
0.5 -0.475 0.5 0.5 0.0 0.0 0.0 0.0 0.0 0.0;
0.0 0.5 0.0 0.0 0.5 0.0 0.0 0.0 0.0 0.0;
0.0 0.5 0.0 -0.475 0.5 0.0 0.5 0.0 0.0 0.0;
0.0 0.0 0.5 0.0 -0.95 0.0 0.0 0.5 0.0 0.0;
0.0 0.0 0.0 0.0 0.5 0.0 0.0 0.0 0.5 0.0;
0.0 0.0 0.0 0.5 0.0 0.0 0.0 0.5 0.0 0.0;
0.0 0.0 0.0 0.0 0.5 0.0 0.5 -0.475 0.5 0.0;
0.0 0.0 0.0 0.0 0.0 0.5 0.0 0.5 -0.4749999999999999 0.5;
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.5 0.475]
e1 = eigvals(A);
Plots.plot(e1)

Then calling eigvals again leads to the errror above:

e1 = eigvals(A)

ArgumentError: invalid argument #4 to LAPACK call

Stacktrace:
 [1] chklapackerror at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\LinearAlgebra\src\lapack.jl:36 [inlined]
 [2] geevx!(::Char, ::Char, ::Char, ::Char, ::Array{Float64,2}) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\LinearAlgebra\src\lapack.jl:2082
 [3] eigvals!(::Array{Float64,2}; permute::Bool, scale::Bool, sortby::typeof(LinearAlgebra.eigsortby)) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\LinearAlgebra\src\eigen.jl:293
 [4] eigvals! at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\LinearAlgebra\src\eigen.jl:292 [inlined]
 [5] #eigvals#73 at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\LinearAlgebra\src\eigen.jl:326 [inlined]
 [6] eigvals(::Array{Float64,2}) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\LinearAlgebra\src\eigen.jl:326
 [7] top-level scope at In[242]:1
 [8] include_string(::Function, ::Module, ::String, ::String) at .\loading.jl:1091

The original error I was getting with my actual code,where I was calculating eigenvalue statistics and plotting a histogram with PyPlot.hist(), was:

LAPACKException(1)

Stacktrace:
 [1] chklapackerror at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\LinearAlgebra\src\lapack.jl:38 [inlined]
 [2] syevr!(::Char, ::Char, ::Char, ::Array{Float64,2}, ::Float64, ::Float64, ::Int64, ::Int64, ::Float64) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\LinearAlgebra\src\lapack.jl:5068
 [3] eigvals! at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\LinearAlgebra\src\symmetric.jl:731 [inlined]
 [4] eigvals!(::Array{Float64,2}; permute::Bool, scale::Bool, sortby::typeof(LinearAlgebra.eigsortby)) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\LinearAlgebra\src\eigen.jl:292
 [5] eigvals! at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\LinearAlgebra\src\eigen.jl:292 [inlined]
 [6] #eigvals#73 at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\LinearAlgebra\src\eigen.jl:326 [inlined]
 [7] eigvals at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\LinearAlgebra\src\eigen.jl:326 [inlined]
 [8] get_stats(::Int64, ::Int64, ::Float64, ::Float64, ::Float64, ::Float64, ::Int64, ::Float64, ::Array{Float64,1}) at .\In[162]:12
 [9] top-level scope at In[197]:1
 [10] include_string(::Function, ::Module, ::String, ::String) at .\loading.jl:1091

But the minimal reproduction gave a slightly different error,.

I can reproduce on Windows, Julia 1.4.2 and 1.5.1 as well using

using LinearAlgebra
using Plots; pyplot()
n  = 8
A = rand(n,n)
e = eigvals(A)
plot(e)
eigvals(A)
 ** On entry to DGEBAL parameter number  3 had an illegal value
 ** On entry to DGEHRD  parameter number  3 had an illegal value
 ** On entry to DHSEQR parameter number  5 had an illegal value
ERROR: ArgumentError: invalid argument #5 to LAPACK call

Another invocation of eigvals(A) works fine. When doing plot(e) again, the error reappears.

Further, for n<8, the error does not appear.

I cannot reproduce this on Ubuntu 16.04. BLAS libraries are the standard openBLAS libraries shipped with Julia, for both the Windows and Ubuntu version.

Tried this and, aside from the complaint I expected, all went ok on a Mac with Julia 1.5.1. PyPlot does not seem to have an idea about plotting complex numbers when invoked with plot. I expected dots on the complex plane, but no joy.

using LinearAlgebra
using PyPlot
n  = 8
A = rand(n,n)
e = eigvals(A)
plot(e)
eigvals(A)

and I got this

julia> n  = 8
8

julia> A = rand(n,n)
8×8 Array{Float64,2}:
 8.02692e-01  4.28226e-01  3.70771e-01  …  4.01601e-01  2.58023e-01
 6.53753e-01  8.44660e-01  5.17042e-01     6.56434e-01  8.51823e-01
 8.16275e-01  1.40932e-01  3.45856e-01     2.60633e-01  8.39385e-02
 4.98498e-01  9.10384e-01  5.39722e-01     9.21009e-01  8.19976e-01
 3.97537e-01  5.39128e-01  6.88891e-02     6.68506e-01  4.97311e-01
 1.69636e-01  8.83659e-01  8.39805e-01  …  9.58478e-02  9.11797e-01
 1.32829e-01  4.76917e-01  6.74946e-01     7.29042e-02  6.22964e-02
 7.45336e-01  4.97381e-01  4.64289e-02     3.09182e-01  2.65707e-01

julia> e = eigvals(A)
8-element Array{Complex{Float64},1}:
 -8.46321e-01 + 0.00000e+00im
 -2.40214e-01 - 5.90445e-02im
 -2.40214e-01 + 5.90445e-02im
  1.62488e-01 - 3.16177e-01im
  1.62488e-01 + 3.16177e-01im
  1.95171e-01 + 0.00000e+00im
  4.69261e-01 + 0.00000e+00im
  4.08752e+00 + 0.00000e+00im

julia> plot(e)
/Users/ctk/.julia/conda/3/lib/python3.7/site-packages/numpy/core/_asarray.py:85: ComplexWarning: Casting complex values to real discards the imaginary part
  return array(a, dtype, copy=False, order=order)
1-element Array{PyCall.PyObject,1}:
 PyObject <matplotlib.lines.Line2D object at 0x7ffb50a32b10>

using LinearAlgebra
using PlotlyJS
n  = 8
A = rand(n,n)
e = eigvals(A)
plot(real(e), imag(e), mode = "markers")
eigvals(A)

On Windows 10, with Julia 1.5.1. So I would say the problem is due to pyplot.

Indeed it would seem that it is a problem with PyPlot on Windows.
Using a different backend for Plots (GR) results in no error also.

There is some recent activity on posts with similar errors to @jamblejoe

** On entry to DHSEQR parameter number 4 had an illegal value

but in the python community, i.e. https://github.com/statsmodels/statsmodels/issues/3596
They seem to point to a recent Windows update causing a problem with OpenBLAS.

This would be inline with the errors I am getting, as I was not getting any for the last year or so doing the same calculations until recently.

Argument #4 is a character (see dgeevx), so this might be the Fortran character argument bug?:

Ah, it could be that by calling into python that you somehow end up calling the LAPACK used by numpy (or the Julia LAPACK uses the numpy BLAS)?

1 Like

Yes I think it could be something along these lines.
I tried to use MKL instead of openBLAS but I kept getting a permissions error when building the MKL package. Like this: https://github.com/JuliaLang/julia/issues/30608