Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve runtests and CI pipeline #38

Merged
merged 5 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 27 additions & 30 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
name: CI
name: Runtests

on:
push:
branches:
- main
tags: ['*']
- 'main'
pull_request:
concurrency:
# Skip intermediate builds: always.
# Cancel intermediate builds: only if it is a pull request build.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
branches:
- 'main'
types:
- opened
- reopened
- synchronize
- ready_for_review

jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} ( ${{ matrix.group }} )
runs-on: ${{ matrix.os }}
permissions: # needed to allow julia-actions/cache to delete old caches that it has created
actions: write
contents: read
if: ${{ !github.event.pull_request.draft }}
strategy:
fail-fast: false
matrix:
Expand All @@ -23,38 +30,28 @@ jobs:
- '1.10'
os:
- ubuntu-latest
- macOS-latest
- windows-latest
arch:
- x64
group:
- Core
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: julia-actions/cache@v1
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
env:
GROUP: ${{ matrix.group }}
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v2
with:
files: lcov.info
docs:
name: Documentation
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
directories: src
- uses: codecov/codecov-action@v4
with:
version: '1'
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-docdeploy@v1
verbose: true
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)'
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
38 changes: 38 additions & 0 deletions .github/workflows/documentation.yml
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)'
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ 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"]
test = ["Test", "SafeTestsets"]
18 changes: 18 additions & 0 deletions test/correlations_and_spectrum.jl
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
98 changes: 98 additions & 0 deletions test/dynamical-shifted-fock.jl
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
108 changes: 108 additions & 0 deletions test/dynamical_fock_dimension_mesolve.jl
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
Loading
Loading