Skip to content

Commit

Permalink
Merge pull request #111 from albertomercurio/dev/patch-2
Browse files Browse the repository at this point in the history
Format Documents
  • Loading branch information
albertomercurio authored May 21, 2024
2 parents f8b508d + ecfb6b7 commit 6066efd
Show file tree
Hide file tree
Showing 42 changed files with 2,495 additions and 1,577 deletions.
8 changes: 8 additions & 0 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
margin=120
always_for_in=true
remove_extra_newlines=true
long_to_short_function_def=true
always_use_return=true
format_docstrings=true
indent_submodule=true
format_markdown=true
31 changes: 31 additions & 0 deletions .github/workflows/JuliaFormatter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: JuliaFormatter PR
on:
schedule:
- cron: '0 0 * * *'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: julia-actions/cache@v1
- name: Install JuliaFormatter and format
run: |
julia -e 'import Pkg; Pkg.add("JuliaFormatter")'
julia -e 'using JuliaFormatter; format(".")'
# https://github.com/marketplace/actions/create-pull-request
# https://github.com/peter-evans/create-pull-request#reference-example
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: Format .jl files
title: 'Automatic JuliaFormatter.jl run'
branch: auto-juliaformatter-pr
delete-branch: true
labels: formatting, automated pr, no changelog
- name: Check outputs
run: |
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
15 changes: 12 additions & 3 deletions benchmarks/correlations_and_spectrum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,20 @@ function benchmark_correlations_and_spectrum()
H = ω * a' * a
c_ops = [sqrt* (nth + 1)) * a, sqrt* nth) * a']

ω_l = range(0, 3, length=1000)
ω_l = range(0, 3, length = 1000)

