Skip to content

Commit c5ee417

Browse files
Improve pseudo inverse spectrum (#388)
Co-authored-by: Yi-Te Huang <[email protected]>
1 parent 0408069 commit c5ee417

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## [Unreleased](https://github.com/qutip/QuantumToolbox.jl/tree/main)
99

1010
- Fix CUDA `sparse_to_dense`. ([#386])
11+
- Improve pseudo inverse spectrum solver. ([#388])
1112

1213
## [v0.25.2]
1314
Release date: 2025-02-02
@@ -107,3 +108,4 @@ Release date: 2024-11-13
107108
[#380]: https://github.com/qutip/QuantumToolbox.jl/issues/380
108109
[#383]: https://github.com/qutip/QuantumToolbox.jl/issues/383
109110
[#386]: https://github.com/qutip/QuantumToolbox.jl/issues/386
111+
[#388]: https://github.com/qutip/QuantumToolbox.jl/issues/388

src/spectrum.jl

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,19 +125,20 @@ function _spectrum(
125125
_tr = SparseVector(D^2, [1 + n * (D + 1) for n in 0:(D-1)], ones(_CType(L), D)) # same as vec(system_identity_matrix)
126126
_tr_A = transpose(_tr) * spre(A).data
127127

128-
cache = nothing
129-
I_cache = I(D^2)
128+
Id = I(D^2)
129+
130+
# DO the idx = 1 case
131+
ω = ωList[1]
132+
cache = init(LinearProblem(L.data - 1im * ω * Id, b), solver.alg, kwargs...)
133+
sol = solve!(cache)
134+
spec[1] = -2 * real(dot(_tr_A, sol.u))
135+
popfirst!(ωList)
130136
for (idx, ω) in enumerate(ωList)
131-
if idx == 1
132-
cache = init(LinearProblem(L.data - 1im * ω * I_cache, b), solver.alg, kwargs...)
133-
sol = solve!(cache)
134-
else
135-
cache.A = L.data - 1im * ω * I_cache
136-
sol = solve!(cache)
137-
end
137+
cache.A = L.data - 1im * ω * Id
138+
sol = solve!(cache)
138139

139140
# trace over the Hilbert space of system (expectation value)
140-
spec[idx] = -2 * real(dot(_tr_A, sol.u))
141+
spec[idx+1] = -2 * real(dot(_tr_A, sol.u))
141142
end
142143

143144
return spec

0 commit comments

Comments
 (0)