Tip
Run this Jupyter Notebook locally: Download Notebook
Tutorial Operators and Functions#
General expansions#
Any operator can be expanded with the Kernel Polynomial Method (KPM). The only requirement is to define the coefficients for every KPM moment.
In kpm_tools we have implemented kpm_tools.kpm_generator.GeneralVectorExpansion to handle all possible operator expansions using the KPM.
We refer with ‘functions’ to the expectation values of these operators, which can be obtained with kpm_tools.kpm_generator.general_function.
Included expansions#
The coefficient functions of typical operators are included in kpm_tools.kpm_funcs: * kpm_tools.kpm_funcs.coef_greens_function_r * kpm_tools.kpm_funcs.coef_delta_function * kpm_tools.kpm_funcs.coef_projector_function
There are a few extra pre-defined coefficient functions for the projector over the unnocupied states, the advanced Green’s functions, and the derivatives of the retarded and advanced Green’s functions.
These coefficients can be used to define operators or functions. The out-of-the-box included functions are * kpm_tools.kpm_funcs.greens_functions * kpm_tools.kpm_funcs.delta_function * kpm_tools.kpm_funcs.projector_operator
Creating a custom expansion#
For any new or custom operator \(O\), we can find the coefficients by solving the integral
and defining a function with signature
def my_coef_function(m, e, ab=(1, 0)):
"""Return the coefficients for my operator.
Parameters
----------
m: int
Order of the Chebyshev moment.
e: float or ndarray
Fermi energy or array of energies in the same units as the Hamiltonian.
ab: tuple[float, float]
Width and center of the spectrum. The bounds defined as `(b-a, b+a)`
must fully contain the spectrum.
Returns
-------
coef: ndarray
Coefficients of the Chebyshev expansio. Must have the same shape as `e`.
"""
...
return coef
Once defined, the coefficients can be passed to kpm_tools.kpm_generator.GeneralVectorExpansionor kpm_tools.kpm_generator.general_function to define the Operator expansion or the expectation value function.
We can demonstrate the application of the projector operator by defining a simple system, a set of initial random states, and those states but projected using our operator.
Then, the spectral density computed with each set of vectors can show the spectral components of the initial and projected vectors.
[1]:
import holoviews as hv
hv.extension()
[2]:
import matplotlib.pyplot, matplotlib.backends
import kwant
import kpm_tools
[3]:
system_size = 20
_, fsyst = kpm_tools.hamiltonians.haldane_obc(
trans_symm=((system_size, 0), (0, system_size)),
e_0=0,
t=1,
t2=0,
)
[4]:
kwant.plot(fsyst);
[5]:
num_vectors = 10
vector_factory = kwant.kpm.RandomVectors(fsyst)
init_vectors = [next(vector_factory) for _ in range(num_vectors)]
[6]:
p_op = kpm_tools.kpm_generator.GeneralVectorExpansion(
fsyst,
params={},
vector_factory=init_vectors,
coef_function=kpm_tools.kpm_funcs.coef_projector_function,
)
e_F = 0.2
p_op_vectors = p_op(e_F)[0]
[7]:
spectrum_full = kpm_tools.kpm_generator.SpectralDensityIterator(
fsyst, params={}, vector_factory=init_vectors
)
[8]:
spectrum_projected = kpm_tools.kpm_generator.SpectralDensityIterator(
fsyst, params={}, vector_factory=p_op_vectors
)
[9]:
(
hv.Area(
(spectrum_full.energies,
spectrum_full.densities.real)
)
*
hv.Area(
(spectrum_projected.energies,
spectrum_projected.densities.real)
).opts(alpha=0.8)
).opts(
xlabel="E[t]",
ylabel="DoS[a.u.]",
)
[9]: