Physics

Self-Consistent Field (SCF)

TensorBinding.cdw_hartree_builder — Method
cdw_hartree_builder(U; background=0.5, maxdim=100, cutoff=1e-8)

Return a simple spinless CDW Hartree builder:

V_H[n] = U * (rho[n] - background)

This is intentionally local and minimal; pass a custom hartree_builder to scf_meanfield for long-range interactions or other channels.

source
TensorBinding.dense_hartree_builder — Method
dense_hartree_builder(V, L, sites; background=nothing, type=Float64, tol=1e-8,
                      maxdim=100, cutoff=1e-8, kwargs...)

Return a Hartree builder backed by a dense interaction kernel. V can be an existing interaction MPO or a function V(i, j) on 0-indexed coordinates; type, tol and kwargs... go to get_mpo when V is a function.

source
TensorBinding.density_profile_from_dm — Method
density_profile_from_dm(density_mpo, sites; mode=:direct) -> MPS

Extract a density profile MPS from the diagonal of a density-matrix MPO. mode=:complement returns 1 - diag(D).

source
TensorBinding.fock_mpo_from_density — Method
fock_mpo_from_density(density_mpo, interaction_op, sites;
                          sign=-1, maxdim=100, cutoff=1e-8) -> MPO

Build a Fock/exchange MPO from a density matrix and a two-body interaction kernel by element-wise multiplication:

F[i, j] = sign * V[i, j] * rho[i, j]

For the usual exchange term use the default sign=-1.

source
TensorBinding.get_scf — Method
get_scf(H0, U, channel; kwargs...) -> NamedTuple

Convenience front-end for the self-consistent mean-field solvers.

Examples:

res = get_scf(H0, U, :CDW; tol=1e-5, maxiters=30, mixing=0.4)
Hmf = res.ham

Supported channels are :CDW, :magnetic, :swave, and :pwave. The wrapper keeps the lower-level SCF routines available while providing a single get_* style entry point for notebooks. It returns the result of the channel's driver: scf_meanfield (:cdw), scf_magnetic_hubbard (:magnetic), scf_swave_hubbard (:swave) or scf_pwave_equalspin (:pwave); their docstrings list the fields, which differ by channel.

Keywords (defaults; the channels a keyword reaches, if not all)

  • interaction=:local (:local, :dense or :distance), distance=1: CDW interaction kind and pair distance (:cdw).
  • background=0.5 (:cdw, :magnetic); fermi=0.0 (:cdw, :magnetic).
  • initial_density=nothing, initial_hartree=nothing, density_mode=:direct, Nel=H0.N ÷ 2, spectral_bounds=nothing, stop_on_increase=false (:cdw).
  • density_method=:sp2, or method (default nothing), which takes precedence.
  • Ncheb=100, scale=nothing, purification_scale_padding=1.05, maxdim=100, cutoff=1e-8, purif_maxiter=40, purif_tol=1e-6, verbose=true. A scale that is not given is left to the driver's default: H0.scale when it is set (:magnetic, and through the BdG builders :swave/:pwave), a DMRG estimate of every mean-field Hamiltonian otherwise and always for :cdw. (Up to v0.1.1 :magnetic received scale=nothing and estimated every iteration by DMRG.)
  • tol=1e-6, maxiters=30, mixing=0.4: passed to the drivers as scf_tol, max_scf_iter and mix. For :cdw with interaction=:dense or :distance, tol is also the QTCI tolerance of the Hartree builder (:local does not use it).
  • builder_kwargs...: for :cdw, forwarded only to dense_hartree_builder (interaction=:dense) and ignored by the :local and :distance builders; for the other channels, forwarded to the driver (scf_magnetic_hubbard, scf_swave_hubbard, scf_pwave_equalspin).
source
TensorBinding.get_scf — Method
get_scf(H0::TBHamiltonian, channel::Symbol; interaction=:dense, kwargs...) -> NamedTuple

Like get_scf(H0, U, channel) but reads the interaction from H0.interaction_mpo (stored via add_interaction!). Supported channels: :cdw, :magnetic.

For :cdw the default interaction=:dense passes the stored MPO directly to dense_hartree_builder. For :magnetic the stored MPO is handled by scf_magnetic_hubbard which dispatches on U::Union{Number,MPO}.

Calling with :swave or :pwave raises an informative error — those channels require an explicit coupling constant. Returns the result of the channel's driver (scf_meanfield for :cdw, scf_magnetic_hubbard for :magnetic); see their docstrings for the fields.

source
TensorBinding.hartree_mpo_from_density — Method
hartree_mpo_from_density(density_mps, interaction_op, sites;
                             background=nothing, maxdim=100, cutoff=1e-8)

Apply an interaction kernel MPO to a density profile and convert the resulting coefficient MPS into a diagonal Hartree MPO.

source
TensorBinding.pair_distance_hartree_builder — Function
pair_distance_hartree_builder(L, sites, distance_or_terms, weight=1;
                              background=nothing, type=Float64, tol=1e-8,
                              maxdim=100, cutoff=1e-8)

Return a Hartree builder for sparse pair interactions generated from non-cyclic shift MPOs. distance_or_terms is either one distance (with weight) or a vector of distance => weight terms (weight is then ignored), as in pair_distance_interaction_mpo.

source
TensorBinding.pair_distance_interaction_mpo — Function
pair_distance_interaction_mpo(L, sites, distance, weight=1; type=Float64, tol=1e-8,
                              maxdim=100, cutoff=1e-8)
pair_distance_interaction_mpo(L, sites, terms; type=Float64, tol=1e-8,
                              maxdim=100, cutoff=1e-8)

Build an interaction MPO for arbitrary fixed-distance site pairs. For a bond weight w(i) on the pair (i, i+d), the operator contains row=i+d,col=i with weight w(i) and row=i,col=i+d with weight w(i). The shifts are non-cyclic, so boundary-wrapping bonds are absent.

source
TensorBinding.pwave_equalspin_anomalous_profiles — Method
pwave_equalspin_anomalous_profiles(density_mpo, Hbdg; distance=1,
                                   maxdim=100, cutoff=1e-8) -> (F_up, F_dn)

Extract nearest-neighbor equal-spin triplet anomalous bond profiles from a spinful BdG density matrix. The profile value at i corresponds to the bond (i, i + distance) in the same non-cyclic convention as build_shift_mpo.

source
TensorBinding.scf_magnetic_hubbard — Method
scf_magnetic_hubbard(H0, U; kwargs...) -> NamedTuple

Two-channel collinear magnetic mean-field loop for the on-site Hubbard model. If H0 is spinful, the spin-up and spin-down one-body blocks are obtained by projecting out the spin core, matching the magnetic RPA convention. If H0 is spinless, the previous two-copy behavior is retained.

H_up = H0_up + U * diag(n_down - background)
H_dn = H0_dn + U * diag(n_up   - background)

Returns (; converged, iterations, rms_error, rho_up, rho_dn, density_up_mpo, density_dn_mpo, H_up, H_dn, history): the mixed spin-resolved density profiles (MPS), the last density matrices of each spin (nothing when no iteration ran), the last mean-field TBHamiltonian of each spin (the bare spin blocks when no iteration ran), and one (; iter, rms_error, rms_up, rms_dn, particle_error) per iteration in history.

source
TensorBinding.scf_meanfield — Method
scf_meanfield(H0, hartree_builder; kwargs...) -> NamedTuple

Generic self-consistent mean-field loop.

Workflow per iteration:

  1. Build H_MF = H0 + H_Hartree.
  2. Compute the density matrix by density_method = :kpm | :mcweeny | :sp2.
  3. Extract a density profile MPS.
  4. Compute RMS error, mix density, rebuild Hartree term.

Returns (; converged, stopped_by_residual_increase, iterations, history, rms_error, density_mpo, density_mps, hartree_mpo, fock_mpo, ham): the density matrix, its density profile (MPS), the Hartree and Fock MPOs (fock_mpo = nothing without fock_builder) and the mean-field TBHamiltonian. When the loop converges they belong to the last iteration and the profile is the mixed one; otherwise (also when stop_on_increase=true stops it) they belong to the iteration with the lowest residual, with its unmixed profile, and rms_error is that residual. history holds one (; iter, rms_error, particle_error, maxlinkdim_H, maxlinkdim_density) per iteration. max_scf_iter must be at least 1.

source
TensorBinding.scf_pwave_equalspin — Method
scf_pwave_equalspin(H0, V; kwargs...) -> NamedTuple

Minimal spinful equal-spin p-wave triplet SCF. The pairing fields live on nearest-neighbor bonds by default:

Delta_up(i) = pairing_sign * V * F_up(i, i + distance)
Delta_dn(i) = pairing_sign * V * F_dn(i, i + distance)

eta_down=-1 gives a helical initial seed, while eta_down=1 starts the two equal-spin channels with the same sign.

Returns (; converged, iterations, rms_error, delta_up_mps, delta_dn_mps, anomalous_up_mps, anomalous_dn_mps, density_mpo, ham, history): the mixed equal-spin gap profiles and the last anomalous profiles (MPS), the last BdG density matrix and BdG TBHamiltonian (nothing when no iteration ran), and one (; iter, rms_error, rms_up, rms_dn, maxlinkdim_H, maxlinkdim_density, maxlinkdim_delta_up, maxlinkdim_delta_dn) per iteration.

source
TensorBinding.scf_swave_hubbard — Method
scf_swave_hubbard(H0, U; kwargs...) -> NamedTuple

Attractive on-site Hubbard s-wave SCF. This is a convenience wrapper around scf_swave_superconducting with the Hartree channel enabled. Positive U means attraction by default:

Delta_i = -U F_i
V_up    = -U (rho_dn - background)
V_dn    = -U (rho_up - background)

Returns the result of scf_swave_superconducting (see there for the fields).

source
TensorBinding.scf_swave_superconducting — Method
scf_swave_superconducting(H0, g; kwargs...) -> NamedTuple

Spin-singlet s-wave pairing SCF. By default this keeps the normal Hamiltonian fixed and updates only the pairing channel. Set include_hartree=true to also self-consistently update spin-resolved onsite Hartree potentials,

Delta_new(i) = pairing_sign * g * F_singlet(i)
V_up(i)      = hartree_sign * hartree_coupling * (rho_dn(i) - background)
V_dn(i)      = hartree_sign * hartree_coupling * (rho_up(i) - background)

where F_singlet is extracted from the Nambu off-diagonal block of the BdG density matrix. If H0 is spinless, a spin degree of freedom is added to a working copy before building BdG Hamiltonians.

Returns (; converged, iterations, rms_error, delta_mps, anomalous_mps, rho_up_mps, rho_dn_mps, hartree_up_mpo, hartree_dn_mpo, density_mpo, ham, history): the mixed gap profile Δ(i) and the last anomalous profile F(i) (MPS), the spin-resolved density profiles (updated only with include_hartree=true, otherwise the initial seeds), the Hartree MPOs (nothing unless include_hartree=true), the last BdG density matrix and BdG TBHamiltonian (nothing when no iteration ran), and one (; iter, rms_error, rms_delta, rms_up, rms_dn, maxlinkdim_H, maxlinkdim_density, maxlinkdim_delta) per iteration.

source
TensorBinding.staggered_magnetic_initial — Method
staggered_magnetic_initial(H; amplitude=0.05, background=0.5)
    -> (rho_up, rho_dn)

Build a simple antiferromagnetic initial guess for a Hubbard mean-field loop. If H is spinful, the spin core is first projected out so the returned profiles live on the same spinless position/sublattice sites as each spin block.

source
TensorBinding.swave_anomalous_profile — Method
swave_anomalous_profile(density_mpo, Hbdg; maxdim=100, cutoff=1e-8) -> MPS

Extract the local singlet anomalous profile from a spinful s-wave BdG density matrix. The returned MPS is the diagonal of the Nambu particle-hole block projected onto the spin-singlet tensor (i sigma_y).

source
TensorBinding.swave_normal_profiles — Method
swave_normal_profiles(density_mpo, Hbdg; mode=:particle,
                           maxdim=100, cutoff=1e-8)
    -> (rho_up, rho_dn)

Extract spin-resolved local normal densities from a spinful BdG density matrix. mode=:particle uses the particle-particle block directly; mode=:hole_complement uses 1 - diag(hole-hole block).

source

Random Phase Approximation (RPA)

TensorBinding.get_bubble_mpo — Method
get_bubble_mpo(H1::TBHamiltonian, H2::TBHamiltonian, ω; ...) -> MPO

Compute the non-interacting polarization bubble Π₀(ω) on H1.sites.

Keyword arguments

  • ϵF : Fermi energy (physical units). Default 0.0. The :kpm density is θ(ϵF − H); McWeeny purification starts from the level H.center + ϵF (the convention of mcweeny_purify, the same level when H.center = 0); purify_method=:sp2 fixes the filling instead and requires ϵF = 0.
  • P_method : :purification (default) or :kpm — how to compute density matrices. With :purification, a density cached by the same purify_method at the same ϵF (McWeeny) or filling (SP2), or one set by hand, is reused.
  • GF_method : :kpm (default) or :krylov — how to compute G_eff(ω).
  • Ncheb : Chebyshev order (KPM methods only). Default 150.
  • maxdim : Maximum bond dimension. Default 200.
  • cutoff : SVD truncation cutoff. Default 1e-8.
  • purify_method : :mcweeny (default) or :sp2.
  • purify_maxdim : Max bond dim during purification. Default 40.
  • purify_maxiters: Max purification iterations. Default 30.
  • purify_tol : Purification convergence tolerance. Default 1e-5.
  • η : Lorentzian broadening for the GF. Default 1e-3.
  • krylov_nsweeps : DMRG sweeps for Krylov solver. Default 12.
  • krylov_maxdim : Max bond dim for Krylov solver. Default 100.
  • krylov_cutoff : SVD cutoff for Krylov solver. Default 1e-8, at every size; nothing takes the size-aware default of get_green_krylov (the solve is on the doubled register, of dimension D² for D sites).
  • krylov_start : start of the Krylov solve, start of get_green_krylov. Default :random (since v0.2.2); :identity is the start up to v0.2.1.
  • krylov_residual_warn : residual_warn of get_green_krylov, the threshold of the warning on the residual of G_eff. Default 0.1; Inf skips the check and its cost.
  • verbose : Print progress. Default false.
source
TensorBinding.get_bubble_mpo_haydock — Method
get_bubble_mpo_haydock(H1, H2, ωlist; N_steps=30, η=1e-2, maxdim=200, cutoff=1e-8,
                        ϵF=0.0, P_method=:purification, purify_method=:mcweeny,
                        purify_maxdim=40, purify_maxiters=30, purify_tol=1e-5,
                        Ncheb=150, verbose=false) -> Vector{MPO}

Compute the bare polarization bubble Π₀(ω) as an L-site MPO for each frequency in ωlist using Haydock recursion on H_eff = I⊗H₂ − H₁⊗I.

The Krylov basis is built once from the seed Φ₀ = I⊗P₂ − P₁⊗I. For each ω, the resolvent (ω+iη−H_eff)⁻¹Φ₀ is recovered by solving the N×N Lanczos tridiagonal system and forming a linear combination of the stored basis MPOs.

Returns a Vector{MPO} compatible with rpa_wynn_from_bubbles.

Keyword arguments

  • N_steps : Haydock recursion depth. Default 30.
  • η : Lorentzian broadening. Default 1e-2.
  • maxdim : Maximum bond dimension. Default 200.
  • cutoff : SVD truncation cutoff. Default 1e-8.
  • ϵF : Fermi energy. Default 0.0. It reaches the density matrices as in get_bubble_mpo.
  • P_method : :purification (default) or :kpm.
  • purify_method : :mcweeny (default) or :sp2.
  • purify_maxdim : Max bond dim during purification. Default 40.
  • purify_maxiters: Max purification iterations. Default 30.
  • purify_tol : Purification convergence tolerance. Default 1e-5.
  • Ncheb : Chebyshev order for :kpm P_method. Default 150.
  • verbose : Print progress. Default false.
source
TensorBinding.chebyshev2d_gf_coeffs — Method
chebyshev2d_gf_coeffs(ω, scale1, center1, scale2, center2, η, N) -> Matrix{ComplexF64}

Compute 2D Chebyshev expansion coefficients c_{mn} for the scalar Green's function

f(x, y) = 1 / (ω + iη − (scale2·y + center2 − scale1·x − center1))

on the domain [-1,1]×[-1,1], using an N×N Chebyshev-Gauss grid and 2D DCT-II.

C[m+1, n+1] = c{mn} in the expansion f(x,y) ≈ Σ{m,n} c{mn} Tm(x) T_n(y).

N should equal length(Tn_list) from KPM_Tn (i.e. Ncheb + 1).

source
TensorBinding.get_bubble_diag_cheb2d — Method
get_bubble_diag_cheb2d(H1, H2, ωlist; Ncheb=50, maxdim=200, cutoff=1e-8,
                        ϵF=0.0, P_method=:purification, purify_method=:mcweeny,
                        purify_maxdim=40, purify_maxiters=30, purify_tol=1e-5,
                        η=1e-3, coeff_tol=1e-12, qft_tol=1e-9, qft_maxdim=100,
                        verbose=false) -> Vector{MPS}

