Skip to content

Commit 72820fb

Browse files
authored
Runic formatter (#303)
* Format algorithms * format environments * format operators * format states * format transfer * format utility * Update formatter workflow * format tests * format remaining things * small refactor to bypass runic issue * Fix missing function
1 parent bac4fbd commit 72820fb

File tree

91 files changed

+4029
-3621
lines changed

Some content is hidden

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

91 files changed

+4029
-3621
lines changed

.github/workflows/Format.yml

Lines changed: 0 additions & 8 deletions
This file was deleted.

.github/workflows/FormatCheck.yml

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,15 @@ name: FormatCheck
33
on:
44
push:
55
branches:
6+
- 'main'
67
- 'master'
78
tags: '*'
89
pull_request:
910
branches:
11+
- 'main'
1012
- 'master'
11-
jobs:
12-
build:
13-
runs-on: ${{ matrix.os }}
14-
strategy:
15-
matrix:
16-
version:
17-
- '1' # automatically expands to the latest stable 1.x release of Julia
18-
os:
19-
- ubuntu-latest
20-
arch:
21-
- x64
22-
steps:
23-
- uses: julia-actions/setup-julia@latest
24-
with:
25-
version: ${{ matrix.version }}
26-
arch: ${{ matrix.arch }}
2713

28-
- uses: actions/checkout@v4
29-
- name: Install JuliaFormatter and format
30-
run: |
31-
julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter"))'
32-
julia -e 'using JuliaFormatter; format(".", verbose=true)'
14+
jobs:
15+
formatcheck:
16+
name: "Format Check"
17+
uses: "QuantumKitHub/QuantumKitHubActions/.github/workflows/FormatCheck.yml@main"

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

0 commit comments

Comments
 (0)