Skip to content

Commit c9c121b

Browse files
committed
Code formatting
1 parent 17fc56e commit c9c121b

8 files changed

Lines changed: 70 additions & 66 deletions

File tree

docs/make.jl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,26 @@ links = InterLinks(
2424
println("Starting makedocs")
2525

2626
makedocs(;
27-
plugins=[links],
28-
authors=AUTHORS,
29-
sitename="QuantumGradientGenerators.jl",
30-
doctest=false,
31-
format=Documenter.HTML(;
32-
prettyurls=true,
33-
canonical="https://juliaquantumcontrol.github.io/QuantumGradientGenerators.jl",
34-
assets=[
27+
plugins = [links],
28+
authors = AUTHORS,
29+
sitename = "QuantumGradientGenerators.jl",
30+
doctest = false,
31+
format = Documenter.HTML(;
32+
prettyurls = true,
33+
canonical = "https://juliaquantumcontrol.github.io/QuantumGradientGenerators.jl",
34+
assets = [
3535
asset(
3636
"https://juliaquantumcontrol.github.io/QuantumControl.jl/dev/assets/topbar/topbar.css"
3737
),
3838
asset(
3939
"https://juliaquantumcontrol.github.io/QuantumControl.jl/dev/assets/topbar/topbar.js"
4040
),
4141
],
42-
footer="[$NAME.jl]($GITHUB) v$VERSION docs powered by [Documenter.jl](https://github.com/JuliaDocs/Documenter.jl)."
42+
footer = "[$NAME.jl]($GITHUB) v$VERSION docs powered by [Documenter.jl](https://github.com/JuliaDocs/Documenter.jl)."
4343
),
44-
pages=["Home" => "index.md", "API" => "api.md",]
44+
pages = ["Home" => "index.md", "API" => "api.md",]
4545
)
4646

4747
println("Finished makedocs")
4848

49-
deploydocs(; repo="github.com/JuliaQuantumControl/QuantumGradientGenerators.jl",)
49+
deploydocs(; repo = "github.com/JuliaQuantumControl/QuantumGradientGenerators.jl",)

src/evaluate.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ function evaluate(O::GradgenOperator, args...; kwargs...)
66
end
77

88

9-
function evaluate!(G::GradgenOperator, gradgen::GradGenerator, args...; vals_dict=IdDict())
9+
function evaluate!(
10+
G::GradgenOperator,
11+
gradgen::GradGenerator,
12+
args...;
13+
vals_dict = IdDict()
14+
)
1015
evaluate!(G.G, gradgen.G, args...; vals_dict)
1116
for (i, control) in enumerate(gradgen.controls)
1217
μ = gradgen.control_derivs[i]
@@ -18,7 +23,7 @@ function evaluate!(G::GradgenOperator, gradgen::GradGenerator, args...; vals_dic
1823
end
1924

2025

21-
function evaluate(gradgen::GradGenerator, args...; vals_dict=IdDict())
26+
function evaluate(gradgen::GradGenerator, args...; vals_dict = IdDict())
2227
G = evaluate(gradgen.G, args...; vals_dict)
2328
control_deriv_ops = [evaluate(μ, args...; vals_dict) for μ gradgen.control_derivs]
2429
num_controls = length(control_deriv_ops)

src/gradgen_operator.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function get_controls(O1::GradgenOperator)
3030
end
3131

3232

33-
function random_state(H::GradgenOperator; rng=GLOBAL_RNG, _...)
33+
function random_state(H::GradgenOperator; rng = GLOBAL_RNG, _...)
3434
state = random_state(H.G; rng)
3535
num_controls = length(H.control_deriv_ops)
3636
grad_states = [random_state(H.G; rng) for i eachindex(H.control_deriv_ops)]

src/linalg.jl

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,12 @@ end
183183
@inline function convert_gradgen_to_dense!(G_full, G::GradGenerator)
184184
N = size(G.G)[1]
185185
L = length(G.control_derivs)
186-
@inbounds for i = 1:L+1
187-
G_full[(i-1)*N+1:i*N, (i-1)*N+1:i*N] .= G.G
186+
@inbounds for i = 1:(L+1)
187+
G_full[((i-1)*N+1):(i*N), ((i-1)*N+1):(i*N)] .= G.G
188188
end
189189
# Set the control-derivatives in the last (block-)column
190190
@inbounds for i = 1:L
191-
G_full[(i-1)*N+1:i*N, L*N+1:(L+1)*N] .= G.control_derivs[i]
191+
G_full[((i-1)*N+1):(i*N), (L*N+1):((L+1)*N)] .= G.control_derivs[i]
192192
end
193193
return G_full
194194
end
@@ -206,9 +206,9 @@ end
206206
N = length.state)
207207
L = length.grad_states)
208208
@inbounds for i = 1:L
209-
Ψ_full[(i-1)*N+1:i*N] .= Ψ.grad_states[i]
209+
Ψ_full[((i-1)*N+1):(i*N)] .= Ψ.grad_states[i]
210210
end
211-
@inbounds Ψ_full[L*N+1:(L+1)*N] .= Ψ.state
211+
@inbounds Ψ_full[(L*N+1):((L+1)*N)] .= Ψ.state
212212
return Ψ_full
213213
end
214214

@@ -217,9 +217,9 @@ end
217217
N = length.state)
218218
L = length.grad_states)
219219
@inbounds for i = 1:L
220-
Ψ.grad_states[i] .= Ψ_full[(i-1)*N+1:i*N]
220+
Ψ.grad_states[i] .= Ψ_full[((i-1)*N+1):(i*N)]
221221
end
222-
@inbounds Ψ.state .= Ψ_full[L*N+1:(L+1)*N]
222+
@inbounds Ψ.state .= Ψ_full[(L*N+1):((L+1)*N)]
223223
return Ψ
224224
end
225225