Diagonal-only variant of get_bubble_mpo_cheb2d.

Returns the k-space diagonal of the non-interacting polarization bubble, diagΠ₀(k, ω) = ⟨k| Π₀(ω) |k⟩, as a Vector{MPS} (one MPS per ω in ωlist) ready for direct plotting. Π₀ is that of `getbubblempocheb2d, with the opposite sign togetbubblempo`.

Compared to get_bubble_mpo_cheb2d, this function:

  • QFTs each D_mn once (inside the (m,n) loop) and extracts its k-space diagonal as an MPS.
  • Accumulates c_mn(ω) · diag(D_mn) as MPS sums instead of MPO sums.
  • Skips the per-ω conjugate_by_qft + extract_diagonal_to_mps steps.

This follows the same paradigm as get_bands: the expensive MPO-level work (Hadamard products, QFT conjugation) is done once per (m,n) pair and shared across all frequencies; per-ω cost is a cheap scalar-weighted MPS addition.

Use get_bubble_mpo_cheb2d when you need the full off-diagonal MPO (e.g. for RPA resummation). Use this function when only χ₀(k,ω) is needed.

H1.sites and H2.sites must be exactly the H.L position qubits: the QFT here treats every site as one, so a spin, Nambu, layer or sublattice index raises an ArgumentError. For a spin-conserving spinful H, the charge bubble is the sum of the results for the two spin sectors TensorBinding._project_spin_sector(H, σ), σ = 1, 2.

Keyword arguments — identical to get_bubble_mpo_cheb2d, plus:

  • qft_tol : truncation tolerance inside conjugate_by_qft. Default 1e-9.
  • qft_maxdim : max bond dimension inside conjugate_by_qft. Default 100.
2D momenta

The diagonal is taken after one QFT over the linear index n = ix + iy·2^Lx, as in get_bands, so on a 2D lattice it is not χ₀(kx, ky, ω): kx and ky are mixed, with a shear. The same holds for get_bubble_diag_cheb2d_svd and get_bubble_diag_cheb2d_tucker. 1D is not affected.

source
TensorBinding.get_bubble_diag_cheb2d_svd — Method
get_bubble_diag_cheb2d_svd(H1, H2, ωlist; Ncheb=50, maxdim=200, cutoff=1e-8,
                            ϵF=0.0, P_method=:purification, purify_method=:mcweeny,
                            purify_maxdim=40, purify_maxiters=30, purify_tol=1e-5,
                            η=1e-3, qft_tol=1e-9, qft_maxdim=100, svd_tol=1e-6,
                            svd_maxrank=20, kernel=:jackson,
                            verbose=false) -> Vector{MPS}

Per-ω SVD-accelerated variant of get_bubble_diag_cheb2d, with the same requirement that H.sites be the H.L position qubits. It takes the keywords of get_bubble_diag_cheb2d except coeff_tol.

For each frequency ω the coefficient matrix C[m,n](ω) is rank-truncated via its own SVD:

`C[m,n](ω) = Σ_s  S_s(ω) · U[m,s](ω) · conj(V[n,s](ω))`   (exact up to truncation)

The per-ω rank r(ω) (typically 2–5 for smooth Lorentzian kernels) is usually much smaller than the Tucker/joint-SVD rank, which must span all frequencies simultaneously. For each (ω, s) one Hadamard product and one QFT are performed, giving

`diag_Π[ω] = Σ_s S_s(ω) · diag(QFT( A_sᵀ ⊙ B_s − C_sᵀ ⊙ E_s ))`

where A_s = Σ_m U[m,s]·TP1[m], B_s = Σ_n conj(V[n,s])·Tn2[n], etc. (the transposes as in get_bubble_mpo_cheb2d). The sign is opposite to that of get_bubble_mpo.

Total Hadamard+QFT operations: Σω r(ω) — compared to N² for the plain variant or rm·rn for Tucker. When r(ω) ≪ rTucker the per-ω SVD is both faster and more accurate, because it uses the optimal basis for each individual C(ω).

Additional keyword arguments (beyond get_bubble_diag_cheb2d):

  • svd_tol : relative singular-value cutoff per ω (fraction of σ_max(ω)). Default 1e-6.
  • svd_maxrank: hard cap on the per-ω rank. Default 20.
  • kernel : Chebyshev damping kernel applied before SVD. :jackson (default) suppresses Gibbs oscillations and dramatically reduces per-ω rank (typically 2–5 instead of ~26). Use :none for exact Chebyshev coefficients.
source
TensorBinding.get_bubble_diag_cheb2d_tucker — Method
get_bubble_diag_cheb2d_tucker(H1, H2, ωlist; Ncheb=50, maxdim=200, cutoff=1e-8,
                               ϵF=0.0, P_method=:purification, purify_method=:mcweeny,
                               purify_maxdim=40, purify_maxiters=30, purify_tol=1e-5,
                               η=1e-3, coeff_tol=1e-12, qft_tol=1e-9, qft_maxdim=100,
                               tucker_tol=1e-3, tucker_maxrank=20, kernel=:jackson,
                               hooi_iters=3, verbose=false) -> Vector{MPS}

Tucker (HOSVD) variant of get_bubble_diag_cheb2d, with the same requirement that H.sites be the H.L position qubits, and the same sign (opposite to that of get_bubble_mpo).

Finds a global low-rank basis in the (m, n) indices shared across all frequencies by stacking the coefficient matrices and performing two mode-SVDs:

  • Mode-1 SVD of [C(ω₁) | C(ω₂) | … | C(ωₙ)] (shape N × N·nω) → basis Um (N × rm)
  • Mode-2 SVD of [C(ω₁)ᵀ | … | C(ωₙ)ᵀ] (shape N × N·nω) → basis Vn (N × rn)

Then for each (s1, s2) ∈ {1…rm} × {1…rn}, one Hadamard product and one QFT are computed (both ω-independent), giving r_m × r_n such operations in total. Per-ω cost reduces to cheap scalar-weighted MPS additions over the core tensor Ã[s1, s2, ω] = Umᵀ C(ω) Vn.

Scaling comparison (assuming rank saturation with Jackson kernel):

  • Plain diagonal: N² Hadamard+QFT
  • Per-ω SVD: nω × rperω Hadamard+QFT
  • Tucker: rm × rn Hadamard+QFT ← frequency-independent

Tucker wins when rm × rn < nω × rperω, which holds for large nω or when the global (m,n) structure is very low-dimensional (as it is after Jackson damping).

Additional keyword arguments (beyond get_bubble_diag_cheb2d):

  • tucker_tol : relative singular-value cutoff for both mode SVDs. Default 1e-3.
  • tucker_maxrank: hard cap on rm and rn. Default 20.
  • kernel : :jackson (default) or :none. Jackson damping is essential here — without it the Tucker rank is high and results are inaccurate.
  • coeff_tol : skip core-tensor entries |Ã[s1,s2,ω]| below this threshold. Default 1e-12.
  • hooi_iters : number of Higher-Order Orthogonal Iteration refinement steps after the initial HOSVD. Each iteration re-optimises Um and Vn jointly, giving the globally optimal Tucker bases for the given rank (vs. the independent mode-SVDs of plain HOSVD). Default 3; set to 0 for HOSVD only.
source
TensorBinding.get_bubble_mpo_cheb2d — Method
get_bubble_mpo_cheb2d(H1, H2, ωlist; Ncheb=50, maxdim=200, cutoff=1e-8,
                       ϵF=0.0, P_method=:purification, purify_method=:mcweeny,
                       purify_maxdim=40, purify_maxiters=30, purify_tol=1e-5,
                       η=1e-3, coeff_tol=1e-12, verbose=false) -> Vector{MPO}

Compute the non-interacting polarization bubble Π₀(ω) for each ω in ωlist using the double Chebyshev decomposition.

Π₀ lives on H1.sites, including any spin, Nambu, layer or sublattice index, and is resolved in those indices, as the result of get_bubble_mpo is. H1 and H2 must have the same site structure.

Sign: the cheb2d bubbles carry the opposite sign to get_bubble_mpo (Π₀ here is −get_bubble_mpo(H1, H2, ω) up to the expansion error).

Instead of building the 2L-site effective Hamiltonian Heff = I⊗H₂ − H₁⊗I and running KPM on it (where bond dimension grows at each Chebyshev step due to entanglement between subsystems), this routine decomposes G_eff as

G_eff(ω) ≈ Σ_{mn} c_{mn}(ω) · T_m(H̃₁) ⊗ T_n(H̃₂)

where Tm, Tn are Chebyshev polynomials of the L-site rescaled Hamiltonians and c_{mn}(ω) are scalar 2D Chebyshev coefficients (cheap, via DCT-II).

The bubble on L-site MPOs is assembled as

Π₀(ω) = Σ_{mn} c_{mn}(ω) · D_{mn},

where D{mn} = (Tm(H̃₁)·P₁)ᵀ ⊙ Tn(H̃₂) − Tm(H̃₁)ᵀ ⊙ (Tn(H̃₂)·P₂) and ⊙ is the site-wise Hadamard product (`hadamardmpo`). The transposes give the Lindhard structure Π₀ = Σab (fa − fb)/(ω + iη − (εb − εa)) · (Pa)ᵀ ⊙ Pb of the eigenprojectors Pa of H₁ and P_b of H₂ (f the occupations of P₁, P₂); for a real H₁ (and P₁) they change nothing and are skipped.

Online multi-ω sweep: All coefficient matrices C[m,n](ω) are precomputed at once (cheap DCT scalars). The (m,n) double loop runs once; each D{mn} is computed once and accumulated into every Π(ω) simultaneously using the scalar c{mn}(ω). This matches the KPM "online" paradigm: the expensive MPO work (Hadamard products) is done once and shared across all frequencies.

Keyword arguments

  • Ncheb : Chebyshev expansion order. Default 50.
  • maxdim : Max bond dimension throughout. Default 200.
  • cutoff : SVD truncation cutoff. Default 1e-8.
  • ϵF : Fermi energy. Default 0.0. It reaches the density matrices as in get_bubble_mpo.
  • P_method : :purification (default) or :kpm.
  • purify_method : :mcweeny (default) or :sp2.
  • purify_maxdim, purify_maxiters, purify_tol : purification controls.
  • η : Lorentzian broadening. Default 1e-3.
  • coeff_tol : Skip (m,n) pairs where |C[m,n]| < coeff_tol, and entire m rows where the row maximum is below coeff_tol. For smooth integrands (large η) this prunes most of the N² terms at negligible accuracy cost. Default 1e-12.
  • verbose : Print progress. Default false.
source
TensorBinding.get_bubble_mpo_cheb2d_tucker — Method
get_bubble_mpo_cheb2d_tucker(H1, H2, ωlist; Ncheb=50, maxdim=200, cutoff=1e-8,
                              ϵF=0.0, P_method=:purification, purify_method=:mcweeny,
                              purify_maxdim=40, purify_maxiters=30, purify_tol=1e-5,
                              η=1e-3, coeff_tol=1e-12, tucker_tol=1e-3,
                              tucker_maxrank=20, kernel=:jackson, hooi_iters=3,
                              verbose=false) -> Vector{MPO}

Tucker-accelerated variant of get_bubble_mpo_cheb2d.

Returns the full non-interacting polarization bubble Π₀(ω) as an MPO at each frequency in ωlist, suitable for RPA resummation and Wynn acceleration on the Dyson geometric series.

The Tucker-2 decomposition of the stacked coefficient tensor finds global bases Um (N×rm) and Vn (N×rn) satisfying

`C[m,n](ω) ≈ Σ_{s₁,s₂} G[s₁,s₂,ω] · (U_m)_{ms₁} · conj((V_n)_{ns₂})`

with C ≈ Um G(ω) Vn†. The rm + rn frequency-independent weighted MPO sums and the rm × rn Hadamard products are computed once; per-ω cost is only rm × rn cheap scalar-weighted MPO additions.

Speedup over get_bubble_mpo_cheb2d: N²→rm·rn Hadamard products.

As in get_bubble_mpo_cheb2d, Π₀ lives on H1.sites, including any spin, Nambu, layer or sublattice index, and carries the opposite sign to get_bubble_mpo.

Additional keyword arguments (beyond get_bubble_mpo_cheb2d):

  • tucker_tol : relative singular-value cutoff for both mode SVDs. Default 1e-3.
  • tucker_maxrank: hard cap on rm and rn. Default 20.
  • kernel : :jackson (default) or :none. Jackson damping reduces Tucker rank.
  • hooi_iters : HOOI refinement iterations after HOSVD initialisation. Default 3.
source
TensorBinding._rpa_pair_sites — Method
_rpa_pair_sites(out_sites) -> Vector{Index}

The 2L-site finalsites for rpa_from_bubble_diag when Π₀ lives on the L indices out_sites: sites 2n-1 and 2n both take dim(out_sites[n]), so interleave_mpo meets no dimension mismatch on a Kagome/Lieb sublattice or a Layer index. Dim-2 sites are the "Qubit" sites siteinds("Qubit", 2L) gives.

source
TensorBinding.get_magnon_bubble — Method
get_magnon_bubble(H, ω; kwargs...) -> MPO

Non-interacting transverse spin polarization bubble Π₀^{+−}(ω) for a spinful TBHamiltonian.

The spin degree of freedom is projected out analytically: the spin-↑ and spin-↓ blocks of H become two independent L-qubit Hamiltonians H_↑ and H_↓, which are passed to get_bubble_mpo(H_↑, H_↓, ω). This corresponds to the Kubo S⁺S⁻ bubble

Π₀^{+−}(ω) = ∑_k (f_{k↓} − f_{k↑}) / (ω − (ε_{k↓} − ε_{k↑}) + iη)

Errors if H.spin_s === nothing. All get_bubble_mpo keyword arguments are accepted and forwarded.

source
TensorBinding.get_magnon_susceptibility — Method
get_magnon_susceptibility(H, MPOV, ω; rpa_nsweeps=20, rpa_maxdim=400,
                          rpa_cutoff=1e-8, rpa_residual_warn=1e-2,
                          return_info=false, kwargs...) -> MPS

RPA transverse spin susceptibility χ^{+−}_RPA(ω) for a spinful TBHamiltonian.

Builds Π₀^{+−}(ω) via get_magnon_bubble, then solves the Dyson equation (I − Π₀ V) χ = Π₀. For a Hubbard-like interaction the interaction MPO is MPOV = U · Id on the orbital sites. Returns the full matrix χ on the spin-projected sites (H.sites without the spin index), vectorized as in rpa_from_bubble_diag (row index on the odd sites, column index on the even ones).

Keyword arguments

  • rpa_nsweeps, rpa_maxdim, rpa_cutoff : Dyson linsolve parameters.
  • rpa_residual_warn, return_info : the residual check of the Dyson solve, as residual_warn and return_info of rpa_from_bubble_diag.
  • All get_bubble_mpo keywords forwarded via kwargs....
source
TensorBinding.get_magnon_susceptibility_wynn — Method
get_magnon_susceptibility_wynn(H, MPOV, ωlist; K_max=6, maxdim_apply=200,
                               cutoff_apply=1e-8, verbose=false,
                               kwargs...) -> (chi_partial, chi_wynn)

Wynn ε-accelerated transverse spin RPA susceptibility over a frequency list.

The spin-↑/↓ sector projections are performed once outside the ω loop; the Neumann-series / Wynn logic is identical to get_rpa_susceptibility_wynn.

Returns (chi_partial, chi_wynn) with the same layout as get_rpa_susceptibility_wynn.

Keyword arguments

  • K_max, maxdim_apply, cutoff_apply, verbose : series / Wynn control.
  • All get_bubble_mpo keywords forwarded via kwargs....
source
TensorBinding.get_rpa_susceptibility — Method
get_rpa_susceptibility(H::TBHamiltonian, MPOV, ω; mode=:charge, rpa_nsweeps=20,
                       rpa_maxdim=400, rpa_cutoff=1e-8, rpa_residual_warn=1e-2,
                       return_info=false, <get_bubble_mpo keywords>) -> MPS

Compute the RPA susceptibility χ(ω) for a system described by H with interaction MPO MPOV. Returns χ = (I − Π₀V)⁻¹Π₀, the full response matrix χij on the sites of Π₀, vectorized as the 2L-site MPS of `rpafrombubblediag(row index i on the odd sites, column index j on the even ones;custom_mpo(χ, sites)turns it into an MPO on thosesites`).

mode keyword

  • :charge (default) — density–density bubble χ^{ρρ}: calls get_bubble_mpo(H, H, ω).
  • :magnetic — transverse spin bubble χ^{+−}: projects H onto its spin-↑ and spin-↓ blocks and calls get_magnon_bubble. Requires H.spin_s !== nothing. MPOV and the result then live on the spin-projected sites (H.sites without the spin index), as in get_magnon_susceptibility.

Internally solves the Dyson equation (I − Π₀V) χ = Π₀. All get_bubble_mpo keyword arguments are accepted and forwarded.

