Skip to content

Commit

Permalink
Merge pull request #54 from albertomercurio/albertomercurio-patch-1
Browse files Browse the repository at this point in the history
Removed SafeTestsets
  • Loading branch information
albertomercurio authored Apr 4, 2024
2 parents 312fbfb + 4850e21 commit 7cd969c
Show file tree
Hide file tree
Showing 15 changed files with 685 additions and 679 deletions.
4 changes: 1 addition & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@ LinearMaps = "3"
LinearSolve = "2"
OrdinaryDiffEq = "6.30"
Reexport = "1"
SafeTestsets = "0.1"
SpecialFunctions = "2.2"
julia = "1.7"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"

[targets]
test = ["Test", "SafeTestsets"]
test = ["Test"]
32 changes: 16 additions & 16 deletions test/correlations_and_spectrum.jl
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
using QuantumToolbox
@testset "Correlations and Spectrum" begin
a = destroy(10)
H = a' * a
c_ops = [sqrt(0.1 * (0.01 + 1)) * a, sqrt(0.1 * (0.01)) * a']

a = destroy(10)
H = a' * a
c_ops = [sqrt(0.1 * (0.01 + 1)) * a, sqrt(0.1 * (0.01)) * a']
ω_l = range(0, 3, length=1000)
ω_l1, spec1 = spectrum(H, ω_l, a', a, c_ops, solver=FFTCorrelation(), progress_bar=false)
ω_l2, spec2 = spectrum(H, ω_l, a', a, c_ops)
spec1 = spec1 ./ maximum(spec1)
spec2 = spec2 ./ maximum(spec2)

ω_l = range(0, 3, length=1000)
ω_l1, spec1 = spectrum(H, ω_l, a', a, c_ops, solver=FFTCorrelation(), progress=false)
ω_l2, spec2 = spectrum(H, ω_l, a', a, c_ops)
spec1 = spec1 ./ maximum(spec1)
spec2 = spec2 ./ maximum(spec2)

test_func1 = maximum(real.(spec1)) * (0.1/2)^2 ./ ((ω_l1 .- 1).^2 .+ (0.1/2)^2)
test_func2 = maximum(real.(spec2)) * (0.1/2)^2 ./ ((ω_l2 .- 1).^2 .+ (0.1/2)^2)
idxs1 = test_func1 .> 0.05
idxs2 = test_func2 .> 0.05
@test sum(abs2.(spec1[idxs1] .- test_func1[idxs1])) / sum(abs2.(test_func1[idxs1])) < 0.01
@test sum(abs2.(spec2[idxs2] .- test_func2[idxs2])) / sum(abs2.(test_func2[idxs2])) < 0.01
test_func1 = maximum(real.(spec1)) * (0.1/2)^2 ./ ((ω_l1 .- 1).^2 .+ (0.1/2)^2)
test_func2 = maximum(real.(spec2)) * (0.1/2)^2 ./ ((ω_l2 .- 1).^2 .+ (0.1/2)^2)
idxs1 = test_func1 .> 0.05
idxs2 = test_func2 .> 0.05
@test sum(abs2.(spec1[idxs1] .- test_func1[idxs1])) / sum(abs2.(test_func1[idxs1])) < 0.01
@test sum(abs2.(spec2[idxs2] .- test_func2[idxs2])) / sum(abs2.(test_func2[idxs2])) < 0.01
end
132 changes: 66 additions & 66 deletions test/dynamical-shifted-fock.jl
Original file line number Diff line number Diff line change
@@ -1,98 +1,98 @@
using QuantumToolbox
@testset "Dynamical Shifted Fock" begin
F = 3
Δ = 0.25
κ = 1
U = 0.01

F = 3
Δ = 0.25
κ = 1
U = 0.01
tlist = LinRange(0,25,300)

tlist = LinRange(0,25,300)
# Single cavity case
N0 = 100
a0 = destroy(N0)
H0 = Δ*a0'*a0 + F*(a0+a0') + U * a0'^2 * a0^2
c_ops0 = [(κ)*a0]

# Single cavity case
N0 = 100
a0 = destroy(N0)
H0 = Δ*a0'*a0 + F*(a0+a0') + U * a0'^2 * a0^2
c_ops0 = [(κ)*a0]
α0 = 1.5
ρ0 = coherent(N0, α0)
sol0 = mesolve(H0, ρ0, tlist, c_ops0, e_ops=[a0'*a0, a0], progress_bar=false)

α0 = 1.5
ρ0 = coherent(N0, α0)
sol0 = mesolve(H0, ρ0, tlist, c_ops0, e_ops=[a0'*a0, a0], progress=false)

N = 5
a = destroy(N)
function H_dsf(op_list, p)
N = 5
a = destroy(N)
function H_dsf(op_list, p)
Δ = p.Δ
F = p.F
U = p.U
a = op_list[1]
Δ*a'*a + F*(a + a') + U * a'^2 * a^2
end
function c_ops_dsf(op_list, p)
end
function c_ops_dsf(op_list, p)
κ = p.κ
a = op_list[1]
[κ * a]
end
function e_ops_dsf(op_list, p)
end
function e_ops_dsf(op_list, p)
a = op_list[1]
[a' * a, a]
end
op_list = [a]
ψ0 = fock(N, 0)
α0_l = [α0]
dsf_params ==Δ, F=F, κ=κ, U=U)
end
op_list = [a]
ψ0 = fock(N, 0)
α0_l = [α0]
dsf_params ==Δ, F=F, κ=κ, U=U)

sol_dsf_me = dsf_mesolve(H_dsf, ψ0, tlist, c_ops_dsf, op_list, α0_l, dsf_params, e_ops=e_ops_dsf, progress=false)
sol_dsf_mc = dsf_mcsolve(H_dsf, ψ0, tlist, c_ops_dsf, op_list, α0_l, dsf_params, e_ops=e_ops_dsf, progress=false, n_traj=500)
val_ss = abs2(sol0.expect[1,end])
@test sum(abs2.(sol0.expect[1,:] .- sol_dsf_me.expect[1,:])) / (val_ss * length(tlist)) < 0.1
@test sum(abs2.(sol0.expect[1,:] .- sol_dsf_mc.expect[1,:])) / (val_ss * length(tlist)) < 0.1
sol_dsf_me = dsf_mesolve(H_dsf, ψ0, tlist, c_ops_dsf, op_list, α0_l, dsf_params, e_ops=e_ops_dsf, progress_bar=false)
sol_dsf_mc = dsf_mcsolve(H_dsf, ψ0, tlist, c_ops_dsf, op_list, α0_l, dsf_params, e_ops=e_ops_dsf, progress_bar=false, n_traj=500)
val_ss = abs2(sol0.expect[1,end])
@test sum(abs2.(sol0.expect[1,:] .- sol_dsf_me.expect[1,:])) / (val_ss * length(tlist)) < 0.1
@test sum(abs2.(sol0.expect[1,:] .- sol_dsf_mc.expect[1,:])) / (val_ss * length(tlist)) < 0.1

# Two cavities case
F = 2
Δ = 0.25
κ = 1
U = 0.01
J = 0.5
tlist = LinRange(0,15,300)
# Two cavities case
F = 2
Δ = 0.25
κ = 1
U = 0.01
J = 0.5
tlist = LinRange(0,15,300)

N0 = 20
a10 = kron(destroy(N0), qeye(N0))
a20 = kron(qeye(N0), destroy(N0))
H0 = Δ*a10'*a10 + Δ*a20'*a20 + U*a10'^2*a10^2 + U*a20'^2*a20^2 + F*(a10+a10') + J*(a10'*a20 + a10*a20')
c_ops0 = [κ*a10, κ*a20]
N0 = 20
a10 = kron(destroy(N0), qeye(N0))
a20 = kron(qeye(N0), destroy(N0))
H0 = Δ*a10'*a10 + Δ*a20'*a20 + U*a10'^2*a10^2 + U*a20'^2*a20^2 + F*(a10+a10') + J*(a10'*a20 + a10*a20')
c_ops0 = [κ*a10, κ*a20]

ρ0 = kron(coherent(N0, α0), coherent(N0, α0))
sol0 = mesolve(H0, ρ0, tlist, c_ops0, e_ops=[a10'*a10, a20'*a20], progress=false)
ρ0 = kron(coherent(N0, α0), coherent(N0, α0))
sol0 = mesolve(H0, ρ0, tlist, c_ops0, e_ops=[a10'*a10, a20'*a20], progress_bar=false)

N = 5
a1 = kron(destroy(N), qeye(N))
a2 = kron(qeye(N), destroy(N))
function H_dsf2(op_list, p)
N = 5
a1 = kron(destroy(N), qeye(N))
a2 = kron(qeye(N), destroy(N))
function H_dsf2(op_list, p)
Δ = p.Δ
F = p.F
U = p.U
J = p.J
a1, a2 = op_list
Δ*a1'*a1 + Δ*a2'*a2 + U*a1'^2*a1^2 + U*a2'^2*a2^2 + F*(a1 + a1') + J*(a1'*a2 + a1*a2')
end
function c_ops_dsf2(op_list, p)
end
function c_ops_dsf2(op_list, p)
κ = p.κ
a1, a2 = op_list
[κ * a1, κ * a2]
end
function e_ops_dsf2(op_list, p)
end
function e_ops_dsf2(op_list, p)
a1, a2 = op_list
[a1' * a1, a2' * a2]
end
op_list = [a1, a2]
ψ0 = kron(fock(N, 0), fock(N, 0))
α0_l = [α0, α0]
dsf_params ==Δ, F=F, κ=κ, U=U, J=J)
end
op_list = [a1, a2]
ψ0 = kron(fock(N, 0), fock(N, 0))
α0_l = [α0, α0]
dsf_params ==Δ, F=F, κ=κ, U=U, J=J)

sol_dsf_me = dsf_mesolve(H_dsf2, ψ0, tlist, c_ops_dsf2, op_list, α0_l, dsf_params, e_ops=e_ops_dsf2, progress=false)
sol_dsf_mc = dsf_mcsolve(H_dsf2, ψ0, tlist, c_ops_dsf2, op_list, α0_l, dsf_params, e_ops=e_ops_dsf2, progress=false, n_traj=500)
sol_dsf_me = dsf_mesolve(H_dsf2, ψ0, tlist, c_ops_dsf2, op_list, α0_l, dsf_params, e_ops=e_ops_dsf2, progress_bar=false)
sol_dsf_mc = dsf_mcsolve(H_dsf2, ψ0, tlist, c_ops_dsf2, op_list, α0_l, dsf_params, e_ops=e_ops_dsf2, progress_bar=false, n_traj=500)

val_ss = abs2(sol0.expect[1,end])
@test sum(abs2.(sol0.expect[1,:] .- sol_dsf_me.expect[1,:])) / (val_ss * length(tlist)) < 0.6
@test sum(abs2.(sol0.expect[1,:] .- sol_dsf_mc.expect[1,:])) / (val_ss * length(tlist)) < 0.6
@test sum(abs2.(sol0.expect[2,:] .- sol_dsf_me.expect[2,:])) / (val_ss * length(tlist)) < 0.6
@test sum(abs2.(sol0.expect[2,:] .- sol_dsf_mc.expect[2,:])) / (val_ss * length(tlist)) < 0.6
val_ss = abs2(sol0.expect[1,end])
@test sum(abs2.(sol0.expect[1,:] .- sol_dsf_me.expect[1,:])) / (val_ss * length(tlist)) < 0.6
@test sum(abs2.(sol0.expect[1,:] .- sol_dsf_mc.expect[1,:])) / (val_ss * length(tlist)) < 0.6
@test sum(abs2.(sol0.expect[2,:] .- sol_dsf_me.expect[2,:])) / (val_ss * length(tlist)) < 0.6
@test sum(abs2.(sol0.expect[2,:] .- sol_dsf_mc.expect[2,:])) / (val_ss * length(tlist)) < 0.6
end
Loading

0 comments on commit 7cd969c

Please sign in to comment.