Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
30 changes: 21 additions & 9 deletions src/spectrum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,14 @@
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 <w₁|
gfNorm = abs(dot(wₖ, vₖ))
vₖ ./= sqrt(gfNorm)
wₖ ./= sqrt(gfNorm)
# Store the normalization factor for the Green's function before renormalizing |v₁> and <w₁|
gfNorm = dot(wₖ, vₖ)
if gfNorm ≈ 0.0
throw(AssertionError("⟨w₀|v₀⟩ = 0, please check your A and B operators."))
end
scalingF = sqrt(abs(gfNorm))
vₖ ./= scalingF
wₖ ./= conj(gfNorm/scalingF)

# Handle input frequency range
ωList = vT(convert(Vector{fT}, ωlist)) # Make sure they're real frequencies and potentially on GPU
Expand All @@ -203,6 +207,7 @@
αₖ = cT(0)
βₖ = cT(-1)
δₖ = fT(+1)
βₖδₖ = βₖ * δₖ

# Current and up to second-to-last A and B Euler sequences
A₋₂ = vT(ones(cT, Length))
Expand Down Expand Up @@ -232,8 +237,8 @@
αₖ = dot(w₊₁, vₖ)

# Update A(k), B(k) and continuous fraction; normalization avoids overflow
Aₖ .= (-1im .* ωList .+ αₖ) .* A₋₁ .- (βₖ * δₖ) .* A₋₂
Bₖ .= (-1im .* ωList .+ αₖ) .* B₋₁ .- (βₖ * δₖ) .* B₋₂
Aₖ .= (-1im .* ωList .+ αₖ) .* A₋₁ .- βₖδₖ .* A₋₂
Bₖ .= (-1im .* ωList .+ αₖ) .* B₋₁ .- βₖδₖ .* B₋₂
lanczosFactor₋₁ .= lanczosFactor
lanczosFactor .= Aₖ ./ Bₖ

Expand Down Expand Up @@ -268,9 +273,16 @@
wₖ, w₊₁ = w₊₁, wₖ

# k-th off-diagonal elements
buf = dot(wₖ, vₖ)
δₖ = sqrt(abs(buf))
βₖ = buf / δₖ
βₖδₖ = dot(wₖ, vₖ)
if βₖδₖ ≈ 0.0
if solver.verbose > 0
@warn "spectrum(): solver::Lanczos experienced orthogonality breakdown after $(k) iterations"
@warn "spectrum(): βₖδₖ = $(βₖδₖ)"

Check warning on line 280 in src/spectrum.jl

View check run for this annotation

Codecov / codecov/patch

src/spectrum.jl#L278-L280

Added lines #L278 - L280 were not covered by tests
end
break

Check warning on line 282 in src/spectrum.jl

View check run for this annotation

Codecov / codecov/patch

src/spectrum.jl#L282

Added line #L282 was not covered by tests
end
δₖ = sqrt(abs(βₖδₖ))
βₖ = βₖδₖ / δₖ

# Normalize (k+1)-th left/right vectors
vₖ ./= δₖ
Expand Down
4 changes: 4 additions & 0 deletions test/core-test/correlations_and_spectrum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Loading