Additional keywords (Dyson solve)

  • rpa_nsweeps : sweeps for the RPA linsolve. Default 20.
  • rpa_maxdim : max bond dim for the RPA linsolve. Default 400.
  • rpa_cutoff : cutoff for the RPA linsolve. Default 1e-8. Close to the RPA instability use a smaller one (see rpa_from_bubble_diag).
  • rpa_residual_warn : warn when the relative residual of the Dyson solve exceeds this value (Inf: no check). Default 1e-2.
  • return_info : return (; chi, residual, residual_floor, maxlinkdim) of the Dyson solve instead of vec(χ). Default false.
source
TensorBinding.get_rpa_susceptibility_column — Method
get_rpa_susceptibility_column(H::TBHamiltonian, MPOV, ω, j; mode=:charge,
                              eta=1e-3, fermi=0.0, rpa_nsweeps=40, rpa_maxdim=400,
                              rpa_cutoff=1e-12, rpa_residual_warn=1e-2,
                              return_info=false, <get_bubble_mpo keywords>) -> MPS

One column of the RPA susceptibility χ = (I − Π₀V)⁻¹Π₀: the L-site MPS x = χ|j⟩, with χij = ⟨i|x⟩, from the Dyson equation (I − Π₀V)x = Π₀|j⟩ on the sites of Π₀. j is the 1-indexed basis state of those sites (`basisstatemps(j − 1, sites): the positionj` when they are position qubits only), or any MPS on them (then x = χ|j⟩).

Where one site's response is enough (χjj, a local probe, one column of a real-space response) the Dyson solve is much cheaper than that of `getrpasusceptibility`, which solves for the whole χ on the 2L-site vectorized register, and it holds its accuracy close to the instability: on a 256-site half-filled chain up to U = 0.999 Uc (condition number 10³), χjj to 1e-7 or better and the column to 1e-6 in 1–4 s, against minutes for the whole χ. The tighter defaults (`rpansweeps = 40,rpacutoff = 1e-12) cost little on L sites. The bubble Π₀(ω) is computed at each call, as ingetrpa_susceptibility`, and usually costs more than the column solve: several columns at one ω pay for it each time.

The bubble is that of get_rpa_susceptibility with the same keywords and defaults (mode, P_method, GF_method, Ncheb, maxdim, cutoff, …), so the result is column j of its χ. The broadening and the Fermi energy are eta and fermi here (the η and ϵF of get_rpa_susceptibility and get_bubble_mpo, which are accepted too). The residual check and return_info (returning (; chi, residual, residual_floor, maxlinkdim)) are those of rpa_from_bubble_diag, with Π₀V built at min(rpa_cutoff, 1e-14).

source
TensorBinding.get_rpa_susceptibility_wynn — Method
get_rpa_susceptibility_wynn(H, MPOV, ωlist; mode=:charge, K_max=6,
                             maxdim_apply=200, cutoff_apply=1e-8, verbose=false,
                             <get_bubble_mpo keywords>) -> (chi_partial, chi_wynn)

Compute the RPA susceptibility χ_RPA(q,ω) for all frequencies in ωlist using the Wynn ε-algorithm for Padé acceleration of the geometric (bubble) series.

mode keyword

  • :charge (default) — density–density channel; uses get_bubble_mpo(H, H, ω).
  • :magnetic — transverse spin channel S⁺S⁻; uses get_magnon_bubble(H, ω). The spin-↑/↓ projections are performed once before the ω loop. Requires H.spin_s !== nothing.

Key idea: instead of inverting (I − Π₀V), build the Neumann series T₀ = Π₀, Tₙ = Tₙ₋₁·V·Π₀ (so Σ Tₙ → χRPA as K→∞), extract scalars sₙ(q,ω) = −Im⟨q|Tₙ(ω)|q⟩ (no 1/π factor) via `getspect_k`, and apply Wynn ε to the partial-sum sequence per (q,ω) for fast convergence.

Returns

  • chi_partial[k+1, i_ω, q] : partial sum Σₙ₌₀ᵏ sₙ(q,ω)
  • chi_wynn[m, i_ω, q] : Wynn ε_{2m}(0) estimate (uses 2m+1 terms)

Keyword arguments

  • mode : :charge (default) or :magnetic.
  • K_max : highest order in the series (total K_max+1 terms). Default 6.
  • maxdim_apply : bond dim for the Tₙ·V·Π₀ products. Default 200.
  • cutoff_apply : truncation cutoff for those products. Default 1e-8.
  • verbose : print per-ω progress. Default false.
  • All get_bubble_mpo keywords (ϵF, P_method, GF_method, Ncheb, maxdim, cutoff, purify_*, η, krylov_*) are accepted and forwarded.
source
TensorBinding.rpa_from_bubble_diag — Method
rpa_from_bubble_diag(Π, MPOV, finalsites, finalfinalsites;
                     nsweeps=20, maxdim=400, cutoff=1e-8, return_info=false,
                     residual_warn=1e-2) -> MPS

Solve the RPA Dyson equation (I − Π₀V) χ = Π₀ for the interacting susceptibility χ using DMRG-style linear solve.

Π (Π₀) and MPOV (V) are MPOs on the L indices finalfinalsites; finalsites are 2L indices, sites 2n−1 and 2n of the dimension of finalfinalsites[n] (_rpa_pair_sites). Returns vec(χ), χ = (I − Π₀V)⁻¹Π₀ the full L-site response matrix χij, as a 2L-site MPS on finalsites in the layout of `vecmpsfrommpo: the row index i on the odd sites, the column index j on the even ones (site n offinalfinalsiteson sites 2n−1 and 2n), so thatcustommpo(χ, finalfinalsites)` is χ as an MPO. The solve is [(I − Π₀V) ⊗ I] vec(χ) = vec(Π₀), with I − Π₀V on the odd sites, started from vec(Π₀).

Near the RPA instability I − Π₀V is nearly singular and the truncation at cutoff limits the accuracy: on a 32-site half-filled chain with V = U·1 at U = 0.999 Uc (condition number 10³) the default cutoff = 1e-8 gives χ to 5e-3, 1e-12 to 1e-7. The relative residual ‖(I − Π₀V)χ − Π₀‖/‖Π₀‖ of the solve is checked, for Π₀V as truncated at cutoff: above `residualwarn(default1e-2) a warning suggests a smallercutoff.returninfo=truereturns(; chi, residual, residualfloor, maxlinkdim)instead of vec(χ);residualis an upper bound that includes the rounding floor of its evaluation (residualfloor, about 1e-7 times the condition number). The check contracts ⟨Aχ|Aχ⟩ once, at χ³w² + χ²w³ operations per site for bond dimensions χ of vec(χ) and w of I − Π₀V: less than a sweep while w is small, more for a high-rank Π₀V. It is skipped, with a message andresidual = NaN, when it would hold more than 2^27 numbers (χ²w² > 6.7e7);residualwarn = Inf` skips it altogether.

source
TensorBinding.rpa_wynn_from_bubbles — Method
rpa_wynn_from_bubbles(Π0_list, MPOV; K_max=6, maxdim_apply=200, cutoff_apply=1e-8,
                      verbose=false) -> (chi_partial, chi_wynn)

Wynn ε-accelerated RPA susceptibility from a pre-computed list of bubble MPOs.

Accepts the output of get_bubble_mpo_cheb2d_tucker (or any Vector{MPO}) directly, skipping the internal bubble calculation. All other logic is identical to get_rpa_susceptibility_wynn: Neumann series T₀ = Π₀, Tₙ = Tₙ₋₁·V·Π₀, followed by per-k-point Wynn ε-acceleration of the partial-sum sequence.

Returns

  • chi_partial[k+1, iω, q] : partial sum Σₙ₌₀ᵏ (−Im⟨q|Tₙ(ω)|q⟩)
  • chi_wynn[m, iω, q] : Wynn ε_{2m}(0) estimate

Keyword arguments

  • K_max : series order (K_max+1 terms). Default 6.
  • maxdim_apply : bond dim for Tₙ·V·Π₀ products. Default 200.
  • cutoff_apply : truncation cutoff for those products. Default 1e-8.
  • verbose : print per-ω progress. Default false.
source
TensorBinding.wynn_epsilon — Method
wynn_epsilon(s) -> Vector{ComplexF64}

Wynn ε-algorithm applied to a scalar sequence s = [s₀, s₁, ..., sK]. Returns the even-column first-row Padé estimates [ε₂(0), ε₄(0), ...]. Uses only additions and reciprocals — no matrix operations.

Two equal entries (|difference| < 1e-30) make the next entry infinite, stored as the sentinel 1e30. Two infinite entries in a column make the correction 1/(∞ − ∞) vanish, so the entry after them is the one two columns back: an exactly converged sequence returns its limit, not the sentinel. A sentinel is still returned where the table is genuinely singular (e.g. an arithmetic sequence).

source

Topology

TensorBinding._chern_marker — Method
_chern_marker(P, L, sites, xfunc, yfunc; l, Λ, maxdim, cutoff, quenched,
              sequential, pk_mpo, to_device=_on_host, device_type=ComplexF64,
              q_add=(), q_trunc=(), c_trunc=(), flat_trunc=(:maxdim, :cutoff),
              progress=nothing, after_step=nothing) -> Function

The Chern-marker assembly of get_C_op_MPO_from_P (documented there), also run on GPU MPOs by chern_marker_gpu. The operators the kernel builds itself (the identity of Q = I − P, the four quenched or two flat position operators, the basis states of the closure) are moved by to_device(·, device_type) (see _on_host). The keywords name the truncation parameters (see _trunc_kwargs) of the steps in which the GPU differs, with the CPU values as defaults: q_add for the sum Q = +(I, −1.0·P) and q_trunc for a truncate! of Q after it (none on the CPU); c_trunc for a truncate! of each of C1–C4 (none); flat_trunc for the one of the flat operator. progress(stage, M) is called with :positions (quenched position operators built), :products (the eight P/Q products), :C1 … :C4 (with that operator) and after_step() after Q, the products, each of C1–C4 and the flat operator.

source
TensorBinding._get_projector — Method
_get_projector(H; method=:kpm, fermi=0.0, Ncheb=300, maxdim=40,
               cutoff=1e-8, Nel=nothing) -> MPO

Compute or retrieve the ground-state projector P for H.

  • method=:kpm (default): uses the cached H._tn_cache if it has at least Ncheb moments; otherwise runs KPM_Tn(H, Ncheb). The Fermi level fermi (in physical units) is rescaled internally.
  • method=:mcweeny: returns H._density_cache if it was computed by McWeeny purification at the same fermi (or set by hand); otherwise runs McWeeny purification with ϵF=fermi.
  • method=:sp2: same (at the same Nel) but uses SP2 purification. Nel sets the target electron count (default: half the number of states, prod(dim, H.sites) ÷ 2).
  • maxdim, cutoff: bond dimension and truncation threshold forwarded to the underlying method.

The projector comes from get_density's dispatcher (_density_matrix, physics/Purification.jl), with the rules above: :kpm here, unlike get_density's, never touches the density cache; :sp2 runs sp2_purify's default 40 iterations. method=:KPM, the spelling up to v0.1.1, is a deprecated alias of :kpm (until v0.1.1 :kpm was an error here). Up to v0.1.1 :KPM also expanded a cached Chebyshev list shorter than Ncheb, always with cutoff 1e-8, and :mcweeny/:sp2 returned a density matrix cached by any method, at any Fermi level or filling.

source
TensorBinding._hermitian_diag — Method
_hermitian_diag(z) -> Complex

The diagonal element ⟨α|(C + C†)/2|α⟩ of the Hermitian part of a marker operator C, given z = ⟨α|C|α⟩ (or a real-weighted sum of them, as the unit-cell value of the _chern_marker closures): since ⟨α|C†|α⟩ = conj(z), it is real(z), kept complex so that the closures keep their return type, and it needs no MPO product for C†.

The Chern-marker operator C = 2πi (Q X P Y Q − P X Q Y P) (and its quenched, sequential and pk_mpo forms) is not Hermitian. Its Hermitian part πi [(Q X P Y Q − Q Y P X Q) − (P X Q Y P − P Y Q X P)] gives the local marker, the mean of the Bianco–Resta P- and Q-forms. The anti-Hermitian remainder is traceless (it drops out of the Chern number) but not locally small: on a trivial Semenoff honeycomb (2 × 2 cells), where P is real and every local marker vanishes, it is up to 0.16i per unit cell. Up to v0.1.1 it was the imaginary part of every get_C (now chern_marker) value.

source
TensorBinding.chern_marker — Function
chern_marker(H::TBHamiltonian, xfunc=nothing, yfunc=nothing;
             method=:kpm, fermi=0.0, l=nothing, Lambda=10,
             Ncheb=300, maxdim=500, cutoff=1e-8,
             Nel=nothing, quenched=true, sequential=false) -> Function

High-level wrapper: compute the ground-state projector via method and return the Chern marker closure from get_C_op_MPO_from_P.

xfunc(i, L_chain) and yfunc(i, L_chain) accept a 0-indexed physical site number i and return raw x/y coordinates. Both default to nothing, in which case they are auto-derived:

  • If H.geometry_uc is set (sublattice models: honeycomb, kagome, lieb, dice, sshsublattice): uses `geometryuc(i+1)[1/2]`, which returns the same Bravais unit-cell position for all sublattice atoms in the same UC.
  • Otherwise falls back to H.geometry(i+1)[1/2].

For a sublattice model the functions still receive the physical site number (0 … n_sub·2^L − 1), while the returned closure takes a unit-cell number uc ∈ 1 … 2^L and sums over the n_sub atoms of that cell (see Returns).

Reuses H._tn_cache or H._density_cache when available. maxdim and cutoff are forwarded uniformly to the projector computation and to all MPO multiplications in the Chern marker assembly.

Lambda is the quenching period Λ (see get_C_op_MPO_from_P). The keywords Λ and Nchebychev and the value method=:KPM (the spellings up to v0.1.1, when this function was get_C) are deprecated aliases of Lambda, Ncheb and :kpm; passing an old and a new spelling together is an ArgumentError (up to v0.1.1 Lambda silently won over Λ).

sequential=true (quenched mode only) skips the C1–C4 MPO×MPO products and instead applies P and the position operators to each basis state inside the closure: cheaper setup, more MPO–MPS applies per evaluated unit cell.

See get_C_op_MPO_from_P for full documentation of the remaining arguments.

Returns

calculate_chern_number(uc::Int) -> ComplexF64 where uc is a 1-indexed unit cell number; the closure sums the marker over all n_sub sublattice atoms in that UC. The value is real (zero imaginary part; see get_C_op_MPO_from_P); real(·) gives the density as a Float64.

source
TensorBinding.get_C_op_MPO_from_P — Method
get_C_op_MPO_from_P(P, L, sites, xfunc, yfunc;
                    l=nothing, Lambda=10, maxdim=500, cutoff=1e-8,
                    quenched=true, sequential=false, pk_mpo=nothing) -> Function

Build the real-space Chern marker and return a closure calculate_chern_number(uc) that evaluates it for unit cell uc (1-indexed; see Returns).

Coordinate functions

xfunc(i, L_chain) and yfunc(i, L_chain) accept a 0-indexed physical site number i and return the raw coordinate (not yet quenched).

  • Plain models (length(sites) == L): i ∈ 0…2^L−1. Examples: xfunc(i, Lchain) = Float64(mod(i, Lchain)) # square x yfunc(i, Lchain) = Float64(div(i, Lchain)) # square y
  • Sublattice models (length(sites) == L+1, last index has dim n_sub): i ∈ 0…n_sub·2^L−1. The function should return the same coordinate for all n_sub atoms within the same unit cell — typically the Bravais position. The auto-derived functions from H.geometry_uc satisfy this automatically. Internally, position MPOs are built on the L position qubits only and extended to the full chain via postpend_op(⋅, sub_s, I).

Quenched mode (quenched=true, default)

Position operators are quenched with the period Λ = Lambda: sin(xfunc/Λ), cos(xfunc/Λ), and similarly for y. The Chern marker uses a 4-term trig decomposition that pre-computes 4 α-independent MPOs (C1–C4) and combines them per site in the closure:

C(α) = 2πi Λ² [ cos_xα cos_yα ⟨α|C1|α⟩ + sin_xα sin_yα ⟨α|C2|α⟩
               − cos_xα sin_yα ⟨α|C3|α⟩ − sin_xα cos_yα ⟨α|C4|α⟩ ]

Exploits sin(θ_r − θ_α) = sinθ_r cosθ_α − cosθ_r sinθ_α to reduce cost from O(N) MPO products to 4 products computed once. Λ² restores physical units.

Flat mode (quenched=false)

Position operators use xfunc/yfunc directly:

C_op = 2πi · (Q x P y Q − P x Q y P)

Most accurate for OBC systems or bulk-averaged quantities (no per-site centring).

In both modes the marker is divided by the unit-cell area A_cell = |a₁ × a₂|, with a₁, a₂ the steps of xfunc/yfunc from unit cell 0 to unit cells 1 and L_chain.

In both modes each ⟨α|C|α⟩ is that of the Hermitian part (C + C†)/2 of the marker operator, i.e. its real part: C itself is not Hermitian, and up to v0.1.1 its traceless anti-Hermitian part gave the local markers imaginary parts of O(0.1) (_hermitian_diag).

