Skip to content

Commit c12ba94

Browse files
committed
formatting
1 parent 97f5bd0 commit c12ba94

File tree

2 files changed

+65
-112
lines changed

2 files changed

+65
-112
lines changed

src/br.jl

Lines changed: 44 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,24 @@ The return depends on `fock_basis`.
2525
- `fock_basis=Val(false)`: return the Bloch-Redfield tensor (in the eigen basis) along with the transformation matrix from eigen to fock basis.
2626
"""
2727
function bloch_redfield_tensor(
28-
H::QuantumObject{Operator},
29-
a_ops::Union{AbstractVector, Tuple},
30-
c_ops::Union{AbstractVector, Tuple, Nothing}=nothing;
31-
sec_cutoff::Real=0.1,
32-
fock_basis::Union{Val,Bool}=Val(false)
33-
)
28+
H::QuantumObject{Operator},
29+
a_ops::Union{AbstractVector,Tuple},
30+
c_ops::Union{AbstractVector,Tuple,Nothing} = nothing;
31+
sec_cutoff::Real = 0.1,
32+
fock_basis::Union{Val,Bool} = Val(false),
33+
)
3434
rst = eigenstates(H)
3535
U = QuantumObject(rst.vectors, Operator(), H.dimensions)
3636
sec_cutoff = float(sec_cutoff)
3737

3838
# in fock basis
3939
R0 = liouvillian(H, c_ops)
40-
40+
4141
# set fock_basis=Val(false) and change basis together at the end
4242
R1 = 0
4343
if !isempty(a_ops)
44-
R1 += mapreduce(x -> _brterm(rst, x[1], x[2], sec_cutoff, Val(false)), +, a_ops)
45-
44+
R1 += mapreduce(x -> _brterm(rst, x[1], x[2], sec_cutoff, Val(false)), +, a_ops)
45+
4646
# do (a_op, spectra)
4747
# _brterm(rst, a_op, spectra, sec_cutoff, Val(false))
4848
# end
@@ -83,12 +83,12 @@ The return depends on `fock_basis`.
8383
- `fock_basis=Val(false)`: return the Bloch-Redfield term (in the eigen basis) along with the transformation matrix from eigen to fock basis.
8484
"""
8585
function brterm(
86-
H::QuantumObject{Operator},
87-
a_op::QuantumObject{Operator},
88-
spectra::Function;
89-
sec_cutoff::Real=0.1,
90-
fock_basis::Union{Bool, Val}=Val(false)
91-
)
86+
H::QuantumObject{Operator},
87+
a_op::QuantumObject{Operator},
88+
spectra::Function;
89+
sec_cutoff::Real = 0.1,
90+
fock_basis::Union{Bool,Val} = Val(false),
91+
)
9292
rst = eigenstates(H)
9393
term = _brterm(rst, a_op, spectra, sec_cutoff, makeVal(fock_basis))
9494
if getVal(fock_basis)
@@ -99,20 +99,19 @@ function brterm(
9999
end
100100

101101
function _brterm(
102-
rst::EigsolveResult,
103-
a_op::T,
104-
spectra::F,
105-
sec_cutoff::Real,
106-
fock_basis::Union{Val{true},Val{false}}
107-
) where {T<:QuantumObject{Operator},F<:Function}
108-
102+
rst::EigsolveResult,
103+
a_op::T,
104+
spectra::F,
105+
sec_cutoff::Real,
106+
fock_basis::Union{Val{true},Val{false}},
107+
) where {T<:QuantumObject{Operator},F<:Function}
109108
_check_br_spectra(spectra)
110109

111-
U, N = rst.vectors, prod(rst.dimensions)
112-
110+
U, N = rst.vectors, prod(rst.dimensions)
111+
113112
skew = @. rst.values - rst.values' |> real
114113
spectrum = spectra.(skew)
115-
114+
116115
A_mat = U' * a_op.data * U
117116

