Skip to content

Commit

Permalink
Format yas style
Browse files Browse the repository at this point in the history
  • Loading branch information
lkdvos committed Dec 1, 2023
1 parent e8659ce commit bd3f830
Show file tree
Hide file tree
Showing 62 changed files with 4,011 additions and 5,275 deletions.
2 changes: 1 addition & 1 deletion .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
style = "blue"
style = "yas"
51 changes: 20 additions & 31 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,26 @@ end
# include MPSKit in all doctests
DocMeta.setdocmeta!(MPSKit, :DocTestSetup, :(using MPSKit); recursive=true)

mathengine = MathJax3(Dict(:loader => Dict("load" => ["[tex]/physics"]),
:tex => Dict("inlineMath" => [["\$", "\$"], ["\\(", "\\)"]],
"tags" => "ams",
"packages" => ["base", "ams", "autoload", "physics"])))
makedocs(;
modules=[MPSKit],
sitename="MPSKit.jl",
format=Documenter.HTML(;
prettyurls=get(ENV, "CI", nothing) == "true",
mathengine=MathJax3(
Dict(
:loader => Dict("load" => ["[tex]/physics"]),
:tex => Dict(
"inlineMath" => [["\$", "\$"], ["\\(", "\\)"]],
"tags" => "ams",
"packages" => ["base", "ams", "autoload", "physics"],
),
),
),
size_threshold=512000,
),
pages=[
"Home" => "index.md",
"Manual" => [
"man/intro.md",
"man/states.md",
"man/operators.md",
"man/algorithms.md",
"man/environments.md",
"man/parallelism.md",
],
"Examples" => "examples/index.md",
"Library" => "lib/lib.md",
],
warnonly=true,
)
modules=[MPSKit],
sitename="MPSKit.jl",
format=Documenter.HTML(;
prettyurls=get(ENV, "CI", nothing) == "true",
mathengine,
size_threshold=512000),
pages=["Home" => "index.md",
"Manual" => ["man/intro.md",
"man/states.md",
"man/operators.md",
"man/algorithms.md",
"man/environments.md",
"man/parallelism.md"],
"Examples" => "examples/index.md",
"Library" => "lib/lib.md"],
warnonly=true)

deploydocs(; repo="github.com/maartenvd/MPSKit.jl.git")
32 changes: 10 additions & 22 deletions examples/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,30 +61,18 @@ function build_example(root, name)
target_dir = joinpath(@__DIR__, "..", "docs", "src", "examples", root, name)

if !iscached(root, name)
Literate.markdown(
source_file,
target_dir;
execute=true,
name="index",
preprocess=attach_notebook_badge(root, name),
mdstrings=true,
nbviewer_root_url="https://nbviewer.jupyter.org/github/maartenvd/MPSKit.jl/blob/gh-pages/dev",
binder_root_url="https://mybinder.org/v2/gh/maartenvd/MPSKit.jl/gh-pages?filepath=dev",
credits=false,
repo_root_url="https://github.com/maartenvd/MPSKit.jl",
)
Literate.notebook(
source_file,
target_dir;
execute=false,
name="main",
preprocess=str -> replace(str, r"(?<!`)``(?!`)" => "\$"),
mdstrings=true,
credits=false,
)
Literate.markdown(source_file, target_dir; execute=true, name="index",
preprocess=attach_notebook_badge(root, name), mdstrings=true,
nbviewer_root_url="https://nbviewer.jupyter.org/github/maartenvd/MPSKit.jl/blob/gh-pages/dev",
binder_root_url="https://mybinder.org/v2/gh/maartenvd/MPSKit.jl/gh-pages?filepath=dev",
credits=false,
repo_root_url="https://github.com/maartenvd/MPSKit.jl")
Literate.notebook(source_file, target_dir; execute=false, name="main",
preprocess=str -> replace(str, r"(?<!`)``(?!`)" => "\$"),
mdstrings=true, credits=false)

foreach(filter(!=("main.jl"), readdir(source_dir))) do f
cp(joinpath(source_dir, f), joinpath(target_dir, f); force=true)
return cp(joinpath(source_dir, f), joinpath(target_dir, f); force=true)
end
setcached(root, name)
end
Expand Down
40 changes: 17 additions & 23 deletions examples/quantum1d/1.ising-cft/main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@ are just unitary matrices that mix the basis.
"""

energies, states = exact_diagonalization(H; num=18, alg=Lanczos(; krylovdim=200));
plot(
real.(energies);
seriestype=:scatter,
legend=false,
ylabel="energy",
xlabel="#eigenvalue",
)
plot(real.(energies);
seriestype=:scatter,
legend=false,
ylabel="energy",
xlabel="#eigenvalue")

md"""
!!! note "Krylov dimension"
Expand Down Expand Up @@ -95,14 +93,12 @@ append!(momenta, fix_degeneracies(states[12:12]))
append!(momenta, fix_degeneracies(states[13:16]))
append!(momenta, fix_degeneracies(states[17:18]))