Arguments

  • P : ground-state projector MPO (over sites)
  • L : number of position qubits; system has 2^L unit cells
  • sites : full ITensor site index list (length == L or L+1 for sublattice)
  • xfunc, yfunc : coordinate functions; i is 0-indexed over all physical sites
  • l : qubits per spatial direction; inferred as L ÷ 2 if nothing
  • Lambda : quenching period Λ (quenching angle = coord / Λ); Λ, the spelling up to v0.1.1, is a deprecated alias
  • maxdim : MPO bond dimension during all multiplications
  • cutoff : truncation threshold during all multiplications and subtractions
  • quenched: true = 4-term sin/cos decomposition; false = flat operators
  • sequential: quenched mode only; true skips the C1–C4 MPO×MPO products and applies P and the position operators to each basis state inside the closure (see chern_marker)
  • pk_mpo : optional MPO PK (e.g. a valley projector, see valley_chern_marker); when given, the marker is evaluated as ⟨α|PK C_op PK|α⟩

Returns

calculate_chern_number(uc::Int) -> ComplexF64 where uc is a 1-indexed unit cell number (1 … 2^L). For sublattice models the value is the sum of the Chern marker over all n_sub atoms within that unit cell. The value is real (its imaginary part is zero); real(·) gives the Chern number density as a Float64.

Example — quenched square lattice

L_chain = 2^(L ÷ 2)
xfunc(i, _) = Float64(mod(i, L_chain))
yfunc(i, _) = Float64(div(i, L_chain))
C_at  = get_C_op_MPO_from_P(P, L, sites, xfunc, yfunc; Lambda=L_chain, maxdim=100)
uc_c  = (L_chain ÷ 2) * L_chain + L_chain ÷ 2 + 1   # central unit cell
C_c   = real(C_at(uc_c))

Example — honeycomb via chern_marker (auto-derived geometry)

C_at  = chern_marker(H)   # xfunc/yfunc from H.geometry_uc automatically
Nx    = 2^(H.L ÷ 2)                                  # unit cells per row
uc_c  = (Nx ÷ 2) * Nx + Nx ÷ 2 + 1                   # central unit cell
C_c   = real(C_at(uc_c))   # sums the A and B atoms of that cell
source
TensorBinding.get_pump_xop — Method
get_pump_xop(L, sites, xfunc; quenched=false, Lambda=-1.0) -> MPO

Diagonal position operator MPO for the Thouless pump formula.

xfunc(i, N) accepts a 0-indexed site index i ∈ 0…N-1 and the chain length N = 2^L, and returns the raw coordinate. For a 1-indexed chain: xfunc(i, N) = Float64(i + 1).

  • quenched=false (default): diagonal entries are xfunc(i, N) directly.
  • quenched=true: entries are Λ * sin(xfunc(i, N) / Λ) with Λ = Lambda, which smooths the discontinuity at PBC at the cost of a Λ prefactor. A negative Lambda (the default -1.0) means Λ = N (one full period), giving sin(x/N) * N ≈ x for x ≪ N.

Λ, the spelling up to v0.1.1, is a deprecated alias of Lambda.

source
TensorBinding.get_sinx_op — Method
get_sinx_op(L, sites, L_chain, Λ, xfunc) -> MPO

Diagonal MPO for sin(xfunc(i, L_chain) / Λ) over the L-qubit position chain given by sites. xfunc(i, L_chain) receives a 0-indexed site/UC number and returns the raw x-coordinate.

source
TensorBinding.get_thouless_pump — Method
get_thouless_pump(H_of_t, Nt, T, xfunc;
                  P_method=:mcweeny, fermi=0.0, Ncheb=200,
                  maxdim=100, cutoff=1e-8,
                  quenched=false, Lambda=-1.0,
                  Nel=nothing, r_center=nothing, verbose=false) -> Float64

High-level Thouless pump: build P(t_k) for k = 0…Nt-1 via P_method, then compute the M1Q invariant C = M1Q(T) − M1Q(0).

Arguments

  • H_of_t : t -> TBHamiltonian — all calls must share the same site indices (pass ref_sites to get_Hamiltonian inside the factory).
  • Nt : number of time steps.
  • T : period of the pump cycle.
  • xfunc : coordinate function (i, N) -> Float64, 0-indexed.
  • P_method : :mcweeny, :sp2, or :kpm; fermi, Ncheb and Nel are passed to _get_projector with it.
  • r_center : 0-indexed bulk site for M1Q evaluation; defaults to N ÷ 2.
  • quenched : false = flat x̂; true = sin-quenched (removes PBC discontinuity).
  • Lambda : quenching period of the sin-quenched x̂ (see get_pump_xop).
  • verbose : print progress.

The keywords Nchebychev and Λ and the value P_method=:KPM (the spellings up to v0.1.1) are deprecated aliases of Ncheb, Lambda and :kpm.

source
TensorBinding.get_valley_operator — Method
get_valley_operator(H::TBHamiltonian; maxdim=500, cutoff=1e-8) -> MPO

Build the valley operator V for a 2D honeycomb Hamiltonian.

V is constructed as the Haldane NNN Hamiltonian (φ = π/2, NN term zeroed) multiplied by an additional sublattice sign η_i: +1 on sublattice A (index 1), −1 on sublattice B (index 2). The global prefactor is −i/(3√3):

t(dx,dy,fs,ts) = (−i / 3√3) · ν_{dx,dy,fs,ts} · η_{fs}

where ν ∈ {±1} is the Haldane chirality (counterclockwise = +1).

H must be a 2D honeycomb model with H.Lx set and a 2-component sublattice index. The returned MPO shares the same site indices as H.mpo.

source
TensorBinding.get_valley_projectors — Method
get_valley_projectors(V_mpo, sites; maxdim=500, cutoff=1e-8) -> (PK, PK_prime)

Return the two valley projectors from the valley operator V_mpo:

PK       = (I + V) / 2   (K  valley)
PK_prime = (I − V) / 2   (K′ valley)
source
TensorBinding.thouless_pump — Method
thouless_pump(P_array, dt, x_op, sites; r_center, maxdim=100, cutoff=1e-8,
              verbose=false, return_trajectory=false)
    -> Float64, or (; C, trajectory) with return_trajectory=true

Compute the Thouless pump invariant (Chern number) using the local M1Q marker:

M1Q(r, t) = ⟨r| P(t) U†(t) x̂ U(t) P(t) |r⟩

where U(t) is the adiabatic evolution operator generated by h(t) = [∂P/∂t, P(t)], propagated with a second-order Taylor step:

U(k) = (I + h(k−1) dt + h(k−1)² dt²/2) U(k−1),  U(0) = I

The invariant is C = M1Q(r, T) − M1Q(r, 0), evaluated at site r_center. Finite differences for ∂P/∂t use central differences (one-sided at endpoints).

Arguments

  • P_array : Vector{MPO} of length Nt, one instantaneous projector per step.
  • dt : time step (T / Nt).
  • x_op : position operator MPO from get_pump_xop.
  • sites : physical site indices (for identity MPO and matrix_checker).
  • r_center : 0-indexed bulk site at which to evaluate M1Q (required).
  • maxdim : max bond dimension for all MPO operations.
  • cutoff : SVD truncation threshold.
  • verbose : print M1Q(0), M1Q(T), and bond dimension at each step.
  • return_trajectory : if true, return (; C, trajectory) where trajectory is a Vector{Float64} of length Nt+1 with M1Q at each step (index 1 = t=0, index k+1 = t=k·dt). Default false. Up to v0.1.1 it was the tuple (C, M1Q_traj), which destructures the same way.
source
TensorBinding.valley_chern_marker — Function
valley_chern_marker(H, xfunc=nothing, yfunc=nothing;
                    valley=:K, use_sign=true, method=:mcweeny, fermi=0.0, l=nothing,
                    Lambda=10, Ncheb=300, maxdim=500, cutoff=1e-8,
                    Nel=nothing, quenched=true, sequential=false) -> Function

Compute the valley-resolved Chern marker and return a closure calculate_valley_chern(uc::Int) -> ComplexF64.

The valley operator V is built automatically via get_valley_operator(H). Its sign S = sign(V) is computed via sign_mpo (McWeeny purification), giving eigenvalues in {−1, +1}. The occupied K-valley projector is then

PK = P · (I ± S) / 2 · P

where P is the ground-state projector and the sign is chosen by valley (:K → +, :K_prime → −). The PK is symmetrized and passed as pk_mpo to get_C_op_MPO_from_P, which evaluates the Chern marker as ⟨α|PK C_op PK|α⟩.

Arguments

  • valley : :K or :K_prime.
  • use_sign : if true (default), sharpen V to eigenvalues {−1,+1} via sign_mpo before forming the valley projector. Set to false to use V directly (cheaper but less accurate when the valley operator spectrum is not already close to ±1).

All remaining arguments are forwarded to _get_projector and get_C_op_MPO_from_P; see those functions for documentation. The keywords Λ and Nchebychev and the value method=:KPM (the spellings up to v0.1.1, when this function was get_valley_C) are deprecated aliases of Lambda, Ncheb and :kpm.

source
TensorBinding.winding_marker — Function
winding_marker(H::TBHamiltonian, xfunc=nothing;
               method=:kpm, fermi=0.0, Ncheb=300,
               maxdim=15, cutoff=1e-8, Nel=nothing,
               quenched=true, l=nothing, Lambda=10) -> Function

Compute the real-space winding number and return a closure calculate_winding(uc::Int) -> ComplexF64 that evaluates the local winding marker of unit cell uc (1-indexed; see Returns).

The winding number operator is

W_op = σ_z · (P x̂ Q + Q x̂ P)

where P is the occupied-band projector, Q = I − P, x̂ is the position operator, and σ_z is the sublattice chirality (A → +1, B → -1).

H must have a 2-component sublattice index (H.sublattice_s with dim 2). σ_z is built automatically as the diagonal operator diag(+1, −1) on that index tensored with identity on the position qubits.

Coordinate function

xfunc(i, L_chain) -> Float64 accepts a 0-indexed physical site number and returns the raw x-coordinate. Defaults to nothing, in which case it is auto-derived from H.geometry_uc (preferred) or H.geometry: xfunc(i, _) = geom(i+1)[1]. Because geometry_uc returns the same Bravais position for both sublattice atoms in a unit cell, this correctly assigns the same x-coordinate to both A and B sites of each UC.

Quenched vs flat mode

  • quenched=true (default): pre-computes two α-independent MPOs W1 and W2. W(α) = Λ · ⟨α| cos(xα/Λ) W1 − sin(xα/Λ) W2 |α⟩, Λ = Lambda
  • quenched=false: builds a global position operator and returns a closure over the resulting W_op MPO.

Arguments

  • method : :kpm, :mcweeny, or :sp2 (see _get_projector).
  • fermi : Fermi level in physical energy units (:kpm and :mcweeny).
  • Ncheb : Chebyshev order when method=:kpm and no cache is present.
  • maxdim : MPO bond dimension during all multiplications.
  • cutoff : truncation threshold during all multiplications.
  • Nel : target electron count for SP2 (default: half the number of states, prod(dim, H.sites) ÷ 2).
  • l : qubits per direction; inferred as H.L ÷ 2 if nothing.
  • Lambda : quenching period Λ (angle = xfunc/Λ); sets the Λ prefactor.

The keywords Nchebychev and Λ and the value method=:KPM (the spellings up to v0.1.1, when this function was get_W) are deprecated aliases of Ncheb, Lambda and :kpm; passing an old and a new spelling together is an ArgumentError.

Returns

calculate_winding(uc::Int) -> ComplexF64 where uc is a 1-indexed unit cell number (1 … 2^L). The value is the sum of the winding marker over both sublattice atoms (A and B) within that unit cell.

source

Density Matrix Purification

TensorBinding._density_matrix — Method
_density_matrix(H, method; ϵF=0.0, Ncheb=150, kernel=:jackson, lambda=4.0,
                maxdim=40, cutoff=1e-8, Nel=_half_filling(H), maxiters=30, tol=1e-5,
                verbose=false, Tn=nothing, store=true) -> MPO

The density-matrix dispatcher behind get_density, which checks the position space, the method and the density cache first; the defaults are get_density's. RPA's _get_density_matrix (physics/rpa/bubble.jl) and Topology's _get_projector (physics/Topology.jl) call it too, after translating their own method symbols, cache rules and defaults (see each).

  • :mcweeny / :sp2: mcweeny_purify(H; ϵF, …) / sp2_purify(H; Nel, …), which store the result in H._density_cache.
  • :kpm: get_density_from_Tn on the Chebyshev list Tn = (Tn_list, N), expanded with maxdim and cutoff. With Tn = nothing that is H._tn_cache, built by KPM_Tn(H, Ncheb; …) when it is absent or shorter than Ncheb (a longer one is used at its own order). The result is stored in H._density_cache unless store=false. The expansion is that of get_density_from_Tn, the occupied-state projector θ(μ − x) (it was θ(x − μ) until v0.1.1).

Each stored result is recorded with its method and the parameters that fix it (_store_density!, _density_key), so that a later get_density, _get_projector or RPA purification for another method, Fermi level, Nel or order does not return it.

source
TensorBinding._half_filling — Method
_half_filling(H) -> Int

Half the number of states of H, prod(dim, H.sites) ÷ 2: every position, sublattice, layer, spin and Nambu state counts. The default SP2 electron count (H.N ÷ 2 up to v0.1.1, which counts unit cells and gave quarter filling on sublattice, spin and BdG models).

source
TensorBinding._idempotency_error — Method
_idempotency_error(ρ, ρ2) -> Float64

Compute ‖ρ² - ρ‖ / ‖ρ‖ as a measure of how far ρ is from a projection. Returns 0 for an exact density matrix.

source
TensorBinding._mcweeny_iterate — Method
_mcweeny_iterate(ρ; maxiters, maxdim, cutoff, tol, trunc=(:maxdim, :cutoff),
                 progress=nothing, after_step=nothing) -> MPO

The McWeeny loop of mcweeny_purify, also run on GPU MPOs by chern_marker_gpu and the GPU purifications of gpu/purification.jl. Each iteration: ρ² = apply(ρ, ρ; maxdim, cutoff), truncate!(ρ²; <trunc>), the residual ‖ρ² − ρ‖/‖ρ‖, progress(iter, err, ρ), a stop when it is below tol, then ρ ← apply(ρ, +(3ρ, −2ρ²; cutoff); maxdim, cutoff), truncate!(ρ; <trunc>) and after_step(). <trunc> passes the parameters named in trunc (see _trunc_kwargs): both on the CPU, (:cutoff,) on the GPU. ρ is not copied.

source
TensorBinding._mpo_sq — Method
_mpo_sq(ρ; maxdim, cutoff, trunc=(:maxdim, :cutoff)) -> MPO

Compute ρ² via apply and truncate immediately. The intermediate bond dimension of apply is controlled by maxdim; the truncation receives the parameters named in trunc ((:cutoff,) in the GPU purifications).

source
TensorBinding._purified_pair — Method
_purified_pair(guess, a₊, a₋; maxiters, maxdim, cutoff, tol, verbose) -> (ρ₊, ρ₋)

McWeeny-purify the initial guess guess(a₊), then guess(a₋), each built just before its purification: the two density matrices whose difference is sign_mpo (a = ±1/scale) and the finite-difference get_ldos_drho / get_dos_drho (a = ω ± δμ, the Fermi level of the initial guess).

source
TensorBinding._sp2_iterate — Method
_sp2_iterate(ρ, Nel; maxiters, maxdim, cutoff, tol, trunc=(:maxdim, :cutoff),
             add_trunc=(:cutoff,), progress=nothing, after_step=nothing) -> MPO

The SP2 loop of sp2_purify, also run on GPU MPOs by chern_marker_gpu. Each iteration: ρ² = apply(ρ, ρ; maxdim, cutoff), truncate!(ρ²; <trunc>), the residual, progress(iter, err, ρ), a stop below tol, the stop on Tr ρ² > Tr ρ (below), then ρ ← ρ² when Tr ρ² ≥ Nel, else ρ ← +(2ρ, −ρ²; <add_trunc>) and truncate!(ρ; <trunc>); after_step() ends every iteration that did not stop. The CPU truncates with both parameters and sums with cutoff; the GPU truncates with cutoff and sums with both. ρ is not copied.

The second stop is the noise floor. With the spectrum in [0, 1], x² ≤ x for every eigenvalue, so Tr ρ² ≤ Tr ρ; only truncation puts eigenvalues outside, and once they outweigh what is left of the genuine non-idempotency Σ x(1 − x), Tr ρ² > Tr ρ. The map then amplifies them: an eigenvalue 1 + δ becomes 1 + 2δ under ρ², and, since it also raises Tr ρ², the rule Tr ρ² ≥ Nel keeps choosing ρ² (likewise −δ under 2ρ − ρ²), so the residual doubles every iteration until the MPO overflows to NaN. At that point the loop returns the iterate with the smallest residual seen so far, or, when that residual is still 0.1 or more, throws an error: then no iterate came near a projector, and the spectrum left [0, 1] because the input is not a valid guess (a non-Hermitian Hamiltonian, or a scale below its spectral radius), where SP2 used to overflow to NaN or return whatever the last iteration gave. The stop cannot fire in exact arithmetic, and a run in which it does not fire returns what it returned up to v0.1.1. It replaces the runaway (to NaN, or to a matrix far from a projector at maxiters) of SP2 runs whose truncation floor lies above tol: with the default cutoff 1e-8 the floor was 1e-5 to 1e-3 on the small chains tested, against the default tol = 1e-5.

