KPM

Installation

This package is currently unregistered. Install the latest version directly from GitHub:

] add https://github.com/Pixley-Research-Group-in-CMT/KPM.jl

Notes:

  • The package supports CUDA.jl versions 4 and 5.
  • After installation import with:
using KPM
  • To update the package run:
] update KPM

and 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_1dFunction
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 matrix

  • NC – Integer. the cut off dimension

  • NR – Integer. number of random vectors used for KPM evaluation

  • NH – Integer. the size of hamiltonian

  • psi_in – Optional. Allow setting random vector manually.

  • force_norm – Boolean, Optional. Apply normalization.

  • verbose – Integer. Default is 0. Enables progress bar if set verbose=1.

  • avg_output – Boolean. Default is true. Whether to output averaged μ (hence size NC) or separate μs (size NR x NC).

source
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.

source
KPM.kpm_2dFunction
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.

Current operator. A sparse 2D array.

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!

source
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.

  • : Current operator. A sparse 2D array.

  • : 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 : Set psi_in_l and psi_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, :ODD and :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)
source

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.dosFunction
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_factor is the normalization of H. Needed when μ is passed.

  • NR random vectors. Needed when H is passed

source

Kernels

Kernels are functions with signature

kernel(n::Int64, N::Int64) -> Float64

such 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.JacksonKernelFunction

JacksonKernel(n::Integer, N::Integer)

Jacksonkernel evaluated at n-th expansion coefficient with N in total (NC)

source

The Lorentz kernel is useful for Green's functions because it preserves certain symmetries. LorentzKernels(λ) returns a kernel function parameterized by λ.

KPM.LorentzKernelsFunction

LorentzKernels(λ::Float64)

Returns function LorentzKernel(n, N) that evaluates Lorentz kernel with parameter λ, at n-th expansion coefficient with N in total (NC)

source

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, dos0
    • ldos_mu
  • Conductivity (DC / optical):

    • d_dc_cond, dc_cond0, dc_cond_single
    • optical_cond1, d_optical_cond1
    • optical_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.JacksonKernelMethod

JacksonKernel(n::Integer, N::Integer)

Jacksonkernel evaluated at n-th expansion coefficient with N in total (NC)

source
KPM.Lambda_nmMethod

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.

source
KPM.LorentzKernelsMethod

LorentzKernels(λ::Float64)

Returns function LorentzKernel(n, N) that evaluates Lorentz kernel with parameter λ, at n-th expansion coefficient with N in total (NC)

source
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]

source
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.

source
KPM.d_dc_condFunction
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_factor is the normalization of H. Needed when μ is passed.

  • NR random vectors. Needed when H is passed

source
KPM.dc_cond0Method

calculate conductivity for EF=0. Only works for longitudinal cond. Garcia et. al. Supp eq.25.

source
KPM.dc_cond_singleMethod

calculate conductivity for arbitrary EF. Only works for longitudinal cond. Garcia et. al. Supp eq.25.

source
KPM.dosFunction
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_factor is the normalization of H. Needed when μ is passed.

  • NR random vectors. Needed when H is passed

source
KPM.fermiFunctionMethod
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.

source
KPM.fermiFunctionsMethod
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.

source
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.

source
KPM.gram_schmidtMethod

orthonormalize the column vectors of A. See gram_schmidt!, the in-place version for details.

source
KPM.kpm_1dFunction
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 matrix

  • NC – Integer. the cut off dimension

  • NR – Integer. number of random vectors used for KPM evaluation

  • NH – Integer. the size of hamiltonian

  • psi_in – Optional. Allow setting random vector manually.

  • force_norm – Boolean, Optional. Apply normalization.

  • verbose – Integer. Default is 0. Enables progress bar if set verbose=1.

  • avg_output – Boolean. Default is true. Whether to output averaged μ (hence size NC) or separate μs (size NR x NC).

source
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.

source
KPM.kpm_1d_currentFunction
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 matrix

  • – 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

  • psi_in – Optional. Allow setting random vector manually.

  • force_norm – Boolean, Optional. Apply normalization.

  • verbose – Integer. Default is 0. Enables progress bar if set verbose=1.

  • avg_output – Boolean. Default is true. Whether to output averaged μ (hence size NC) or separate μs (size NR x NC).

source
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.

  • – 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.

source
KPM.kpm_2dFunction
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.

Current operator. A sparse 2D array.

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!

source
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.

  • : Current operator. A sparse 2D array.

  • : 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 : Set psi_in_l and psi_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, :ODD and :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)
source
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.

Current operator. A sparse 2D array.

Current operator. A sparse 2D array.

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!

source
KPM.normalize_by_colMethod

Normalize a collection of vectors in an (NH, NR) array psi_in, where each column (that is psi_in[:, NRi]) represent a separate vector.

source
KPM.whichcoreMethod

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.

source
KPM.ΓnmMethod

Calculate Γnm. Details see Garcia et.al, PRL 114, 116602 (2015)

source
KPM.ΓnmμnmαβMethod

Calculate Γnmμnmαβ. The input μtilde should be the moment that has already applied kernel and hn

source
KPM.ΛnMethod
  • beta : Inf is zero temperature. beta = 1/T.

  • E_f : Fermi energy. Between -1 and 1 because Hamiltonian is normalized.

source
KPM.ΛnmpMethod
  • beta : Inf is zero temperature. beta = 1/T.

  • E_f : Fermi energy. Between -1 and 1 because Hamiltonian is normalized.

source