@@ -236,8 +236,8 @@ function Base.convert(
236236
L = num_controls
237237
N = length(vec) ÷ (L + 1) # dimension of state
238238
@assert length(vec) == (L + 1) * N
239-
grad_states = [convert(T, vec[(i-1)*N+1:i*N]) for i = 1:L]
240-
state = convert(T, vec[L*N+1:(L+1)*N])
239+
grad_states = [convert(T, vec[((i-1)*N+1):(i*N)]) for i = 1:L]
240+
state = convert(T, vec[(L*N+1):((L+1)*N)])
241241
return GradVector{num_controls,T}(state, grad_states)
242242
end
243243

@@ -247,8 +247,7 @@ function Base.Array{T}(G::GradgenOperator) where {T}
247247
𝟘 = zeros(T, N, M)
248248
μ = G.control_deriv_ops
249249
block_rows = [
250-
hcat([𝟘 for j = 1:i-1]..., Array{T}(G.G), [𝟘 for j = i+1:L]..., Array{T}(μ[i]))
251-
for i = 1:L
250+
hcat([𝟘 for j = 1:(i-1)]..., Array{T}(G.G), [𝟘 for j = (i+1):L]..., Array{T}(μ[i])) for i = 1:L
252251
]
253252
last_block_row = hcat([𝟘 for j = 1:L]..., Array{T}(G.G))
254253
return Base.Array{T}(vcat(block_rows..., last_block_row))

test/clean.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
Clean up build/doc/testing artifacts. Restore to clean checkout state
55
(distclean)
66
"""
7-
function clean(; distclean=false, _exit=true)
7+
function clean(; distclean = false, _exit = true)
88

99
_glob(folder, ending) =
10-
[name for name in readdir(folder; join=true) if (name |> endswith(ending))]
10+
[name for name in readdir(folder; join = true) if (name |> endswith(ending))]
1111
_exists(name) = isfile(name) || isdir(name)
1212
_push!(lst, name) = _exists(name) && push!(lst, name)
1313

@@ -33,12 +33,12 @@ function clean(; distclean=false, _exit=true)
3333

3434
for name in CLEAN
3535
@info "rm $name"
36-
rm(name, force=true, recursive=true)
36+
rm(name, force = true, recursive = true)
3737
end
3838
if distclean
3939
for name in DISTCLEAN
4040
@info "rm $name"
41-
rm(name, force=true, recursive=true)
41+
rm(name, force = true, recursive = true)
4242
end
4343
if _exit
4444
@info "Exiting"
@@ -48,4 +48,4 @@ function clean(; distclean=false, _exit=true)
4848

4949
end
5050

51-
distclean() = clean(distclean=true)
51+
distclean() = clean(distclean = true)

test/test_gradgen.jl

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ using QuantumPropagators.Controls: evaluate
8989

9090
Ψ̃_out_full = exp(-𝕚 * G̃_full * dt) * Ψ̃_full
9191
# propagation correct?
92-
@test norm(Ψ̃_out_full[2N+1:3N] - Û_Ψ) < 1e-10
92+
@test norm(Ψ̃_out_full[(2N+1):3N] - Û_Ψ) < 1e-10
9393

9494
# do we get the same results as from newton?
95-
@test norm(Ψ̃_out_full[2N+1:3N] - Ψ̃_out.state) < 1e-10
95+
@test norm(Ψ̃_out_full[(2N+1):3N] - Ψ̃_out.state) < 1e-10
9696
@test norm(Ψ̃_out_full[1:N] - Ψ̃_out.grad_states[1]) < 1e-10
97-
@test norm(Ψ̃_out_full[N+1:2N] - Ψ̃_out.grad_states[2]) < 1e-10
97+
@test norm(Ψ̃_out_full[(N+1):2N] - Ψ̃_out.grad_states[2]) < 1e-10
9898

9999
###########################################################################
100100
# Test custom expprop
@@ -111,12 +111,12 @@ using QuantumPropagators.Controls: evaluate
111111

112112
Ψ̃_out_full = exp(-𝕚 * G̃_full * dt) * Ψ̃_full
113113
# propagation correct?
114-
@test norm(Ψ̃_out_full[2N+1:3N] - Û_Ψ) < 1e-10
114+
@test norm(Ψ̃_out_full[(2N+1):3N] - Û_Ψ) < 1e-10
115115

116116
# do we get the same results as from newton?
117-
@test norm(Ψ̃_out_full[2N+1:3N] - Ψ̃_out.state) < 1e-10
117+
@test norm(Ψ̃_out_full[(2N+1):3N] - Ψ̃_out.state) < 1e-10
118118
@test norm(Ψ̃_out_full[1:N] - Ψ̃_out.grad_states[1]) < 1e-10
119-
@test norm(Ψ̃_out_full[N+1:2N] - Ψ̃_out.grad_states[2]) < 1e-10
119+
@test norm(Ψ̃_out_full[(N+1):2N] - Ψ̃_out.grad_states[2]) < 1e-10
120120

121121
###########################################################################
122122
# Test standard expprop
@@ -125,10 +125,10 @@ using QuantumPropagators.Controls: evaluate
125125
Ψ̃,
126126
G̃,
127127
[0, dt];
128-
method=:expprop,
129-
inplace=true,
130-
convert_state=Vector{ComplexF64},
131-
convert_operator=Matrix{ComplexF64}
128+
method = :expprop,
129+
inplace = true,
130+
convert_state = Vector{ComplexF64},
131+
convert_operator = Matrix{ComplexF64}
132132
)
133133
Ψ̃_out_exp = prop_step!(propagator)
134134
@test norm(Ψ̃_out_exp - Ψ̃_out) < 1e-11
@@ -162,14 +162,14 @@ using QuantumPropagators.Controls: evaluate
162162
Ψ̃_out_full2 = exp(-𝕚 * G̃_full2 * dt) * Ψ̃_full2
163163

164164
# propagation correct?
165-
@test norm(Ψ̃_out_full1[N+1:2N] - Û_Ψ) < 1e-12
166-
@test norm(Ψ̃_out_full2[N+1:2N] - Û_Ψ) < 1e-12
165+
@test norm(Ψ̃_out_full1[(N+1):2N] - Û_Ψ) < 1e-12
166+
@test norm(Ψ̃_out_full2[(N+1):2N] - Û_Ψ) < 1e-12
167167

168168
# do we get the same results as with the combined grad-gen?
169169
@test norm(Ψ̃_out_full1[1:N] - Ψ̃_out_full[1:N]) < 1e-12
170-
@test norm(Ψ̃_out_full2[1:N] - Ψ̃_out_full[N+1:2N]) < 1e-12
171-
@test norm(Ψ̃_out_full1[N+1:2N] - Ψ̃_out_full[2N+1:3N]) < 1e-12
172-
@test norm(Ψ̃_out_full2[N+1:2N] - Ψ̃_out_full[2N+1:3N]) < 1e-12
170+
@test norm(Ψ̃_out_full2[1:N] - Ψ̃_out_full[(N+1):2N]) < 1e-12
171+
@test norm(Ψ̃_out_full1[(N+1):2N] - Ψ̃_out_full[(2N+1):3N]) < 1e-12
172+
@test norm(Ψ̃_out_full2[(N+1):2N] - Ψ̃_out_full[(2N+1):3N]) < 1e-12
173173

174174
###########################################################################
175175
# Compare against Zygote

test/test_interface.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,42 +36,42 @@ end
3636
@testset "GradGenerator Interface" begin
3737

3838
N = 10
39-
Ĥ₀ = random_matrix(N, hermitian=true)
40-
Ĥ₁ = random_matrix(N, hermitian=true)
41-
Ĥ₂ = random_matrix(N, hermitian=true)
39+
Ĥ₀ = random_matrix(N, hermitian = true)
40+
Ĥ₁ = random_matrix(N, hermitian = true)
41+
Ĥ₂ = random_matrix(N, hermitian = true)
4242
ϵ₁(t) = 1.0
4343
ϵ₂(t) = 1.0
4444
Ĥ_of_t = hamiltonian(Ĥ₀, (Ĥ₁, ϵ₁), (Ĥ₂, ϵ₂))
4545

46-
tlist = collect(range(0, 10; length=101))
46+
tlist = collect(range(0, 10; length = 101))
4747

4848
G̃_of_t = GradGenerator(Ĥ_of_t)
4949

5050
Ψ = random_state_vector(N)
5151
Ψ̃ = GradVector(Ψ, length(get_controls(G̃_of_t)))
5252

53-
@test check_generator(G̃_of_t; state=Ψ̃, tlist, for_gradient_optimization=false)
53+
@test check_generator(G̃_of_t; state = Ψ̃, tlist, for_gradient_optimization = false)
5454

5555
end
5656

5757

5858
@testset "GradGenerator Interface (Static)" begin
5959

6060
N = 10
61-
Ĥ₀ = SMatrix{N,N,ComplexF64}(random_matrix(N, hermitian=true))
62-
Ĥ₁ = SMatrix{N,N,ComplexF64}(random_matrix(N, hermitian=true))
63-
Ĥ₂ = SMatrix{N,N,ComplexF64}(random_matrix(N, hermitian=true))
61+
Ĥ₀ = SMatrix{N,N,ComplexF64}(random_matrix(N, hermitian = true))
62+
Ĥ₁ = SMatrix{N,N,ComplexF64}(random_matrix(N, hermitian = true))
63+
Ĥ₂ = SMatrix{N,N,ComplexF64}(random_matrix(N, hermitian = true))
6464
ϵ₁(t) = 1.0
6565
ϵ₂(t) = 1.0
6666
Ĥ_of_t = hamiltonian(Ĥ₀, (Ĥ₁, ϵ₁), (Ĥ₂, ϵ₂))
6767

68-
tlist = collect(range(0, 10; length=101))
68+
tlist = collect(range(0, 10; length = 101))
6969

7070
G̃_of_t = GradGenerator(Ĥ_of_t)
7171

7272
Ψ = SVector{N,ComplexF64}(random_state_vector(N))
7373
Ψ̃ = GradVector(Ψ, length(get_controls(G̃_of_t)))
7474

75-
@test check_generator(G̃_of_t; state=Ψ̃, tlist, for_gradient_optimization=false)
75+
@test check_generator(G̃_of_t; state = Ψ̃, tlist, for_gradient_optimization = false)
7676

7777
end

test/test_specrad.jl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ using QuantumPropagators.Controls: evaluate
1010

1111
N = 10 # size of Hilbert space
1212
ρ = 1.0 # spectral radius
13-
Ĥ₀ = random_matrix(N; hermitian=true, spectral_radius=ρ)
14-
Ĥ₁ = random_matrix(N; hermitian=true, spectral_radius=ρ)
15-
Ĥ₂ = random_matrix(N; hermitian=true, spectral_radius=ρ)
13+
Ĥ₀ = random_matrix(N; hermitian = true, spectral_radius = ρ)
14+
Ĥ₁ = random_matrix(N; hermitian = true, spectral_radius = ρ)
15+
Ĥ₂ = random_matrix(N; hermitian = true, spectral_radius = ρ)
1616
Zero = zeros(ComplexF64, N, N)
1717
ϵ₁ = t -> 1.0
1818
ϵ₂ = t -> 1.0
@@ -43,14 +43,14 @@ using QuantumPropagators.Controls: evaluate
4343
@test abs(H_E_min - G_E_min) < 1e-12
4444
@test abs(H_E_max - G_E_max) < 1e-12
4545

46-
G_range_diag = collect(specrange(G̃, method=:diag))
46+
G_range_diag = collect(specrange(G̃, method = :diag))
4747
@test eltype(G_range_diag) Float64
4848
@test norm(G_range_diag - [G_E_min, G_E_max]) < 1e-12
4949

50-
H_range_diag = collect(specrange(Ĥ, method=:diag))
50+
H_range_diag = collect(specrange(Ĥ, method = :diag))
5151
@test norm(H_range_diag - G_range_diag) < 1e-12
5252

53-
G_range_arnoldi = collect(specrange(G̃, method=:arnoldi, m_max=100))
53+
G_range_arnoldi = collect(specrange(G̃, method = :arnoldi, m_max = 100))
5454
@test eltype(G_range_arnoldi) Float64
5555
@test norm(G_range_arnoldi - [H_E_min, H_E_max]) < 1e-2
5656
# `specrange(Ĥ, method=:arnoldi)` isn't very exact, so we don't
@@ -63,9 +63,9 @@ end
6363
N = 100 # size of Hilbert space
6464
ρ = 1.0 # spectral radius
6565
density = 0.1
66-
Ĥ₀ = random_matrix(N; hermitian=true, spectral_radius=ρ, density)
67-
Ĥ₁ = random_matrix(N; hermitian=true, spectral_radius=ρ, density)
68-
Ĥ₂ = random_matrix(N; hermitian=true, spectral_radius=ρ, density)
66+
Ĥ₀ = random_matrix(N; hermitian = true, spectral_radius = ρ, density)
67+
Ĥ₁ = random_matrix(N; hermitian = true, spectral_radius = ρ, density)
68+
Ĥ₂ = random_matrix(N; hermitian = true, spectral_radius = ρ, density)
6969
Zero = zeros(ComplexF64, N, N)
7070
ϵ₁ = t -> 1.0
7171
ϵ₂ = t -> 1.0
@@ -97,11 +97,11 @@ end
9797
@test abs(H_E_min - G_E_min) < 1e-12
9898
@test abs(H_E_max - G_E_max) < 1e-12
9999

100-
G_range_diag = collect(specrange(G̃, method=:diag))
100+
G_range_diag = collect(specrange(G̃, method = :diag))
101101
@test eltype(G_range_diag) Float64
102102
@test norm(G_range_diag - [G_E_min, G_E_max]) < 1e-12
103103

104-
G_range_arnoldi = collect(specrange(G̃, method=:arnoldi, m_max=100))
104+
G_range_arnoldi = collect(specrange(G̃, method = :arnoldi, m_max = 100))
105105
@test eltype(G_range_arnoldi) Float64
106106
@test norm(G_range_arnoldi - [G_E_min, G_E_max]) < 0.2
107107

0 commit comments

Comments
 (0)