Skip to content

Commit 935d6a2

Browse files
committed
format remaining things
1 parent feaad18 commit 935d6a2

File tree

11 files changed

+364
-279
lines changed

11 files changed

+364
-279
lines changed

docs/make.jl

Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
if Base.active_project() != joinpath(@__DIR__, "Project.toml")
33
using Pkg
44
Pkg.activate(@__DIR__)
5-
Pkg.develop(PackageSpec(; path=(@__DIR__) * "/../"))
5+
Pkg.develop(PackageSpec(; path = (@__DIR__) * "/../"))
66
Pkg.resolve()
77
Pkg.instantiate()
88
end
@@ -23,41 +23,55 @@ end
2323

2424
# bibliography
2525
bibpath = joinpath(@__DIR__, "src", "assets", "mpskit.bib")
26-
bib = CitationBibliography(bibpath; style=:authoryear)
26+
bib = CitationBibliography(bibpath; style = :authoryear)
2727

2828
# interlinks
29-
links = InterLinks("TensorKit" => "https://jutho.github.io/TensorKit.jl/stable/",
30-
"TensorOperations" => "https://jutho.github.io/TensorOperations.jl/stable/",
31-
"KrylovKit" => "https://jutho.github.io/KrylovKit.jl/stable/",
32-
"BlockTensorKit" => "https://lkdvos.github.io/BlockTensorKit.jl/dev/")
29+
links = InterLinks(
30+
"TensorKit" => "https://jutho.github.io/TensorKit.jl/stable/",
31+
"TensorOperations" => "https://jutho.github.io/TensorOperations.jl/stable/",
32+
"KrylovKit" => "https://jutho.github.io/KrylovKit.jl/stable/",
33+
"BlockTensorKit" => "https://lkdvos.github.io/BlockTensorKit.jl/dev/"
34+
)
3335

3436
# include MPSKit in all doctests
35-
DocMeta.setdocmeta!(MPSKit, :DocTestSetup, :(using MPSKit, TensorKit); recursive=true)
37+
DocMeta.setdocmeta!(MPSKit, :DocTestSetup, :(using MPSKit, TensorKit); recursive = true)
3638

37-
mathengine = MathJax3(Dict(:loader => Dict("load" => ["[tex]/physics"]),
38-
:tex => Dict("inlineMath" => [["\$", "\$"], ["\\(", "\\)"]],
39-
"tags" => "ams",
40-
"packages" => ["base", "ams", "autoload", "physics"])))
39+
mathengine = MathJax3(
40+
Dict(
41+
:loader => Dict("load" => ["[tex]/physics"]),
42+
:tex => Dict(
43+
"inlineMath" => [["\$", "\$"], ["\\(", "\\)"]],
44+
"tags" => "ams",
45+
"packages" => ["base", "ams", "autoload", "physics"]
46+
)
47+
)
48+
)
4149
makedocs(;
42-
sitename="MPSKit.jl",
43-
format=Documenter.HTML(;
44-
prettyurls=true,
45-
mathengine,
46-
assets=["assets/custom.css"],
47-
size_threshold=1024000,),
48-
pages=["Home" => "index.md",
49-
"Manual" => ["man/intro.md",
50-
"man/states.md",
51-
"man/operators.md",
52-
"man/algorithms.md",
53-
# "man/environments.md",
54-
"man/parallelism.md",
55-
"man/lattices.md"],
56-
"Examples" => "examples/index.md",
57-
"Library" => "lib/lib.md",
58-
"References" => "references.md"],
59-
checkdocs=:exports,
60-
doctest=true,
61-
plugins=[bib, links])
50+
sitename = "MPSKit.jl",
51+
format = Documenter.HTML(;
52+
prettyurls = true,
53+
mathengine,
54+
assets = ["assets/custom.css"],
55+
size_threshold = 1024000,
56+
),
57+
pages = [
58+
"Home" => "index.md",
59+
"Manual" => [
60+
"man/intro.md",
61+
"man/states.md",
62+
"man/operators.md",
63+
"man/algorithms.md",
64+
# "man/environments.md",
65+
"man/parallelism.md",
66+
"man/lattices.md",
67+
],
68+
"Examples" => "examples/index.md",
69+
"Library" => "lib/lib.md",
70+
"References" => "references.md",
71+
],
72+
checkdocs = :exports,
73+
doctest = true,
74+
plugins = [bib, links]
75+
)
6276