SUITE["Correlations and Spectrum"]["FFT Correlation"] = @benchmarkable spectrum($H, $ω_l, $(a'), $a, $c_ops, solver=FFTCorrelation(), progress_bar=false)
SUITE["Correlations and Spectrum"]["FFT Correlation"] = @benchmarkable spectrum(
$H,
$ω_l,
$(a'),
$a,
$c_ops,
solver = FFTCorrelation(),
progress_bar = false,
)

SUITE["Correlations and Spectrum"]["Exponential Series"] = @benchmarkable spectrum($H, $ω_l, $(a'), $a, $c_ops)
SUITE["Correlations and Spectrum"]["Exponential Series"] =
@benchmarkable spectrum($H, $ω_l, $(a'), $a, $c_ops)
end

benchmark_correlations_and_spectrum()
13 changes: 11 additions & 2 deletions benchmarks/dynamical_fock_dimension.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,20 @@ function benchmark_dfd()
maxdims = [50, 50]

ψ0 = tensor(fock(3, 0), fock(20, 15))
dfd_params ==Δ, F=F, κ=κ, J=J)
dfd_params = = Δ, F = F, κ = κ, J = J)

tlist = range(0, 15 / κ, 100)

SUITE["Time Evolution"]["Dynamical Fock Dimension"] = @benchmarkable dfd_mesolve(H_dfd2, $ψ0, $tlist, c_ops_dfd2, $maxdims, $dfd_params, e_ops=e_ops_dfd2, progress_bar=false)
SUITE["Time Evolution"]["Dynamical Fock Dimension"] = @benchmarkable dfd_mesolve(
H_dfd2,
$ψ0,
$tlist,
c_ops_dfd2,
$maxdims,
$dfd_params,
e_ops = e_ops_dfd2,
progress_bar = false,
)
end

benchmark_dfd()
5 changes: 3 additions & 2 deletions benchmarks/eigenvalues.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ function benchmark_eigenvalues()
n_thermal = 0.1

H = ωc * a_d * a + ωb * b_d * b + g * (a + a_d) * (b + b_d)
c_ops = [((1+n_thermal)*κ) * a, κ * b, (n_thermal*κ) * a_d]
c_ops = [((1 + n_thermal) * κ) * a, κ * b, (n_thermal * κ) * a_d]
L = liouvillian(H, c_ops)

SUITE["Eigenvalues"]["eigenstates"]["dense"] = @benchmarkable eigenstates($L)
SUITE["Eigenvalues"]["eigenstates"]["sparse"] = @benchmarkable eigenstates($L, sparse=true, sigma=0.01, k=5)
SUITE["Eigenvalues"]["eigenstates"]["sparse"] =
@benchmarkable eigenstates($L, sparse = true, sigma = 0.01, k = 5)
end

benchmark_eigenvalues()
58 changes: 43 additions & 15 deletions benchmarks/timeevolution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,72 @@ function benchmark_timeevolution()
g = 0.1
ωd = 0.99
F = 0.07

Δc = ωc - ωd
Δq = ωq - ωd

# Operators definition
N = 20 # cutoff for the cavity Hilbert space
a = tensor(destroy(N), qeye(2))
σm = tensor(qeye(N), sigmam())
σz = tensor(qeye(N), sigmaz())

# Hamiltonian
H = Δc * a' * a + Δq * σz / 2 + g * (a' * σm + a * σm') + F * (a + a')
e_ops = [a'*a, σz]

e_ops = [a' * a, σz]

# Initial state
ψ0 = tensor(coherent(N, 0), fock(2, 1))

## sesolve ##

tlist = range(0, 2π * 10 / g, 1000)

SUITE["Time Evolution"]["time-independent"]["sesolve"] = @benchmarkable sesolve($H, $ψ0, $tlist, e_ops=$e_ops, progress_bar=false)

SUITE["Time Evolution"]["time-independent"]["sesolve"] =
@benchmarkable sesolve($H, $ψ0, $tlist, e_ops = $e_ops, progress_bar = false)

## mesolve ##

nth = 0.01
γ = 0.05
c_ops = [sqrt* (nth + 1)) * a, sqrt* nth) * a', sqrt(γ) * σm]

tlist = range(0, 10/γ, 100)

SUITE["Time Evolution"]["time-independent"]["mesolve"] = @benchmarkable mesolve($H, $ψ0, $tlist, $c_ops, e_ops=$e_ops, progress_bar=false)

tlist = range(0, 10 / γ, 100)

SUITE["Time Evolution"]["time-independent"]["mesolve"] = @benchmarkable mesolve(
$H,
$ψ0,
$tlist,
$c_ops,
e_ops = $e_ops,
progress_bar = false,
)

## mcsolve ##

SUITE["Time Evolution"]["time-independent"]["mcsolve"]["Serial"] = @benchmarkable mcsolve($H, $ψ0, $tlist, $c_ops, n_traj=100, e_ops=$e_ops, progress_bar=false, ensemble_method=EnsembleSerial())
SUITE["Time Evolution"]["time-independent"]["mcsolve"]["Multithreaded"] = @benchmarkable mcsolve($H, $ψ0, $tlist, $c_ops, n_traj=100, e_ops=$e_ops, progress_bar=false, ensemble_method=EnsembleThreads())
SUITE["Time Evolution"]["time-independent"]["mcsolve"]["Serial"] =
@benchmarkable mcsolve(
$H,
$ψ0,
$tlist,
$c_ops,
n_traj = 100,
e_ops = $e_ops,
progress_bar = false,
ensemble_method = EnsembleSerial(),
)
SUITE["Time Evolution"]["time-independent"]["mcsolve"]["Multithreaded"] =
@benchmarkable mcsolve(
$H,
$ψ0,
$tlist,
$c_ops,
n_traj = 100,
e_ops = $e_ops,
progress_bar = false,
ensemble_method = EnsembleThreads(),
)
end

benchmark_timeevolution()
47 changes: 21 additions & 26 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,43 +1,38 @@
using QuantumToolbox
using Documenter

DocMeta.setdocmeta!(QuantumToolbox, :DocTestSetup, :(using QuantumToolbox); recursive=true)
DocMeta.setdocmeta!(QuantumToolbox, :DocTestSetup, :(using QuantumToolbox); recursive = true)

makedocs(;
modules=[QuantumToolbox],
authors="Alberto Mercurio",
modules = [QuantumToolbox],
authors = "Alberto Mercurio",
repo = Remotes.GitHub("albertomercurio", "QuantumToolbox.jl"),
sitename="QuantumToolbox.jl",
format=Documenter.HTML(;
prettyurls=get(ENV, "CI", "false") == "true",
canonical="https://albertomercurio.github.io/QuantumToolbox.jl",
edit_link="main",
assets=[
"assets/favicon.ico"
],
mathengine = MathJax3(Dict(
:loader => Dict("load" => ["[tex]/physics"]),
:tex => Dict(
"inlineMath" => [["\$","\$"], ["\\(","\\)"]],
"tags" => "ams",
"packages" => ["base", "ams", "autoload", "physics"],
sitename = "QuantumToolbox.jl",
format = Documenter.HTML(;
prettyurls = get(ENV, "CI", "false") == "true",
canonical = "https://albertomercurio.github.io/QuantumToolbox.jl",
edit_link = "main",
assets = String[],
mathengine = MathJax3(
Dict(
:loader => Dict("load" => ["[tex]/physics"]),
:tex => Dict(
"inlineMath" => [["\$", "\$"], ["\\(", "\\)"]],
"tags" => "ams",
"packages" => ["base", "ams", "autoload", "physics"],
),
),
)),
),
),
pages=[
pages = [
"index.md",
"api.md",
"Tutorials" => [
"Creation of the QuantulToolbox.jl logo" => "tutorials/logo.md",
"Low Rank Master Equation" => "tutorials/lowrank.md",
],
"Benchmarks" => [
"Benchmark History" => "benchmarks/benchmark_history.md",
]
"Benchmarks" => ["Benchmark History" => "benchmarks/benchmark_history.md"],
],
)

deploydocs(;
repo="github.com/albertomercurio/QuantumToolbox.jl",
devbranch="main",
)
deploydocs(; repo = "github.com/albertomercurio/QuantumToolbox.jl", devbranch = "main")
23 changes: 15 additions & 8 deletions ext/QuantumToolboxCUDAExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import SparseArrays: SparseVector, SparseMatrixCSC
If `A.data` is a dense array, return a new [`QuantumObject`](@ref) where `A.data` is in the type of `CUDA.CuArray` for gpu calculations.
"""
CuArray(A::QuantumObject{Tq}) where Tq<:Union{Vector,Matrix} = QuantumObject(CuArray(A.data), A.type, A.dims)
CuArray(A::QuantumObject{Tq}) where {Tq<:Union{Vector,Matrix}} = QuantumObject(CuArray(A.data), A.type, A.dims)

@doc raw"""
CuArray{T}(A::QuantumObject)
Expand All @@ -31,7 +31,7 @@ CuSparseVector(A::QuantumObject{<:SparseVector}) = QuantumObject(CuSparseVector(
If `A.data` is a sparse vector, return a new [`QuantumObject`](@ref) where `A.data` is in the type of `CUDA.CUSPARSE.CuSparseVector` with element type `T` for gpu calculations.
"""
CuSparseVector{T}(A::QuantumObject{<:SparseVector}) where T = QuantumObject(CuSparseVector{T}(A.data), A.type, A.dims)
CuSparseVector{T}(A::QuantumObject{<:SparseVector}) where {T} = QuantumObject(CuSparseVector{T}(A.data), A.type, A.dims)

@doc raw"""
CuSparseMatrixCSC(A::QuantumObject)
Expand All @@ -45,7 +45,8 @@ CuSparseMatrixCSC(A::QuantumObject{<:SparseMatrixCSC}) = QuantumObject(CuSparseM
If `A.data` is in the type of `SparseMatrixCSC`, return a new [`QuantumObject`](@ref) where `A.data` is in the type of `CUDA.CUSPARSE.CuSparseMatrixCSC` with element type `T` for gpu calculations.
"""
CuSparseMatrixCSC{T}(A::QuantumObject{<:SparseMatrixCSC}) where T = QuantumObject(CuSparseMatrixCSC{T}(A.data), A.type, A.dims)
CuSparseMatrixCSC{T}(A::QuantumObject{<:SparseMatrixCSC}) where {T} =
QuantumObject(CuSparseMatrixCSC{T}(A.data), A.type, A.dims)

@doc raw"""
CuSparseMatrixCSR(A::QuantumObject)
Expand All @@ -59,7 +60,8 @@ CuSparseMatrixCSR(A::QuantumObject{<:SparseMatrixCSC}) = QuantumObject(CuSparseM
If `A.data` is in the type of `SparseMatrixCSC`, return a new [`QuantumObject`](@ref) where `A.data` is in the type of `CUDA.CUSPARSE.CuSparseMatrixCSR` with element type `T` for gpu calculations.
"""
CuSparseMatrixCSR{T}(A::QuantumObject{<:SparseMatrixCSC}) where T = QuantumObject(CuSparseMatrixCSR{T}(A.data), A.type, A.dims)
CuSparseMatrixCSR{T}(A::QuantumObject{<:SparseMatrixCSC}) where {T} =
QuantumObject(CuSparseMatrixCSR{T}(A.data), A.type, A.dims)

@doc raw"""
cu(A::QuantumObject; word_size::Int=32)
Expand All @@ -70,10 +72,15 @@ Return a new [`QuantumObject`](@ref) where `A.data` is in the type of `CUDA` arr
- `A::QuantumObject`: The [`QuantumObject`](@ref)
- `word_size::Int`: The word size of the element type of `A`, can be either `32` or `64`. Default to `32`.
"""
cu(A::QuantumObject; word_size::Int=32) = ((word_size == 64) || (word_size == 32)) ? cu(A, Val(word_size)) : throw(DomainError(word_size, "The word size should be 32 or 64."))
cu(A::QuantumObject{T}, word_size::TW) where {T<:Union{Vector,Matrix},TW<:Union{Val{32},Val{64}}} = CuArray{_change_eltype(eltype(A), word_size)}(A)
cu(A::QuantumObject{<:SparseVector}, word_size::TW) where TW<:Union{Val{32},Val{64}} = CuSparseVector{_change_eltype(eltype(A), word_size)}(A)
cu(A::QuantumObject{<:SparseMatrixCSC}, word_size::TW) where TW<:Union{Val{32},Val{64}} = CuSparseMatrixCSC{_change_eltype(eltype(A), word_size)}(A)
cu(A::QuantumObject; word_size::Int = 32) =
((word_size == 64) || (word_size == 32)) ? cu(A, Val(word_size)) :
throw(DomainError(word_size, "The word size should be 32 or 64."))
cu(A::QuantumObject{T}, word_size::TW) where {T<:Union{Vector,Matrix},TW<:Union{Val{32},Val{64}}} =
CuArray{_change_eltype(eltype(A), word_size)}(A)
cu(A::QuantumObject{<:SparseVector}, word_size::TW) where {TW<:Union{Val{32},Val{64}}} =
CuSparseVector{_change_eltype(eltype(A), word_size)}(A)
cu(A::QuantumObject{<:SparseMatrixCSC}, word_size::TW) where {TW<:Union{Val{32},Val{64}}} =
CuSparseMatrixCSC{_change_eltype(eltype(A), word_size)}(A)

_change_eltype(::Type{T}, ::Val{64}) where {T<:Int} = Int64
_change_eltype(::Type{T}, ::Val{32}) where {T<:Int} = Int32
Expand Down
Loading

0 comments on commit 6066efd

Please sign in to comment.