Skip to content
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
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
*.jl.*.cov
*.jl.cov
*.jl.mem
/Manifest.toml
/**/Manifest.*
/deps/build.log
/docs/build/


*.log
*.log
.vscode/
3 changes: 0 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ Reexport = "189a3867-3050-52da-a836-e630ba90ab69"

[extensions]

[compat]
QuanEstimationBase = "0.1.0"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

Expand Down
97 changes: 0 additions & 97 deletions docs/Manifest.toml

This file was deleted.

2 changes: 2 additions & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[deps]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
DocumenterCitations = "daee34ce-89f3-4625-b898-19384cb65244"
DocumenterMarkdown = "997ab1e6-3595-5248-9280-8efb232c3433"
QuanEstimation = "088c8dff-a786-4a66-974c-03d3f6773f87"
50 changes: 13 additions & 37 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,51 +1,27 @@
using QuanEstimation
using Documenter
using DocumenterMarkdown
import Documenter.Writers.MarkdownWriter: render, renderdoc
using DocumenterCitations

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

# function render(io::IO, mime::MIME"text/plain", anchor::Documenter.Anchors.Anchor, page, doc)
# println(io, "\n", lstrip(Documenter.Anchors.fragment(anchor), '#', " "))
# if anchor.nth == 1 # add legacy id
# legacy = lstrip(Documenter.Anchors.fragment(anchor), '#', " ") * "-1"
# println(io, "\n", legacy)
# end
# render(io, mime, anchor.object, page, doc)
# end
bib = CitationBibliography("src/refs.bib")

function render(io::IO, mime::MIME"text/plain", node::Documenter.Documents.DocsNode, page, doc)
# Docstring header based on the name of the binding and it's category.
anchor = "## "
header = "**`$(node.object.binding)`** — *$(Documenter.Utilities.doccat(node.object))*."
println(io, anchor, " ", header, "\n\n")
# Body. May contain several concatenated docstrings.
renderdoc(io, mime, node.docstr, page, doc)
end