63-
deploydocs(; repo="github.com/QuantumKitHub/MPSKit.jl.git", push_preview=true)
77+
deploydocs(; repo = "github.com/QuantumKitHub/MPSKit.jl.git", push_preview = true)

examples/classic2d/1.hard-hexagon/main.jl

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function virtual_space(D::Integer)
2525
return Vect[FibonacciAnyon](sector => _D for sector in (:I, ))
2626
end
2727

28-
@assert isapprox(dim(virtual_space(100)), 100; atol=3)
28+
@assert isapprox(dim(virtual_space(100)), 100; atol = 3)
2929

3030
md"""
3131
## The leading boundary
@@ -39,10 +39,10 @@ Additionally, we can compute the entanglement entropy as well as the correlation
3939
D = 10
4040
V = virtual_space(D)
4141
ψ₀ = InfiniteMPS([P], [V])
42-
ψ, envs, = leading_boundary(ψ₀, mpo,
43-
VUMPS(; verbosity=0,
44-
alg_eigsolve=MPSKit.Defaults.alg_eigsolve(;
45-
ishermitian=false))) # use non-hermitian eigensolver
42+
ψ, envs, = leading_boundary(
43+
ψ₀, mpo,
44+
VUMPS(; verbosity = 0, alg_eigsolve = MPSKit.Defaults.alg_eigsolve(; ishermitian = false))
45+
) # use non-hermitian eigensolver
4646
F = real(expectation_value(ψ, mpo))
4747
S = real(first(entropy(ψ)))
4848
ξ = correlation_length(ψ)
@@ -57,8 +57,10 @@ First we need to know the entropy and correlation length at a bunch of different
5757
According to the scaling hypothesis we should have ``S \propto \frac{c}{6} log(ξ)``. Therefore we should find ``c`` using
5858
"""
5959

