Arpack.jl icon indicating copy to clipboard operation
Arpack.jl copied to clipboard

Arpack-ng bug preventing us upgrading from 3.5 to 3.8

Open ViralBShah opened this issue 3 years ago • 23 comments

If I have done my analysis right - the failure is introduced in https://github.com/opencollab/arpack-ng/compare/0e7d01d..7fc42e5

I'm not sure if we are doing something wrong in our wrappers or Arpack-ng introduced a bug, but it is somewhere in there. The relevant issue is #118.

ViralBShah avatar Nov 17 '21 18:11 ViralBShah

@andreasnoack does eyeballing that diff suggest something insightful?

ViralBShah avatar Nov 17 '21 18:11 ViralBShah

My guess would be https://github.com/opencollab/arpack-ng/commit/d04bdf19b9189a971f8c3bf2561b8058994e9cb4 but I'm not really sure.

andreasnoack avatar Nov 25 '21 20:11 andreasnoack

That's my best bet too. I wonder if we are calling arpack differently than other systems that makes this buggy for us.

ViralBShah avatar Nov 27 '21 14:11 ViralBShah

@ViralBShah: did you try to remove the patch https://github.com/opencollab/arpack-ng/pull/80#issuecomment-1286377413? Does it solve the problem? @caliarim: could you have a look?

fghoussen avatar Oct 21 '22 07:10 fghoussen

Both the problem described here and the problem related to "Force the residual vector to be in the range of OP" depend on a bad choice of the initial random vector. Many iterative algorithms have some conditions on the initial values which we usually cannot verify and we hope for the best. Matlab has a similar problem with normest(toeplitz([-2,1,0,0])). So, I have no solution. Of course, this is a general comment, it could be that for this specific example there is a specific bug, but I have no time to investigate now.

caliarim avatar Oct 21 '22 10:10 caliarim

depend on a bad choice of the initial random vector

@ViralBShah: how to do initialize your vectors?

fghoussen avatar Oct 21 '22 11:10 fghoussen

@fghoussen We do not initialize the vectors: https://github.com/JuliaLinearAlgebra/Arpack.jl/blob/master/src/libarpack.jl#L109

What should we be doing here? I thought ARPACK would initialize them for us.

ViralBShah avatar Oct 21 '22 12:10 ViralBShah

What should we be doing here?

@caliarim may answer. I never had specific problems with initialization (but a lot on computations! :))

fghoussen avatar Oct 21 '22 12:10 fghoussen

I'll note that in #118, just using a rand initialized v0 is sufficient to not trigger the error any more in the case described.

cc @amontoison as well.

ViralBShah avatar Oct 21 '22 13:10 ViralBShah

just using a rand initialized v0 is sufficient to not trigger the error any more

Would say make sense to me (in difficult cases). AFAIR, this way, one may better span the vectorial space solution. Hope @caliarim could give better explanations / clarifications. Try to init with rand: does it work better?

fghoussen avatar Oct 21 '22 16:10 fghoussen

Yes, init with rand does work better.

ViralBShah avatar Oct 21 '22 18:10 ViralBShah

@ViralBShah It's relevant to have a random v0. It should be related to the initial vector of the Arnoldi process. We use it to generate the Krylov subspace and the associated projection (Upper Hessenberg matrix). It's the b vector here. The eigenvalues of the Upper Hessenberg (Ritz values) converge to the dominant eigenvalues of A because for a random vector v0, A^n * v0 converges to the eigenvector associated to the dominant eigenvalue of A. We expect to have this behaviour when v0 doesn't have a specific structure.

amontoison avatar Oct 22 '22 03:10 amontoison

BTW, in corner cases where arpack would still fail, you can restart arpack using the previous "not-good-enough" solution as v0: for difficult cases, you may run arpack twice, but, the second time using a better initial guess. Hope this helps!

fghoussen avatar Oct 22 '22 07:10 fghoussen

@amontoison I was of the opinion that if we don't provide one, ARPACK will automatically pick a starting initial vector. Would it make sense to use rand to initialize the v0 by default in Arpack.jl?

@fghoussen Thanks for the suggestion. We can add that to the documentation.

ViralBShah avatar Oct 22 '22 15:10 ViralBShah

Ok, so with ARPACK-ng 3.8, the problem that is provided in #118 fails reliably on every test, even when I give it a starting v0. With ARPACK 3.5, it seems to work reliably with a random v0.

I have created #145 which makes it easy to try out and debug ARPACK 3.8.

ViralBShah avatar Oct 22 '22 15:10 ViralBShah

Could you export your A/B matrix to ASCII matrix market format? If so, we'll have more chance to understand if the problem comes from arpack-ng or not.

fghoussen avatar Feb 26 '23 11:02 fghoussen

https://gist.github.com/ViralBShah/ae892fe6df0884185313f3f0e10c03cc

ViralBShah avatar Mar 08 '23 04:03 ViralBShah

OK, I'll try to have a look when possible. What are the constraints of your solve: complex numbers in double precision? is A sym? nb EV? nb CV? Magnitude? Want / need to shift / invert? Tol needed? Ritz or Schur vectors? File is 1-based? etc

fghoussen avatar Mar 08 '23 20:03 fghoussen

Seems I can compute OK the 200 first EV with LM magnitude, no shift, no invert, regular tol / nb it. Ritz vectors OK, but Schur vector fail.

fghoussen avatar Mar 08 '23 21:03 fghoussen

The actual failure case is when doing d, rest = eigs(L, nev=2, which=:LR), in Julia's Arpack.jl (actual Julia code in https://github.com/JuliaLinearAlgebra/Arpack.jl/issues/118). I know there will be questions about how things are being set up etc., but the behaviour changed between 3.5 and 3.8.

The file is what MatrixMarket.jl generates, I assume 1-based.

ViralBShah avatar Mar 08 '23 21:03 ViralBShah

OK, I'll have a look when possible. Is the problem symmetric? Can you regenerate the file formatting lines this way i j (real_ij, imag_ij)?

fghoussen avatar Mar 08 '23 21:03 fghoussen

It is not.

ViralBShah avatar Mar 08 '23 23:03 ViralBShah

Can you regenerate the file formatting lines this way i j (real_ij, imag_ij) (unless I can't use the file)? Missing (, , and ) prevent me from reading the file correctly

fghoussen avatar Mar 10 '23 20:03 fghoussen