KPM
KPM.JacksonKernelKPM.Lambda_nmKPM.LorentzKernelsKPM.broadcast_dot_1d_1d!KPM.broadcast_dot_reduce_avg_2d_1d!KPM.d_dc_condKPM.dc_cond0KPM.dc_cond0KPM.dc_cond_singleKPM.dc_cond_singleKPM.dosKPM.dos0KPM.fermiFunctionKPM.fermiFunctionsKPM.gram_schmidtKPM.gram_schmidt!KPM.isNotBoundaryKPM.kpm_1dKPM.kpm_1d!KPM.kpm_1d_currentKPM.kpm_1d_current!KPM.kpm_2dKPM.kpm_2d!KPM.kpm_3dKPM.kpm_3d!KPM.mu2D_apply_kernel_and_h_no_mutateKPM.normalizeHKPM.normalize_by_colKPM.whichcoreKPM.wrapAddKPM.ΓnmKPM.ΓnmμnmαβKPM.ΛnKPM.Λnmp
Installation
This package is currently unregistered. Install the latest version directly from GitHub:
] add https://github.com/Pixley-Research-Group-in-CMT/KPM.jlNotes:
- The package supports CUDA.jl versions 4 and 5.
- After installation import with:
using KPM- To update the package run:
] update KPMand provide your GitHub username/password if prompted.
For more details see the project's README.
Quick examples
1) Density of States (DOS) — concise example
using KPM, LinearAlgebra, SparseArrays, Plots
# small 1D tight-binding (periodic)
function tb1dchain(N; t=1.0)
H = spzeros(N,N)
for i in 1:N-1
H[i,i+1] = -t; H[i+1,i] = -t
end
H[1,N] = -t; H[N,1] = -t
return H
end
N = 1000
NC = 256
NR = 4
H = tb1dchain(N)
# rescale H to (-1,1)
a, Hn = KPM.normalizeH(H)
mu = KPM.kpm_1d(Hn, NC, NR)
E, rho = KPM.dos(mu, a; kernel=KPM.JacksonKernel, N_tilde=500)
plot(E, rho, xlabel="E", ylabel="DOS", legend=false)Reference (full example):
using KPM
using LinearAlgebra
using SparseArrays
# Simple dense 1D tight-binding Hamiltonian (periodic)
function tb1dchain(N::Integer; t::Real=1.0)
H = zeros(Float64, N, N)
for i in 1:(N-1)
H[i, i+1] = -t
H[i+1, i] = -t
end
H[1, N] = -t
H[N, 1] = -t
return H
end
# Parameters
N = 1000 # system size
NC = 1024 # Chebyshev order
NR = 10 # number of random vectors for stochastic trace
nE = 1000 # output energy grid points
H = tb1dchain(N)
# Rescale H -> (-1, 1)
#Hsparse = sparse(H.*(1+0*1im)) # make the Hamiltonian sparse under complex number
b, H_norm = KPM.normalizeH(H)
# Compute Chebyshev moments (DOS)
mu = KPM.kpm_1d(H_norm, NC, NR) # returns moments (array-like)
# Reconstruct DOS on a grid and map energies back to physical scale
E, rho1024 = KPM.dos(mu, b;kernel = KPM.JacksonKernel, N_tilde=nE)
E, rho64 = KPM.dos(mu[1:64], b;kernel = KPM.JacksonKernel, N_tilde=nE)
E, rho32 = KPM.dos(mu[1:32], b;kernel = KPM.JacksonKernel, N_tilde=nE)
# Analytical DOS
rho_exact = zeros(length(E))
mask = abs.(E) .< 2
rho_exact[mask] = 1.0 ./ (π * sqrt.(4 .- E[mask].^2))
# plot the DOS
plot(xlabel=L"E", ylabel="DOS"*L"\;\rho(E)",
legend = :top,
#xlim=[-0.1,0.8586],ylim=[-0.001,0.035],
framestyle = :box,grid=false,
xtickfontsize=12, ytickfontsize=12,
xguidefontsize=12, yguidefontsize=12,
legendfontsize=12,
)
plot!(E, [rho1024 rho64 rho32], lw=[4 3 2],label=[L"N_C=1024" L"N_C=64" L"N_C=32"])
plot!(E, rho_exact, c=:black, ls=:dash, label=L"\mathrm{Analytic}")2) Optical conductivity (graphene) — concise example
using KPM, Plots
include("examples/GrapheneModel.jl") # provides GrapheneLattice
L = 60
Ham, Jx, Jy, Jxx, Jxy, Jyy = GrapheneLattice(L, L)
a = 3.5
Hn = Ham / a
NC = 256; NR = 6
mu2d = zeros(ComplexF64, NC, NC)
psi = exp.(2π*1im*rand(Hn.n, NR))
KPM.normalize_by_col(psi, NR)
KPM.kpm_2d!(Hn, Jy, Jy, NC, NR, Hn.n, mu2d, psi, psi)
# compute a sample optical conductivity (2D contribution) at ω=0.5
ω = 0.5
σ2 = KPM.d_optical_cond2(mu2d, NC, ω, 0.0)
println("Optical conductivity (2D part) at ω=", ω, " : ", σ2)Reference (full example):
using Plots
using LaTeXStrings
using KPM
include("GrapheneModel.jl") # Include the GrapheneLattice function and related structures
function full_optical_condT0(mu1d,mu2d, NC, ω; δ=1e-5, λ=0.0, kernel=KPM.JacksonKernel,
h = 0.001, Emin= -0.8, Emax = 0.0
)
# This function is used to calculate the full optical conductivity
# by combining the 1D and 2D contributions.
x_all = collect(Emin:h:Emax)
y_1 = zeros(ComplexF64, length(x_all))
y_2 = zeros(ComplexF64, length(x_all))
mu1d_dev = KPM.maybe_to_device(mu1d[1:NC])
mu2d_dev = KPM.maybe_to_device(mu2d[1:NC, 1:NC])
for (i, x) in enumerate(x_all)
y_1[i] += KPM.d_optical_cond1(mu1d_dev, NC, x; δ=δ, λ=λ, kernel=kernel)
y_2[i] += KPM.d_optical_cond2(mu2d_dev, NC, ω, x; δ=δ, λ=λ, kernel=kernel)
end
return (sum(y_1) * h * (-1im / ω), sum(y_2) * h * (-1im / ω))
#y_all = y_1 .+ y_2;
#y_integral = sum(y_all) * h;
#return y_integral*(-1im / ω) # -ie^2 / (ħ^2 * ω)
end
L = 200
Ham, Jx, Jy,Jxx,Jxy,Jyy = GrapheneLattice(L,L);
a = 3.5
H_norm = Ham ./ a
NC = 512 #512
NR = 10
NH = H_norm.n
mu_2d_yy = zeros(ComplexF64, NC, NC)
psi_in_l = exp.(2pi * 1im * rand(NH, NR));
KPM.normalize_by_col(psi_in_l, NR)
psi_in_r = psi_in_l
@time KPM.kpm_2d!(H_norm, Jy, Jy, NC, NR, NH, mu_2d_yy, psi_in_l, psi_in_r; verbose=1);
mu_1d_yy = KPM.kpm_1d_current(H_norm,Jyy, NC, NR; verbose=1)
t = 2.3
μ = 0.466
Ef = μ/t/a
λ = 38.8*10^(-3)/t/a
ωs = collect(LinRange(0.03, 0.982, 100))
res = zeros(ComplexF64, length(ωs))
res2 = zeros(ComplexF64, length(ωs))
for (i, ω) in enumerate(ωs)
res[i], res2[i] = full_optical_condT0(mu_1d_yy,mu_2d_yy, NC, ω;λ=λ,Emax=Ef)
#res[i] = full_optical_condT0(mu_1d_yy,mu_2d_yy, NC, ω;λ=λ,Emax=Ef)
println(i)
end
σyyreal = real.(res2)./a
σyyimag = imag.(t*a*res.+res2)./a
ωsreno = ωs*t*a
plot(ylabel = L"\sigma^{yy}/\sigma_0",xlabel = L"\hbar \omega(\mathrm{eV})",
framestyle = :box,grid=false,legend=:topright,
xtickfontsize=12, ytickfontsize=12,
xguidefontsize=12, yguidefontsize=12,
legendfontsize=12,#titlefontsize=12,
ylim=(-2,8)
)
scatter!(ωs*t*a, σyyreal, label="real",markerstrokewidth=0.0)
scatter!(ωs*t*a, σyyimag, label="imag",markerstrokewidth=0.0)Moment calculation
The first step in KPM is calculating moments using Hamiltonians (and current operators for conductivity, etc.). Functions with ! are the more efficient in-place versions; functions without ! are convenient wrappers that call the in-place implementations.
KPM.kpm_1d — Function
kpm_1d(H, NC, NR; kwargs...)defined at /home/runner/work/KPMsub.jl/KPMsub.jl/src/moment.jl:302.
kpm_1d(
H,
NC,
NR,
NH;
psi_in,
psi_in_l,
psi_in_r,
force_norm,
verbose,
avg_output,
NR_parallel
)defined at /home/runner/work/KPMsub.jl/KPMsub.jl/src/moment.jl:303.
The simple version of 1D KPM that returns the moment.
H– Hamiltonian. A matrix or sparse matrixNC– Integer. the cut off dimensionNR– Integer. number of random vectors used for KPM evaluationNH– Integer. the size of hamiltonianpsi_in– Optional. Allow setting random vector manually.force_norm– Boolean, Optional. Apply normalization.verbose– Integer. Default is 0. Enables progress bar if setverbose=1.avg_output– Boolean. Default is true. Whether to output averaged μ (hence size NC) or separate μs (size NR x NC).
KPM.kpm_1d! — Function
kpm_1d!(H, NC, NR, NH, mu_all, psi_in; verbose, α_all)defined at /home/runner/work/KPMsub.jl/KPMsub.jl/src/moment.jl:364.
kpm_1d!(H, NC, NR, NH, mu; kwargs...)defined at /home/runner/work/KPMsub.jl/KPMsub.jl/src/moment.jl:426.
kpm_1d!(H, NC, NR, NH, mu, psi_in_l, psi_in_r; kwargs...)defined at /home/runner/work/KPMsub.jl/KPMsub.jl/src/moment.jl:435.
The in-place version of 1D KPM. Calculate the moments μ defined in KPM. Output is saved in mu.
H– Hamiltonian. A matrix or sparse matrix.NC– Integer. the cut off dimension.NR– Integer. number of random vectors used for KPM evaluation.NH– Integer. the size of hamiltonian.mu_all– Array. Output for each random vector. Size (NR, NC).psi_in– Array (optional). Input array on the right side. A ket.
KPM.kpm_2d — Function
kpm_2d(
H,
Jα,
Jβ,
NC,
NR,
NH;
psi_in,
psi_in_l,
psi_in_r,
arr_size,
moment_parity,
verbose
)defined at /home/runner/work/KPMsub.jl/KPMsub.jl/src/moment.jl:595.
The simple version of 2D KPM that returns the moment. Calculate moments for 2D KPM.
Calculates ψ0l * Tm(H) * Jβ * Tn(H) * Jα * ψ0r. When ψ0r and ψ0l are chosen to be random and identical, the output approximates tr(Tm(H) Jβ Tn(H) Jα). The accuracy is ~ O(1/sqrt(NR * NH)). NC controls the energy resolution of the result.
Output: μ, a 2D array in ComplexF64. μ[n, m] is the momentum for 2D KPM.
ARGS
H
Hamiltonian. A sparse 2D array.
Jα
Current operator. A sparse 2D array.
Jβ
Current operator. A sparse 2D array.
NC
Integer. KPM cutoff order.
NR
Integer. Number of random vectors to choose from. When skipped, understood as NR=1.
NH
Integer. Dimension of H, Jα and Jβ
KWARGS
psi_in_l
Passes value to ψ0l. The array is not updated. Size should be (NH, NR) (preferred) or (NR, NH) if set.
psi_in_r
Passes value to ψ0r. The array is not updated. Size should be (NH, NR) (preferred) or (NR, NH) if set.
psi_in
Cannot be used together with psiinl and psiinr. Sets psiinl=psiinr=psi_in if set.
kwargs
other kwargs in KPM_2D!
KPM.kpm_2d! — Function
kpm_2d!(
H,
Jα,
Jβ,
NC,
NR,
NH,
μ,
psi_in_l,
psi_in_r;
arr_size,
verbose,
mn_sym,
moment_parity,
ψ0r,
Jψ0r,
JTnHJψr,
ψall_r,
ψ0l,
ψall_l,
ψw
)defined at /home/runner/work/KPMsub.jl/KPMsub.jl/src/moment.jl:618.
kpm_2d!(H, Jα, Jβ, NC, NR, NH, μ, psi_in; kwargs...)defined at /home/runner/work/KPMsub.jl/KPMsub.jl/src/moment.jl:755.
kpm_2d!(H, Jα, Jβ, NC, NR, NH, μ; kwargs...)defined at /home/runner/work/KPMsub.jl/KPMsub.jl/src/moment.jl:765.
In place KPM2D. This is also the main building block for KPM_2D. This method only provide NR=1.
Calculates ψ0l * Tm(H) * Jβ * Tn(H) * Jα * ψ0r. When ψ0r and ψ0l are chosen to be random and identical, the output approximates tr(Tm(H) Jβ Tn(H) Jα). The accuracy is $\sim O(1/sqrt(NR * NH))$ with NR repetitions. NC controls the energy resolution of the result.
Output: nothing. Result is saved on μ.
ARGS
H: Hamiltonian. A sparse 2D array.Jα: Current operator. A sparse 2D array.Jβ: Current operator. A sparse 2D array.NC: Integer. KPM cutoff order.NR: Integer. Number of random vectors.NH: Integer. Dimension of H, Jα and Jβμ: 2D Array of dimension (NC, NC). Results will be updated here. Any data
will be overwritten.
psi_in: Setpsi_in_landpsi_in_r. Size is (NH, NR). The array is not updated.
Whether the input is normalized or not, it is assumed to be intended. Usually psi_in should be normalized.
psi_in_l: Passes value to ψ0l. Size is (NH, NR). The array is not updated.
Whether the input is normalized or not, it is assumed to be intended. Usually psi_in_l should be normalized. psi_in_l is given as column vector of ket $|ψl> = <ψl|^\dagger$
psi_in_r: Passes value to ψ0r. Size is (NH, NR). The array is not updated.
Whether the input is normalized or not, it is assumed to be intended. Usually psi_in_r should be normalized. psi_in_r is given as column vector of ket $|ψr>$.
KWARGS
arr_size: The buffer array size. Minimum is 3. Determines the number of
left states to be kept in memory for each loop of right states. The time complexity is reduced from $O(N\times NC^2)$ to $O(N\times NC\times arr\_size)$ while space complexity is increased from $O(N\times NC)$ to $O(N\times NC\times arr\_size)$.
moment_parity: The condition enforced on μmn. Choose from:NONE,:ODDand:EVEN.
:NONE will calculate all μmn; :ODD will calculate μmn such that mod(m+n, 2)==1; :EVEN will calculate μmn such that mod(m+n, 2)==0. As an example, moment_parity=:EVEN can be used when calculating longitudinal conductivity on model with particle-hole symmetry to save time and increase accuracy.
working spaces KWARGS: The following keyword args are simply providing working place arrays to avoid repetitive allocation and GC. They are automatically created if not set. However, when using KPM_2D! for many times, it is beneficial to reuse those arrays. CONVENTION: args with ψ are all working space arr.
ψ0r=maybe_on_device_zeros(NH, NR)Jψ0r=maybe_on_device_zeros(NH, NR)JTnHJψr=maybe_on_device_zeros(NH, NR)ψall_r=maybe_on_device_zeros(3, NH, NR)ψ0l=maybe_on_device_zeros(NH, NR)ψall_l=maybe_on_device_zeros(arr_size, NH, NR)ψw=maybe_on_device_zeros(NH, NR)
Applications
DOS
To calculate the density of states (DOS) first calculate moments using kpm_1d / kpm_1d! with default (random) input vectors. Then use the returned moments (mu) to evaluate the DOS. There is also a convenience overload that accepts a Hamiltonian directly and performs the moment calculation for you via dos.
KPM.dos — Function
dos(
H;
NC,
NR,
E_grid,
N_tilde,
E_range,
kernel,
fix_normalization,
dE_order
)defined at /home/runner/work/KPMsub.jl/KPMsub.jl/src/applications/dos.jl:31.
dos(
μ,
H_rescale_factor;
E_grid,
N_tilde,
E_range,
NC,
kernel,
dE_order
)defined at /home/runner/work/KPMsub.jl/KPMsub.jl/src/applications/dos.jl:49.
Calculate DOS for a fermi energy grid spanning E_range with N_tilde total points. If E_range is not set, automatically set it to be sightly smaller than full size. Otherwise an explicit array of E_grid can be passed in. Don't do both.
Either a) pass in a 1d array as moment and as normalization factor; or b) pass in a Hamiltonian that is rescaled with an optional keyword rescale_factor that default to 1.
H_rescale_factoris the normalization of H. Needed when μ is passed.NRrandom vectors. Needed when H is passed
Kernels
Kernels are functions with signature
kernel(n::Int64, N::Int64) -> Float64such that when n == 0 the kernel returns 1, and when n == N-1 it returns a small number close to 0.
The package provides the JacksonKernel (the default for most applications) and LorentzKernels.
KPM.JacksonKernel — Function
JacksonKernel(n::Integer, N::Integer)
Jacksonkernel evaluated at n-th expansion coefficient with N in total (NC)
The Lorentz kernel is useful for Green's functions because it preserves certain symmetries. LorentzKernels(λ) returns a kernel function parameterized by λ.
KPM.LorentzKernels — Function
LorentzKernels(λ::Float64)
Returns function LorentzKernel(n, N) that evaluates Lorentz kernel with parameter λ, at n-th expansion coefficient with N in total (NC)
API overview
Below is a concise list of the main public APIs provided by the package.
Moment / KPM core:
kpm_1d,kpm_1d!kpm_1d_current,kpm_1d_current!kpm_2d,kpm_2d!kpm_3d,kpm_3d!
DOS / LDOS:
dos,dos0ldos_mu
Conductivity (DC / optical):
d_dc_cond,dc_cond0,dc_cond_singleoptical_cond1,d_optical_cond1optical_cond2,d_optical_cond2
Nonlinear / CPGE:
cpge,d_cpge- Integration helpers:
Λnmp,Λn,Λnm,gn_R,gn_A,Δn
Kernels:
JacksonKernel,LorentzKernels
Utilities (KPM.Utils / device helpers):
wrapAdd,normalizeH,isNotBoundary,timestamp- device helpers:
whichcore,maybe_to_device,maybe_to_host,maybe_on_device_rand,maybe_on_device_zeros
For more details see the full API reference below.
KPM.JacksonKernel — Method
JacksonKernel(n::Integer, N::Integer)
Jacksonkernel evaluated at n-th expansion coefficient with N in total (NC)
KPM.Lambda_nm — Method
Lambda_nm is integral of f(Ef)/(1-Ef^2)^2 * Γnm(Ef). Notice that all Ef is scaled to -1 to 1.
δ is the amount around ±1 to avoid.
KPM.LorentzKernels — Method
LorentzKernels(λ::Float64)
Returns function LorentzKernel(n, N) that evaluates Lorentz kernel with parameter λ, at n-th expansion coefficient with N in total (NC)
KPM.broadcast_dot_1d_1d! — Function
Vl and Vr are both [NH, NR] sized array. Each corresponding [:, NR] slice pair is dotted, saving into the target of [NR], multiplying by alpha and plus beta. Beta is either a number or vector of [NR]
KPM.broadcast_dot_reduce_avg_2d_1d! — Method
Dot product each column of Vls with vector Vr, save in target. Each view has NR replica of NH. This function take the average.
target: 1D Array (n), n >= NCcols. Vls: 1D Array of 2D views, shape (n), each view (NH, NR), where n >= NCcols. Vr: 2D Array, shape NH, NR NCcols: Integer, number of columns.
KPM.d_dc_cond — Function
d_dc_cond(μ, a, E; kwargs...)defined at /home/runner/work/KPMsub.jl/KPMsub.jl/src/applications/conductivity.jl:82.
d_dc_cond(μ, a, E; NC, kernel, dE_order)defined at /home/runner/work/KPMsub.jl/KPMsub.jl/src/applications/conductivity.jl:84.
Calculate the integrand for conductivity of an energy grid spanning E_range with N_tilde total points. If E_range is not set, automatically set it to be sightly smaller than full size. Otherwise an explicit array of E_grid can be passed in. Don't do both.
Either a) pass in a 2d array as moment and a normalization factor; or b) pass in a Hamiltonian that is rescaled with an optional keyword rescale_factor that default to 1, as well as two current operators Jα and Jβ
H_rescale_factoris the normalization of H. Needed when μ is passed.NRrandom vectors. Needed when H is passed
KPM.dc_cond0 — Function
dc_cond0(mu, H_rescale_factor; kernel, NC)defined at /home/runner/work/KPMsub.jl/KPMsub.jl/src/applications/conductivity.jl:127.
Calculate DOS and its energy derivatives (by setting dE_order) at zero energy.
Warning: This method does not have correct normalization at the moment.
KPM.dc_cond0 — Method
calculate conductivity for EF=0. Only works for longitudinal cond. Garcia et. al. Supp eq.25.
KPM.dc_cond_single — Function
dc_cond_single(mu, H_rescale_factor, Ef; kernel, NC)defined at /home/runner/work/KPMsub.jl/KPMsub.jl/src/applications/conductivity.jl:139.
Calculate DOS at a given energy.
KPM.dc_cond_single — Method
calculate conductivity for arbitrary EF. Only works for longitudinal cond. Garcia et. al. Supp eq.25.
KPM.dos — Function
dos(
H;
NC,
NR,
E_grid,
N_tilde,
E_range,
kernel,
fix_normalization,
dE_order
)defined at /home/runner/work/KPMsub.jl/KPMsub.jl/src/applications/dos.jl:31.
dos(
μ,
H_rescale_factor;
E_grid,
N_tilde,
E_range,
NC,
kernel,
dE_order
)defined at /home/runner/work/KPMsub.jl/KPMsub.jl/src/applications/dos.jl:49.
Calculate DOS for a fermi energy grid spanning E_range with N_tilde total points. If E_range is not set, automatically set it to be sightly smaller than full size. Otherwise an explicit array of E_grid can be passed in. Don't do both.
Either a) pass in a 1d array as moment and as normalization factor; or b) pass in a Hamiltonian that is rescaled with an optional keyword rescale_factor that default to 1.
H_rescale_factoris the normalization of H. Needed when μ is passed.NRrandom vectors. Needed when H is passed
KPM.dos0 — Function
dos0(μ, H_rescale_factor; NC, kernel, dE_order)defined at /home/runner/work/KPMsub.jl/KPMsub.jl/src/applications/dos.jl:136.
Calculate DOS and its energy derivatives (by setting dE_order) at zero energy.
KPM.fermiFunction — Method
fermiFunction(E, E_f, beta)calculate Fermi-Dirac function at energy E, Fermi energy μ and temperature β =1/T. Input and output all Float64. Infinite β only allowed when accessing fermi energy through fermiFunctions(). [For performance reason for now. TODO: allow β=Inf here withouth perf. reduction. ]
Allow sloppy use of type as long as convertion is available, if using keyword arguments.
KPM.fermiFunctions — Method
fermiFunctions(E_f::Float64, beta::Float64)returns a fermi function with given E_f and beta.
Allow sloppy use of type as long as convertion is available, if using keyword arguments.
KPM.gram_schmidt! — Method
orthonormalize the column vectors of A. In-place.
Using classical Gram-Schmit.
When orthogonality is extremely important, applying the same method twice may help, according to this note.
KPM.gram_schmidt — Method
orthonormalize the column vectors of A. See gram_schmidt!, the in-place version for details.
KPM.isNotBoundary — Method
give 0 for OBC=1 direction if i,i_ is on boundary. Otherwise 1
KPM.kpm_1d — Function
kpm_1d(H, NC, NR; kwargs...)defined at /home/runner/work/KPMsub.jl/KPMsub.jl/src/moment.jl:302.
kpm_1d(
H,
NC,
NR,
NH;
psi_in,
psi_in_l,
psi_in_r,
force_norm,
verbose,
avg_output,
NR_parallel
)defined at /home/runner/work/KPMsub.jl/KPMsub.jl/src/moment.jl:303.
The simple version of 1D KPM that returns the moment.
H– Hamiltonian. A matrix or sparse matrixNC– Integer. the cut off dimensionNR– Integer. number of random vectors used for KPM evaluationNH– Integer. the size of hamiltonianpsi_in– Optional. Allow setting random vector manually.force_norm– Boolean, Optional. Apply normalization.verbose– Integer. Default is 0. Enables progress bar if setverbose=1.avg_output– Boolean. Default is true. Whether to output averaged μ (hence size NC) or separate μs (size NR x NC).
KPM.kpm_1d! — Function
kpm_1d!(H, NC, NR, NH, mu_all, psi_in; verbose, α_all)defined at /home/runner/work/KPMsub.jl/KPMsub.jl/src/moment.jl:364.
kpm_1d!(H, NC, NR, NH, mu; kwargs...)defined at /home/runner/work/KPMsub.jl/KPMsub.jl/src/moment.jl:426.
kpm_1d!(H, NC, NR, NH, mu, psi_in_l, psi_in_r; kwargs...)defined at /home/runner/work/KPMsub.jl/KPMsub.jl/src/moment.jl:435.
The in-place version of 1D KPM. Calculate the moments μ defined in KPM. Output is saved in mu.
H– Hamiltonian. A matrix or sparse matrix.NC– Integer. the cut off dimension.NR– Integer. number of random vectors used for KPM evaluation.NH– Integer. the size of hamiltonian.mu_all– Array. Output for each random vector. Size (NR, NC).psi_in– Array (optional). Input array on the right side. A ket.
KPM.kpm_1d_current — Function
kpm_1d_current(H, Jα, NC, NR; kwargs...)defined at /home/runner/work/KPMsub.jl/KPMsub.jl/src/moment.jl:445.
kpm_1d_current(
H,
Jα,
NC,
NR,
NH;
psi_in,
psi_in_l,
psi_in_r,
force_norm,
verbose,
avg_output,
NR_parallel
)defined at /home/runner/work/KPMsub.jl/KPMsub.jl/src/moment.jl:446.
The simple version of 1D KPM with current operator that returns the moment. Calculate moments Γn^α = Tr[Jα T_n(H)].
H– Hamiltonian. A matrix or sparse matrixJα– Current operator. A matrix or sparse matrixNC– Integer. the cut off dimensionNR– Integer. number of random vectors used for KPM evaluationNH– Integer. the size of hamiltonianpsi_in– Optional. Allow setting random vector manually.force_norm– Boolean, Optional. Apply normalization.verbose– Integer. Default is 0. Enables progress bar if setverbose=1.avg_output– Boolean. Default is true. Whether to output averaged μ (hence size NC) or separate μs (size NR x NC).
KPM.kpm_1d_current! — Function
kpm_1d_current!(
H,
Jα,
NC,
NR,
NH,
mu_all,
psi_in;
verbose,
α_all,
Jα_psi
)defined at /home/runner/work/KPMsub.jl/KPMsub.jl/src/moment.jl:507.
kpm_1d_current!(H, Jα, NC, NR, NH, mu; kwargs...)defined at /home/runner/work/KPMsub.jl/KPMsub.jl/src/moment.jl:570.
kpm_1d_current!(
H,
Jα,
NC,
NR,
NH,
mu,
psi_in_l,
psi_in_r;
kwargs...
)defined at /home/runner/work/KPMsub.jl/KPMsub.jl/src/moment.jl:580.
The in-place version of 1D KPM with current operator. Calculate the moments μ defined in KPM: Γn^α = Tr[Jα T_n(H)]. Output is saved in mu.
H– Hamiltonian. A matrix or sparse matrix.Jα– Current operator. A matrix or sparse matrix.NC– Integer. the cut off dimension.NR– Integer. number of random vectors used for KPM evaluation.NH– Integer. the size of hamiltonian.mu_all– Array. Output for each random vector. Size (NR, NC).psi_in– Array (optional). Input array on the right side. A ket.
KPM.kpm_2d — Function
kpm_2d(
H,
Jα,
Jβ,
NC,
NR,
NH;
psi_in,
psi_in_l,
psi_in_r,
arr_size,
moment_parity,
verbose
)defined at /home/runner/work/KPMsub.jl/KPMsub.jl/src/moment.jl:595.
The simple version of 2D KPM that returns the moment. Calculate moments for 2D KPM.
Calculates ψ0l * Tm(H) * Jβ * Tn(H) * Jα * ψ0r. When ψ0r and ψ0l are chosen to be random and identical, the output approximates tr(Tm(H) Jβ Tn(H) Jα). The accuracy is ~ O(1/sqrt(NR * NH)). NC controls the energy resolution of the result.
Output: μ, a 2D array in ComplexF64. μ[n, m] is the momentum for 2D KPM.
ARGS
H
Hamiltonian. A sparse 2D array.
Jα
Current operator. A sparse 2D array.
Jβ
Current operator. A sparse 2D array.
NC
Integer. KPM cutoff order.
NR
Integer. Number of random vectors to choose from. When skipped, understood as NR=1.
NH
Integer. Dimension of H, Jα and Jβ
KWARGS
psi_in_l
Passes value to ψ0l. The array is not updated. Size should be (NH, NR) (preferred) or (NR, NH) if set.
psi_in_r
Passes value to ψ0r. The array is not updated. Size should be (NH, NR) (preferred) or (NR, NH) if set.
psi_in
Cannot be used together with psiinl and psiinr. Sets psiinl=psiinr=psi_in if set.
kwargs
other kwargs in KPM_2D!
KPM.kpm_2d! — Function
kpm_2d!(
H,
Jα,
Jβ,
NC,
NR,
NH,
μ,
psi_in_l,
psi_in_r;
arr_size,
verbose,
mn_sym,
moment_parity,
ψ0r,
Jψ0r,
JTnHJψr,
ψall_r,
ψ0l,
ψall_l,
ψw
)defined at /home/runner/work/KPMsub.jl/KPMsub.jl/src/moment.jl:618.
kpm_2d!(H, Jα, Jβ, NC, NR, NH, μ, psi_in; kwargs...)defined at /home/runner/work/KPMsub.jl/KPMsub.jl/src/moment.jl:755.
kpm_2d!(H, Jα, Jβ, NC, NR, NH, μ; kwargs...)defined at /home/runner/work/KPMsub.jl/KPMsub.jl/src/moment.jl:765.
In place KPM2D. This is also the main building block for KPM_2D. This method only provide NR=1.
Calculates ψ0l * Tm(H) * Jβ * Tn(H) * Jα * ψ0r. When ψ0r and ψ0l are chosen to be random and identical, the output approximates tr(Tm(H) Jβ Tn(H) Jα). The accuracy is $\sim O(1/sqrt(NR * NH))$ with NR repetitions. NC controls the energy resolution of the result.
Output: nothing. Result is saved on μ.
ARGS
H: Hamiltonian. A sparse 2D array.Jα: Current operator. A sparse 2D array.Jβ: Current operator. A sparse 2D array.NC: Integer. KPM cutoff order.NR: Integer. Number of random vectors.NH: Integer. Dimension of H, Jα and Jβμ: 2D Array of dimension (NC, NC). Results will be updated here. Any data
will be overwritten.
psi_in: Setpsi_in_landpsi_in_r. Size is (NH, NR). The array is not updated.
Whether the input is normalized or not, it is assumed to be intended. Usually psi_in should be normalized.
psi_in_l: Passes value to ψ0l. Size is (NH, NR). The array is not updated.
Whether the input is normalized or not, it is assumed to be intended. Usually psi_in_l should be normalized. psi_in_l is given as column vector of ket $|ψl> = <ψl|^\dagger$
psi_in_r: Passes value to ψ0r. Size is (NH, NR). The array is not updated.
Whether the input is normalized or not, it is assumed to be intended. Usually psi_in_r should be normalized. psi_in_r is given as column vector of ket $|ψr>$.
KWARGS
arr_size: The buffer array size. Minimum is 3. Determines the number of
left states to be kept in memory for each loop of right states. The time complexity is reduced from $O(N\times NC^2)$ to $O(N\times NC\times arr\_size)$ while space complexity is increased from $O(N\times NC)$ to $O(N\times NC\times arr\_size)$.
moment_parity: The condition enforced on μmn. Choose from:NONE,:ODDand:EVEN.
:NONE will calculate all μmn; :ODD will calculate μmn such that mod(m+n, 2)==1; :EVEN will calculate μmn such that mod(m+n, 2)==0. As an example, moment_parity=:EVEN can be used when calculating longitudinal conductivity on model with particle-hole symmetry to save time and increase accuracy.
working spaces KWARGS: The following keyword args are simply providing working place arrays to avoid repetitive allocation and GC. They are automatically created if not set. However, when using KPM_2D! for many times, it is beneficial to reuse those arrays. CONVENTION: args with ψ are all working space arr.
ψ0r=maybe_on_device_zeros(NH, NR)Jψ0r=maybe_on_device_zeros(NH, NR)JTnHJψr=maybe_on_device_zeros(NH, NR)ψall_r=maybe_on_device_zeros(3, NH, NR)ψ0l=maybe_on_device_zeros(NH, NR)ψall_l=maybe_on_device_zeros(arr_size, NH, NR)ψw=maybe_on_device_zeros(NH, NR)
KPM.kpm_3d — Function
kpm_3d(
H,
Jα,
Jβ,
Jγ,
NC,
NR,
NH;
arr_size,
verbose,
psi_in_l,
psi_in_r,
psi_in
)defined at /home/runner/work/KPMsub.jl/KPMsub.jl/src/moment.jl:867.
TODO: add doc.
KPM.kpm_3d! — Function
kpm_3d!(
H,
Jα,
Jβ,
Jγ,
NC,
NR,
NH,
μ,
psi_in_l,
psi_in_r;
arr_size,
verbose,
ψ0r,
JTn1HJψr,
ψall_r,
ψ0l,
sub_ψ0r,
sub_Jψ0r,
sub_JTnHJψr,
sub_ψall_r,
sub_ψ0l,
sub_ψall_l,
sub_ψw
)defined at /home/runner/work/KPMsub.jl/KPMsub.jl/src/moment.jl:781.
The simple version of tripple KPM that returns the moment. Calculate moments for tripple KPM.
Calculates ψ0l * Tn3(H) * Jγ * Tn2(H) * Jβ * Tn1(H) * Jα * ψ0r. When ψ0r and ψ0l are chosen to be random and identical, the output approximates tr(Tn3(H) Jγ Tn2(H) Jβ Tn1(H) Jα). The accuracy is ~ O(1/sqrt(NR * NH)). NC controls the energy resolution of the result.
Output: μ, a 3D array in ComplexF64. μ[n3, n2, n1] is the momentum for 2D KPM.
ARGS
H
Hamiltonian. A sparse 2D array.
Jα
Current operator. A sparse 2D array.
Jβ
Current operator. A sparse 2D array.
Jγ
Current operator. A sparse 2D array.
NC
Integer. KPM cutoff order.
NR
Integer. Number of random vectors to choose from. When skipped, understood as NR=1.
NH
Integer. Dimension of H, Jα, Jβ and Jγ
KWARGS
psi_in_l
Passes value to ψ0l. The array is not updated. Size should be (NH, NR) (preferred) or (NR, NH) if set.
psi_in_r
Passes value to ψ0r. The array is not updated. Size should be (NH, NR) (preferred) or (NR, NH) if set.
psi_in
Cannot be used together with psiinl and psiinr. Sets psiinl=psiinr=psi_in if set.
kwargs
other kwargs in KPM_2D!
KPM.mu2D_apply_kernel_and_h_no_mutate — Method
Create μtilde based on mu, by applying both kernel function and hn(n) for each direction.
μtilde is ComplexF64 array.
No mutate version, takes more memory
KPM.normalizeH — Method
Normalize H. If requested, allow renormalizing it to fixed value.
KPM.normalize_by_col — Method
Normalize a collection of vectors in an (NH, NR) array psi_in, where each column (that is psi_in[:, NRi]) represent a separate vector.
KPM.whichcore — Method
Report whether GPU support is active.
Base package defaults to CPU-only behavior; CUDA-specific activation is provided by the optional package extension in ext/KPMCUDAExt.jl.
KPM.wrapAdd — Method
wrapAdd find the sum of x and y, with L+1=1
KPM.Γnmμnmαβ — Method
Calculate Γnmμnmαβ. The input μtilde should be the moment that has already applied kernel and hn