118117
ac_term = (A_mat .* spectrum) * A_mat
@@ -128,16 +127,14 @@ function _brterm(
128127
vec_skew = vec(skew)
129128
M_cut = @. abs(vec_skew - vec_skew') < sec_cutoff
130129
end
131-
132-
out = 0.5 * (
133-
+ _sprepost(A_mat .* trans(spectrum), A_mat)
134-
+ _sprepost(A_mat, A_mat .* spectrum)
135-
- _spost(ac_term, Id)
136-
- _spre(bd_term, Id)
137-
)
130+
131+
out =
132+
0.5 * (
133+
+ _sprepost(A_mat .* trans(spectrum), A_mat) + _sprepost(A_mat, A_mat .* spectrum) - _spost(ac_term, Id) -
134+
_spre(bd_term, Id)
135+
)
138136

139137
(sec_cutoff != -1) && (out .*= M_cut)
140-
141138

142139
if getVal(fock_basis)
143140
SU = _sprepost(U, U')
@@ -147,8 +144,6 @@ function _brterm(
147144
end
148145
end
149146

150-
151-
152147
@doc raw"""
153148
brmesolve(
154149
H::QuantumObject{Operator},
@@ -183,25 +178,23 @@ Solves for the dynamics of a system using the Bloch-Redfield master equation, gi
183178
- `sol::TimeEvolutionSol`: The solution of the time evolution. See also [`TimeEvolutionSol`](@ref)
184179
"""
185180
function brmesolve(
186-
H::QuantumObject{Operator},
187-
ψ0::QuantumObject,
188-
tlist::AbstractVector,
189-
a_ops::Union{Nothing, AbstractVector, Tuple},
190-
c_ops::Union{Nothing, AbstractVector, Tuple}=nothing;
191-
sec_cutoff::Real=0.1,
192-
e_ops::Union{Nothing, AbstractVector}=nothing,
193-
kwargs...,
194-
)
195-
196-
R = bloch_redfield_tensor(H, a_ops, c_ops; sec_cutoff=sec_cutoff, fock_basis=Val(true))
197-
198-
return mesolve(R, ψ0, tlist, nothing; e_ops=e_ops, kwargs...)
181+
H::QuantumObject{Operator},
182+
ψ0::QuantumObject,
183+
tlist::AbstractVector,
184+
a_ops::Union{Nothing,AbstractVector,Tuple},
185+
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
186+
sec_cutoff::Real = 0.1,
187+
e_ops::Union{Nothing,AbstractVector} = nothing,
188+
kwargs...,
189+
)
190+
R = bloch_redfield_tensor(H, a_ops, c_ops; sec_cutoff = sec_cutoff, fock_basis = Val(true))
191+
192+
return mesolve(R, ψ0, tlist, nothing; e_ops = e_ops, kwargs...)
199193
end
200194

201195
function _check_br_spectra(f::Function)
202196
meths = methods(f, [Real])
203-
length(meths.ms) == 0 && throw(
204-
ArgumentError("The following function must accept one argument: `$(meths.mt.name)(ω)` with ω<:Real")
205-
)
197+
length(meths.ms) == 0 &&
198+
throw(ArgumentError("The following function must accept one argument: `$(meths.mt.name)(ω)` with ω<:Real"))
206199
return nothing
207200
end

test/core-test/brme.jl

Lines changed: 21 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,20 @@
1-
@testset "Bloch-Redfield tensor sec_cutoff = $sec_cutoff" for sec_cutoff in [0,0.1,1,3,-1]
1+
@testset "Bloch-Redfield tensor sec_cutoff = $sec_cutoff" for sec_cutoff in [0, 0.1, 1, 3, -1]
22
N = 5
33
H = num(N)
44
a = destroy(N)
55
A_op = a+a'
66
spectra(x) = (x>0) * 0.5
77

8-
R = bloch_redfield_tensor(
9-
H,
10-
[(A_op, spectra)],
11-
[a^2],
12-
sec_cutoff=sec_cutoff,
13-
fock_basis=true
14-
)
15-
R_eig, evecs = bloch_redfield_tensor(
16-
H,
17-
[(A_op, spectra)],
18-
[a^2],
19-
sec_cutoff=sec_cutoff,
20-
fock_basis=false
21-
)
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)
2210
@test isa(R, QuantumObject)
2311
@test isa(R_eig, QuantumObject)
2412
@test isa(evecs, QuantumObject)
2513
state = rand_dm(N) |> mat2vec
2614
fock_computed = R * state
2715
eig_computed = (sprepost(evecs, evecs') * R_eig * sprepost(evecs', evecs)) * state
2816

29-
@test isapprox(fock_computed, eig_computed, atol=1e-15)
17+
@test isapprox(fock_computed, eig_computed, atol = 1e-15)
3018
end;
3119

3220
@testset "brterm lindblad" begin
@@ -35,89 +23,61 @@ end;
3523
a = destroy(N) + destroy(N)^2/2
3624
A_op = a+a'
3725
spectra(x) = x>0
38-
26+
3927
# this test applys for limited cutoff
4028
lindblad = lindblad_dissipator(a)
41-
computation = brterm(H, A_op, spectra, sec_cutoff=1.5, fock_basis=true)
42-
@test isapprox(lindblad, computation, atol=1e-15)
29+
computation = brterm(H, A_op, spectra, sec_cutoff = 1.5, fock_basis = true)
30+
@test isapprox(lindblad, computation, atol = 1e-15)
4331
end;
4432

45-
@testset "brterm basis for sec_cutoff = $sec_cutoff" for sec_cutoff in [0,0.1,1,3,-1]
33+
@testset "brterm basis for sec_cutoff = $sec_cutoff" for sec_cutoff in [0, 0.1, 1, 3, -1]
4634
N = 5
4735
H = num(N)
4836
a = destroy(N) + destroy(N)^2/2
4937
A_op = a+a'
50-
spectra(x) = x>0
51-
52-
R = brterm(
53-
H,
54-
A_op,
55-
spectra,
56-
sec_cutoff=sec_cutoff,
57-
fock_basis=true
58-
)
59-
R_eig, evecs = brterm(
60-
H,
61-
A_op,
62-
spectra,
63-
sec_cutoff=sec_cutoff,
64-
fock_basis=false
65-
)
38+
spectra(x) = x>0
39+
40+
R = brterm(H, A_op, spectra, sec_cutoff = sec_cutoff, fock_basis = true)
41+
R_eig, evecs = brterm(H, A_op, spectra, sec_cutoff = sec_cutoff, fock_basis = false)
6642
@test isa(R, QuantumObject)
6743
@test isa(R_eig, QuantumObject)
6844
@test isa(evecs, QuantumObject)
6945
state = rand_dm(N) |> mat2vec
7046
fock_computed = R * state
7147
eig_computed = (sprepost(evecs, evecs') * R_eig * sprepost(evecs', evecs)) * state
7248

73-
@test isapprox(fock_computed, eig_computed, atol=1e-15)
49+
@test isapprox(fock_computed, eig_computed, atol = 1e-15)
7450
end;
7551

7652
f(x) = exp(x)/10
77-
function g(x)
53+
function g(x)
7854
nbar = n_thermal(abs(x), 1)
7955
if x > 0
8056
return nbar
8157
elseif x < 0
8258
return 1 + nbar
8359
else
84-
return 0.
60+
return 0.0
8561
end
8662
end
8763

88-
spectras = [
89-
(x -> (x>0), "positive frequency filter"),
90-
(x -> one(x), "no filter"),
91-
(f, "smooth filter"),
92-
(g, "thermal field")
93-
]
64+
spectras =
65+
[(x -> (x>0), "positive frequency filter"), (x -> one(x), "no filter"), (f, "smooth filter"), (g, "thermal field")]
9466

9567
@testset "brterms sprectra with $description" for (spectra, description) in spectras
9668
N = 5
9769
H = num(N)
9870
a = destroy(N) + destroy(N)^2/2
9971
A_op = a+a'
10072

101-
R = brterm(
102-
H,
103-
A_op,
104-
spectra,
105-
sec_cutoff=0.1,
106-
fock_basis=true
107-
)
108-
R_eig, evecs = brterm(
109-
H,
110-
A_op,
111-
spectra,
112-
sec_cutoff=0.1,
113-
fock_basis=false
114-
)
73+
R = brterm(H, A_op, spectra, sec_cutoff = 0.1, fock_basis = true)
74+
R_eig, evecs = brterm(H, A_op, spectra, sec_cutoff = 0.1, fock_basis = false)
11575
@test isa(R, QuantumObject)
11676
@test isa(R_eig, QuantumObject)
11777
@test isa(evecs, QuantumObject)
11878
state = rand_dm(N) |> mat2vec
11979
fock_computed = R * state
12080
eig_computed = (sprepost(evecs, evecs') * R_eig * sprepost(evecs', evecs)) * state
12181

122-
@test isapprox(fock_computed, eig_computed, atol=1e-15)
123-
end;
82+
@test isapprox(fock_computed, eig_computed, atol = 1e-15)
83+
end;

0 commit comments

Comments
 (0)