diff --git a/CHANGELOG.md b/CHANGELOG.md index 64145e2db..f7dee851a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased](https://github.com/qutip/QuantumToolbox.jl/tree/main) +- Check for orthogonality breakdown in `Lanczos` solver for `spectrum`. ([#501]) + ## [v0.32.1] Release date: 2025-06-24 @@ -253,3 +255,4 @@ Release date: 2024-11-13 [#487]: https://github.com/qutip/QuantumToolbox.jl/issues/487 [#489]: https://github.com/qutip/QuantumToolbox.jl/issues/489 [#494]: https://github.com/qutip/QuantumToolbox.jl/issues/494 +[#501]: https://github.com/qutip/QuantumToolbox.jl/issues/501 diff --git a/src/spectrum.jl b/src/spectrum.jl index 367470605..b97488575 100644 --- a/src/spectrum.jl +++ b/src/spectrum.jl @@ -186,10 +186,14 @@ function _spectrum( Ivec = SparseVector(D^2, [1 + n * (D + 1) for n in 0:(D-1)], ones(cT, D)) # same as vec(system_identity_matrix) wₖ = spre(A).data' * vT(Ivec) - # Store the norm of the Green's function before renormalizing |v₁> and and 0 + @warn "spectrum(): solver::Lanczos experienced orthogonality breakdown after $(k) iterations" + @warn "spectrum(): βₖδₖ = $(βₖδₖ)" + end + break + end + δₖ = sqrt(abs(βₖδₖ)) + βₖ = βₖδₖ / δₖ # Normalize (k+1)-th left/right vectors vₖ ./= δₖ diff --git a/test/core-test/correlations_and_spectrum.jl b/test/core-test/correlations_and_spectrum.jl index bd9a2a918..71c875034 100644 --- a/test/core-test/correlations_and_spectrum.jl +++ b/test/core-test/correlations_and_spectrum.jl @@ -50,6 +50,10 @@ @test last(outlines) == "spectrum(): Consider increasing maxiter and/or tol" end + @testset "Orthogonal input vectors Lanczos" begin + @test_throws AssertionError spectrum(H, ω_l2, [c_ops[1]], a', a; solver = Lanczos()) + end + # tlist and τlist checks t_fft_wrong = [0, 1, 10] t_wrong1 = [1, 2, 3]