Skip to content

Commit 69e063f

Browse files
authored
Format .jl files
1 parent 4a13f90 commit 69e063f

File tree

96 files changed

+5520
-4017
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+5520
-4017
lines changed

docs/make.jl

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,18 @@ using DocumenterCitations
55

66
bib = CitationBibliography("src/refs.bib")
77

8-
makedocs(bib;
9-
root = ".",
10-
source = "src",
11-
build = "build",
12-
clean = true,
8+
makedocs(
9+
bib;
10+
root = ".",
11+
source = "src",
12+
build = "build",
13+
clean = true,
1314
doctest = true,
1415
modules = [QuanEstimation],
1516
authors = "Hauiming Yu <[email protected]> and contributors",
1617
repo = "https://github.com/QuanEstimation/QuanEstimation.jl/blob/{commit}{path}#{line}",
1718
sitename = "QuanEstimation.jl",
18-
pages = [
19-
"API" => [
20-
"api/GeneralAPI.md",
21-
"api/BaseAPI.md",
22-
"api/NVMagnetometerAPI.md"
23-
]
24-
]
19+
pages = ["API" => ["api/GeneralAPI.md", "api/BaseAPI.md", "api/NVMagnetometerAPI.md"]],
2520
)
2621

2722
#deploydocs(; repo = "github.com/QuanEstimation/QuanEstimation.jl")

examples/Bayesian_CramerRao_bounds.jl

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,56 +3,56 @@ using Trapz
33

44
# free Hamiltonian
55
function H0_func(x)
6-
return 0.5*B*omega0*(sx*cos(x)+sz*sin(x))
6+
return 0.5 * B * omega0 * (sx * cos(x) + sz * sin(x))
77
end
88
# derivative of the free Hamiltonian on x
99
function dH_func(x)
10-
return [0.5*B*omega0*(-sx*sin(x)+sz*cos(x))]
10+
return [0.5 * B * omega0 * (-sx * sin(x) + sz * cos(x))]
1111
end
1212
# prior distribution
1313
function p_func(x, mu, eta)
14-
return exp(-(x-mu)^2/(2*eta^2))/(eta*sqrt(2*pi))
14+
return exp(-(x - mu)^2 / (2 * eta^2)) / (eta * sqrt(2 * pi))
1515
end
1616
function dp_func(x, mu, eta)
17-
return -(x-mu)*exp(-(x-mu)^2/(2*eta^2))/(eta^3*sqrt(2*pi))
17+
return -(x - mu) * exp(-(x - mu)^2 / (2 * eta^2)) / (eta^3 * sqrt(2 * pi))
1818
end
1919

20-
B, omega0 = 0.5*pi, 1.0
21-
sx = [0. 1.; 1. 0.0im]
22-
sy = [0. -im; im 0.]
23-
sz = [1. 0.0im; 0. -1.]
20+
B, omega0 = 0.5 * pi, 1.0
21+
sx = [0.0 1.0; 1.0 0.0im]
22+
sy = [0.0 -im; im 0.0]
23+
sz = [1.0 0.0im; 0.0 -1.0]
2424
# initial state
25-
rho0 = 0.5*ones(2, 2)
25+
rho0 = 0.5 * ones(2, 2)
2626
# prior distribution
27-
x = range(-0.5*pi, stop=0.5*pi, length=100) |>Vector
27+
x = range(-0.5 * pi, stop = 0.5 * pi, length = 100) |> Vector
2828
mu, eta = 0.0, 0.2
2929
p_tp = [p_func(x[i], mu, eta) for i in eachindex(x)]
3030
dp_tp = [dp_func(x[i], mu, eta) for i in eachindex(x)]
3131
# normalization of the distribution
3232
c = trapz(x, p_tp)
33-
p = p_tp/c
34-
dp = dp_tp/c
33+
p = p_tp / c
34+
dp = dp_tp / c
3535
# time length for the evolution
36-
tspan = range(0., stop=1., length=1000)
36+
tspan = range(0.0, stop = 1.0, length = 1000)
3737
# dynamics
3838
rho = Vector{Matrix{ComplexF64}}(undef, length(x))
3939
drho = Vector{Vector{Matrix{ComplexF64}}}(undef, length(x))
40-
for i in eachindex(x)
40+
for i in eachindex(x)
4141
H0_tp = H0_func(x[i])
4242
dH_tp = dH_func(x[i])
4343
rho_tp, drho_tp = QuanEstimation.expm(tspan, rho0, H0_tp, dH_tp)
4444
rho[i], drho[i] = rho_tp[end], drho_tp[end]
4545
end
4646

4747
# Classical Bayesian bounds
48-
f_BCRB1 = QuanEstimation.BCRB([x], p, [], rho, drho, btype=1)
49-
f_BCRB2 = QuanEstimation.BCRB([x], p, [], rho, drho, btype=2)
50-
f_BCRB3 = QuanEstimation.BCRB([x], p, dp, rho, drho, btype=3)
48+
f_BCRB1 = QuanEstimation.BCRB([x], p, [], rho, drho, btype = 1)
49+
f_BCRB2 = QuanEstimation.BCRB([x], p, [], rho, drho, btype = 2)
50+
f_BCRB3 = QuanEstimation.BCRB([x], p, dp, rho, drho, btype = 3)
5151
f_VTB = QuanEstimation.VTB([x], p, dp, rho, drho)
5252

5353
# Quantum Bayesian bounds
54-
f_BQCRB1 = QuanEstimation.BQCRB([x], p, [], rho, drho, btype=1)
55-
f_BQCRB2 = QuanEstimation.BQCRB([x], p, [], rho, drho, btype=2)
56-
f_BQCRB3 = QuanEstimation.BQCRB([x], p, dp, rho, drho, btype=3)
54+
f_BQCRB1 = QuanEstimation.BQCRB([x], p, [], rho, drho, btype = 1)
55+
f_BQCRB2 = QuanEstimation.BQCRB([x], p, [], rho, drho, btype = 2)
56+
f_BQCRB3 = QuanEstimation.BQCRB([x], p, dp, rho, drho, btype = 3)
5757
f_QVTB = QuanEstimation.QVTB([x], p, dp, rho, drho)
5858
f_QZZB = QuanEstimation.QZZB([x], p, rho)

examples/Bayesian_estimation.jl

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,31 @@ using StatsBase
44

55
# free Hamiltonian
66
function H0_func(x)
7-
return 0.5*B*omega0*(sx*cos(x)+sz*sin(x))
7+
return 0.5 * B * omega0 * (sx * cos(x) + sz * sin(x))
88
end
99
# derivative of the free Hamiltonian on x
1010
function dH_func(x)
11-
return [0.5*B*omega0*(-sx*sin(x)+sz*cos(x))]
11+
return [0.5 * B * omega0 * (-sx * sin(x) + sz * cos(x))]
1212
end
1313

14-
B, omega0 = pi/2.0, 1.0
15-
sx = [0. 1.; 1. 0.0im]
16-
sy = [0. -im; im 0.]
17-
sz = [1. 0.0im; 0. -1.]
14+
B, omega0 = pi / 2.0, 1.0
15+
sx = [0.0 1.0; 1.0 0.0im]
16+
sy = [0.0 -im; im 0.0]
17+
sz = [1.0 0.0im; 0.0 -1.0]
1818
# initial state
19-
rho0 = 0.5*ones(2, 2)
19+
rho0 = 0.5 * ones(2, 2)
2020
# measurement
21-
M1 = 0.5*[1.0+0.0im 1.; 1. 1.]
22-
M2 = 0.5*[1.0+0.0im -1.; -1. 1.]
21+
M1 = 0.5 * [1.0+0.0im 1.0; 1.0 1.0]
22+
M2 = 0.5 * [1.0+0.0im -1.0; -1.0 1.0]
2323
M = [M1, M2]
2424
# prior distribution
25-
x = range(0., stop=0.5*pi, length=100) |>Vector
26-
p = (1.0/(x[end]-x[1]))*ones(length(x))
25+
x = range(0.0, stop = 0.5 * pi, length = 100) |> Vector
26+
p = (1.0 / (x[end] - x[1])) * ones(length(x))
2727
# time length for the evolution
28-
tspan = range(0., stop=1., length=1000)
28+
tspan = range(0.0, stop = 1.0, length = 1000)
2929
# dynamics
3030
rho = Vector{Matrix{ComplexF64}}(undef, length(x))
31-
for i in eachindex(x)
31+
for i in eachindex(x)
3232
H0_tp = H0_func(x[i])
3333
dH_tp = dH_func(x[i])
3434
rho_tp, drho_tp = QuanEstimation.expm(tspan, rho0, H0_tp, dH_tp)
@@ -37,15 +37,15 @@ end
3737

3838
# Generation of the experimental results
3939
Random.seed!(1234)
40-
y = [0 for i in 1:500]
41-
res_rand = sample(1:length(y), 125, replace=false)
40+
y = [0 for i = 1:500]
41+
res_rand = sample(1:length(y), 125, replace = false)
4242
for i in eachindex(res_rand)
4343
y[res_rand[i]] = 1
4444
end
4545

4646
#===============Maximum a posteriori estimation===============#
47-
pout, xout = QuanEstimation.Bayes([x], p, rho, y; M=M, estimator="MAP",
48-
savefile=false)
47+
pout, xout =
48+
QuanEstimation.Bayes([x], p, rho, y; M = M, estimator = "MAP", savefile = false)
4949

5050
#===============Maximum likelihood estimation===============#
51-
Lout, xout = QuanEstimation.MLE([x], rho, y, M=M; savefile=false)
51+
Lout, xout = QuanEstimation.MLE([x], rho, y, M = M; savefile = false)

examples/CMopt_NV.jl

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,50 +6,54 @@ using LinearAlgebra
66
rho0 = zeros(ComplexF64, 6, 6)
77
rho0[1:4:5, 1:4:5] .= 0.5
88
# Hamiltonian
9-
sx = [0. 1.; 1. 0.]
10-
sy = [0. -im; im 0.]
11-
sz = [1. 0.; 0. -1.]
12-
s1 = [0. 1. 0.; 1. 0. 1.; 0. 1. 0.]/sqrt(2)
13-
s2 = [0. -im 0.; im 0. -im; 0. im 0.]/sqrt(2)
14-
s3 = [1. 0. 0.; 0. 0. 0.; 0. 0. -1.]
9+
sx = [0.0 1.0; 1.0 0.0]
10+
sy = [0.0 -im; im 0.0]
11+
sz = [1.0 0.0; 0.0 -1.0]
12+
s1 = [0.0 1.0 0.0; 1.0 0.0 1.0; 0.0 1.0 0.0] / sqrt(2)
13+
s2 = [0.0 -im 0.0; im 0.0 -im; 0.0 im 0.0] / sqrt(2)
14+
s3 = [1.0 0.0 0.0; 0.0 0.0 0.0; 0.0 0.0 -1.0]
1515
Is = I1, I2, I3 = [kron(I(3), sx), kron(I(3), sy), kron(I(3), sz)]
1616
S = S1, S2, S3 = [kron(s1, I(2)), kron(s2, I(2)), kron(s3, I(2))]
1717
B = B1, B2, B3 = [5.0e-4, 5.0e-4, 5.0e-4]
1818
# All numbers are divided by 100 in this example
1919
# for better calculation accurancy
2020
cons = 100
21-
D = (2pi*2.87*1000)/cons
22-
gS = (2pi*28.03*1000)/cons
23-
gI = (2pi*4.32)/cons
24-
A1 = (2pi*3.65)/cons
25-
A2 = (2pi*3.03)/cons
26-
H0 = sum([D*kron(s3^2, I(2)), sum(gS*B.*S), sum(gI*B.*Is),
27-
A1*(kron(s1, sx) + kron(s2, sy)), A2*kron(s3, sz)])
21+
D = (2pi * 2.87 * 1000) / cons
22+
gS = (2pi * 28.03 * 1000) / cons
23+
gI = (2pi * 4.32) / cons
24+
A1 = (2pi * 3.65) / cons
25+
A2 = (2pi * 3.03) / cons
26+
H0 = sum([
27+
D * kron(s3^2, I(2)),
28+
sum(gS * B .* S),
29+
sum(gI * B .* Is),
30+
A1 * (kron(s1, sx) + kron(s2, sy)),
31+
A2 * kron(s3, sz),
32+
])
2833
# derivatives of the free Hamiltonian on B1, B2 and B3
29-
dH = gS*S+gI*Is
34+
dH = gS * S + gI * Is
3035
# control Hamiltonians
3136
Hc = [S1, S2, S3]
3237
# dissipation
33-
decay = [[S3, 2pi/cons]]
38+
decay = [[S3, 2pi / cons]]
3439
# generation of a set of POVM basis
3540
dim = size(rho0, 1)
36-
POVM_basis = [QuanEstimation.basis(dim, i)*QuanEstimation.basis(dim, i)'
37-
for i in 1:dim]
41+
POVM_basis = [QuanEstimation.basis(dim, i) * QuanEstimation.basis(dim, i)' for i = 1:dim]
3842
# time length for the evolution
39-
tspan = range(0., 2., length=4000)
43+
tspan = range(0.0, 2.0, length = 4000)
4044
# control and measurement optimization
41-
opt = QuanEstimation.CMopt(ctrl_bound=[-0.2,0.2], seed=1234)
45+
opt = QuanEstimation.CMopt(ctrl_bound = [-0.2, 0.2], seed = 1234)
4246

4347
##==========choose comprehensive optimization algorithm==========##
4448
##-------------algorithm: DE---------------------##
45-
alg = QuanEstimation.DE(p_num=10, max_episode=1000, c=1.0, cr=0.5)
49+
alg = QuanEstimation.DE(p_num = 10, max_episode = 1000, c = 1.0, cr = 0.5)
4650
# input the dynamics data
47-
dynamics = QuanEstimation.Lindblad(opt, tspan, rho0, H0, dH, Hc,
48-
decay=decay, dyn_method=:Expm)
51+
dynamics =
52+
QuanEstimation.Lindblad(opt, tspan, rho0, H0, dH, Hc, decay = decay, dyn_method = :Expm)
4953
# objective function: CFI
50-
obj = QuanEstimation.CFIM_obj()
54+
obj = QuanEstimation.CFIM_obj()
5155
# run the comprehensive optimization problem
52-
QuanEstimation.run(opt, alg, obj, dynamics; savefile=false)
56+
QuanEstimation.run(opt, alg, obj, dynamics; savefile = false)
5357

5458
##-------------algorithm: PSO---------------------##
5559
# alg = QuanEstimation.PSO(p_num=10, max_episode=[1000,100], c0=1.0,

examples/CMopt_qubit.jl

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
11
using QuanEstimation
22

33
# initial state
4-
rho0 = 0.5*ones(2, 2)
4+
rho0 = 0.5 * ones(2, 2)
55
# free Hamiltonian
66
omega = 1.0
7-
sx = [0. 1.; 1. 0.0im]
8-
sy = [0. -im; im 0.]
9-
sz = [1. 0.0im; 0. -1.]
10-
H0 = 0.5*omega*sz
7+
sx = [0.0 1.0; 1.0 0.0im]
8+
sy = [0.0 -im; im 0.0]
9+
sz = [1.0 0.0im; 0.0 -1.0]
10+
H0 = 0.5 * omega * sz
1111
# derivative of the free Hamiltonian on omega
12-
dH = [0.5*sz]
12+
dH = [0.5 * sz]
1313
# control Hamiltonians
1414
Hc = [sx, sy, sz]
1515
# dissipation
16-
sp = [0. 1.; 0. 0.0im]
17-
sm = [0. 0.; 1. 0.0im]
16+
sp = [0.0 1.0; 0.0 0.0im]
17+
sm = [0.0 0.0; 1.0 0.0im]
1818
decay = [[sp, 0.0], [sm, 0.1]]
1919
# measurement
20-
M1 = 0.5*[1.0+0.0im 1.; 1. 1.]
21-
M2 = 0.5*[1.0+0.0im -1.; -1. 1.]
20+
M1 = 0.5 * [1.0+0.0im 1.0; 1.0 1.0]
21+
M2 = 0.5 * [1.0+0.0im -1.0; -1.0 1.0]
2222
M = [M1, M2]
2323
# time length for the evolution
24-
tspan = range(0., 10., length=2500)
24+
tspan = range(0.0, 10.0, length = 2500)
2525
# control and measurement optimization
26-
opt = QuanEstimation.CMopt(ctrl_bound=[-2.0,2.0], seed=1234)
26+
opt = QuanEstimation.CMopt(ctrl_bound = [-2.0, 2.0], seed = 1234)
2727

2828
##==========choose comprehensive optimization algorithm==========##
2929
##-------------algorithm: DE---------------------##
30-
alg = QuanEstimation.DE(p_num=10, max_episode=1000, c=1.0, cr=0.5)
30+
alg = QuanEstimation.DE(p_num = 10, max_episode = 1000, c = 1.0, cr = 0.5)
3131
# input the dynamics data
32-
dynamics = QuanEstimation.Lindblad(opt, tspan, rho0, H0, dH, Hc,
33-
decay=decay, dyn_method=:Expm)
32+
dynamics =
33+
QuanEstimation.Lindblad(opt, tspan, rho0, H0, dH, Hc, decay = decay, dyn_method = :Expm)
3434
# objective function: CFI
35-
obj = QuanEstimation.CFIM_obj()
35+
obj = QuanEstimation.CFIM_obj()
3636
# run the comprehensive optimization problem
37-
QuanEstimation.run(opt, alg, obj, dynamics; savefile=false)
37+
QuanEstimation.run(opt, alg, obj, dynamics; savefile = false)
3838

3939
##-------------algorithm: PSO---------------------##
4040
# alg = QuanEstimation.PSO(p_num=10, max_episode=[1000,100], c0=1.0,

examples/CramerRao_bounds.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
using QuanEstimation
22

33
# initial state
4-
rho0 = 0.5*ones(2, 2)
4+
rho0 = 0.5 * ones(2, 2)
55
# free Hamiltonian
66
omega = 1.0
7-
sx = [0. 1.; 1. 0.0im]
8-
sy = [0. -im; im 0.]
9-
sz = [1. 0.0im; 0. -1.]
10-
H0 = 0.5*omega*sz
7+
sx = [0.0 1.0; 1.0 0.0im]
8+
sy = [0.0 -im; im 0.0]
9+
sz = [1.0 0.0im; 0.0 -1.0]
10+
H0 = 0.5 * omega * sz
1111
# derivative of the free Hamiltonian on omega
12-
dH = [0.5*sz]
12+
dH = [0.5 * sz]
1313
# dissipation
14-
sp = [0. 1.; 0. 0.0im]
15-
sm = [0. 0.; 1. 0.0im]
14+
sp = [0.0 1.0; 0.0 0.0im]
15+
sm = [0.0 0.0; 1.0 0.0im]
1616
decay = [[sp, 0.0], [sm, 0.1]]
1717
# measurement
18-
M1 = 0.5*[1.0+0.0im 1.; 1. 1.]
19-
M2 = 0.5*[1.0+0.0im -1.; -1. 1.]
18+
M1 = 0.5 * [1.0+0.0im 1.0; 1.0 1.0]
19+
M2 = 0.5 * [1.0+0.0im -1.0; -1.0 1.0]
2020
M = [M1, M2]
2121
# time length for the evolution
22-
tspan = range(0., 50., length=2000)
22+
tspan = range(0.0, 50.0, length = 2000)
2323
# dynamics
24-
rho, drho = QuanEstimation.expm(tspan, rho0, H0, dH, decay=decay)
24+
rho, drho = QuanEstimation.expm(tspan, rho0, H0, dH, decay = decay)
2525
# calculation of the CFI and QFI
2626
Im, F = Float64[], Float64[]
27-
for ti in 2:length(tspan)
27+
for ti = 2:length(tspan)
2828
# CFI
2929
I_tp = QuanEstimation.CFIM(rho[ti], drho[ti], M)
3030
append!(Im, I_tp)

examples/HCRB_NHB.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,32 @@ using QuanEstimation
22
using LinearAlgebra
33

44
# initial state
5-
psi0 = [1., 0., 0., 1.]/sqrt(2)
6-
rho0 = psi0*psi0'
5+
psi0 = [1.0, 0.0, 0.0, 1.0] / sqrt(2)
6+
rho0 = psi0 * psi0'
77
# free Hamiltonian
88
omega1, omega2, g = 1.0, 1.0, 0.1
9-
sx = [0. 1.; 1. 0.0im]
10-
sy = [0. -im; im 0.]
11-
sz = [1. 0.0im; 0. -1.]
12-
H0 = omega1*kron(sz, I(2)) + omega2*kron(I(2), sz) + g*kron(sx, sx)
9+
sx = [0.0 1.0; 1.0 0.0im]
10+
sy = [0.0 -im; im 0.0]
11+
sz = [1.0 0.0im; 0.0 -1.0]
12+
H0 = omega1 * kron(sz, I(2)) + omega2 * kron(I(2), sz) + g * kron(sx, sx)
1313
# derivatives of the free Hamiltonian with respect to omega2 and g
1414
dH = [kron(I(2), sz), kron(sx, sx)]
1515
# dissipation
1616
decay = [[kron(sz, I(2)), 0.05], [kron(I(2), sz), 0.05]]
1717
# measurement
18-
m1 = [1., 0., 0., 0.]
19-
M1 = 0.85*m1*m1'
20-
M2 = 0.1*ones(4, 4)
21-
M = [M1, M2, I(4)-M1-M2]
18+
m1 = [1.0, 0.0, 0.0, 0.0]
19+
M1 = 0.85 * m1 * m1'
20+
M2 = 0.1 * ones(4, 4)
21+
M = [M1, M2, I(4) - M1 - M2]
2222
# weight matrix
2323
W = one(zeros(2, 2))
2424
# time length for the evolution
25-
tspan = range(0., 5., length=200)
25+
tspan = range(0.0, 5.0, length = 200)
2626
# dynamics
2727
rho, drho = QuanEstimation.expm(tspan, rho0, H0, dH, decay)
2828
# calculation of the CFIM, QFIM and HCRB
2929
f_HCRB, f_NHB = [], []
30-
for ti in 2:length(tspan)
30+
for ti = 2:length(tspan)
3131
# HCRB
3232
f_tp1 = QuanEstimation.HCRB(rho[ti], drho[ti], W)
3333
append!(f_HCRB, f_tp1)

0 commit comments

Comments
 (0)