Skip to content

Commit 0996550

Browse files
Improve efficiency of bloch_redfield_tensor
1 parent 99b93ec commit 0996550

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

src/time_evolution/brmesolve.jl

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,16 @@ function bloch_redfield_tensor(
3737
U = QuantumObject(rst.vectors, Operator(), H.dimensions)
3838
sec_cutoff = float(sec_cutoff)
3939

40-
# in fock basis
41-
R0 = liouvillian(H, c_ops)
40+
H_new = getVal(fock_basis) ? H : QuantumObject(Diagonal(real.(rst.values)), Operator(), H.dimensions)
41+
c_ops_new = isnothing(c_ops) ? nothing : map(x -> getVal(fock_basis) ? x : U' * x * U, c_ops)
42+
R = liouvillian(H_new, c_ops_new)
4243

43-
# set fock_basis=Val(false) and change basis together at the end
44-
R1 = 0
45-
isempty(a_ops) || (R1 += mapreduce(x -> _brterm(rst, x[1], x[2], sec_cutoff, Val(false)), +, a_ops))
44+
isempty(a_ops) || (R += sum(x -> _brterm(rst, x[1], x[2], sec_cutoff, fock_basis), a_ops))
4645

47-
SU = sprepost(U, U') # transformation matrix from eigen basis back to fock basis
4846
if getVal(fock_basis)
49-
return R0 + SU * R1 * SU'
47+
return R
5048
else
51-
return SU' * R0 * SU + R1, U
49+
return R, U
5250
end
5351
end
5452

test/core-test/brmesolve.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
A_op = a+a'
66
spectra(x) = (x>0) * 0.5
77
for sec_cutoff in [0, 0.1, 1, 3, -1]
8-
R = bloch_redfield_tensor(H, [(A_op, spectra)], [a^2], sec_cutoff = sec_cutoff, fock_basis = true)
9-
R_eig, evecs = bloch_redfield_tensor(H, [(A_op, spectra)], [a^2], sec_cutoff = sec_cutoff, fock_basis = false)
8+
R = bloch_redfield_tensor(H, ((A_op, spectra), ), [a^2], sec_cutoff = sec_cutoff, fock_basis = Val(true))
9+
R_eig, evecs = bloch_redfield_tensor(H, ((A_op, spectra), ), [a^2], sec_cutoff = sec_cutoff, fock_basis = Val(false))
1010
@test isa(R, QuantumObject)
1111
@test isa(R_eig, QuantumObject)
1212
@test isa(evecs, QuantumObject)
@@ -27,7 +27,7 @@ end
2727

2828
# this test applies for limited cutoff
2929
lindblad = lindblad_dissipator(a)
30-
computation = brterm(H, A_op, spectra, sec_cutoff = 1.5, fock_basis = true)
30+
computation = brterm(H, A_op, spectra, sec_cutoff = 1.5, fock_basis = Val(true))
3131
@test isapprox(lindblad, computation, atol = 1e-15)
3232
end
3333

@@ -38,8 +38,8 @@ end
3838
A_op = a+a'
3939
spectra(x) = x>0
4040
for sec_cutoff in [0, 0.1, 1, 3, -1]
41-
R = brterm(H, A_op, spectra, sec_cutoff = sec_cutoff, fock_basis = true)
42-
R_eig, evecs = brterm(H, A_op, spectra, sec_cutoff = sec_cutoff, fock_basis = false)
41+
R = brterm(H, A_op, spectra, sec_cutoff = sec_cutoff, fock_basis = Val(true))
42+
R_eig, evecs = brterm(H, A_op, spectra, sec_cutoff = sec_cutoff, fock_basis = Val(false))
4343
@test isa(R, QuantumObject)
4444
@test isa(R_eig, QuantumObject)
4545
@test isa(evecs, QuantumObject)
@@ -76,8 +76,8 @@ end
7676
a = destroy(N) + destroy(N)^2/2
7777
A_op = a+a'
7878
for spectra in spectra_list
79-
R = brterm(H, A_op, spectra, sec_cutoff = 0.1, fock_basis = true)
80-
R_eig, evecs = brterm(H, A_op, spectra, sec_cutoff = 0.1, fock_basis = false)
79+
R = brterm(H, A_op, spectra, sec_cutoff = 0.1, fock_basis = Val(true))
80+
R_eig, evecs = brterm(H, A_op, spectra, sec_cutoff = 0.1, fock_basis = Val(false))
8181
@test isa(R, QuantumObject)
8282
@test isa(R_eig, QuantumObject)
8383
@test isa(evecs, QuantumObject)
@@ -112,4 +112,4 @@ end
112112

113113
@test all(me.expect .== brme.expect)
114114
end
115-
end;
115+
end

0 commit comments

Comments
 (0)