-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from ytdHuang/opt/runtests
Improve runtests and CI pipeline
- Loading branch information
Showing
17 changed files
with
814 additions
and
777 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: Documentation | ||
|
||
on: | ||
push: | ||
branches: | ||
- 'main' | ||
tags: | ||
- '*' | ||
pull_request: | ||
branches: | ||
- 'main' | ||
types: | ||
- opened | ||
- reopened | ||
- synchronize | ||
- ready_for_review | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
if: ${{ !github.event.pull_request.draft }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: julia-actions/setup-julia@v1 | ||
with: | ||
version: '1' | ||
- uses: julia-actions/julia-buildpkg@v1 | ||
- uses: julia-actions/julia-docdeploy@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
- run: | | ||
julia --project=docs -e ' | ||
using Documenter: DocMeta, doctest | ||
using QuantumToolbox | ||
DocMeta.setdocmeta!(QuantumToolbox, :DocTestSetup, :(using QuantumToolbox); recursive=true) | ||
doctest(QuantumToolbox)' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using QuantumToolbox | ||
|
||
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=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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
using QuantumToolbox | ||
|
||
F = 3 | ||
Δ = 0.25 | ||
κ = 1 | ||
U = 0.01 | ||
|
||
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] | ||
|
||
α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) | ||
Δ = 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) | ||
κ = p.κ | ||
a = op_list[1] | ||
[√κ * a] | ||
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) | ||
|
||
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 | ||
|
||
# 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] | ||
|
||
ρ0 = kron(coherent(N0, α0), coherent(N0, α0)) | ||
sol0 = mesolve(H0, ρ0, tlist, c_ops0, e_ops=[a10'*a10, a20'*a20], progress=false) | ||
|
||
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) | ||
κ = p.κ | ||
a1, a2 = op_list | ||
[√κ * a1, √κ * a2] | ||
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) | ||
|
||
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) | ||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
using Test | ||
using QuantumToolbox | ||
|
||
### DYNAMICAL FOCK DIMENSION ### | ||
F, Δ, κ = 5, 0.25, 1 | ||
t_l = range(0, 15, length=100) | ||
|
||
N0 = 140 | ||
a0 = destroy(N0) | ||
H0 = Δ * a0' * a0 + F * (a0 + a0') | ||
c_ops0 = [√κ * a0] | ||
e_ops0 = [a0' * a0] | ||
ψ00 = fock(N0, 0) | ||
sol0 = mesolve(H0, ψ00, t_l, c_ops0, e_ops=e_ops0, progress=false) | ||
|
||
function H_dfd0(dims, p) | ||
Δ = p.Δ | ||
F = p.F | ||
a = destroy(dims[1]) | ||
Δ * a' * a + F * (a + a') | ||
end | ||
function c_ops_dfd0(dims, p) | ||
κ = p.κ | ||
a = destroy(dims[1]) | ||
[√κ * a] | ||
end | ||
function e_ops_dfd0(dims, p) | ||
a = destroy(dims[1]) | ||
[a' * a] | ||
end | ||
maxdims = [150] | ||
ψ0 = fock(3, 0) | ||
dfd_params = (Δ=Δ, F=F, κ=κ) | ||
sol = dfd_mesolve(H_dfd0, ψ0, t_l, c_ops_dfd0, maxdims, dfd_params, e_ops=e_ops_dfd0, progress=false); | ||
|
||
@test sum(abs.((sol.expect[1, :] .- sol0.expect[1, :]) ./ (sol0.expect[1, :] .+ 1e-16))) < 0.01 | ||
|
||
###################### | ||
|
||
F = 0 | ||
H0 = Δ * a0' * a0 + F * (a0 + a0') | ||
c_ops0 = [√κ * a0] | ||
e_ops0 = [a0' * a0] | ||
ψ00 = fock(N0, 50) | ||
sol0 = mesolve(H0, ψ00, t_l, c_ops0, e_ops=e_ops0, progress=false) | ||
|
||
function H_dfd1(dims, p) | ||
Δ = p.Δ | ||
F = p.F | ||
a = destroy(dims[1]) | ||
Δ * a' * a + F * (a + a') | ||
end | ||
function c_ops_dfd1(dims, p) | ||
κ = p.κ | ||
a = destroy(dims[1]) | ||
[√κ * a] | ||
end | ||
function e_ops_dfd1(dims, p) | ||
a = destroy(dims[1]) | ||
[a' * a] | ||
end | ||
maxdims = [150] | ||
ψ0 = fock(70, 50) | ||
dfd_params = (Δ=Δ, F=F, κ=κ) | ||
sol = dfd_mesolve(H_dfd1, ψ0, t_l, c_ops_dfd1, maxdims, dfd_params, e_ops=e_ops_dfd1, progress=false) | ||
|
||
@test sum(abs.((sol.expect[1, :] .- sol0.expect[1, :]) ./ (sol0.expect[1, :] .+ 1e-16))) < 0.01 | ||
|
||
|
||
###################### | ||
|
||
F, Δ, κ, J = 1.5, 0.25, 1, 0.05 | ||
N0 = 25 | ||
N1 = 20 | ||
a0 = kron(destroy(N0), qeye(N1)) | ||
a1 = kron(qeye(N0), destroy(N1)) | ||
H0 = Δ * a0' * a0 + F * (a0 + a0') + Δ * a1' * a1 + J * (a0' * a1 + a0 * a1') | ||
c_ops0 = [√κ * a0, √κ * a1] | ||
e_ops0 = [a0' * a0, a1' * a1] | ||
ψ00 = kron(fock(N0, 0), fock(N1, 15)) | ||
sol0 = mesolve(H0, ψ00, t_l, c_ops0, e_ops=e_ops0, progress=false) | ||
|
||
function H_dfd2(dims, p) | ||
Δ = p.Δ | ||
F = p.F | ||
J = p.J | ||
a = kron(destroy(dims[1]), qeye(dims[2])) | ||
b = kron(qeye(dims[1]), destroy(dims[2])) | ||
Δ * a' * a + F * (a + a') + Δ * b' * b + J * (a' * b + a * b') | ||
end | ||
function c_ops_dfd2(dims, p) | ||
κ = p.κ | ||
a = kron(destroy(dims[1]), qeye(dims[2])) | ||
b = kron(qeye(dims[1]), destroy(dims[2])) | ||
[√κ * a, √κ * b] | ||
end | ||
function e_ops_dfd2(dims, p) | ||
a = kron(destroy(dims[1]), qeye(dims[2])) | ||
b = kron(qeye(dims[1]), destroy(dims[2])) | ||
[a' * a, b' * b] | ||
end | ||
maxdims = [50, 50] | ||
ψ0 = kron(fock(3, 0), fock(20, 15)) | ||
dfd_params = (Δ=Δ, F=F, κ=κ, J=J) | ||
sol = dfd_mesolve(H_dfd2, ψ0, t_l, c_ops_dfd2, maxdims, dfd_params, e_ops=e_ops_dfd2, progress=false) | ||
|
||
@test sum(abs.((sol.expect[1, :] .- sol0.expect[1, :]) ./ (sol0.expect[1, :] .+ 1e-16))) + | ||
sum(abs.((sol.expect[2, :] .- sol0.expect[2, :]) ./ (sol0.expect[2, :] .+ 1e-16))) < 0.01 |
Oops, something went wrong.