Skip to content

Commit 97f5bd0

Browse files
committed
add tests
1 parent dc5c84e commit 97f5bd0

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed

test/core-test/brme.jl

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
@testset "Bloch-Redfield tensor sec_cutoff = $sec_cutoff" for sec_cutoff in [0,0.1,1,3,-1]
2+
N = 5
3+
H = num(N)
4+
a = destroy(N)
5+
A_op = a+a'
6+
spectra(x) = (x>0) * 0.5
7+
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+
)
22+
@test isa(R, QuantumObject)
23+
@test isa(R_eig, QuantumObject)
24+
@test isa(evecs, QuantumObject)
25+
state = rand_dm(N) |> mat2vec
26+
fock_computed = R * state
27+
eig_computed = (sprepost(evecs, evecs') * R_eig * sprepost(evecs', evecs)) * state
28+
29+
@test isapprox(fock_computed, eig_computed, atol=1e-15)
30+
end;
31+
32+
@testset "brterm lindblad" begin
33+
N = 5
34+
H = num(N)
35+
a = destroy(N) + destroy(N)^2/2
36+
A_op = a+a'
37+
spectra(x) = x>0
38+
39+
# this test applys for limited cutoff
40+
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)
43+
end;
44+
45+
@testset "brterm basis for sec_cutoff = $sec_cutoff" for sec_cutoff in [0,0.1,1,3,-1]
46+
N = 5
47+
H = num(N)
48+
a = destroy(N) + destroy(N)^2/2
49+
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+
)
66+
@test isa(R, QuantumObject)
67+
@test isa(R_eig, QuantumObject)
68+
@test isa(evecs, QuantumObject)
69+
state = rand_dm(N) |> mat2vec
70+
fock_computed = R * state
71+
eig_computed = (sprepost(evecs, evecs') * R_eig * sprepost(evecs', evecs)) * state
72+
73+
@test isapprox(fock_computed, eig_computed, atol=1e-15)
74+
end;
75+
76+
f(x) = exp(x)/10
77+
function g(x)
78+
nbar = n_thermal(abs(x), 1)
79+
if x > 0
80+
return nbar
81+
elseif x < 0
82+
return 1 + nbar
83+
else
84+
return 0.
85+
end
86+
end
87+
88+
spectras = [
89+
(x -> (x>0), "positive frequency filter"),
90+
(x -> one(x), "no filter"),
91+
(f, "smooth filter"),
92+
(g, "thermal field")
93+
]
94+
95+
@testset "brterms sprectra with $description" for (spectra, description) in spectras
96+
N = 5
97+
H = num(N)
98+
a = destroy(N) + destroy(N)^2/2
99+
A_op = a+a'
100+
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+
)
115+
@test isa(R, QuantumObject)
116+
@test isa(R_eig, QuantumObject)
117+
@test isa(evecs, QuantumObject)
118+
state = rand_dm(N) |> mat2vec
119+
fock_computed = R * state
120+
eig_computed = (sprepost(evecs, evecs') * R_eig * sprepost(evecs', evecs)) * state
121+
122+
@test isapprox(fock_computed, eig_computed, atol=1e-15)
123+
end;

0 commit comments

Comments
 (0)