makedocs(;
format = Markdown(),
makedocs(bib;
root = ".",
source = "docs/src",
build = "docs/build",
source = "src",
build = "build",
clean = true,
doctest = true,
modules = [QuanEstimation],
authors = "Hauiming Yu <Huaimingyuuu@gmail.com> and contributors",
repo = "https://github.com/QuanEstimation/QuanEstimation.jl/blob/{commit}{path}#{line}",
sitename = "QuanEstimation.jl",
# format = Documenter.HTML(;
# prettyurls = get(ENV, "CI", "false") == "true",
# canonical = "https://HuaimingYuuu.github.io/QuanEstimation.jl",
# assets = String[],
# ),
# pages = [api.md"],

pages = [
"API" => [
"api/GeneralAPI.md",
"api/BaseAPI.md",
"api/NVMagnetometerAPI.md"
]
]
)

deploydocs(; repo = "github.com/QuanEstimation/QuanEstimation.jl")
#deploydocs(; repo = "github.com/QuanEstimation/QuanEstimation.jl")
9 changes: 9 additions & 0 deletions docs/src/api/BaseAPI.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Base

```@meta
CurrentModule = QuanEstimationBase
```

```@autodocs
Modules = [QuanEstimationBase]
```
2 changes: 2 additions & 0 deletions docs/src/api.md → docs/src/api/GeneralAPI.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# General

```@meta
CurrentModule = QuanEstimation
```
Expand Down
9 changes: 9 additions & 0 deletions docs/src/api/NVMagnetometerAPI.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# NVMagnetometer

```@meta
CurrentModule = NVMagnetometer
```

```@autodocs
Modules = [NVMagnetometer]
```
1 change: 1 addition & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# QuanEstimation.jl
Empty file added docs/src/refs.bib
Empty file.
6 changes: 3 additions & 3 deletions examples/Bayesian_CramerRao_bounds.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ rho0 = 0.5*ones(2, 2)
# prior distribution
x = range(-0.5*pi, stop=0.5*pi, length=100) |>Vector
mu, eta = 0.0, 0.2
p_tp = [p_func(x[i], mu, eta) for i in 1:length(x)]
dp_tp = [dp_func(x[i], mu, eta) for i in 1:length(x)]
p_tp = [p_func(x[i], mu, eta) for i in eachindex(x)]
dp_tp = [dp_func(x[i], mu, eta) for i in eachindex(x)]
# normalization of the distribution
c = trapz(x, p_tp)
p = p_tp/c
Expand All @@ -37,7 +37,7 @@ tspan = range(0., stop=1., length=1000)
# dynamics
rho = Vector{Matrix{ComplexF64}}(undef, length(x))
drho = Vector{Vector{Matrix{ComplexF64}}}(undef, length(x))
for i = 1:length(x)
for i in eachindex(x)
H0_tp = H0_func(x[i])
dH_tp = dH_func(x[i])
rho_tp, drho_tp = QuanEstimation.expm(tspan, rho0, H0_tp, dH_tp)
Expand Down
4 changes: 2 additions & 2 deletions examples/Bayesian_estimation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ p = (1.0/(x[end]-x[1]))*ones(length(x))
tspan = range(0., stop=1., length=1000)
# dynamics
rho = Vector{Matrix{ComplexF64}}(undef, length(x))
for i = 1:length(x)
for i in eachindex(x)
H0_tp = H0_func(x[i])
dH_tp = dH_func(x[i])
rho_tp, drho_tp = QuanEstimation.expm(tspan, rho0, H0_tp, dH_tp)
Expand All @@ -39,7 +39,7 @@ end
Random.seed!(1234)
y = [0 for i in 1:500]
res_rand = sample(1:length(y), 125, replace=false)
for i in 1:length(res_rand)
for i in eachindex(res_rand)
y[res_rand[i]] = 1
end

Expand Down
20 changes: 10 additions & 10 deletions examples/control_optimization_NV.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ tspan = range(0., 2., length=4000)
# guessed control coefficients
cnum = 10
rng = MersenneTwister(1234)
ini_1 = [zeros(cnum) for _ in 1:length(Hc)]
ini_2 = 0.2.*[ones(cnum) for _ in 1:length(Hc)]
ini_3 = -0.2.*[ones(cnum) for _ in 1:length(Hc)]
ini_4 = [[range(-0.2, 0.2, length=cnum)...] for _ in 1:length(Hc)]
ini_5 = [[range(-0.2, 0., length=cnum)...] for _ in 1:length(Hc)]
ini_6 = [[range(0., 0.2, length=cnum)...] for _ in 1:length(Hc)]
ini_7 = [-0.2*ones(cnum)+0.01*rand(rng,cnum) for _ in 1:length(Hc)]
ini_8 = [-0.2*ones(cnum)+0.01*rand(rng,cnum) for _ in 1:length(Hc)]
ini_9 = [-0.2*ones(cnum)+0.05*rand(rng,cnum) for _ in 1:length(Hc)]
ini_10 = [-0.2*ones(cnum)+0.05*rand(rng,cnum) for _ in 1:length(Hc)]
ini_1 = [zeros(cnum) for _ in eachindex(Hc)]
ini_2 = 0.2.*[ones(cnum) for _ in eachindex(Hc)]
ini_3 = -0.2.*[ones(cnum) for _ in eachindex(Hc)]
ini_4 = [[range(-0.2, 0.2, length=cnum)...] for _ in eachindex(Hc)]
ini_5 = [[range(-0.2, 0., length=cnum)...] for _ in eachindex(Hc)]
ini_6 = [[range(0., 0.2, length=cnum)...] for _ in eachindex(Hc)]
ini_7 = [-0.2*ones(cnum)+0.01*rand(rng,cnum) for _ in eachindex(Hc)]
ini_8 = [-0.2*ones(cnum)+0.01*rand(rng,cnum) for _ in eachindex(Hc)]
ini_9 = [-0.2*ones(cnum)+0.05*rand(rng,cnum) for _ in eachindex(Hc)]
ini_10 = [-0.2*ones(cnum)+0.05*rand(rng,cnum) for _ in eachindex(Hc)]
ctrl0 = [Symbol("ini_", i)|>eval for i in 1:10]
# choose the optimization type
opt = QuanEstimation.ControlOpt(ctrl=ini_1, ctrl_bound=[-0.2, 0.2], seed=1234)
Expand Down
2 changes: 1 addition & 1 deletion examples/control_optimization_qubit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ M = [M1, M2]
tspan = range(0., 10., length=2500)
# guessed control coefficients
cnum = length(tspan)-1
ctrl = [zeros(cnum) for _ in 1:length(Hc)]
ctrl = [zeros(cnum) for _ in eachindex(Hc)]
ctrl_bound = [-2., 2.]
# choose the optimization type
opt = ControlOpt(ctrl=ctrl, ctrl_bound=ctrl_bound, seed=1234)
Expand Down
20 changes: 10 additions & 10 deletions src/QuanEstimationBase/src/Algorithm/AD.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ end

function update_ctrl!(alg::autoGRAPE_Adam, obj, dynamics, δ)
(; epsilon, beta1, beta2) = alg
for ci in 1:length(δ)
for ci in eachindex(δ)
mt, vt = 0.0, 0.0
for ti in 1:length(δ[1])
for ti in eachindex(δ[1])
dynamics.data.ctrl[ci][ti], mt, vt = Adam(δ[ci][ti], ti,
dynamics.data.ctrl[ci][ti], mt, vt, epsilon, beta1, beta2, obj.eps)
end
Expand Down Expand Up @@ -66,7 +66,7 @@ end
function update_state!(alg::AD_Adam, obj, dynamics, δ)
(; epsilon, beta1, beta2) = alg
mt, vt = 0.0, 0.0
for ti in 1:length(δ)
for ti in eachindex(δ)
dynamics.data.ψ0[ti], mt, vt = Adam(δ[ti], ti, dynamics.data.ψ0[ti], mt, vt, epsilon, beta1, beta2, obj.eps)
end
end
Expand Down Expand Up @@ -111,9 +111,9 @@ end

function update_M!(opt::Mopt_LinearComb, alg::AD_Adam, obj, δ)
(; epsilon, beta1, beta2) = alg
for ci in 1:length(δ)
for ci in eachindex(δ)
mt, vt = 0.0, 0.0
for ti in 1:length(δ[1])
for ti in eachindex(δ[1])
opt.B[ci][ti], mt, vt = Adam(δ[ci][ti], ti, opt.B[ci][ti], mt, vt, epsilon, beta1, beta2, obj.eps)
end
end
Expand All @@ -132,12 +132,12 @@ function update!(opt::Mopt_Rotation, alg::AbstractAD, obj, dynamics, output)
suN = suN_generator(dim)
opt.Lambda = Matrix{ComplexF64}[]
append!(opt.Lambda, [Matrix{ComplexF64}(I,dim,dim)])
append!(opt.Lambda, [suN[i] for i in 1:length(suN)])
append!(opt.Lambda, [suN[i] for i in eachindex(suN)])

# if ismissing(Lambda)
# opt.Lambda = Matrix{ComplexF64}[]
# append!(opt.Lambda, [Matrix{ComplexF64}(I,dim,dim)])
# append!(opt.Lambda, [suN[i] for i in 1:length(suN)])
# append!(opt.Lambda, [suN[i] for i in eachindex(suN)])
# end

U = rotation_matrix(opt.s, opt.Lambda)
Expand Down Expand Up @@ -171,7 +171,7 @@ end
function update_M!(opt::Mopt_Rotation, alg::AD_Adam, obj, δ)
(; epsilon, beta1, beta2) = alg
mt, vt = 0.0, 0.0
for ti in 1:length(δ)
for ti in eachindex(δ)
opt.s[ti], mt, vt = Adam(δ[ti], ti, opt.s[ti], mt, vt, epsilon, beta1, beta2, obj.eps)
end
end
Expand Down Expand Up @@ -213,9 +213,9 @@ end

function update_ctrl!(alg::AD_Adam, obj, dynamics, δ)
(; epsilon, beta1, beta2) = alg
for ci in 1:length(δ)
for ci in eachindex(δ)
mt, vt = 0.0, 0.0
for ti in 1:length(δ[1])
for ti in eachindex(δ[1])
dynamics.data.ctrl[ci][ti], mt, vt = Adam(δ[ci][ti], ti,
dynamics.data.ctrl[ci][ti], mt, vt, epsilon, beta1, beta2, obj.eps)
end
Expand Down
2 changes: 1 addition & 1 deletion src/QuanEstimationBase/src/Algorithm/DDPG.jl
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ function _step!(env::ControlEnv, a)
reward_current = log(f_current / env.f_noctrl[env.t])
env.reward = reward_current
env.total_reward += reward_current
[append!(env.ctrl_list[i], a[i]) for i = 1:length(a)]
[append!(env.ctrl_list[i], a[i]) for i in eachindex(a)]
if env.done
set_f!(env.output, f_out)
set_buffer!(env.output, env.ctrl_list)
Expand Down
4 changes: 2 additions & 2 deletions src/QuanEstimationBase/src/Algorithm/DE.jl
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,12 @@ function update!(opt::Mopt_Rotation, alg::DE, obj, dynamics, output)
suN = suN_generator(dim)
Lambda = Matrix{ComplexF64}[]
append!(Lambda, [Matrix{ComplexF64}(I,dim,dim)])
append!(Lambda, [suN[i] for i in 1:length(suN)])
append!(Lambda, [suN[i] for i in eachindex(suN)])

# if ismissing(Lambda)
# Lambda = Matrix{ComplexF64}[]
# append!(Lambda, [Matrix{ComplexF64}(I,dim,dim)])
# append!(Lambda, [suN[i] for i in 1:length(suN)])
# append!(Lambda, [suN[i] for i in eachindex(suN)])
# end

M_num = length(POVM_basis)
Expand Down
2 changes: 1 addition & 1 deletion src/QuanEstimationBase/src/Algorithm/NM.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function update!(opt::StateOpt, alg::NM, obj, dynamics, output)
if length(ini_state) > p_num
ini_state = [ini_state[i] for i in 1:p_num]
end
for pj in 1:length(ini_state)
for pj in eachindex(ini_state)
nelder_mead[pj].data.ψ0 = [ini_state[pj][i] for i in 1:dim]
end
for pj in (length(ini_state)+1):p_num
Expand Down
Loading