60-
function scaling_simulations(ψ₀, mpo, Ds; verbosity=0, tol=1e-6,
61-
alg_eigsolve=MPSKit.Defaults.alg_eigsolve(; ishermitian=false))
60+
function scaling_simulations(
61+
ψ₀, mpo, Ds; verbosity = 0, tol = 1.0e-6,
62+
alg_eigsolve = MPSKit.Defaults.alg_eigsolve(; ishermitian = false)
63+
)
6264
entropies = similar(Ds, Float64)
6365
correlations = similar(Ds, Float64)
6466
alg = VUMPS(; verbosity, tol, alg_eigsolve)
@@ -68,7 +70,7 @@ function scaling_simulations(ψ₀, mpo, Ds; verbosity=0, tol=1e-6,
6870
correlations[1] = correlation_length(ψ)
6971

7072
for (i, d) in enumerate(diff(Ds))
71-
ψ, envs = changebonds(ψ, mpo, OptimalExpand(; trscheme=truncdim(d)), envs)
73+
ψ, envs = changebonds(ψ, mpo, OptimalExpand(; trscheme = truncdim(d)), envs)
7274
ψ, envs, = leading_boundary(ψ, mpo, alg, envs)
7375
entropies[i + 1] = real(entropy(ψ)[1])
7476
correlations[i + 1] = correlation_length(ψ)
@@ -83,8 +85,8 @@ Ss, ξs = scaling_simulations(ψ₀, mpo, bond_dimensions)
8385
f = fit(log.(ξs), 6 * Ss, 1)
8486
c = f.coeffs[2]
8587

86-
#+
88+
#+
8789

88-
p = plot(; xlabel="logarithmic correlation length", ylabel="entanglement entropy")
89-
p = plot(log.(ξs), Ss; seriestype=:scatter, label=nothing)
90-
plot!(p, ξ -> f(ξ) / 6; label="fit")
90+
p = plot(; xlabel = "logarithmic correlation length", ylabel = "entanglement entropy")
91+
p = plot(log.(ξs), Ss; seriestype = :scatter, label = nothing)
92+
plot!(p, ξ -> f(ξ) / 6; label = "fit")

examples/make.jl

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
if Base.active_project() != joinpath(@__DIR__, "Project.toml")
33
using Pkg
44
Pkg.activate(@__DIR__)
5-
Pkg.develop(PackageSpec(; path=(@__DIR__) * "/../"))
5+
Pkg.develop(PackageSpec(; path = (@__DIR__) * "/../"))
66
Pkg.resolve()
77
Pkg.instantiate()
88
end
@@ -17,21 +17,21 @@ using TOML, SHA
1717

1818
const CACHEFILE = joinpath(@__DIR__, "Cache.toml")
1919

20-
getcache() = isfile(CACHEFILE) ? TOML.parsefile(CACHEFILE) : Dict{String,Any}()
20+
getcache() = isfile(CACHEFILE) ? TOML.parsefile(CACHEFILE) : Dict{String, Any}()
2121

2222
function iscached(root, name)
2323
cache = getcache()
2424
return haskey(cache, root) &&
25-
haskey(cache[root], name) &&
26-
cache[root][name] == checksum(root, name)
25+
haskey(cache[root], name) &&
26+
cache[root][name] == checksum(root, name)
2727
end
2828

2929
function setcached(root, name)
3030
cache = getcache()
3131
if haskey(cache, root)
3232
cache[root][name] = checksum(root, name)
3333
else
34-
cache[root] = Dict{String,Any}(name => checksum(root, name))
34+
cache[root] = Dict{String, Any}(name => checksum(root, name))
3535
end
3636
return open(f -> TOML.print(f, cache), CACHEFILE, "w")
3737
end
@@ -68,19 +68,23 @@ function build_example(root, name)
6868
source_file = joinpath(source_dir, "main.jl")
6969
target_dir = joinpath(@__DIR__, "..", "docs", "src", "examples", root, name)
7070

71-
if !iscached(root, name)
72-
Literate.markdown(source_file, target_dir; execute=true, name="index",
73-
preprocess=attach_notebook_badge(root, name), mdstrings=true,
74-
nbviewer_root_url="https://nbviewer.jupyter.org/github/QuantumKitHub/MPSKit.jl/blob/gh-pages/dev",
75-
binder_root_url="https://mybinder.org/v2/gh/QuantumKitHub/MPSKit.jl/gh-pages?filepath=dev",
76-
credits=false,
77-
repo_root_url="https://github.com/QuantumKitHub/MPSKit.jl")
78-
Literate.notebook(source_file, target_dir; execute=false, name="main",
79-
preprocess=str -> replace(str, r"(?<!`)``(?!`)" => "\$"),
80-
mdstrings=true, credits=false)
71+
return if !iscached(root, name)
72+
Literate.markdown(
73+
source_file, target_dir; execute = true, name = "index",
74+
preprocess = attach_notebook_badge(root, name), mdstrings = true,
75+
nbviewer_root_url = "https://nbviewer.jupyter.org/github/QuantumKitHub/MPSKit.jl/blob/gh-pages/dev",
76+
binder_root_url = "https://mybinder.org/v2/gh/QuantumKitHub/MPSKit.jl/gh-pages?filepath=dev",
77+
credits = false,
78+
repo_root_url = "https://github.com/QuantumKitHub/MPSKit.jl"
79+
)
80+
Literate.notebook(
81+
source_file, target_dir; execute = false, name = "main",
82+
preprocess = str -> replace(str, r"(?<!`)``(?!`)" => "\$"),
83+
mdstrings = true, credits = false
84+
)
8185

8286
foreach(filter(!=("main.jl"), readdir(source_dir))) do f
83-
return cp(joinpath(source_dir, f), joinpath(target_dir, f); force=true)
87+
return cp(joinpath(source_dir, f), joinpath(target_dir, f); force = true)
8488
end
8589
setcached(root, name)
8690
end

examples/quantum1d/1.ising-cft/main.jl

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,11 @@ tensor is equivalent to optimixing a state in the entire Hilbert space, as all o
2727
are just unitary matrices that mix the basis.
2828
"""
2929

30-
energies, states = exact_diagonalization(H; num=18, alg=Lanczos(; krylovdim=200));
31-
plot(real.(energies);
32-
seriestype=:scatter,
33-
legend=false,
34-
ylabel="energy",
35-
xlabel="#eigenvalue")
30+
energies, states = exact_diagonalization(H; num = 18, alg = Lanczos(; krylovdim = 200));
31+
plot(
32+
real.(energies);
33+
seriestype = :scatter, legend = false, ylabel = "energy", xlabel = "#eigenvalue"
34+
)
3635

3736
md"""
3837
!!! note "Krylov dimension"
@@ -104,11 +103,13 @@ v = 2.0
104103
Δ = real.(energies[1:18] .- energies[1]) ./ (2π * v / L)
105104
S = momenta ./ (2π / L)
106105

107-
p = plot(S, real.(Δ);
108-
seriestype=:scatter, xlabel="conformal spin (S)", ylabel="scaling dimension (Δ)",
109-
legend=false)
110-
vline!(p, -3:3; color="gray", linestyle=:dash)
111-
hline!(p, [0, 1 / 8, 1, 9 / 8, 2, 17 / 8]; color="gray", linestyle=:dash)
106+
p = plot(
107+
S, real.(Δ);
108+
seriestype = :scatter, xlabel = "conformal spin (S)", ylabel = "scaling dimension (Δ)",
109+
legend = false
110+
)
111+
vline!(p, -3:3; color = "gray", linestyle = :dash)
112+
hline!(p, [0, 1 / 8, 1, 9 / 8, 2, 17 / 8]; color = "gray", linestyle = :dash)
112113
p
113114

114115
md"""
@@ -129,7 +130,7 @@ ansatz. This returns quasiparticle states, which can be converted to regular `Fi
129130
objects.
130131
"""
131132

132-
E_ex, qps = excitations(H_mps, QuasiparticleAnsatz(), ψ, envs; num=18)
133+
E_ex, qps = excitations(H_mps, QuasiparticleAnsatz(), ψ, envs; num = 18)
133134
states_mps = vcat(ψ, map(qp -> convert(FiniteMPS, qp), qps))
134135
energies_mps = map(x -> expectation_value(x, H_mps), states_mps)
135136

@@ -148,9 +149,11 @@ v = 2.0
148149
Δ_mps = real.(energies_mps[1:18] .- energies_mps[1]) ./ (2π * v / L_mps)
149150
S_mps = momenta_mps ./ (2π / L_mps)
150151

151-
p_mps = plot(S_mps, real.(Δ_mps);
152-
seriestype=:scatter, xlabel="conformal spin (S)",
153-
ylabel="scaling dimension (Δ)", legend=false)
154-
vline!(p_mps, -3:3; color="gray", linestyle=:dash)
155-
hline!(p_mps, [0, 1 / 8, 1, 9 / 8, 2, 17 / 8]; color="gray", linestyle=:dash)
152+
p_mps = plot(
153+
S_mps, real.(Δ_mps);
154+
seriestype = :scatter, xlabel = "conformal spin (S)",
155+
ylabel = "scaling dimension (Δ)", legend = false
156+
)
157+
vline!(p_mps, -3:3; color = "gray", linestyle = :dash)
158+
hline!(p_mps, [0, 1 / 8, 1, 9 / 8, 2, 17 / 8]; color = "gray", linestyle = :dash)
156159
p_mps

examples/quantum1d/2.haldane/main.jl

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,26 @@ H = heisenberg_XXX(symmetry, chain; J, spin)
4242
physical_space = SU2Space(1 => 1)
4343
virtual_space = SU2Space(0 => 12, 1 => 12, 2 => 5, 3 => 3)
4444
ψ₀ = FiniteMPS(L, physical_space, virtual_space)
45-
ψ, envs, delta = find_groundstate(ψ₀, H, DMRG(; verbosity=0))
45+
ψ, envs, delta = find_groundstate(ψ₀, H, DMRG(; verbosity = 0))
4646
E₀ = real(expectation_value(ψ, H))
47-
En_1, st_1 = excitations(H, QuasiparticleAnsatz(), ψ, envs; sector=SU2Irrep(1))
48-
En_2, st_2 = excitations(H, QuasiparticleAnsatz(), ψ, envs; sector=SU2Irrep(2))
47+
En_1, st_1 = excitations(H, QuasiparticleAnsatz(), ψ, envs; sector = SU2Irrep(1))
48+
En_2, st_2 = excitations(H, QuasiparticleAnsatz(), ψ, envs; sector = SU2Irrep(2))
4949
ΔE_finite = real(En_2[1] - En_1[1])
5050

5151
md"""
5252
We can go even further and doublecheck the claim that ``S = 1`` is an edge excitation, by plotting the energy density.
5353
"""
5454

55-
p_density = plot(; xaxis="position", yaxis="energy density")
55+
p_density = plot(; xaxis = "position", yaxis = "energy density")
5656
excited_1 = convert(FiniteMPS, st_1[1])
5757
excited_2 = convert(FiniteMPS, st_2[1])
58-
SS = -S_exchange(ComplexF64, SU2Irrep; spin=1)
58+
SS = -S_exchange(ComplexF64, SU2Irrep; spin = 1)
5959
e₀ = [real(expectation_value(ψ, (i, i + 1) => SS)) for i in 1:(L - 1)]
6060
e₁ = [real(expectation_value(excited_1, (i, i + 1) => SS)) for i in 1:(L - 1)]
6161
e₂ = [real(expectation_value(excited_2, (i, i + 1) => SS)) for i in 1:(L - 1)]
62-
plot!(p_density, e₀; label="S = 0")
63-
plot!(p_density, e₁; label="S = 1")
64-
plot!(p_density, e₂; label="S = 2")
62+
plot!(p_density, e₀; label = "S = 0")
63+
plot!(p_density, e₁; label = "S = 1")
64+
plot!(p_density, e₂; label = "S = 2")
6565

6666
md"""
6767
Finally, we can obtain a value for the Haldane gap by extrapolating our results for different system sizes.
@@ -72,20 +72,20 @@ Ls = 12:4:30
7272
@info "computing L = $L"
7373
ψ₀ = FiniteMPS(L, physical_space, virtual_space)
7474
H = heisenberg_XXX(symmetry, FiniteChain(L); J, spin)
75-
ψ, envs, delta = find_groundstate(ψ₀, H, DMRG(; verbosity=0))
76-
En_1, st_1 = excitations(H, QuasiparticleAnsatz(), ψ, envs; sector=SU2Irrep(1))
77-
En_2, st_2 = excitations(H, QuasiparticleAnsatz(), ψ, envs; sector=SU2Irrep(2))
75+
ψ, envs, delta = find_groundstate(ψ₀, H, DMRG(; verbosity = 0))
76+
En_1, st_1 = excitations(H, QuasiparticleAnsatz(), ψ, envs; sector = SU2Irrep(1))
77+
En_2, st_2 = excitations(H, QuasiparticleAnsatz(), ψ, envs; sector = SU2Irrep(2))
7878
return real(En_2[1] - En_1[1])
7979
end
8080

8181
f = fit(Ls .^ (-2), ΔEs, 1)
8282
ΔE_extrapolated = f.coeffs[1]
8383

84-
#+
84+
#+
8585

86-
p_size_extrapolation = plot(; xaxis="L^(-2)", yaxis="ΔE", xlims=(0, 0.015))
87-
plot!(p_size_extrapolation, Ls .^ (-2), ΔEs; seriestype=:scatter, label="numerical")
88-
plot!(p_size_extrapolation, x -> f(x); label="fit")
86+
p_size_extrapolation = plot(; xaxis = "L^(-2)", yaxis = "ΔE", xlims = (0, 0.015))
87+
plot!(p_size_extrapolation, Ls .^ (-2), ΔEs; seriestype = :scatter, label = "numerical")
88+
plot!(p_size_extrapolation, x -> f(x); label = "fit")
8989

9090
md"""
9191
## Thermodynamic limit
@@ -103,14 +103,14 @@ chain = InfiniteChain(1)
103103
H = heisenberg_XXX(symmetry, chain; J, spin)
104104
virtual_space_inf = Rep[SU₂](1 // 2 => 16, 3 // 2 => 16, 5 // 2 => 8, 7 // 2 => 4)
105105
ψ₀_inf = InfiniteMPS([physical_space], [virtual_space_inf])
106-
ψ_inf, envs_inf, delta_inf = find_groundstate(ψ₀_inf, H; verbosity=0)
106+
ψ_inf, envs_inf, delta_inf = find_groundstate(ψ₀_inf, H; verbosity = 0)
107107

108108
kspace = range(0, π, 16)
109-
Es, _ = excitations(H, QuasiparticleAnsatz(), kspace, ψ_inf, envs_inf; sector=SU2Irrep(1))
109+
Es, _ = excitations(H, QuasiparticleAnsatz(), kspace, ψ_inf, envs_inf; sector = SU2Irrep(1))
110110

111111
ΔE, idx = findmin(real.(Es))
112112
println("minimum @k = $(kspace[idx]):\t ΔE = $(ΔE)")
113113

114-
#+
114+
#+
115115

116-
plot(kspace, real.(Es); xaxis="momentum", yaxis="ΔE", label="S = 1")
116+
plot(kspace, real.(Es); xaxis = "momentum", yaxis = "ΔE", label = "S = 1")

0 commit comments

Comments
 (0)