plot(
momenta,
real.(energies[1:18]);
seriestype=:scatter,
xlabel="momentum",
ylabel="energy",
legend=false,
)
plot(momenta,
real.(energies[1:18]);
seriestype=:scatter,
xlabel="momentum",
ylabel="energy",
legend=false)

md"""
## Finite bond dimension
Expand Down Expand Up @@ -137,11 +133,9 @@ append!(momenta_mps, fix_degeneracies(states[10:11]))
append!(momenta_mps, fix_degeneracies(states[12:12]))
append!(momenta_mps, fix_degeneracies(states[13:16]))

plot(
momenta_mps,
real.(energies[1:16]);
seriestype=:scatter,
xlabel="momentum",
ylabel="energy",
legend=false,
)
plot(momenta_mps,
real.(energies[1:16]);
seriestype=:scatter,
xlabel="momentum",
ylabel="energy",
legend=false)
2 changes: 1 addition & 1 deletion examples/quantum1d/2.haldane/main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ In contrast with the finite size case, we now should specify a momentum label to
This way, it is possible to scan the dispersion relation over the entire momentum space.
"""

virtual_space_inf = Rep[SU₂](1//2 => 16, 3//2 => 16, 5//2 => 8, 7//2 => 4)
virtual_space_inf = Rep[SU₂](1 // 2 => 16, 3 // 2 => 16, 5 // 2 => 8, 7 // 2 => 4)
ψ₀_inf = InfiniteMPS([physical_space], [virtual_space_inf])
ψ_inf, envs_inf, delta_inf = find_groundstate(ψ₀_inf, H)

Expand Down
26 changes: 12 additions & 14 deletions examples/quantum1d/4.xxz-heisenberg/main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Then we specify an initial guess, which we then further optimize.
Working directly in the thermodynamic limit, this is achieved as follows:
"""

H = heisenberg_XXX(; spin=1//2);
H = heisenberg_XXX(; spin=1 // 2);

md"""
We then need an intial state, which we shall later optimize. In this example we work directly in the thermodynamic limit.
Expand Down Expand Up @@ -69,19 +69,18 @@ Alternatively, the hamiltonian can be constructed directly on a two-site unitcel
"""

## H2 = repeat(H, 2); -- copies the one-site version
H2 = heisenberg_XXX(ComplexF64, Trivial, InfiniteChain(2); spin=1//2)
groundstate, cache, delta = find_groundstate(
state, H2, VUMPS(; maxiter=100, tol_galerkin=1e-12)
);
H2 = heisenberg_XXX(ComplexF64, Trivial, InfiniteChain(2); spin=1 // 2)
groundstate, cache, delta = find_groundstate(state, H2,
VUMPS(; maxiter=100, tol_galerkin=1e-12));

md"""
We get convergence, but it takes an enormous amount of iterations.
The reason behind this becomes more obvious at higher bond dimensions:
"""

groundstate, cache, delta = find_groundstate(
state, H2, IDMRG2(; trscheme=truncdim(50), maxiter=20, tol_galerkin=1e-12)
)
groundstate, cache, delta = find_groundstate(state, H2,
IDMRG2(; trscheme=truncdim(50), maxiter=20,
tol_galerkin=1e-12))
entanglementplot(groundstate)

md"""
Expand All @@ -101,7 +100,7 @@ The XXZ Heisenberg hamiltonian is SU(2) symmetric and we can exploit this to gre
It is cumbersome to construct symmetric hamiltonians, but luckily su(2) symmetric XXZ is already implemented:
"""

H2 = heisenberg_XXX(ComplexF64, SU2Irrep, InfiniteChain(2); spin=1//2);
H2 = heisenberg_XXX(ComplexF64, SU2Irrep, InfiniteChain(2); spin=1 // 2);

md"""
Our initial state should also be SU(2) symmetric.
Expand All @@ -113,8 +112,8 @@ The staggering thus happens on the virtual level.
An alternative constructor for the initial state is
"""

P = Rep[SU₂](1//2 => 1)
V1 = Rep[SU₂](1//2 => 10, 3//2 => 5, 5//2 => 2)
P = Rep[SU₂](1 // 2 => 1)
V1 = Rep[SU₂](1 // 2 => 10, 3 // 2 => 5, 5 // 2 => 2)
V2 = Rep[SU₂](0 => 15, 1 => 10, 2 => 5)
state = InfiniteMPS([P, P], [V1, V2]);

Expand All @@ -124,6 +123,5 @@ Even though the bond dimension is higher than in the example without symmetry, c

println(dim(V1))
println(dim(V2))
groundstate, cache, delta = find_groundstate(
state, H2, VUMPS(; maxiter=400, tol_galerkin=1e-12)
);
groundstate, cache, delta = find_groundstate(state, H2,
VUMPS(; maxiter=400, tol_galerkin=1e-12));
16 changes: 7 additions & 9 deletions examples/quantum1d/5.haldane-spt/main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ non-injective MPS.
"""

= SU2Space(1 => 1)
V_wrong = SU2Space(0 => 8, 1//2 => 8, 1 => 3, 3//2 => 3)
V_wrong = SU2Space(0 => 8, 1 // 2 => 8, 1 => 3, 3 // 2 => 3)
ψ = InfiniteMPS(ℋ, V_wrong)
ψ, environments, δ = find_groundstate(ψ, H, VUMPS(; maxiter=10))
sectors = SU2Irrep[0, 1//2, 1, 3//2]
sectors = SU2Irrep[0, 1 // 2, 1, 3 // 2]
transferplot(ψ; sectors, title="Transfer matrix spectrum", legend=:outertop)

md"""
Expand Down Expand Up @@ -109,19 +109,17 @@ E_plus = expectation_value(ψ_plus, H)

#+

V_minus = SU2Space(1//2 => 10, 3//2 => 5, 5//2 => 3)
V_minus = SU2Space(1 // 2 => 10, 3 // 2 => 5, 5 // 2 => 3)
ψ_minus = InfiniteMPS(ℋ, V_minus)
ψ_minus, = find_groundstate(ψ_minus, H, VUMPS(; maxiter=100))
E_minus = expectation_value(ψ_minus, H)

#+

transferp_plus = transferplot(
ψ_plus; sectors=SU2Irrep[0, 1, 2], title="ψ_plus", legend=:outertop
)
transferp_minus = transferplot(
ψ_minus; sectors=SU2Irrep[0, 1, 2], title="ψ_minus", legend=:outertop
)
transferp_plus = transferplot(ψ_plus; sectors=SU2Irrep[0, 1, 2], title="ψ_plus",
legend=:outertop)
transferp_minus = transferplot(ψ_minus; sectors=SU2Irrep[0, 1, 2], title="ψ_minus",
legend=:outertop)
plot(transferp_plus, transferp_minus; layout=(1, 2), size=(800, 400))

#+
Expand Down
2 changes: 1 addition & 1 deletion examples/windowmps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using MPSKit, MPSKitModels, TensorKit, Plots
let
#defining the hamiltonian
th = nonsym_ising_ham(; lambda=0.3)
(sx, sy, sz) = nonsym_spintensors(1//2)
sx, sy, sz = nonsym_spintensors(1 // 2)

#initilizing a random mps
ts = InfiniteMPS([ℂ^2], [ℂ^12])
Expand Down
2 changes: 1 addition & 1 deletion src/MPSKit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export PeriodicArray, Window
export MPSTensor
export QP, LeftGaugedQP, RightGaugedQP
export leftorth,
rightorth, leftorth!, rightorth!, poison!, uniform_leftorth, uniform_rightorth
rightorth, leftorth!, rightorth!, poison!, uniform_leftorth, uniform_rightorth
export r_LL, l_LL, r_RR, l_RR, r_RL, r_LR, l_RL, l_LR # should be properties

# useful utility functions?
Expand Down
32 changes: 12 additions & 20 deletions src/algorithms/ED.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
"""
Use krylovkit to perform exact diagonalization
"""
function exact_diagonalization(
opp::MPOHamiltonian;
sector=first(sectors(oneunit(opp.pspaces[1]))),
len::Int=opp.period,
num::Int=1,
which::Symbol=:SR,
alg::KrylovKit.KrylovAlgorithm=Lanczos(),
)
function exact_diagonalization(opp::MPOHamiltonian;
sector=first(sectors(oneunit(opp.pspaces[1]))),
len::Int=opp.period, num::Int=1, which::Symbol=:SR,
alg::KrylovKit.KrylovAlgorithm=Lanczos())
left = ℂ[typeof(sector)](sector => 1)
right = oneunit(left)

Expand All @@ -24,22 +20,18 @@ function exact_diagonalization(
ACs = Vector{Union{Missing,mpst_type}}(missing, len)

for i in 1:(middle_site - 1)
ALs[i] = isomorphism(
storagetype(Ot), left * opp.pspaces[i], fuse(left * opp.pspaces[i])
)
ALs[i] = isomorphism(storagetype(Ot), left * opp.pspaces[i],
fuse(left * opp.pspaces[i]))
left = _lastspace(ALs[i])'
end
for i in len:-1:(middle_site + 1)
ARs[i] = _transpose_front(
isomorphism(
storagetype(Ot), fuse(right * opp.pspaces[i]'), right * opp.pspaces[i]'
),
)
ARs[i] = _transpose_front(isomorphism(storagetype(Ot),
fuse(right * opp.pspaces[i]'),
right * opp.pspaces[i]'))
right = _firstspace(ARs[i])
end
ACs[middle_site] = randomize!(
similar(opp[1][1, 1], left * opp.pspaces[middle_site] right)
)
ACs[middle_site] = randomize!(similar(opp[1][1, 1],
left * opp.pspaces[middle_site] right))
norm(ACs[middle_site]) == 0 && throw(ArgumentError("invalid sector"))
normalize!(ACs[middle_site])

Expand All @@ -54,7 +46,7 @@ function exact_diagonalization(
state_vecs = map(vecs) do v
cs = copy(state)
cs.AC[middle_site] = v
cs
return cs
end

return vals, state_vecs, convhist
Expand Down
Loading

0 comments on commit bd3f830

Please sign in to comment.