source
TensorBinding.get_density — Method
get_density(H::TBHamiltonian; method=:mcweeny, ϵF=0.0, Ncheb=150, kernel=:jackson,
            lambda=4.0, maxdim=40, cutoff=1e-8, Nel=_half_filling(H), maxiters=30,
            tol=1e-5, verbose=false) -> MPO

Compute and cache the zero-temperature density matrix P = θ(ϵF − H).

If H._density_cache holds a density matrix computed by the same method for the same projector (ϵF for :mcweeny and :kpm, Nel for :sp2, and for :kpm the Chebyshev order expanded, kernel and lambda), or one stored there by hand, it is returned immediately, whatever the truncation keywords (maxdim, cutoff, maxiters, tol); any other is recomputed (and replaced). Set H._density_cache = nothing to force a fresh computation. An unknown method is an error even when a density matrix is cached (up to v0.1.1 the cache answered every method, Fermi level, Nel and order).

method

  • :mcweeny (default) — McWeeny purification P{n+1} = 3Pn² − 2P_n³
  • :sp2 — SP2 purification (1 MPO product/step), requires Nel
  • :kpm — KPM Chebyshev expansion of the Fermi step function

Keyword arguments

  • ϵF : Fermi energy in physical units (:kpm and :mcweeny; :sp2 fixes the filling through Nel instead). Default 0.0.
  • Ncheb : Chebyshev order (:kpm only). Default 150. Reuses H._tn_cache if already built at order ≥ Ncheb; otherwise calls KPM_Tn to build and cache it.
  • kernel : KPM kernel — :jackson (default). HODC is not meaningful for the step function so only convolution kernels are supported.
  • lambda : Jackson kernel damping parameter. Default 4.0.
  • maxdim : Maximum bond dimension. Default 40.
  • cutoff : SVD truncation cutoff. Default 1e-8.
  • Nel : Target electron count (:sp2 only). Default: half the number of states, prod(dim, H.sites) ÷ 2 (H.N ÷ 2, half the unit cells, up to v0.1.1).
  • maxiters: Maximum purification iterations. Default 30.
  • tol : Idempotency convergence tolerance (purification). Default 1e-5.
  • verbose : Print iteration progress. Default false.
source
TensorBinding.get_dos_drho — Method
get_dos_drho(H::TBHamiltonian, ω; dmu=0.05, maxdim=40, cutoff=1e-8,
             maxiters=30, tol=1e-5, verbose=false) -> Float64

get_dos_drho(H::TBHamiltonian, ωs::AbstractVector; ...) -> Vector{Float64}

Compute the total density of states at energy ω as the finite-difference derivative of Tr[ρ(μ)] with respect to μ:

DOS(ω) ≈ (Tr[ρ(ω + δμ)] − Tr[ρ(ω − δμ)]) / (2δμ)

This is the cheapest variant: only the scalar trace of each purified density matrix is needed, so no MPO or MPS subtraction is performed. All other arguments are identical to get_ldos_drho.

source
TensorBinding.get_ldos_drho — Method
get_ldos_drho(H::TBHamiltonian, ω; mode=:mpo, dmu=0.05, maxdim=40,
              cutoff=1e-8, maxiters=30, tol=1e-5, verbose=false) -> MPO or MPS

get_ldos_drho(H::TBHamiltonian, ωs::AbstractVector; ...) -> Vector{MPO} or Vector{MPS}

Compute the local density-of-states at energy ω as the finite-difference derivative of the McWeeny density matrix with respect to μ:

A(ω) ≈ [ρ(ω + δμ) − ρ(ω − δμ)] / (2δμ)

where ρ(μ) = θ(μ − H) is the purified density matrix at Fermi level μ.

Modes

  • mode=:mpo (default): returns the full MPO A(ω). Its diagonal elements give the LDoS: LDoS(r, ω) = ⟨r|A(ω)|r⟩. Subtraction and truncation are performed on the full MPO bond structure.

  • mode=:mps: extracts the diagonal of each ρ as an MPS via extract_diagonal_to_mps before taking the difference. The returned MPS encodes diag(ρ(ω+δμ)) − diag(ρ(ω−δμ)) scaled by 1/(2δμ). This is cheaper than :mpo since the subtraction and all subsequent operations stay in the MPS bond space (no MPO–MPO off-diagonal contributions).

Arguments

  • ω : energy (or ωs: vector) at which to evaluate LDoS
  • mode : :mpo (full operator) or :mps (diagonal only, cheaper)
  • dmu : finite-difference step / broadening
  • maxdim : bond dimension for purification and the final combination
  • cutoff : SVD truncation threshold throughout
  • maxiters: maximum McWeeny iterations per purification call
  • tol : idempotency convergence threshold ‖ρ²−ρ‖/‖ρ‖
  • verbose : print McWeeny residuals
source
TensorBinding.mcweeny_purify — Method
mcweeny_purify(ρ0; maxiters=30, maxdim=40, cutoff=1e-8,
              tol=1e-5, verbose=false) -> MPO

Iterate the McWeeny map ρ{n+1} = 3ρn² - 2ρ_n³ until the idempotency residual ‖ρ² - ρ‖/‖ρ‖ < tol or maxiters is reached.

Arguments

  • ρ0 : initial density matrix MPO (need not be idempotent)
  • maxiters : maximum number of iterations
  • maxdim : maximum MPO bond dimension during multiplication
  • cutoff : cutoff during truncation
  • tol : convergence threshold on ‖ρ²−ρ‖/‖ρ‖
  • verbose : print the residual every 15 iterations

Returns

Purified density matrix MPO.

source
TensorBinding.mcweeny_purify — Method
mcweeny_purify(H::TBHamiltonian; ϵF=0.0, maxiters=30, maxdim=40, cutoff=1e-8,
               tol=1e-5, verbose=false) -> MPO

High-level overload: builds the initial guess from H, runs McWeeny purification, caches the result in H._density_cache (recorded with ϵF, which get_density checks), and returns the purified density matrix.

ϵF shifts the Fermi level of the initial guess ρ₀ = (I − (H − (center + ϵF)·I)/scale) / 2 (see purification_initial_guess), allowing purification to target a band other than half-filling. Default 0.0.

source
TensorBinding.purification_initial_guess — Method
purification_initial_guess(H_mpo, scale, sites; maxdim=40, cutoff=1e-8) -> MPO
purification_initial_guess(H::TBHamiltonian; ϵF=0.0, maxdim=40, cutoff=1e-8) -> MPO

Construct the simplest valid initial guess for purification:

ρ₀ = (I - (H − center·I)/scale) / 2

This maps the rescaled spectrum ∈ [-1, 1] to ρ₀ eigenvalues ∈ [0, 1], the required input range for both mcweeny_purify and sp2_purify.

The TBHamiltonian overload calls _ensure_scale! automatically and accounts for a non-zero spectral center; ϵF shifts the level of the guess, ρ₀ = (I − (H − (center + ϵF)·I)/scale) / 2.

source
TensorBinding.sign_mpo — Method
sign_mpo(A::MPO, sites; scale=1.0, maxdim=500, cutoff=1e-8,
         maxiters=30, tol=1e-5, verbose=false) -> MPO

Compute sign(A) for a Hermitian MPO A via two McWeeny purifications:

sign(A) = θ(A) − θ(−A)

where θ(A) is the projector onto the positive-eigenvalue subspace of A. The two initial guesses

ρ₀₊ = (I + A/scale) / 2   →  McWeeny  →  θ(A)
ρ₀₋ = (I − A/scale) / 2   →  McWeeny  →  θ(−A)

map eigenvalues of ±A from [−scale, +scale] to [0, 1] before purification. scale must be ≥ the spectral radius of A; it defaults to 1.0, which is correct when A has already been constructed with normalised eigenvalues (e.g. from get_valley_operator whose spectrum lies in (−1, +1)).

The returned MPO has eigenvalues in {−1, +1}.

source
TensorBinding.sp2_purify — Method
sp2_purify(ρ0, Nel; maxiters=40, maxdim=40, cutoff=1e-8,
           tol=1e-5, verbose=false) -> MPO

Iterate the SP2 map until convergence:

if Tr(ρ_n²) ≥ N_el:   ρ_{n+1} = ρ_n²          (contract)
else:                  ρ_{n+1} = 2ρ_n - ρ_n²   (expand)

Each step costs one MPO-MPO product. The direction rule drives Tr(ρ) toward Nel and simultaneously pushes eigenvalues to 0 or 1. Convergence is quadratic.

The iteration stops when the residual ‖ρ²−ρ‖/‖ρ‖ is below tol, after maxiters iterations, or once Tr(ρ²) > Tr(ρ): the spectrum has then left [0, 1], which only truncation (or an invalid ρ0) can do, and the map would amplify it (see _sp2_iterate); the iterate with the smallest residual is returned in that case, or an error thrown when that residual is still 0.1 or more.

The spectrum of ρ0 must lie in [0, 1]; normalise with ρ0 = (Id - H/scale) / 2 if starting from scratch.

Arguments

  • ρ0 : initial density matrix MPO with spectrum ⊆ [0,1]
  • Nel : target electron number (Tr of the converged projector)
  • remaining kwargs: same as mcweeny_purify
source
TensorBinding.sp2_purify — Method
sp2_purify(H::TBHamiltonian; Nel=_half_filling(H), maxiters=40, maxdim=40,
           cutoff=1e-8, tol=1e-5, verbose=false) -> MPO

High-level overload: builds the initial guess from H, runs SP2 purification, caches the result in H._density_cache (recorded with Nel, which get_density checks), and returns the purified density matrix. Nel defaults to half-filling: half the number of states, prod(dim, H.sites) ÷ 2 (sublattice, layer, spin and Nambu states included; H.N ÷ 2 up to v0.1.1).

source

Two-Particle / Exciton

TensorBinding.Exciton_Hamiltonian — Method
Exciton_Hamiltonian(H_c, H_v, Ufunc; on_site=nothing, tol_quantics=1e-8,
                    maxbonddim_quantics=100, tol=nothing, cutoff=1e-8,
                    maxdim=200) -> MPO

Build the exciton Hamiltonian on the interleaved 2L-site electron-hole space:

H_exc = (H_c ⊗ I_h − I_e ⊗ H_v) + U

where U is the contact interaction diagonal MPO built from Ufunc by build_interaction_op_exciton; it carries −Ufunc(x) on the states with electron and hole both at x, so a positive Ufunc is attractive.

H_c and H_v are TBHamiltonian objects for the electron and hole single-particle sectors (any geometry: "chain_1d", "square_2d", etc.). Both must have the same L and distinct site indices. The MPO lives on [H_c.sites[1], H_v.sites[1], H_c.sites[2], …]: H_c acts on the electron (odd) sites, H_v on the hole (even) sites, each as given (not transposed). Ufunc(x) gives the interaction strength at site x ∈ {1, …, 2^L} (1-indexed).

on_site keyword (optional): a function V(x) representing the conduction band edge modulation, compressed via QTCI. Applied as +V to the electron sector and −V to the valence sector, so that the hole also feels +V after the H_c − H_v subtraction (type-I semiconductor convention: both carriers confined). tol_quantics and maxbonddim_quantics control the QTCI compression of V.

tol is the cutoff of the sums that add V, by default min(1e-8, 0.1/D) with D the dimension of a sector's site space (1e-8 up to D = 2^23); the keywords cutoff and maxdim are accepted but unused (the returned MPO is not truncated).

Examples

# 1D, uniform hopping, attractive contact interaction −U (U > 0), Gaussian confinement
H_c = get_Hamiltonian("chain_1d", t; L=L)
H_v = get_Hamiltonian("chain_1d", t; L=L)
H_exc = Exciton_Hamiltonian(H_c, H_v, x -> U;
                             on_site = x -> -V0 * exp(-((x - N/2)^2) / (2σ^2)))

# 2D square lattice
H_c = get_Hamiltonian("square_2d", t; L=Lx+Ly, Lx=Lx, Ly=Ly)
H_v = get_Hamiltonian("square_2d", t; L=Lx+Ly, Lx=Lx, Ly=Ly)
H_exc = Exciton_Hamiltonian(H_c, H_v, Ufunc; on_site = x -> dot_potential(x))
source
TensorBinding.build_interaction_op_exciton — Method
build_interaction_op_exciton(L, sites, Ufunc) -> MPO

Build the electron-hole interaction MPO on the 2L-site interleaved space. Ufunc(x) gives the interaction strength when electron and hole are both at position x (contact interaction). sites must be the 2L-site interleaved site index vector.

The returned diagonal MPO holds −Ufunc(x) on the states with electron and hole both at x and zero elsewhere: a positive Ufunc is attractive.

source
TensorBinding.exciton_hamiltonian — Method
exciton_hamiltonian(geometry, params, Ufunc; L, on_site=nothing, scale=nothing,
    tol_quantics=1e-8, maxbonddim_quantics=100, tol=nothing, cutoff=1e-8,
    maxdim=200, kwargs...) -> TBHamiltonian

exciton_hamiltonian(H_c, H_v, Ufunc; on_site=nothing, scale=nothing,
    tol_quantics=1e-8, maxbonddim_quantics=100, tol=nothing, cutoff=1e-8,
    maxdim=200) -> TBHamiltonian

Build an exciton Hamiltonian and wrap it in a TBHamiltonian for use with TensorBinding's KPM, DMRG, and spectral tools.

Site encoding (2L sites total, L = H_c.L):

  • Odd sites (1, 3, …) : electron position qubits (H_c.sites, where H_c acts)
  • Even sites (2, 4, …) : hole position qubits (H_v.sites, where −H_v acts; interleaved)

TBHamiltonian.L = L counts position qubits per sector; TBHamiltonian.sites holds all 2L interleaved MPO sites.

Two calling modes

  1. Geometry string — both bands built from the same geometry and parameters via get_Hamiltonian; any extra kwargs are forwarded to it:

    H = exciton_hamiltonian("square_2d", t, Ufunc; L=Lx+Ly, Lx=Lx, Ly=Ly,
                             on_site = x -> V(x))
  2. Pre-built sectors — pass explicit TBHamiltonian objects for the electron (H_c) and hole (H_v) bands when the two sectors differ (different hopping, disorder, external fields):

    H_c = get_Hamiltonian("chain_1d", t_c; L=L)
    H_v = get_Hamiltonian("chain_1d", t_v; L=L)
    H   = exciton_hamiltonian(H_c, H_v, Ufunc)

Keyword arguments

  • on_site : conduction band edge modulation V(x), 1-indexed. Applied as +V to electron and −V to valence sector (type-I confinement). Compressed via QTCI.
  • scale : exciton spectral half-bandwidth; nothing (default) stores 0.0, i.e. a lazy DMRG estimate on first use.
  • tol_quantics : QTCI tolerance for on_site. Default 1e-8. (The contact term from Ufunc is interpolated at a fixed 1e-8, see build_interaction_op_exciton.)
  • maxbonddim_quantics : QTCI max bond dimension for on_site. Default 100.
  • tol : MPO assembly truncation tolerance, by default min(1e-8, 0.1/2^L) (1e-8 up to L = 23). The geometry method also passes it to get_Hamiltonian for both sectors, whose default is the same: with the fixed 1e-8 of v0.2.0 a 1D sector lost the bond across the middle of the chain from L = 26 (see "Large systems" in get_Hamiltonian).
  • maxdim : the geometry method passes it to get_Hamiltonian for both sectors (default 200, not get_Hamiltonian's 15); the assembled exciton MPO itself is not truncated, so with pre-built sectors it has no effect.
  • cutoff : accepted but unused (default 1e-8): Exciton_Hamiltonian assembles the MPO with tol only (passing cutoff=0.5 gives the same MPO).
source
TensorBinding.mpsexcitonKQ — Method
mpsexcitonKQ(k, Q, sites) -> MPS

Product momentum-basis electron-hole continuum state at fixed total momentum:

|k, Q - k>

Both k and Q are 1-indexed (1:2^LPhys) in the public API. Internally they are shifted to 0-indexed modular arithmetic, and the hole momentum is computed as h = Q - k (mod N).

This is the incoherent continuum probe complement to mpsexcitonQ. mpsexcitonQ(Q, sites) builds the coherent pair state (1 / sqrt(N)) * sum_k |k, Q-k>, while mpsexcitonKQ(k, Q, sites) builds one rank-1 product basis vector in that fixed-Q sector. Stochastic continuum traces sample many such k values and average the resulting MPS-KPM spectra.

The site convention matches the QFT momentum convention: site pair 1 carries bit 0 (LSB-first), with electron bits on odd sites and hole bits on even sites.

source
TensorBinding.mpsexcitonQ — Method
mpsexcitonQ(Q, sites) -> MPS

Normalized fixed-total-momentum exciton state on the interleaved electron-hole chain:

|Q> = (1 / sqrt(N)) * sum_k |k, -k + Q>

Q is 1-indexed (Q in 1:2^LPhys), matching mpsexciton and the rest of the public exciton sampling API. Internally the modular momentum arithmetic is 0-indexed and uses the QFT momentum convention: site pair 1 carries bit 0 (LSB-first).

The construction encodes the constraint k + h = Q (mod N) as a small finite-state MPS rather than explicitly summing over all N = 2^LPhys momenta. For each electron-hole bit pair (a_i, b_i) it keeps a binary carry on the MPS bond and allows only local configurations satisfying

a_i + b_i + carry_in = Q_i + 2 * carry_out

where Q_i is the ith bit of Q - 1. The first bit has carry_in = 0, and the final carry is not fixed, giving addition modulo 2^LPhys.

Scaling: the probe has 2LPhys physical sites, bond dimension at most 2 between bit pairs (the carry), and a local intermediate link of dimension 4 inside each electron-hole pair. Building the probe is therefore O(LPhys) in storage and time, not O(2^LPhys). For very large systems the expensive part is the subsequent MPS-KPM recursion with H_QFT; this compact probe construction should not be the bottleneck.

source
TensorBinding.mpsexcitonQTrace — Method
mpsexcitonQTrace(Q, sites; rng=Random.default_rng()) -> MPS

Random-phase fixed-total-momentum trace probe for the electron-hole continuum:

|r_Q> = (1 / sqrt(N)) * sum_k eta_k |k, Q-k>

where the phases are Rademacher signs eta_k = +/-1. The signs are generated as a product over the bits of k, so the state still has the same compact finite-state structure as mpsexcitonQ: it enforces k + h = Q (mod N) with a carry bond of dimension at most 2, while adding random signs to the electron-bit tensors.

This is the MPS probe used for stochastic continuum traces. For an operator restricted to the fixed-Q sector,

E[<r_Q|A|r_Q>] = (1 / N) * sum_k <k,Q-k|A|k,Q-k>

because the random signs satisfy E[eta_k eta_l] = delta_kl. Building one probe is O(LPhys) and avoids launching one KPM recursion per explicit relative momentum k.

source

Non-Hermitian Extensions

TensorBinding.NonHermitianHamiltonian — Type
NonHermitianHamiltonian

Wrapper for a non-Hermitian TBHamiltonian together with its hermitized block Hamiltonian.

Fields

  • parent : original TBHamiltonian, not modified in-place
  • z : complex reference point used in zI - H
  • block_s : dim-2 auxiliary Index tagged "NHBlock"
  • hermitized : Hermitian TBHamiltonian on [parent.sites...; block_s] ([block_s; parent.sites...] for block_placement = :pre)
  • block_placement : :post or :pre, where block_s sits in hermitized.sites
  • convention : :z_minus_H or :H_minus_z, the upper block hermitize was given
  • scale : the scale hermitize was given (0.0: estimated lazily), not the estimate hermitized.scale may hold later

hermitize(NH; z=…) rebuilds the block Hamiltonian with the same block_placement, convention and scale unless they are passed. The five-argument constructor NonHermitianHamiltonian(parent, z, block_s, hermitized, block_placement) records convention = :z_minus_H and scale = 0.0, the hermitize defaults.

The hermitized Hamiltonian can be passed to existing MPO/KPM routines. Avoid calling tight-binding mutation helpers like add_onsite! on hermitized; mutate parent first and call hermitize again.

source
TensorBinding.add_loss! — Method
add_loss!(H, f; coefficient=-1im, Lx=nothing, tol=nothing, maxdim=200,
          type=Float64, space=:full)

Add a loss/gain term coefficient * diag(f) to the original Hamiltonian MPO. This only modifies H.mpo; it does not create the hermitized NH block. tol is the relative cutoff of the sum, by default min(1e-8, 0.1/D) as for add_onsite!.

source
TensorBinding.add_nh_nonreciprocal_hopping! — Method
add_nh_nonreciprocal_hopping!(H, t_forward, t_backward; nn=1, tol=nothing,
                              maxdim=200, type=ComplexF64)

Add asymmetric hopping directly to H. This is the skin-effect helper: choose, for example, t_forward=t*exp(g) and t_backward=t*exp(-g).

source
TensorBinding.add_nh_onsite! — Method
add_nh_onsite!(H, v; Lx=nothing, tol=nothing, maxdim=200, type=ComplexF64)

Add a possibly complex onsite potential to a position-only TBHamiltonian.

v may be:

  • a number, e.g. 1im * gamma
  • v(n) with n = 0, ..., H.N-1
  • v(ix, iy) with 0-indexed coordinates, requiring Lx=...

This is the non-Hermitian counterpart of add_onsite!; unlike the generic version it preserves complex values by default. tol is the relative cutoff of the sum, by default min(1e-8, 0.1/D) as for add_onsite! (see "Large systems" in get_Hamiltonian).

source
TensorBinding.add_nh_skin_hopping! — Method
add_nh_skin_hopping!(H, t, g; nn=1, convention=:exp, tol=nothing, maxdim=200)

Convenience wrapper for non-reciprocal skin hopping.

  • convention=:exp uses t_R = t * exp(g), t_L = t * exp(-g).
  • convention=:linear uses t_R = t + g, t_L = t - g.
source
TensorBinding.hermitize — Method
hermitize(NH; z=NH.z, cutoff=nothing, maxdim=200, scale=NH.scale,
          convention=NH.convention, block_placement=NH.block_placement)
    -> NonHermitianHamiltonian

Rebuild the hermitized block Hamiltonian from NH.parent, optionally at a new reference point z. The block placement, convention and requested scale of NH carry over unless passed; cutoff and maxdim take their defaults.

source
TensorBinding.hermitized_hamiltonian — Method
hermitized_hamiltonian(H; z=0.0, block_s=nh_block_index(), cutoff=nothing,
                       maxdim=200, scale=0.0, convention=:z_minus_H,
                       block_placement=:post) -> TBHamiltonian

Return the Hermitian block Hamiltonian

[ 0        zI - H ;
  (zI-H)'  0      ]

as a TBHamiltonian. convention=:z_minus_H (default) puts zI - H in the upper block as written; convention=:H_minus_z uses H - zI instead. block_placement controls where the auxiliary block site lives:

  • :post (default) — site order [H.sites...; block_s]; position qubits occupy 1:L directly
  • :pre — site order [block_s; H.sites...]; original layout before postpend change

scale=0.0 keeps the usual lazy KPM spectral-bound estimation. cutoff defaults to min(1e-8, 0.1r/D), D the dimension of the block space and r = min(1, ‖H‖²/‖zI − H‖²) (the block grows with |z|; see "Large systems" in get_Hamiltonian). The non-Hermitian KPM entry points pass their own cutoff here; at large L pass a smaller one (an explicit value above 0.3r/D warns).

The result is a copy of H with the block operator as mpo, the extra site in sites and aux_side = block_placement (the side of the block index, the outermost auxiliary index). L and N stay those of H: they count the position register, as for any auxiliary index; the block index is not recorded in an auxiliary field (spin_s, …), so routines that locate sites through those fields do not know it.

source
TensorBinding.loss_profile_mpo — Method
loss_profile_mpo(H, f; Lx=nothing, type=Float64, space=:full)

Build the real diagonal profile MPO diag(f) used for loss/gain terms. This function does not multiply by im and does not hermitize anything.

By default space=:full, so the diagonal is built on the full Hamiltonian site space H.sites, with basis coordinate n = 0, ..., 2^length(H.sites)-1. Use space=:position only when the profile should live on position qubits before any auxiliary spaces are attached.

source
TensorBinding.nh_block_index — Method
nh_block_index() -> Index

Create the dim-2 auxiliary block index used for non-Hermitian hermitization. State 1 is the upper block, state 2 is the lower block. The index keeps a "Qubit" tag so generic MPO(sites, "Id") construction remains compatible with the existing KPM code paths.

source
TensorBinding.nh_nonreciprocal_hopping_mpo — Method
nh_nonreciprocal_hopping_mpo(H, t_forward, t_backward; nn=1, tol=nothing,
                             maxdim=200, type=ComplexF64)

Build the position-space MPO

t_forward  * K_+^nn + t_backward * K_-^nn

without imposing Hermiticity. t_forward and t_backward may be numbers or site-dependent one-argument functions t(n) with 0-indexed n.

source
TensorBinding._nh_diag_online — Method
_nh_diag_online(NH, n; scale=nothing, nh_scale_padding=1.05, maxdim=100,
                cutoff=1e-8, dmrg_nsweeps=5, dmrg_maxdim=[10, 20, 40],
                dmrg_linkdim=4, source_row=2, source_col=1,
                block_row=2, block_col=1) -> (A_mps, dos)

Online NH KPM diagonal spectral function: run the partial Chebyshev recursion and accumulate the site-resolved diagonal MPS A(r, z) in a single pass, keeping only two partial MPOs in memory at a time.

Compared with nh_kpm_partials + nh_reconstruct_spectral_mps:

  • Memory: O(2 χP²) instead of O(N χP²).
  • Diagonal extractions: N/2 (only even Julia-index partials contribute).
source
TensorBinding._nh_kpm_mps_ldos — Method
_nh_kpm_mps_ldos(NH, n, probe_site; scale, maxdim=100, cutoff=1e-8) -> Real

Online MPS NH KPM: compute the site-resolved spectral weight A(probe_site, z) using the dual-chain MPS partial recursion, keeping only 4 MPS in memory at a time.

probe_site is a 0-indexed physical site. The probes are localized basis states: ketprobe = |block=1⟩ ⊗ |probesite⟩ braprobe = |block=2⟩ ⊗ |probesite⟩

so inner(braprobe, pk) = ⟨2, probesite | Pk | 1, probesite⟩, which is the diagonal element of block{2,1}(Pk) at site probesite — the correct LDOS contribution at that site.

Two chains are propagated on the hermitized block space: |tk⟩ = Tk(A)|ketprobe⟩ (Chebyshev, A = Hherm / scale) |pk⟩ = Pk|ket_probe⟩ (NH partial sum)

with partial recurrence: |p0⟩ = 0, |p1⟩ = S|ketprobe⟩ |pk⟩ = 2S|t{k-1}⟩ + 2A|p{k-1}⟩ − |p_{k-2}⟩

Cost per z-point: O(Ncheb × χH × χψ) instead of O(Ncheb × χ_P²) for MPO mode.

source
TensorBinding._nh_kpm_probe_mps — Method
_nh_kpm_probe_mps(sites, block_s, block_state, site_r) -> MPS

Product-state MPS on the hermitized block space. The block site carries block_state (1-indexed); position sites are set to the big-endian binary encoding of the 0-indexed physical site site_r. Bond dimension 1.

Works for both :pre (sites = [block_s; pos_sites...]) and :post (sites = [pos_sites...; block_s]) layouts — placement is auto-detected.

source
TensorBinding._nh_scalar_online — Method
_nh_scalar_online(NH, n; scale=nothing, nh_scale_padding=1.05, maxdim=100,
                  cutoff=1e-8, dmrg_nsweeps=5, dmrg_maxdim=[10, 20, 40],
                  dmrg_linkdim=4, source_row=2, source_col=1,
                  block_row=2, block_col=1) -> ComplexF64

Online NH KPM scalar DOS: run the partial Chebyshev recursion and accumulate Tr[block{2,1}(Pk)] contributions in a single pass, keeping only two partial MPOs in memory at a time.

Avoids the O(N·χP²) memory cost of `nhkpmpartials` and skips building the intermediate Amps entirely — each contributing step adds only one scalar to the accumulator.

source
TensorBinding._nh_stochastic_online — Method
_nh_stochastic_online(NH, n; scale=nothing, nh_scale_padding=1.05, n_random=10,
                      maxdim=100, cutoff=1e-8, dmrg_nsweeps=5,
                      dmrg_maxdim=[10, 20, 40], dmrg_linkdim=4, source_row=2,
                      source_col=1, block_row=2, block_col=1) -> Real

Stochastic trace NH KPM DOS: estimate Tr[block{2,1}(Pk)] via Monte Carlo averaging over n_random random product-state probes on the position sites.

Each realization draws |φ⟩ = ⊗i (random local state) and runs the dual-chain MPS recursion with ket = |1⟩block ⊗ |φ⟩, bra = |2⟩block ⊗ |φ⟩. The same position state is shared between bra and ket so the estimator is unbiased: E[⟨2,φ|Pk|1,φ⟩] = Tr[P_k] / D, D = 2^L

Cost: O(nrandom × Ncheb × χH × χ_ψ) — no MPO×MPO products.

source
TensorBinding.contract_nh_block — Method
contract_nh_block(W, block_s; row=2, col=1) -> MPO

Extract the (row, col) block of an MPO whose first or last site is block_s, returning an MPO on the remaining sites. The block position is auto-detected (the last site is tried first); the contraction is project_aux's, off the diagonal (_project_end_site, core/AuxDOF.jl).

source
TensorBinding.nh_block_source — Method
nh_block_source(NH; row=2, col=1) -> MPO
nh_block_source(Hh, block_s; row=2, col=1) -> MPO

Build the off-diagonal block source |row><col| x I. The default row=2, col=1 matches the old I_ldn source used in the non-Hermitian KPM recursion.

source
TensorBinding.nh_kpm_partials — Method
nh_kpm_partials(Hh, n; source, scale=nothing, maxdim=100, cutoff=1e-8)
    -> Vector{MPO}
nh_kpm_partials(NH, n; source=nothing, source_row=2, source_col=1, scale=nothing,
                nh_scale_padding=1.05, maxdim=100, cutoff=1e-8, dmrg_nsweeps=5,
                dmrg_maxdim=[10, 20, 40], dmrg_linkdim=4) -> Vector{MPO}

Compute the auxiliary "partial" Chebyshev recursion used by the old non-Hermitian spectral algorithm. If A = Hh / scale and S is the block source, the recurrence is

P_0 = 0
P_1 = S
P_k = 2 S T_{k-1}(A) + 2 A P_{k-1} - P_{k-2}

while T_k(A) is advanced in parallel. The returned vector has length 2n and stores P_0, P_1, ..., P_{2n-1}.

The NonHermitianHamiltonian method builds S with nh_block_source(NH; row=source_row, col=source_col) unless source is given, and resolves the scale: a positive scale as given, otherwise (nothing or 0.0) NH.hermitized.scale when it is set, else nh_kpm_scale at NH.z.

source
TensorBinding.nh_kpm_scale — Method
nh_kpm_scale(H, z_points; scale=nothing, padding=1.05, maxdim=200,
             cutoff=1e-8, convention=:z_minus_H, block_placement=:post,
             dmrg_nsweeps=5, dmrg_maxdim=[10,20,40], dmrg_linkdim=4,
             printinfo=false)

Return one universal, zero-centered Chebyshev scale for NH KPM over all complex points in z_points.

For scale=nothing or scale=0, the parent operator norm is estimated from the Hermitian zero-shift block Hamiltonian

[ 0  -H ; -H'  0 ]

whose spectral radius is ||H||_2. The scale then uses the triangle bound

||zI - H||_2 <= |z| + ||H||_2

and returns padding * (maximum(abs(z_points)) + ||H||_2). This is deliberately conservative and uses the same scale for every point, keeping values comparable across a grid. Passing a positive numeric scale bypasses the estimator.

source
TensorBinding.nh_preprocess_partials — Method
nh_preprocess_partials(partials, block_s; row=2, col=1) -> Vector{MPS}

For each partial MPO, extract the requested NH block and then extract its diagonal as an MPS. This is the old pre_process step without global state.

source
TensorBinding.nh_reconstruct_spectral_mps — Method
nh_reconstruct_spectral_mps(partials, n, block_s; maxdim=100,
                            row=2, col=1) -> (A_mps, dos)

Apply the old Jackson reconstruction to the even partial terms:

A = 2/(pi^2 (2n+1)) * sum_l (-1)^(l/2-1) g_l diag(P_l)

where l = 2, 4, ..., 2n in one-based Julia indexing of the partial list. Returns the diagonal spectral MPS and its summed value.

source
TensorBinding.nh_spectral_function — Method
nh_spectral_function(NH, n; scale=nothing, nh_scale_padding=1.05, maxdim=100,
                     cutoff=1e-8, dmrg_nsweeps=5, dmrg_maxdim=[10, 20, 40],
                     dmrg_linkdim=4, source_row=2, source_col=1,
                     block_row=2, block_col=1) -> (A_mps, dos, partials)

Convenience wrapper for the full non-Hermitian KPM spectral calculation at the reference point stored in NH.z. n is half the expansion: the NH recursion keeps the 2n Chebyshev terms P_0 … P_{2n-1}.

source
TensorBinding.nh_spectrum_grid — Method
nh_spectrum_grid(H, xlims, nx, ylims, ny, n; scale=nothing,
                 nh_scale_padding=1.05, convention=:z_minus_H,
                 block_placement=:post, mode=:scalar, probe_site=0,
                 n_random=10, maxdim=100, cutoff=1e-8, dmrg_nsweeps=5,
                 dmrg_maxdim=[10, 20, 40], dmrg_linkdim=4, verbose=false)

Evaluate the NH KPM spectral weight on a rectangular complex energy grid.

Modes

modeAlgorithmReturns
:scalarMPO×MPO (default)(xgrid, ygrid, Z)
:mpsonline dual-chain MPS, one site(xgrid, ygrid, Z)
:diagMPO×MPO + diagonal extraction(xgrid, ygrid, Z, Z_spatial)
:stochasticstochastic trace, n_random probes(xgrid, ygrid, Z)
  • :scalar — full NH partial MPO recursion; total DOS. O(Ncheb × χ_P²).
  • :mps — dual-chain MPS at a single site (probe_site, 0-indexed). Z is the LDOS at that site, not the total DOS of the other modes. O(χH × χψ) per step.
  • :diag — same as :scalar but also extracts site-resolved diagonal MPS A(r,z). Extra return Z_spatial has shape (H.N, ny, nx) and is complex like Z; its sum over the sites is Z.
  • :stochastic — Monte Carlo trace: average over n_random random product-state probes. Total DOS estimate. O(nrandom × Ncheb × χH × χ_ψ). No MPO×MPO products.

n is half the expansion: every mode uses 2n Chebyshev terms (the progress line prints Ncheb = 2n). Set verbose=true to print one progress line per Re(z) column. If scale is omitted or zero, a single conservative scale is estimated from nh_kpm_scale and reused over the whole grid.

source

Quasiparticle Interference (QPI)

TensorBinding._impurity_mpo — Method
_impurity_mpo(x0, L, sites, V) -> MPO

Build the on-site impurity potential V · |x₀−1⟩⟨x₀−1| as a bond-dimension-1 MPO using OpSum — exact, no QTCI required.

x0 is 1-indexed. The quantics encoding is big-endian (matching binary_to_MPS): site i carries bit (L−i) of the 0-indexed address x0−1, so site 1 holds the MSB.

Uses "projUp" (|0⟩⟨0|) and "projDn" (|1⟩⟨1|) operators defined for SiteType"Qubit".

source
TensorBinding.get_qpi — Method
get_qpi(H, Ncheb, ω_phys_vals;
        impurity_site=nothing, V=1.0, impurity_mode=:delta, sigma=1.5,
        window_fraction=nothing, window_sigma=1.5,
        kernel=:jackson, lambda=4.0,
        maxdim=100, cutoff=1e-8, verbose=false)
    -> Matrix{Float64}

Compute the Quasiparticle Interference (QPI) pattern from a single on-site impurity.

Algorithm

  1. Place impurity V · |x₀−1⟩⟨x₀−1| at site x₀ = impurity_site (default: geometric center via central_index). The impurity MPO is built analytically from OpSum (no QTCI); impurity_mode=:gaussian adds a Gaussian potential instead.
  2. Run an online KPM Chebyshev recursion for the clean (H) and perturbed (H_imp) systems and accumulate the site-resolved diagonal LDOS as one MPS per energy (no T_n cache is stored).
  3. For each energy ω:
    • Subtract LDOS MPS: δA_mps = ldos_imp[ω] − ldos_clean[ω].
    • If window_fraction is set, multiply δA_mps element-wise by a smooth disk mask (built via QTCI using the same SDF machinery as mask_hamiltonian). The mask equals 1 deep in the bulk and rolls off to 0 at the boundary over window_sigma lattice units, suppressing Gibbs-like ringing from open edges.
    • Apply the forward QFT MPO (position → momentum) directly to δA_mps. This works because we already have the diagonal of the spectral function as an MPS; no conjugate_by_qft (which operates on full MPOs) is needed.
    • Read out QPI(k, ω) = |⟨k|δÃ_mps⟩|² using LSB-first bit encoding (site 1 = bit 0), consistent with the TCI.reverse QFT convention.

Arguments

  • H : TBHamiltonian with no auxiliary DOFs (spinless, no Nambu/layer/sublattice).
  • Ncheb : Number of Chebyshev moments for KPM.
  • ω_phys_vals : Physical energies to evaluate.

Keyword arguments

  • impurity_site : 1-indexed site index for the impurity (default: central_index(H)).
  • V : Impurity potential strength. Default: 1.0.
  • impurity_mode : :delta (default) — exact rank-1 projector V·|x₀⟩⟨x₀| via OpSum; :gaussian — smooth Gaussian potential V·exp(-|r−r₀|²/2σ²) built via add_onsite! (lower bond dimension for the KPM recursion). Requires H.geometry to be set when :gaussian.
  • sigma : Gaussian half-width in physical distance units (only used when impurity_mode=:gaussian). Default: 1.5.
  • window_fraction : If set, build a circular (2D) or interval (1D) apodization mask with radius window_fraction × min_half_extent of the bounding box. Requires H.geometry to be set. Default: nothing (no windowing).
  • window_sigma : Sigmoid roll-off half-width in lattice units. Default: 1.5.
  • kernel : KPM kernel (:jackson (default), :lorentz, :fejer or :dirichlet).
  • lambda : Lorentz kernel parameter. Default: 4.0.
  • maxdim : Maximum bond dimension for MPS/MPO operations. Default: 100.
  • cutoff : SVD truncation cutoff. Default: 1e-8.
  • verbose : Print progress. Default: false.

Returns Matrix{Float64} of shape (Nω, N) where N = H.N. Column index k+1 (1-based) corresponds to 0-indexed momentum k.

Example

H     = get_Hamiltonian("square_2d", 1.0; L=8, Lx=4)
ωlist = [0.0]
qpi   = get_qpi(H, 80, ωlist; V=2.0, window_fraction=0.8)
# Reshape to 2D: reshape(qpi[1,:], 2^Lx, 2^Ly)'

Normalisation: built from LDOS in the package's KPM convention (see get_ldos_from_mun): per unit rescaled energy (ω − H.center)/H.scale and times 1/π; multiply by π/H.scale for physical units.

2D maps

As in get_bands, the momenta come from one QFT over the linear index n = ix + iy·2^Lx, not from a QFT along x times one along y, so the reshape above does not give a (kx, ky) map: a modulation along x shows up along y, with a shear, and for Lx ≠ Ly the map is scrambled. 1D is not affected.

source

Quantum Fourier Transform & Band Structure

TensorBinding._embed_displacement_in_full_sites — Method
_embed_displacement_in_full_sites(H, mpo_pos) -> MPO

Like _embed_in_full_sites but pads auxiliary sites with all-ones matrices instead of identity. Required for current-operator construction: the displacement (xᵣ − xᵣ′) depends only on position, so it must be broadcast uniformly across all auxiliary (sublattice, layer, spin, Nambu) index pairs, including off-diagonal ones where physical hoppings exist.

Using identity at an aux site with off-diagonal hoppings (e.g. sublattice A↔B in honeycomb, or inter-layer tunneling in bilayers) would set those current matrix elements to zero and give σ = 0.

source
TensorBinding._embed_in_full_sites — Method
_embed_in_full_sites(H, mpo_pos) -> MPO

Embed mpo_pos (which lives on _pos_sites(H)) into the full H.sites space by prepending/appending dim-1 identity tensors at each auxiliary site.

source
TensorBinding.conjugate_by_qft — Method
conjugate_by_qft(W; tol=1e-9, maxdim=100) -> MPO

Return U · W · U† where U is the Quantum Fourier Transform MPO built from QuanticsTCI.quanticsfouriermpo (normalised, with TCI.reverse applied).

TCI.reverse places the LSB at site 1, matching the quantics encoding used throughout this codebase. The resulting k-space MPO has the same site structure as W but with momenta as the diagonal degree of freedom.

Calling this on the Chebyshev spectral MPO T_n and then extracting the diagonal gives the k-resolved contribution to A(k,ω).

source
TensorBinding.conjugate_by_qft — Method
conjugate_by_qft(H::TBHamiltonian, W::MPO; tol=1e-9, maxdim=100) -> MPO

TBHamiltonian-aware version of conjugate_by_qft. Applies U·W·U† where U is the QFT acting only on the position (Qubit) sites of H, with identity operators at all auxiliary sites (Layer, spin, sublattice, Nambu).

Use this overload whenever W lives on the full H.sites space (including aux indices), as is the case in the bubble pipeline after replace_sites.

source
TensorBinding.conjugate_by_qft_exciton — Method
conjugate_by_qft_exciton(H::TBHamiltonian, W; tol=1e-9, maxdim=100) -> MPO

Two-particle (electron–hole) analogue of conjugate_by_qft for the interleaved 2L-site exciton encoding produced by Exciton_Hamiltonian / exciton_hamiltonian, where one carrier occupies the odd sites (1, 3, …) and the other the even sites (2, 4, …).

Returns U · W · U† where U = U_e ⊗ U_h is the product of two independent Quantum Fourier Transforms, one acting on each carrier's R = H.L position qubits. Conjugating the exciton spectral MPO T_n by U rotates both carriers into momentum space; extracting the diagonal then resolves the joint (kₑ, k_h) weight (apply a relative-/centre-of-mass-momentum shift first to read a fixed total momentum q).

The site list comes from _pos_sites(H) — the same canonical accessor the single-particle conjugate_by_qft(H, W) overload uses — rather than being reverse-engineered from siteinds(W).

The construction mirrors the single-particle conjugate_by_qft but builds the full two-particle transform first:

  1. Two single-particle QFT cores from QuanticsTCI.quanticsfouriermpo (TCI.reverse, normalize=true) — sign=-1 and sign=+1, identical to conjugate_by_qft so the per-carrier convention matches.
  2. The same core is interleaved onto both carrier registers — the even sites (interleave_mpo(…, 0)) and the odd sites (interleave_mpo(…, 1)) — and the two halves are multiplied into the full transforms U and U† (= U_e ⊗ U_h). The product contracts away the interleaved identity tensors, leaving dense cores.
  3. fix_sites re-canonicalises the combined MPOs onto the physical sites (interleave_mpo embeds each core untransposed, so the reversed QFT, which is not symmetric, keeps its orientation).
  4. The conjugation U · W · U† is applied exactly as in the single-particle routine (swapprime left-multiply); the result stays on sites.

Verified to machine precision against the dense U·W·U† (with U taken from the single-particle conjugate_by_qft) for R = 2, 3, 4. As with the 2L-site MPOs involved, raise maxdim (and/or tighten tol) for larger R; the default maxdim=100 starts truncating around R ≳ 4.

See also conjugate_by_qft, Exciton_Hamiltonian, interleave_mpo, fix_sites.

source
TensorBinding.get_spect_k — Method
get_spect_k(W; tol=1e-9, maxdim=100) -> Vector{ComplexF64}

Extract the k-space diagonal of MPO W as a dense vector of 2^L values.

Conjugates W by the QFT (giving W̃ = QFT·W·QFT†), extracts the diagonal as an MPS, then evaluates each ⟨k|W̃|k⟩ for the 2^L quantics k-indices. Uses LSB-first quantics convention (site 1 = least significant bit).

source
TensorBinding.get_bands — Method
get_bands(H_mpo, scale, center, sites, Ncheb, D, ω_vals; kwargs...) -> Matrix{Float64}

Memory-efficient band structure via online Chebyshev KPM accumulation. See the block comment of section 1 above for the projection pipeline (Steps 0–3).

Arguments

  • H_mpo : unscaled Hamiltonian MPO on all sites (position + any aux).
  • scale, center: energy rescaling so that H̃ = (H−center)/scale ∈ (−1, 1).
  • sites : the full site list of H_mpo including any aux indices. Position-only site count is inferred as L_pos = L − n_aux.
  • Ncheb : number of Chebyshev moments.
  • D : spatial dimension (1 or 2).
  • ω_vals : rescaled energies ∈ (−1, 1) at which to evaluate A(k,ω).

Projection keyword arguments

Each projection flag is independent; any combination is valid. An index passed as nambu_s, layer_s or sublat_s is not a position qubit, so it must be projected: with its flag (nambu_proj, layer_proj, sublat_proj) off the QFT would treat the aux site as one more momentum bit, and get_bands throws an ArgumentError instead.

Nambu (BdG particle/hole) projection — Step 0:

  • nambu_proj : project each T_n onto Nambu sectors (default false).
  • proj_nambu : 1 = particle only, 2 = hole only, nothing = sum both.
  • nambu_s : the Nambu Index (auto-detected from H.nambu_s via the TBHamiltonian overload).
  • nambu_side : :pre (default) or :post — position of the Nambu site.

Spin projection — Step 1:

  • spin_proj : project each T_n onto spin channels (default false).
  • proj_s : 1 = ↑ only, 2 = ↓ only, nothing = sum both.
  • spin_s_aux : explicit spin Index; when nothing, falls back to sites[1]. Set automatically by the TBHamiltonian overload so that spin is correctly identified even when Nambu is also prepended at site 1.
  • spin_side : :pre (default) or :post — position of the spin site (add_spin!(H; position=:post) postpends it; the TBHamiltonian overload passes it).

Layer projection — Step 1c (bilayer / multilayer):

  • layer_proj : project each T_n onto individual layers (default false).
  • proj_layer : k = layer k only, nothing = sum all layers.
  • layer_s : the layer Index (auto-detected from H.layer_s).
  • layer_side : :pre (default) — layer is always prepended.

Sublattice auxiliary projection — Step 1b (kagome, Lieb, honeycomb):

  • sublat_proj : project each T_n onto sublattice aux sectors (default false).
  • proj_sl : k = sublattice k only, nothing = sum all. Shared with the legacy sublattice flag (Step 2).
  • sublat_s : the sublattice Index (auto-detected from H.sublattice_s).
  • sublat_side : :post (default) or :pre — position of the sublattice site.

Legacy sublattice mask projection — Step 2 (2-sublattice models without aux index):

  • sublattice : apply a mask sandwich mask · T_n · mask (default false).
  • proj_sl : 1 = mask A only, 2 = mask B only, nothing = both.

k-point sampling keyword arguments

  • xmin, xmax, num_x : grid in x (1D) or kx (2D). Default: full range, 10 pts.
  • ymin, ymax, num_y : grid in ky (2D only). In 2D the kx and ky grids are zipped, not crossed: without kpath or k_groups_override the columns lie on the diagonal cut from (xmin, ymin) to (xmax, ymax) (see kspace_sampling_plan), not on a num_x × num_y grid; use kpath for band paths.
  • num_avg : number of offset points averaged around each center (default 1).
  • k_groups_override : explicit k-point groups (e.g. from kpath_2d); bypasses the grid parameters above (default nothing).

Truncation and performance

  • kernel : KPM broadening kernel (:jackson, :lorentz, :fejer or :dirichlet; default :jackson).
  • lambda : Lorentz kernel width (ignored for Jackson).
  • tol, maxdim, cutoff : MPO truncation parameters passed to apply and truncate!.
  • printinfo : print maxlinkdim every 10 Chebyshev steps (default false).

Returns

Matrix{Float64} of shape (Nω, num_x).

2D: one QFT over the linear index

In 2D the momenta come from one QFT over all position qubits (conjugate_by_qft), i.e. over the linear index n = ix + iy·2^Lx, not from a QFT along x times one along y. The label (ky << Lx) | kx of a k-group is then misread: its low Ly bits are the true ky and its high bits the true kx, plus a shear of (label mod 2^Ly)/2^Ly (for Lx = Ly, ky comes from the x bits and kx from the y bits), so 2D bands are not resolved by (kx, ky). Along Γ → X an anisotropic 8×8 torus (tx = 1, ty = 0.3) follows the ty band, and on 4×4 to 8×8 tori the off-diagonal part of the conjugated Hamiltonian is 0.5–0.7 of its diagonal in Frobenius norm; that part decays with size, the relabelling and the shear do not (checked against dense diagonalisation). 1D is not affected. Until a separable 2D transform is added, use 1D cuts or a dense calculation for 2D bands.

source
TensorBinding.get_bands — Method
get_bands(H, Ncheb, ω_phys_vals; kwargs...)

Convenience overload that infers the spatial dimension D from H.geometry (via length(H.geometry(1))), so callers do not need to pass D explicitly. All keyword arguments are forwarded unchanged to the 4-argument form.

Errors if H.geometry is nothing (custom or geometry-free Hamiltonians must still pass D explicitly via the 4-argument form).

source
TensorBinding.get_bands — Method
get_bands(H, Ncheb, D, ω_phys_vals; kwargs...)
    -> Matrix{Float64}  or  NamedTuple(Ak, ticks, labels)

High-level overload of get_bands for a TBHamiltonian.

Physical energies ω_phys_vals are rescaled via H.scale and H.center.

Auto-detection: All auxiliary site Indices (Nambu, spin, layer, sublattice) and their positions (:pre/:post) are read from the struct fields and excluded from position k-space automatically — no manual index passing required.

Projection kwargs (forwarded verbatim to the low-level MPO method): spin_proj, proj_s, nambu_proj, proj_nambu, layer_proj, proj_layer, sublat_proj, proj_sl, sublattice. The projection flag of every aux index present on H is switched on automatically (_autoenable_proj, one @info record per flag it enables).

The k-point sampling and truncation keywords (k_groups_override, xmin, xmax, num_x, num_avg, ymin, ymax, num_y, kernel, lambda, tol, maxdim, cutoff, printinfo) are those of the low-level method, with the same defaults except num_x, which defaults to 60. In 1D (without kpath) that default is clamped to the number of momenta in [xmin, xmax], so a chain with fewer than 60 momenta (L < 6) samples every one of them; an explicit num_x is used as given (in 2D the planner clamps it to the window).

High-symmetry k-path shortcut — replaces the manual hsk_* + kpath_2d

  • k_groups_override boilerplate with a single call:
res = get_bands(H, Ncheb, 2, omega;
                kpath=[:G, :M, :Kp, :G], kpath_lattice=:honeycomb, num_x=30)
  • kpath : symbol vector defining the path. Use Latin aliases: G=Γ, M, K, Kp=K', X — no special characters needed.
  • kpath_lattice : :honeycomb, :square, or :triangular.
  • kpath_Lx : Lx for the 2D grid; defaults to H.L ÷ 2.
  • num_x : reused as npts_per_segment when kpath is given.

When kpath is set the return value is a NamedTuple: (Ak = Matrix{Float64}(Nω×Nk), ticks = Vector{Int}, labels = Vector{String})

julia heatmap(1:size(res.Ak,2), omega, res.Ak; xticks=(res.ticks, res.labels)) vline!(p, res.ticks; ls=:dash, color=:white)

Otherwise returns Matrix{Float64} as usual (backward-compatible).

Normalisation: the package's KPM convention (see get_ldos_from_mun): the result is the spectral density per unit rescaled energy (ω − H.center)/H.scale times 1/π, so each momentum state integrates to 1/π; multiply by π/H.scale for physical units.

2D bands

In 2D (D = 2) the momenta are not those of a 2D Fourier transform: one QFT runs over the linear index n = ix + iy·2^Lx, which mixes kx and ky (see the low-level method). The kpath labels are therefore not the high-symmetry points they name. 1D is not affected.

source
TensorBinding.hsk_honeycomb — Method
hsk_honeycomb(Lx, Ly) -> NamedTuple

High-symmetry k-points for the honeycomb sublattice Hamiltonian (honeycomb_sublattice_hamiltonian) in quantics integer units (kxidx ∈ [0, 2^Lx−1], kyidx ∈ [0, 2^Ly−1]).

Derivation. The Bloch off-diagonal element is h(k) = t ( 1 + e^{2πi kx/Nx} + e^{2πi ky/Ny} ) Dirac points h=0 require θx = 2π/3 AND θy = 4π/3 (or their conjugates): K : (kxidx, kyidx) = (Nx/3, 2Ny/3) → Cartesian (2π/3, 2π/√3) K' : (kxidx, kyidx) = (2Nx/3, Ny/3) → Cartesian (4π/3, 0)

Because Nx = 2^Lx is never divisible by 3, the K/K' indices are rounded to the nearest integer. Use a large Lx (≥4) for a good approximation.

M is the edge midpoint adjacent to K' along the kx axis: M : (Nx/2, Ny/4) → Cartesian (π, 0) — |h|=1, saddle point

PointSymbolCartesian (b₁/b₂ frame)Quantics index
ΓG(0, 0)(0, 0)
MM(π, 0)(Nx÷2, Ny÷4)
KK(2π/3, 2π/√3)(round(Nx/3), round(2Ny/3))
K'Kp(4π/3, 0)(round(2Nx/3), round(Ny/3))

Standard G–M–Kp–G path (along the kx direction, K' corner at (4π/3,0)):

hs = hsk_honeycomb(Lx, Ly)
kg, ticks = kpath_2d([hs.G, hs.M, hs.Kp, hs.G], Lx; npts_per_segment=30)
Ak = get_bands(H, Ncheb, 2, omega; k_groups_override=kg)
# or using the kpath shortcut:
res = get_bands(H, Ncheb, 2, omega; kpath=[:G, :M, :Kp, :G],
                kpath_lattice=:honeycomb, num_x=30)
source
TensorBinding.hsk_square — Method
hsk_square(Lx, Ly) -> NamedTuple

High-symmetry k-points for a 2D square lattice in quantics integer units.

PointSymbolMeaningQuantics index
ΓGzone centre(0, 0)
XXzone-edge midpoint(Nx÷2, 0)
MMzone corner(Nx÷2, Ny÷2)

Standard path: [:G, :X, :M, :G]

source
TensorBinding.hsk_triangular — Method
hsk_triangular(Lx, Ly) -> NamedTuple

Approximate high-symmetry k-points for a 2D triangular lattice in quantics integer units.

PointSymbolQuantics index
ΓG(0, 0)
MM(Nx÷2, 0)
KK(Nx÷3, Ny÷3)

Standard path: [:G, :M, :K, :G]

source
TensorBinding.kpath_2d — Method
kpath_2d(hs_points, Lx; npts_per_segment=20) -> (k_groups, tick_positions)

Build k-groups for get_bands(H, Ncheb, 2, ω; k_groups_override=k_groups) sampling along a high-symmetry path.

hs_points is an ordered list of (kx_idx, ky_idx) integer tuples defining the path vertices (0-based, kxidx ∈ [0, 2^Lx−1]). `nptsper_segment` points are linearly interpolated between each consecutive pair of vertices.

Returns:

  • k_groups : Vector{Vector{Int}} — single-element groups in the (ky << Lx) | kx linear-index format expected by get_bands. Pass as k_groups_override.
  • tick_positions : 1-based indices into k_groups at each vertex; use as x-axis tick positions when plotting.
# Low-level: explicit tuples
hs = hsk_honeycomb(Lx, Ly)
kg, ticks = kpath_2d([hs.G, hs.M, hs.Kp, hs.G], Lx; npts_per_segment=30)
Ak = get_bands(H, Ncheb, 2, omega; k_groups_override=kg)

# High-level shortcut (preferred):
res = get_bands(H, Ncheb, 2, omega;
                kpath=[:G, :M, :Kp, :G], kpath_lattice=:honeycomb, num_x=30)
# heatmap(1:size(res.Ak,2), omega, res.Ak; xticks=(res.ticks, res.labels))
source
TensorBinding.kpath_setup — Method
kpath_setup(lattice, Lx, Ly, path_syms; npts_per_segment=20)
    -> (k_groups, ticks, labels)

Build k-path inputs for get_bands from a list of high-symmetry symbols. path_syms is a vector of symbols such as [:G, :M, :Kp, :G] (use G for Γ — the Latin alias avoids non-ASCII input). npts_per_segment is the number of points between each consecutive pair.

Returns (k_groups, ticks, labels) ready to pass to get_bands as k_groups_override, and to heatmap as xticks=(ticks, labels).

source
TensorBinding.get_exciton_bands — Method
get_exciton_bands(H_QFT, H, Ncheb, omega_phys_vals; Q_list=nothing, Q_groups=nothing,
                  num_q=nothing, num_avg=1, q_start=nothing, q_end=nothing,
                  kernel=:jackson, lambda=4.0, eta=0.0, m_order=4, maxdim=100,
                  cutoff=1e-8, verbose=false, printinfo=false,
                  q_groups=nothing, K_list=nothing, K_groups=nothing, k_groups=nothing,
                  num_k=H.N, k_start=1, k_end=H.N) -> Matrix{Float64}

CPU momentum-space exciton bands from an already-QFT-conjugated exciton MPO. This is the MPS-KPM analogue of get_exciton_ldos_spatial: for each total momentum label Q it runs an online MPS Chebyshev recursion from mpsexcitonQ(Q, H.sites) = (1 / sqrt(N)) * sum_k |k, -k + Q> and accumulates all requested energies in one pass. The exciton must not use the MPO-KPM get_bands pipeline.

H_QFT supplies the MPO used in the recurrence. The original real-space H::TBHamiltonian supplies metadata (sites, N, L, scale, center) and sets the basis convention for mpsexcitonQ.

Rows are energies, columns are total momenta/groups. Q_list selects momenta directly. Q_groups (or alias q_groups) averages several momentum probes into one output column. K_list, K_groups, k_groups, num_k, k_start, and k_end are accepted as backward-compatible aliases; num_q, q_start and q_end fall back to num_k = H.N, k_start = 1 and k_end = H.N. Momenta are 1-indexed. With the same num_q, the default momenta here (a sampling plan of num_q coarse cells) and in get_exciton_continuum differ, e.g. [1, 4, 7, 10, 13] and [1, 5, 8, 12, 16] for N = 16, num_q = 5: pass Q_list to both to compare them at the same momenta.

Normalisation: the package's KPM convention (see get_ldos_from_mun): with the convolution kernels the result is the spectral density per unit rescaled energy (ω − H.center)/H.scale times 1/π, so each state integrates to 1/π; multiply by π/H.scale for physical units. kernel=:hodc is normalised to 1 (multiply by 1/H.scale).

source
TensorBinding.get_exciton_continuum — Method
get_exciton_continuum(H_QFT, H, Ncheb, omega_phys_vals;
                      Q_list=nothing, num_q=H.N, q_start=1, q_end=H.N,
                      N_sample=4, k_list=nothing, seed=42, normalize=true,
                      kernel=:jackson, lambda=4.0, eta=0.0, m_order=4,
                      maxdim=100, cutoff=1e-8, verbose=false,
                      printinfo=false) -> Matrix{Float64}

Stochastic MPS-KPM trace over the electron-hole continuum at fixed total momentum. For each selected total momentum Q, this estimates

A_cont(Q, omega) = (1 / N) * sum_k <k, Q-k| delta(omega - H_QFT) |k, Q-k>

with random-phase trace probes built by mpsexcitonQTrace(Q, H.sites). This is an incoherent trace over relative momentum, unlike get_exciton_bands, which probes the coherent pair state mpsexcitonQ(Q, H.sites).

H_QFT supplies the already-QFT-conjugated MPO used in the MPS recursion. The original H::TBHamiltonian supplies metadata (sites, N, L, scale, center) and the exciton site convention. The exciton continuum remains an MPS-KPM calculation: no exciton MPO-KPM / get_bands path is used.

Rows are energies, columns are total momenta (1-indexed; with the same num_q the default momenta differ from those of get_exciton_bands, see there). If k_list is provided, those 1-indexed relative momenta are used deterministically for every Q; otherwise N_sample compact random-phase trace probes are drawn for each Q. Each trace probe is a randomized superposition over all |k,Q-k> states, so this avoids a full KPM recursion for every explicit relative momentum.

With normalize=true (default), the result estimates the per-relative-momentum average (1/N) * Tr_Q. With normalize=false, it is multiplied by H.N and estimates the total fixed-Q trace Tr_Q.

Normalisation: the package's KPM convention (see get_ldos_from_mun): with the convolution kernels the result is the spectral density per unit rescaled energy (ω − H.center)/H.scale times 1/π, so each state integrates to 1/π; multiply by π/H.scale for physical units. kernel=:hodc is normalised to 1 (multiply by 1/H.scale).

source

Superconductivity / Nambu

TensorBinding.bdg_hamiltonian — Method
bdg_hamiltonian(H_kin, H_pair, nambu_s; cutoff=nothing) -> MPO

Build a spinless Bogoliubov–de Gennes Hamiltonian on [nambu_s; pos_sites…], in the Nambu basis (c, c†):

H_BdG = P_p ⊗ H_kin  +  P_h ⊗ (−H_kin*)  +  τ_+ ⊗ H_pair  +  τ_- ⊗ H_pair†

For a real H_kin the first two terms are τ_z ⊗ H_kin, built as one term; up to v0.2.0 every H_kin got τ_z ⊗ H_kin, whose hole block −H_kin is wrong when H_kin has imaginary entries (Peierls phases, complex hoppings).

H_kin is the single-particle kinetic/hopping MPO measured from the chemical potential (H_kin = H_tb − μ·I). H_pair encodes the pairing amplitude Δ(i,j).

Note: for spinless fermions c_i† c_j† = −c_j† c_i†, so the pairing matrix must satisfy Δ(i,j) = −Δ(j,i). On-site (s-wave) pairing is therefore forbidden; the minimal allowed symmetry is p-wave (nearest-neighbour, antisymmetric). For the Kitaev chain with uniform p-wave amplitude Δ on the L position sites sites:

H_pair = pairingNNN(L, sites, Δ * MPO(sites, "Id"), 1)   # Δ(i,i+1) = +Δ, Δ(i+1,i) = −Δ

H_pair must hold both entries of each antisymmetric pair itself; the h.c. term τ_- ⊗ H_pair† is built automatically. For a general Δ(i,j) use pairing2MPO.

The result is Hermitian for any H_kin = H_kin† and any complex H_pair.

cutoff is the relative cutoff of the sums, by default min(1e-8, 0.1/D), D the dimension of the BdG site space (1e-8 up to D = 2^23; see "Large systems" in get_Hamiltonian).

source
TensorBinding.bdg_spin_hamiltonian — Method
bdg_spin_hamiltonian(H_kin_up, H_kin_down, H_pair, spin_s, nambu_s;
                     H_soc=nothing, cutoff=nothing) -> MPO

Build a spin-½ singlet BdG Hamiltonian on [nambu_s, spin_s; pos_sites…].

Nambu–spin convention: Ψ = (c_↑, c_↓, c†_↑, c†_↓)ᵀ, the basis in which the singlet pairing is i·σ_y ⊗ Δ (up to v0.2.0 this docstring named the basis (c_↑, c_↓, c†_↓, −c†_↑), in which the singlet pairing would be 1 ⊗ Δ instead).

H_BdG = N(P_↑ ⊗ H_kin_up)  +  N(P_↓ ⊗ H_kin_down)
      + τ_+⊗(i·σ_y) ⊗ H_pair  +  τ_-⊗(−i·σ_y) ⊗ H_pair†
      [+ N(S_z ⊗ H_soc)]

with N(M) = P_p ⊗ M + P_h ⊗ (−M*), the particle and hole blocks. For a real M, N(M) = τ_z ⊗ M, built as one term; up to v0.2.0 every M got τ_z ⊗ M, whose hole block is wrong when M has imaginary entries.

The first two lines are the kinetic energy (allowing spin-dependent fields, e.g. Zeeman: pass H_kin_up = H_tb − (μ+h)·I, H_kin_down = H_tb − (μ−h)·I).

The pairing lines implement singlet Cooper-pair creation via the antisymmetric spin factor i·σ_y = [[0,1],[−1,0]]. For on-site s-wave pairing, build H_pair as a diagonal MPO with Δ on the diagonal.

H_soc (optional) adds an Ising-type spin-orbit coupling N(S_z ⊗ H_soc).

The result is Hermitian for real or complex H_pair and any H_kin_up/dn.

cutoff is the relative cutoff of the sums, by default min(1e-8, 0.1/D), D the dimension of the spinful BdG site space (1e-8 up to D = 2^23; see "Large systems" in get_Hamiltonian).

source
TensorBinding.pairing2MPO — Method
pairing2MPO(f, N, sites; tol=1e-8, type=ComplexF64,
            initial_positions=[], unfoldingscheme=:interleaved, check=false) -> MPO

Antisymmetric analogue of hopping2MPO for superconducting pairing.

Compresses a general N×N pairing matrix Δ[i,j] = f(i,j) into an MPO via Quantics TCI. f is passed directly to TCI — the caller is responsible for providing an antisymmetric function (f(i,j) = −f(j,i)).

For nearest-neighbour pairing prefer pairingNNN — it is exact and avoids TCI. Use pairing2MPO for longer-range or d-wave / p±ip patterns.

H_pair is passed directly to bdg_hamiltonian or bdg_spin_hamiltonian. check=true runs the sampled self-check of hopping2MPO (a sparse f, such as a short-range pairing, can make the default QTCI pivots miss whole bond classes); add_superconductivity!(H, Δ; type=:custom) turns it on.

source
TensorBinding.pairingNNN — Method
pairingNNN(L, sites, hopping, nn; apply_kwargs=NamedTuple()) -> MPO

Antisymmetric analogue of kineticNNN for superconducting pairing.

Returns

H_pair = hopping · Kf^nn  −  Kb^nn · dag(hopping)

where Kf / Kb are the quantics forward / backward unit-shift operators. The sign flip relative to kineticNNN (+ → −) produces an antisymmetric matrix Δ(i,j) = −Δ(j,i), satisfying the Fermi constraint c_i†c_j† = −c_j†c_i†.

For uniform pairing hopping = Δ·I:

H_pair = Δ · (Kf^nn − Kb^nn)

H_pair is passed directly to bdg_hamiltonian or bdg_spin_hamiltonian; the τ_- ⊗ H_pair† (hole-particle) term is built automatically there.

source
TensorBinding.spin_hamiltonian — Method
spin_hamiltonian(H_up, H_down, spin_s;
                 H_Zeeman=nothing, cutoff=nothing) -> MPO

Build a spin-resolved Hamiltonian on [spin_s; pos_sites…]:

H = P_↑ ⊗ H_up  +  P_↓ ⊗ H_down  [+  S_z ⊗ H_Zeeman]

H_up, H_down are MPOs on the same position sites (they may differ for spin-orbit coupling or magnetic exchange). H_Zeeman is an optional position-MPO encoding a local magnetic field h(x); it enters as S_z ⊗ H_Zeeman so spin-↑ gains +½ h(x) and spin-↓ gains −½ h(x).

cutoff is the relative cutoff of the sums, by default min(1e-8, 0.1/D), D the dimension of the spinful site space (1e-8 up to D = 2^23; see "Large systems" in get_Hamiltonian).

source