Core
Utilities
TensorBinding._eval_diag_mps — Method
_eval_diag_mps(A, x) -> Float64Evaluate the diagonal MPS A at the 0-indexed position x using a LSB-first bit encoding (site 1 = bit 0 of x). Equivalent to eval_mps (MSB-first) at the bit-reversed position, but contracts each site tensor with a one-hot vector instead of constructing the full basis MPS.
TensorBinding._mpo_dense_matrix — Method
_mpo_dense_matrix(mpo::MPO) -> Matrix{ComplexF64}Dense matrix of mpo: rows on the primed (output) site indices, columns on the unprimed ones, the first MPO site the most significant digit. Contracted one site at a time with ordinary matrix products, so it stays cheap up to a few thousand states (get_matrix evaluates D² inner products). Every tensor must carry one site index (and its prime); several link indices on a bond are merged. Creates no new indices.
TensorBinding.binary_to_MPS — Method
binary_to_MPS(n, L, sites) -> MPSReturn the computational-basis state |n> as an L-site MPS, where n is encoded in big-endian binary across the L qubit sites.
Example
sites = siteinds("Qubit", 4)
psi = binary_to_MPS(5, 4, sites) # |0101>TensorBinding.build_shift_mpo — Method
build_shift_mpo(sites, q, cyclic) -> MPO
build_shift_mpo(sites, q; cyclic=false) -> MPOBinary adder |n⟩ → |n + q⟩ on the L = length(sites) qubits (site 1 the most significant bit), a bond-dimension-2 carry MPO, for 0 ≤ q < 2^L: modulo 2^L with cyclic = true, otherwise the states with n + q ≥ 2^L are mapped to zero. The keyword form defaults to the open shift; the positional cyclic has no default (its former default true was never reached: a two-argument call dispatches to the keyword method). Negative shifts: shift_mpo.
TensorBinding.constant_mps — Method
constant_mps(sites, value) -> MPSRank-1 MPS whose amplitude is value on every computational-basis state.
TensorBinding.custom_mpo — Method
custom_mpo(mps, new_sites) -> MPOConvert a 2N-site MPS produced by QTCI on an interleaved 2D quantics grid into an N-site MPO by contracting each pair of tensors (2i-1, 2i) and mapping old site indices to new_sites[i].
The first index of each pair becomes the bra (primed) site and the second becomes the ket (unprimed) site, consistent with ITensors MPO conventions.
TensorBinding.custom_mps — Method
custom_mps(qtt, sites) -> MPSReplace the site indices of an MPS obtained from a 1D TCI tensor train with the physical sites of the target system.
TensorBinding.eval_mps — Method
eval_mps(A, n) -> RealEvaluate a profile MPS at the 0-indexed basis coordinate n using the big-endian convention of binary_to_MPS. Do not use _eval_diag_mps for this purpose — that helper uses LSB-first ordering for the QFT momentum convention.
TensorBinding.eval_mps_spatial — Method
eval_mps_spatial(A::MPS; num_x=N, num_avg=1, x_start=1, x_end=N,
x_groups=nothing, box_half=0, Lx=nothing)
-> (; values, centers, groups)Higher-level spatial sampler for a profile MPS such as an SCF occupation/density profile (res.rho_up). It mirrors get_ldos_spatial's num_x / num_avg / x_groups / box_half sampling-and-averaging API, but evaluates the MPS directly with eval_mps instead of running a KPM recursion — so it is cheap enough to sweep a very large system by sampling a grid of positions and averaging, rather than evaluating all 2^L sites.
For each sampled group of (1-indexed) site coordinates the returned value is the mean of eval_mps(A, x-1) over that group. With box_half > 0 each sampled position is expanded into a (2·box_half+1)² neighborhood on the 2D grid (periodic wrap), exactly like get_ldos_spatial; this needs the 2D layout, taken from Lx (defaults to L÷2, with Ly = L - Lx).
Keyword arguments
N = prod(dim(s) for s in siteinds(A)) is the register size (2^L for qubits).
num_x: number of sampled grid positions (default: all2^Lsites).num_avg: sub-positions averaged per grid point along the 1D index (stride).x_start,x_end: 1-indexed sampling window (default1 … 2^L).x_groups: explicit groups — a vector of site indices (one per group) or a vector of vectors (each averaged). Overridesnum_x/num_avg/x_start/x_end.box_half: 2D neighborhood half-width for averaging (0 = no box averaging).Lx: number of x qubits for the 2D layout (defaultnothing;L÷2is used whenbox_half > 0).
Returns
values:Vector{Float64}, the averaged MPS value per group.centers:Vector{Int}, the 1-indexed center site of each sampled group.groups:Vector{Vector{Int}}, the site indices averaged over per group.
For a 2D map, the center (ix, iy) of group g is ix = (centers[g]-1) % 2^Lx, iy = (centers[g]-1) ÷ 2^Lx.
TensorBinding.extract_diagonal_to_mps — Method
extract_diagonal_to_mps(M) -> MPSExtract the diagonal of an MPO M as an MPS by projecting each local bra/ket pair onto equal physical values; the MPS carries the ket (unprimed) site index, whichever order the tensors store their legs in. This is shared by KPM trace/LDOS, SCF, RPA, QFT, and purification routines.
TensorBinding.fibonacci_ldos_sampling_plan — Method
fibonacci_ldos_sampling_plan(L; depth=0, num_x=100, num_avg=1,
orientation=:standard, alignment=:atomic,
centered=true, origin=0)
fibonacci_ldos_sampling_plan(H::TBHamiltonian; kwargs...)Build a deterministic, bounded-size LDOS sampling plan for an L-qubit Fibonacci approximant, the projected-space counterpart of spatial_sampling_plan. At depth == 0 the plan covers the complete F_(L+2) conumber interval. Each additional depth selects the nested atomic renormalization window from fibonacci_rg_partition, with effective_L == L - 3depth.
The selected inherited interval is split into min(num_x, window_count) contiguous integer intervals whose widths differ by at most one. Up to num_avg equidistant conumbers (including both interval endpoints when there is more than one sample) are chosen in each interval and mapped directly to physical sites with fibonacci_site_from_conumber. No full conumber permutation or other F_(L+2)-element array is constructed; storage is proportional to the requested output and sample counts.
Returned fields useful to an LDOS/Slurm/HDF5 workflow include:
groups: physical-site vectors to pass asx_groupswithordering=:physical;centers: physical sites at the representative interval conumbers;conumber_axis: those representative conumbers in the originalLcoordinate system;intervals,interval_first, andinterval_last: represented inherited conumber intervals;sample_conumbers: the inherited conumbers corresponding togroups;sample_sites_flat,sample_conumbers_flat, one-basedgroup_offsets, and zero-basedgroup_offsets_zero: flat representations convenient for Julia and Python/HDF5 consumers respectively (flat[group_offsets[i]: group_offsets[i+1]-1]reconstructs groupiin Julia);column_indices: stable one-based output-column identifiers;depth,effective_L, the originalLandN, requested/actual sampling counts, and all conumber conventions.
intervals and every field containing conumber use the requested centered label convention. The corresponding *_rank* fields are always uncentered ranks in 0:N-1. Thus a zoom always retains its original-L coordinates; the selected sites are never re-conumbered as an independent shorter chain.
When num_avg is larger than an interval, that interval is sampled at every integer conumber and its group_sizes entry is smaller than num_avg. num_x in the result is the actual number of output columns, while num_x_requested records the input value.
Nested (depth > 0) windows are defined only for the canonical atomic phase, so they require alignment=:atomic and origin=0. Reversing the orientation is supported because it maps the canonical atomic interval onto itself.
The TBHamiltonian convenience method is defined in position_spaces/Fibonacci.jl.
TensorBinding.fix_sites — Method
fix_sites(mpo, sites) -> MPOReplace the site indices of mpo (typically built from a TCI tensor train whose indices do not match the system's physical sites) with sites: the ket leg of tensor i becomes sites[i] and the bra leg sites[i]', whichever order the tensor stores them in. Modifies mpo in-place and returns it.
TensorBinding.fused_mpo — Method
fused_mpo(mps, new_sites) -> MPOConvert an N-site MPS with dim-4 physical indices produced by QTCI on a :fused 2D quantics grid into an N-site MPO. Each dim-4 physical index encodes one (bra-bit, ket-bit) pair; a combiner splits it into new_sites[i]' (bra) and new_sites[i] (ket).
TensorBinding.get_diagonal_mpo — Method
get_diagonal_mpo(L, sites, f; type=Float64, tol=1e-8, check=false) -> MPO
get_diagonal_mpo(L, sites, v::AbstractVector; tol=1e-8) -> MPOBuild a diagonal MPO with entry f(x) at 1-indexed site x ∈ {1, ..., 2^L}. Wraps get_mpo with a 1→0 index shift for backward compatibility.
The QTCI build can lose narrow features (a box of a few sites, a single impurity) for some RNG states, or throw on a profile that vanishes almost everywhere; see get_mps. A vector v (v[x] at site x, length 2^L) is compressed exactly by TT-SVD instead, and check=true checks a function's build (and replaces a wrong one).
Example
pot = get_diagonal_mpo(L, sites, x -> 0.01 * x)
imp = get_diagonal_mpo(L, sites, [x == 37 ? 1.0 : 0.0 for x in 1:2^L]) # TT-SVDTensorBinding.get_matrix — Method
get_matrix(mpo, sites) -> Matrix{ComplexF64}
get_matrix(mpo, L, sites) -> Matrix{ComplexF64} (L ignored)Return the full D x D dense matrix of mpo, where D = prod(dim(s_i)). Works for any site types (Qubit, Layer, Spin, Nambu, ...). Feasible only for small systems (D <= 512).
TensorBinding.get_mpo — Method
get_mpo(L, sites, f; type=Float64, tol=1e-8, check=false, kwargs...) -> MPO
get_mpo(L, sites, v::AbstractVector; tol=1e-8) -> MPOCompress a function into an MPO via QTCI using 0-indexed coordinates n = 0, ..., 2^L-1. Dispatches on arity:
- 1-argument
f(n): builds a diagonal MPO (on-site potential), throughget_mps(check=truechecks it, see there). - 2-argument
f(i, j): builds a full interaction MPO by 2D QTCI, pairing the interleaved quantics legs into bra/ket viacustom_mpo.checkis not available here (hopping2MPO(f, N, sites; check=true)checks a hopping matrix).
A vector v (v[n+1] = f(n)) gives the diagonal MPO by TT-SVD, exact up to tol.
TensorBinding.get_mps — Method
get_mps(L, sites, f; type=Float64, tol=1e-8, check=false) -> MPS
get_mps(L, sites, v::AbstractVector; tol=1e-8) -> MPSCompress a scalar profile f(n) on n = 0, ..., 2^L-1 into an MPS via QTCI (site 1 the most significant bit).
QTCI samples f from a few pivots (the first point and five random ones, from the global RNG) and checks nothing afterwards, so a narrow feature on a flat background can be lost, depending on the RNG state, and a profile that vanishes almost everywhere can make it throw "maxsamplevalue is zero!" (L = 10: a 4-site box on a 0.1 background was lost for 3 of 5 seeds; a single nonzero site threw for 5 of 5). Two ways round it:
- a vector
v(v[n+1] = f(n), length2^L) is compressed by TT-SVD: sequential SVDs, exact up to abouttol · max|v|per entry, with no sampling and no RNG; check=truechecks the QTCI build againstfand returns it as it is when it passes; an entry fails when it is off by more than√tol · max|f|(1e-4 of the largest value at the defaulttol). Up to 2^20 points the check covers every point and a failed build (or a throw) is replaced by the TT-SVD of those values. Above, it covers a sample (both ends, the carry boundaries2^k − 2 … 2^k + 1and a golden-ratio stride of 4096 points), and a failed build is rebuilt by QTCI from the sampled points it missed as pivots, without random pivots, then checked again; a second failure is an error. Features between the sampled points cannot be checked there: pass a vector instead.
check=false (the default) keeps the plain QTCI build of v0.2.0.
TensorBinding.hadamard_mpo — Method
hadamard_mpo(A, B, out_sites; maxdim=100, cutoff=1e-8) -> MPOSite-wise Hadamard product of two MPOs: C[i,j] = A[i,j] * B[i,j]. out_sites may be any index set, including A/B's own sites; fresh working indices are created internally and the result is remapped to out_sites.
TensorBinding.ilinspace — Method
ilinspace(xmin, xmax, num_x) -> Vector{Int}Return num_x as almost evenly spaced integers in [xmin, xmax], inclusive, with a preference for the endpoints. Used to build the k-point center grid for band-structure sampling.
TensorBinding.interval_sampling_plan — Method
interval_sampling_plan(N; x_groups=nothing, num_x=min(N, 100), num_avg=1,
x_start=1, x_end=N, caller="interval_sampling_plan")
-> Vector{Vector{Int}}Probe groups over the physical sites 1:N of a one-dimensional register (N = H.N), the plan of get_ldos_spatial_mps_gpu: one group per output column, each group a vector of 1-based sites whose values are averaged.
x_groupsgiven: a vector of sites (one group each) or a vector of site vectors, used as they are.- otherwise the window
x_start:x_endis cut intonum_xintervals of nearly equal length (intervalicoversx_start + fld((i-1)·w, num_x)tox_start + fld(i·w, num_x) - 1,wthe window length), and each interval holdsmin(num_avg, its length)approximately equidistant probes (both ends included). OnlyO(num_x · num_avg)indices are allocated, so a huge projected space can be sampled without enumerating it.
Every group must be non-empty and inside 1:N. Errors are ArgumentErrors whose message starts with caller.
TensorBinding.kspace_sampling_plan — Method
kspace_sampling_plan(L_pos, D; num_x, num_y=10, num_avg=1,
xmin=0, xmax=nothing, ymin=0, ymax=nothing,
k_groups_override=nothing) -> (; k_groups, num_x)Momentum-space sampling plan shared by get_bands and get_bands_gpu, the k-space counterpart of spatial_sampling_plan. Momenta are 0-indexed QFT register labels k in 0:2^L_pos-1.
k_groups_override(for example fromkpath_2d) is passed through untouched and setsnum_x = length(k_groups).D == 1:num_xcentres fromilinspaceover[xmin, xmax](xmaxdefaults to2^L_pos - 1); withnum_avg > 1each centre is widened tonum_avgequidistant offsets within half a step on either side, clamped to the register.D == 2:Lx = L_pos ÷ 2;nx = min(num_x, xmax - xmin + 1, ymax - ymin + 1)points of the diagonal cut from(xmin, ymin)to(xmax, ymax)(xmax,ymaxdefault to the last label of each axis): theilinspacegrids ofnxpoints inxand iny, zipped into row-major labels(y << Lx) | x, again with optionalnum_avgwidening. This is the legacy diagonal cut through the 2D zone; for high-symmetry paths usekpath_2d.
TensorBinding.matrix_checker — Method
matrix_checker(mpo, sites, i, j) -> Number
matrix_checker(mpo, L, sites, i, j) -> Number (L ignored)Return the matrix element <i|mpo|j>. Works for any site types (Qubit, Layer, Spin, Nambu, ...). Intended for small-system validation.
TensorBinding.mps2mpo — Method
mps2mpo(L, sites, density_mps) -> MPOConvert a diagonal MPS (a function sampled on computational-basis states) into a diagonal MPO by calling Quantics._asdiagonal on each site tensor.
TensorBinding.mps_to_diagonal_mpo — Method
mps_to_diagonal_mpo(mps, sites) -> MPOConvert an MPS into a diagonal MPO on sites by replacing each physical index with a bra-ket pair tied by a 3-leg delta. Used to convert the output of a 2D QTCI (encoded as a flat MPS) into a diagonal MPO on the interleaved (e.g. electron-hole) site space.
TensorBinding.postpend_op — Method
postpend_op(H_mpo, s, mat) -> MPO explicit matrix
postpend_op(H_mpo, s, op::Symbol) -> MPO named op (Spin / Nambu index)
postpend_op(H_mpo, s, k, l) -> MPO sparse |k><l| (Layer / any index)
postpend_op(H_mpo, s, k) -> MPO projector |k><k|Append a single-site operator on index s to the end of H_mpo, extending it from L sites to L+1 sites. The returned MPO has site indices [original...; s].
Symmetric counterpart of prepend_op; dispatch rules are identical.
TensorBinding.prepend_layer_hopping — Method
prepend_layer_hopping(H, s, k, l) -> MPOPrepend the off-diagonal operator |k⟩⟨l| on the layer index s (1-based). Equivalent to prepend_op(H, s, k, l).
TensorBinding.prepend_layer_projector — Method
prepend_layer_projector(H, s, k) -> MPOPrepend the diagonal projector |k⟩⟨k| on the layer index s (1-based). Equivalent to prepend_op(H, s, k).
TensorBinding.prepend_op — Method
prepend_op(H_mpo, s, mat) -> MPO explicit matrix
prepend_op(H_mpo, s, op::Symbol)-> MPO named op (Spin / Nambu index)
prepend_op(H_mpo, s, k, l) -> MPO sparse |k><l| (Layer / any index)
prepend_op(H_mpo, s, k) -> MPO projector |k><k|Prepend a single-site operator on index s to H_mpo, extending it from L sites to L+1 sites. The returned MPO has site indices [s; original...].
Dispatch rules
- Matrix form:
mat[i,j]= <i|op|j> (1-indexed). Element type is preserved. - Symbol form: named operator looked up by the type of
s(tag"Spin"or"Nambu"). Defined in core/AuxDOF.jl after the op dictionaries. - Integer pair
(k, l): places a single 1 at rowk, collin adim(s) x dim(s)zero matrix. Covers layer hops and projectors for any dimension Layer index. - Single integer
k: shorthand for the projector|k><k|.
TensorBinding.qtt_mpo — Method
qtt_mpo(L, xvals, sites, func; tol_quantics=1e-8, maxbonddim_quantics=50) -> MPOCompress a scalar function func(x) evaluated on the explicit integer grid xvals (typically 0:2^L-1) into a diagonal MPO via Quantics Tensor Cross Interpolation.
The result is diag(func(0), func(1), ..., func(2^L-1)) stored as an L-site MPO. Use this to encode spatially varying on-site potentials or hopping amplitudes as diagonal MPOs for use with kineticNNN and the 2D kinetic builders.
xvals = 0:2^L-1 for a 1D chain of 2^L sites xvals = 0:Nx*Ny-1 for a row-major flattened 2D grid
See also get_diagonal_mpo (also in core/Utils.jl) for a simpler 1-based-index wrapper.
TensorBinding.replace_sites — Method
replace_sites(MPOin, newsites) -> MPOReplace the physical (bra + ket) indices of each site in MPOin with the corresponding index from newsites, preserving prime levels.
TensorBinding.rms_error — Method
rms_error(a, b) -> Float64RMS distance between two MPS objects over all computational-basis states.
TensorBinding.spatial_sampling_plan — Method
spatial_sampling_plan(L; Lx=nothing, grid=false, reduce=:point, n_sub=1,
num_x=0, num_y=nothing, num_avg=1, x_start=1, x_end=2^L,
xwin=nothing, ywin=nothing, x_groups=nothing,
box_half=0, sublattice=:auto)
-> (; centers, groups, resolve_sublattice, n_sub, stride_x, stride_y,
grid, reduce, a, b)Geometry-aware real-space sampling plan shared by every spatial sampler (eval_mps_spatial, get_ldos_spatial, get_ldos_spatial_gpu, get_scf_magnetization_gpu). It decides where to sample, how each output pixel reduces the cells under it (reduce), and — for multi-atom unit cells — whether to resolve or average the sublattice.
The two sampling procedures (reduce)
A spatial map of a 2^Lx × 2^Ly-unit-cell system at a coarse output resolution can reduce the cells beneath each pixel in two qualitatively different ways. The right choice depends on whether the quantity is smooth on the large scale (e.g. a Chern marker, an SCF density envelope) or a thin feature on a flat background (e.g. in-gap edge/domain-wall LDOS, width ξ ≪ system size).
:point(default) — point / box sampling. Lay outnum_x[×num_y]sample positions and read the profile at each one. Withbox_half > 0each pixel is the mean over a(2·box_half+1)²neighbourhood (smoothing). Cost ∝ (number of pixels) × (box cells).Aliasing caveat. The pixels probe only the cells they land on (±
box_half). On a grid coarser than a feature's width this misses thin features that fall between pixels: a domain-wall LDOS channel of width ξ sampled at strides ≫ ξis caught only on the rare pixel withinbox_halfof it. Making the box tile the plane (box_half ≈ s/2) closes the gaps but then evaluates essentially every cell — i.e. full-resolution cost. Use:pointfor smooth quantities or for a fully-resolved zoom (grid=true+ a small window).:block— block integration (gap-free coarse-graining). Partition the system intonum_x × num_yequal blocks (num_x = 2^a,num_y = 2^b, powers of two) and report, per pixel, the sum over its whole block. This is computed by tracing out the low-order position bits (contracting the within-block bits of the profile MPS with[1,1]and keeping thea + bhigh-order block bits) — a partial contraction, not a per-cell sweep, so the cost is independent of block size and scales toLx, Ly ≈ 14+.Because every cell belongs to exactly one block, a thin feature cannot fall between pixels — whichever blocks it threads light up, on an otherwise dark (gapped) background. This is the tool for imaging edge / domain-wall networks on a heavily downsampled map. Block centres are reported in
centers; the per-axis block widths arestride_x = 2^(Lx-a),stride_y = 2^(Ly-b). IfLxis omitted, the same mode becomes a 1D partition intonum_x = 2^acontiguous intervals withstride_x = 2^(L-a).
The fields reduce, a, b echo the chosen mode back to the caller; for :point they are (:point, 0, 0).
Sublattice resolve vs average
For a multi-atom unit cell (n_sub > 1) the plan also decides whether to resolve the sublattice (one output column per atom) or average it (one value per unit cell, atoms traced out), via sublattice:
:auto(default) — resolve only at the atomic scale: consecutive samples are adjacent unit cells (:pointwithstride == 1andbox_half == 0). Otherwise (coarse grid,box_half > 0, or any:blockmap) average, since the intra-cell sublattice is below the sampling resolution.:resolve/:averageforce the choice.n_sub == 1is alwaysfalse.
Layout (:point mode)
groups/centers are 1-indexed unit-cell indices with n = ix + iy·2^Lx.
grid=false(default) — centers on a 1D linear sweep of the row-major index (x_start/x_end,num_xpoints,num_avgsub-probes per block). Stridedx = window ÷ num_x.Lxis used only for the optionalbox_halfneighbourhood.grid=true(needsLx) — centers on a 2D xy grid ofnum_x × num_ypoints over the unit-cell windowxwin=(ix0,ix1),ywin=(iy0,iy1)(0-indexed; default full system). Per-axis stridesNx_win÷num_x,Ny_win÷num_y.
x_groups overrides the :point layout entirely; the stride is then unknown, so :auto resolves (treats it as atomic) unless box_half > 0.
TensorBinding.to_binary_vector — Method
to_binary_vector(n, L) -> Vector{String}Convert non-negative integer n to a length-L vector of "0"/"1" strings (big-endian), suitable as state labels for MPS(sites, state).
Example
to_binary_vector(5, 4) # -> ["0", "1", "0", "1"]MPO Tools
TensorBinding._checked_sum_mpos — Method
_checked_sum_mpos(terms; cutoff, maxdim, rtol=1e-11) -> MPOsum_mpos(terms; cutoff) followed by truncate!(·; maxdim, cutoff), the assembly of the sublattice builders, checked against the exact direct sum H of terms: the result is returned as it is unless it lies further than rtol ‖H‖ (Frobenius) from H while the SVD truncation of H at the same cutoff and maxdim stays within rtol ‖H‖; then that SVD truncation is returned instead. Where the truncation does remove weight, or the sum is right, the output is that of sum_mpos bit for bit.
+ compresses every partial sum with ITensors' density-matrix algorithm, which projects on the eigenvectors of a Hermitian eigensolver; for (nearly) degenerate eigenvalues LAPACK can return them non-orthonormal, and the sum then carries spurious entries (1e-5 in honeycomb_sublattice_hamiltonian(2, 1), whatever the cutoff). terms is iterated twice.
TensorBinding.collapse_mpo_pairs — Method
collapse_mpo_pairs(mpo2L, out_sites) -> MPOMerge each consecutive pair of sites (2n-1, 2n) in a 2L-site MPO into a single site of an L-site MPO by contracting and tying the shared bra and ket indices to out_sites[n].
TensorBinding.compose_power — Method
compose_power(base, nn; side=:right, apply_kwargs=NamedTuple()) -> MPOCompose base with itself nn times using exponentiation-by-squaring (O(log n) applies). Replaces the old arbitarty_offline helper which used O(n) sequential applies.
side = :right:acc = apply(acc, base)at each set bitside = :left:acc = apply(base, acc)at each set bit
apply_kwargs (e.g. (; cutoff=1e-8, maxdim=200)) are forwarded to every apply call. nn = 0 returns the identity MPO; nn = 1 returns base unchanged.
TensorBinding.interleave_mpo — Method
interleave_mpo(target_mpo, phys_sites, n) -> MPOEmbed an L-site MPO into a 2L-site space by interleaving it with identity operators. phys_sites must have length 2L.
n = 0: operator sits at even positions (2, 4, 6, …), identities at oddn = 1: operator sits at odd positions (1, 3, 5, …), identities at even
The embedded operator is target_mpo itself, not its transpose: the ket leg of tensor i becomes phys_sites[k] and the bra leg phys_sites[k]', whichever order the tensor stores them in (_mpo_site_pair; for the unrelated legs of a converted QTCI tensor train the first leg is the bra).
Note: phys_sites must be interleaved as [A[1], B[1], A[2], B[2], …] so that each operator site lands on an index with the correct dimension. For heterogeneous site spaces (layer, sublattice, …), use interleave_mpo_tb which builds the interleaved site list automatically.
TensorBinding.interleave_mpo_tb — Method
interleave_mpo_tb(op, sites_A, sites_B, which) -> MPOGeneralization of interleave_mpo for heterogeneous site spaces (Layer, Qubit, Honeycomb, etc.). Embeds an N-site MPO op into the 2N-site product space whose physical indices are ordered as
[sites_A[1], sites_B[1], sites_A[2], sites_B[2], …, sites_A[N], sites_B[N]]so every consecutive pair (sites_A[i], sites_B[i]) shares the same dimension regardless of site type.
which = :A:opacts onsites_A(odd positions), identity onsites_Bwhich = :B:opacts onsites_B(even positions), identity onsites_A
TensorBinding.mpo_kron — Method
mpo_kron(A, B) -> MPOConcatenate two MPOs into a single MPO on the combined site space, joined by a bond-dimension-1 link.
TensorBinding.sum_mpos — Method
sum_mpos(terms; kwargs...) -> MPOSum the MPOs in terms from left to right, ((t₁ + t₂) + t₃) + …, compressing each partial sum as +(a, b; kwargs...) does (cutoff, maxdim, …). A single term is returned as it is.
The order is part of the result: every partial sum is truncated, so summing the same terms in another order (or with the multi-argument +(t₁, t₂, t₃; …)) moves the output at the cutoff level. terms may be a lazy generator; each term is then built just before it is added.
TensorBinding.swap_every_other_legs — Method
swap_every_other_legs(MPOin, newsites) -> MPOReplace site indices and additionally swap bra↔ket on every odd-numbered site (the first register of an interleaved pair). Used to convert the 2L-site bubble MPO from the interleaved ordering into the form expected by collapse_mpo_pairs. The legs are read by prime level (_mpo_site_pair), not in storage order.
Hamiltonian Builders
TensorBinding.hopping2MPO — Method
hopping2MPO(f, N, sites; tol=1e-8, initial_positions=[], type=Float64,
unfoldingscheme=:interleaved, nrandominitpivot=5,
nsearchglobalpivot=5, check=false) -> MPOCompress an arbitrary NxN hopping matrix H[i,j] = f(i,j) into an MPO using Quantics Tensor Cross Interpolation on a 2D quantics grid (N must be a power of 2).
unfoldingscheme controls the bit ordering of the 2D quantics grid:
:interleaved(default): row and column bits alternate: rL cL ... r1 c1:fused: all row bits first, then column bits: rL ... r1 cL ... c1
initial_positions seeds the TCI pivots; useful when the matrix has known structure (e.g. near-diagonal for short-time propagators).
nrandominitpivot (extra random initial pivots) and nsearchglobalpivot (random global-pivot search points per sweep) are passed to QuanticsTCI; the defaults are QuanticsTCI's own. Both draw from the global RNG, so the result depends on its state. With structural initial_positions, setting both to 0 gives a deterministic build that leaves the global RNG untouched.
check=true guards against the weakness of QTCI on sparse f: from its default pivot (the corner entry) and a few random ones it can miss whole bond classes, giving a wrong MPO or "maxsamplevalue is zero!", depending on the RNG. The build then runs as without check, and its MPO is compared with f on a fixed sample of entries (a spread of rows, column offsets 0, ±1, ±2, ±3, ±2^k and ±(2^k ± 1)); if it passes, it is returned as it is. Otherwise (or if QTCI threw "maxsamplevalue is zero!") the MPO is rebuilt from the nonzero sampled entries as pivots (plus initial_positions) without random pivots, and checked again; a second failure, or f vanishing on every sample, is an error. An entry fails when it is off by more than half of |f(i, j)|, or by more than 1e-3 of the largest sampled |f|: a missed or spurious bond, not the small deviations of an approximate compression. The sample calls f a few thousand times and draws nothing from the RNG. get_Hamiltonian("custom", f), add_hopping!(H, f) with a two-argument f, add_superconductivity!(H, Δ; type=:custom) (through pairing2MPO) and add_soc!(H, λ; type=:custom) with a two-argument λ turn the check on (their keyword check); the default here is false.
The QTCI output is truncated at a relative cutoff of min(1e-8, 0.1/N): the fixed 1e-8 of v0.2.0 dropped bonds carried by a single matrix element from N = 2^26 on, such as the bond across the middle of a chain (see "Large systems" in get_Hamiltonian).
TensorBinding.kineticNNN — Method
kineticNNN(L, sites, hopping, nn; apply_kwargs=NamedTuple(), boundary=:open,
bc=nothing) -> MPOBuild a kinetic MPO for a 1D chain with a spatially varying hopping field encoded as the diagonal MPO hopping, and a neighbor reach controlled by nn.
Construction uses the shared shift-hopping helper: hopping * shift(nn) + shift(nn)' * dag(hopping).
boundary=:open is the default. Use boundary=:periodic (or bc=:pbc) for a cyclic shift on the quantics chain.
TensorBinding.kinetic_1d_nn — Method
kinetic_1d_nn(L, sites; boundary=:open, bc=nothing) -> MPOBuild the nearest-neighbour hopping MPO for a 1D chain of 2^L sites in the quantics binary representation. Hopping amplitude = 1; scale by multiplying the result. The default boundary=:open preserves the package's open-chain convention; boundary=:periodic adds the wrap-around bond. bc (e.g. :pbc), when given, overrides boundary.
TensorBinding.qtci_matrix_to_MPO — Method
qtci_matrix_to_MPO(A_fun, L, sites; tol=1e-8, type=Float64,
initial_positions=[]) -> MPOLike hopping2MPO but works with a (2^L)x(2^L) matrix function and applies an extra truncation step with maxdim=20.
TBSystem
TensorBinding.AbstractPositionSpace — Type
AbstractPositionSpacePolicy object describing how physical positions are embedded in the tensor-product register. BinaryPositionSpace is the ordinary N = 2^L quantics basis. Other position spaces (see position_spaces/) specialize physical_projector, physical_site_state, site_axis, and site_permutation after TBHamiltonian is defined below.
TensorBinding.BinaryPositionSpace — Type
BinaryPositionSpace()Ordinary binary position register containing all 2^L basis states.
TensorBinding.TBHamiltonian — Type
TBHamiltonianCentral object representing a tight-binding Hamiltonian in the quantics MPO framework.
Fields
Core
L: number of position qubit sites (log₂ of the physical system size)N: number of physical sites / unit cells (2^Lfor the binary basis)sites: ITensor site indices (position qubits + any auxiliary DOF indices)mpo: accumulated Hamiltonian as an ITensor MPOgeometry: functioni -> position_vector(1-indexed);nothingfor implicit 1Dposition_space: policy describing the physical basis inside the tensor register
KPM spectral bounds
scale: energy half-bandwidth;H/scalehas spectrum in[-1, 1]. Set analytically at construction for standard geometries. Reset to0.0by_invalidate_cache!after any modification —_ensure_scale!then re-estimates it on demand via DMRG (add_superconductivity!then sets a bound scale again).center: spectral centre;0.0for particle-hole symmetric Hamiltonians.
Auxiliary DOF indices (nothing until the corresponding add_*! is called)
spin_s: dim-2 spin index (prepended byadd_spin!)nambu_s: dim-2 Nambu index (prepended byadd_superconductivity!)layer_s: dim-k layer index (set by bilayer/multilayer constructors)sublattice_s: dim-k sublattice index (set by kagomé/Lieb/honeycomb/dice constructors)aux_side::preor:post— position of the outermost aux index insites
Lazy caches (emptied by the add_*! mutators through _invalidate_cache!, and when mpo, sites, position_space, or a different scale or center is assigned; editing the MPO in place, as truncate!(H.mpo) or H.mpo[j] = … do, does not empty them, but assigning mpo, sites or position_space empties them even when the assigned object is the stored one, so H.mpo = H.mpo after an in-place edit does)
_tn_cache: MPO Chebyshev list; set byKPM_Tn(H, N; mode=:mpo)_tn_mps_cache: MPS Chebyshev state list; set byKPM_Tn(H, N; mode=:mps, psi0=…)_tn_Ncheb: order of the Chebyshev list built last, MPO or MPS; each reader takes the order of its own list from the list (_tn_order)_density_cache: cached density-matrix MPO
Stored interaction MPOs (set via add_interaction!)
interaction_mpo: Hartree/CDW interaction kernel (fully scaled); used byget_scf(H, channel)fock_mpo: Fock/exchange interaction kernel (fully scaled)
Build one with get_Hamiltonian or a lattice builder. The keyword constructor TBHamiltonian(; L, N, sites, mpo, …) builds one from its fields, and TBHamiltonian(H; field=value, …) copies one, replacing the named fields.
TensorBinding.TBHamiltonian — Method
TBHamiltonian(H::TBHamiltonian; field=value, ...) -> TBHamiltonianCopy H field by field, replacing the fields named as keywords. Every other field, including Lx, interaction_mpo, fock_mpo and position_space, keeps the value from H; MPOs and index vectors are shared, not deep-copied. The lazy caches (_tn_cache, _tn_mps_cache, _tn_Ncheb, _density_cache) start empty unless passed explicitly, since a copy usually carries a different operator.
Hbdg = TBHamiltonian(H; sites=[nambu_s; spin_s; H.sites], mpo=bdg_mpo,
spin_s=spin_s, nambu_s=nambu_s, aux_side=:pre)TensorBinding.TBHamiltonian — Method
TBHamiltonian(; L, N, sites, mpo, geometry=nothing, geometry_uc=nothing,
scale=0.0, center=0.0, spin_s=nothing, nambu_s=nothing,
layer_s=nothing, sublattice_s=nothing, aux_side=:pre, Lx=nothing,
position_space=BinaryPositionSpace(), interaction_mpo=nothing,
fock_mpo=nothing) -> TBHamiltonianBuild a TBHamiltonian from its fields, by name. L, N, sites and mpo are required. Every other field defaults to "not set": no geometry, scale = 0.0 (the KPM scale is then estimated by DMRG on first use), no auxiliary index, aux_side = :pre, no Lx (1D), the binary position space and no stored interaction. The lazy caches start empty. Values are converted to the field types, so scale = 3 stores 3.0.
The builders behind get_Hamiltonian, lattice/ and position_spaces/ construct their Hamiltonians this way. To change some fields of an existing Hamiltonian, use the copy constructor TBHamiltonian(H; field=value, ...).
s = siteinds("Qubit", 3)
H = TBHamiltonian(; L=3, N=8, sites=s, mpo=kinetic_1d_nn(3, s), scale=2.5)TensorBinding._invalidate_cache! — Method
_invalidate_cache!(H) -> HClear all cached intermediate results. Called by the mutators that change mpo (e.g. add_hopping!, add_onsite!, add_zeeman!, add_superconductivity!).
Clears: _tn_cache, _tn_mps_cache, _tn_Ncheb, _density_cache. Resets scale and center to 0.0 so that _ensure_scale! re-estimates them via DMRG on the next KPM call.
TensorBinding._pos_sites — Method
_pos_sites(H) -> Vector{<:Index}Return the L position-qubit indices, filtering out any auxiliary (spin, Nambu, layer) indices regardless of whether they sit at the front or back of H.sites.
TensorBinding.add_hopping! — Method
add_hopping!(H, f; nn=1, boundary=:open, bc=nothing, maxdim=15, tol=nothing,
type=ComplexF64, apply_kwargs=NamedTuple(), sublat=nothing,
sublat_from=nothing, sublat_to=nothing, check=true) -> HAdd a hopping term to H.
f modes (selected automatically by type):
f::Number— uniformnn-th-neighbour hopping (amplitudef, shellnn).f(i), 1-argFunction— spatially varying amplitude per site, QTCI-compressed.f(i,j), 2-argFunction— full N×N matrix, QTCI-compressed (nnignored).
Sublattice keywords (H.sublattice_s must be set; call before add_spin! etc.)
sublat=k— intra-sublattice: restrict the full kinetic term to sublatticekby postpending the projector|k⟩⟨k|. Works with all threefmodes.add_hopping!(H, -0.1; sublat=1, nn=2) # NNN within sublattice Asublat_from=k, sublat_to=l— inter-sublattice: addsf · K_u^nn ⊗ |l⟩⟨k| + conj(f) · K_d^nn ⊗ |k⟩⟨l|(Hermitian,fmust be scalar). Usenn=0for intra-cell bonds (no position shift; useful to correct individual bond amplitudes in an existing sublattice Hamiltonian):add_hopping!(H, -0.3; sublat_from=1, sublat_to=2, nn=1) # A↔B NN inter-cell add_hopping!(H, δt; sublat_from=2, sublat_to=3, nn=0) # B↔C intra-cell only
Other keywords
boundary=:openor:periodic(bcoverrides it): boundary of the position shift for scalar and 1-argfand for the inter-sublattice hops.maxdim,tol: truncation of the summed MPO;toldefaults tomin(1e-8, 0.1/D), D the dimension of the site space (1e-8up to D = 2^23; see "Large systems" inget_Hamiltonian). A giventolis also the QTCI tolerance of a 2-argf(default1e-8).type: element type of the QTCI compression of a 2-argf.check=true: the sampled self-check ofhopping2MPOfor a 2-argf(the default QTCI pivots miss bond classes of a sparsef; a build that passes it is kept).apply_kwargs: keywords for theapplycalls insidekineticNNN(scalar and 1-argf).
On a 2D Hamiltonian (H.Lx set) the call is forwarded to add_hopping_2D! with Lx = H.Lx, Ly = H.L - H.Lx, nn, maxdim and tol; the sublattice keywords are not supported there.
Without sublattice keywords the function errors if any auxiliary DOF is already attached. Invalidates all caches.
TensorBinding.add_interaction! — Method
add_interaction!(H, V; channel=:hartree, type=Float64, tol=1e-8, kwargs...) -> HStore a pre-built interaction MPO in H for later use with get_scf(H, channel).
V can be:
MPO— stored directlyNumber— scalar coupling; stored asV · Idon the position sitesFunctionwith 1 arg — on-site potentialV(i), 0-indexed; stored as diagonal MPOFunctionwith 2 args — interaction kernelV(i,j), 0-indexed; stored as full 2D MPO
channel:
:hartreeor:default→ stored inH.interaction_mpo(used by:cdwand:magneticSCF):fockor:exchange→ stored inH.fock_mpo
type, tol and kwargs are passed to get_mpo for a Function V (it forwards kwargs to the QTCI of a 2-arg kernel).
TensorBinding.add_onsite! — Method
add_onsite!(H, f; layer=nothing, sublat=nothing, Lx=nothing,
tol=nothing, maxdim=nothing, check=false) -> HAdd a diagonal (on-site) potential to H.
f argument — same conventions as add_hopping_2D!
f::Number— uniform constant (compressed by QTCI like the functions);f = 0adds nothing and leavesH.mpoas it is.f(n)— 1-arg function;n ∈ {0, …, N-1}is the 0-indexed unit-cell index.f(ix, iy)— 2-arg function;ix, iyare 0-indexed 2D coordinates (ix = n % Nx,iy = n ÷ Nx). RequiresLx=keyword so thatNx = 2^Lx.f::AbstractVector— the values themselves,f[n+1]at unit celln(lengthN; a 2D mapV[ix+1, iy+1]isvec(V)), compressed exactly by TT-SVD.
The functions are compressed by QTCI, which can lose narrow features (a box of a few cells, a single impurity) for some RNG states, or throw on a profile that vanishes almost everywhere (see get_mps). Pass the values as a vector, or check=true to check the QTCI build against f and replace it when it is wrong (false by default, the build of v0.2.0).
sublat keyword (H.sublattice_s must be set)
sublat=nothing(default) — appliesfequally to all sublattices.sublat=k— restricts the potential to sublatticekonly via|k⟩⟨k|.Canonical use-case — Semenoff mass on a honeycomb Hamiltonian:
add_onsite!(H_hc, +M; sublat=1) # +M on sublattice A add_onsite!(H_hc, -M; sublat=2) # −M on sublattice B → gap = 2MWorks for any sublattice-carrying
TBHamiltonian(kagome, Lieb, dice, …) and for spatially-varyingfas well.
layer keyword (H.layer_s must be set)
layer=nothing— apply the same onsite term to every layer.layer=k— apply only to layerk.layer=[...]— apply to the selected layers.
For layered sublattice Hamiltonians, the onsite term is first built on the position ⊗ sublattice monolayer space, then wrapped with the selected layer projectors.
Spin and Nambu indices (not layered): on a spinful Hamiltonian the potential is the identity on the spin (a spin-dependent one goes through add_zeeman!); on a BdG Hamiltonian it enters as τ_z ⊗ V, V in the particle and −V in the hole block, so f must be real there. Up to v0.2.0 add_onsite! threw on a Hamiltonian with a spin or Nambu index; it had to come before add_spin! and add_superconductivity!, which give the same result.
tol is the relative cutoff of the sum, by default min(1e-8, 0.1/D), D the dimension of the site space (1e-8 up to D = 2^23; see "Large systems" in get_Hamiltonian).
Invalidates all caches.
TensorBinding.ambient_dimension — Method
ambient_dimension(H) -> IntegerDimension of the position tensor register before any physical-subspace projection. This is 2^H.L for the quantics encodings supported by TensorBinding. Projected position spaces may return a BigInt when the ambient register exceeds Int.
TensorBinding.central_index — Method
central_index(geom, N) -> Int
central_index(H) -> IntReturn the 1-indexed site index whose position is closest to the geometric centroid of the lattice. Accepts either a geometry function geom(i) and system size N, or a TBHamiltonian directly.
Errors if H.geometry is nothing.
TensorBinding.chirality — Method
chirality(r1, r2) -> IntTextbook Haldane sign ν = ±1 of the next-nearest-neighbour hop between the sites at r1 and r2 of the honeycomb_positions lattice: ν = sign((d1 × d2)_z) for the path r1 → k → r2 through their common nearest neighbour k (d1 = r_k - r1, d2 = r2 - r_k), so +1 when the path turns left at k.
On that lattice the bonds of an A site (x ∈ 1.5ℤ) point at 0° and ±120° and those of a B site at 180° and ±60°, so ν = -σ sign(sin 3θ), with θ the angle of r2 - r1 and σ the sublattice sign of r1 (-1 on A, +1 on B). The three hops of a C3-related triple share one sign, and chirality(r2, r1) == -chirality(r1, r2). The result is meaningless for pairs that are not next-nearest neighbours of that lattice.
TensorBinding.get_Hamiltonian — Method
get_Hamiltonian(geometry, params; L, scale=nothing, tol=nothing, maxdim=15,
ref_sites=nothing, kwargs...) -> TBHamiltonianBuild a TBHamiltonian from a named geometry and model parameters.
L, and Lx/Ly for the 2D geometries, are qubit counts: a 2D system has 2^Lx × 2^Ly unit cells with L = Lx + Ly, and Lx defaults to L ÷ 2, Ly to L - Lx. A keyword that a geometry does not take is an error, except for the multi-atom lattices, which ignore it.
Direct builders
geometry | params | Extra kwargs |
|---|---|---|
"chain_1d" | hopping amplitude t::Number | boundary=:open or :periodic (bc overrides it); direct MPO, no QTCI; use add_onsite! for potentials |
"haldane" | (t2, phi, M) NamedTuple | rs (N×2 positions from honeycomb_positions, required); no other kwargs |
"custom" | hopping function f(i,j) | scale (required: a number, :dmrg, or :small up to 1024 sites), geometry (i -> position or an N×2 matrix), type=ComplexF64, check=true (the sampled self-check of hopping2MPO) |
Projected position spaces (quasicrystals; H.N counts the admissible sites only)
geometry | params | Extra kwargs |
|---|---|---|
"fibonacci" | (A, B[, t, onsite]) NamedTuple or Dict | model=:hopping or :onsite, boundary=:periodic or :open, padding |
"metallic_mean" | (A, B[, t, onsite]) NamedTuple or Dict | m (required; m=2 silver mean), model, boundary, padding |
"kbonacci" | (A, B, C, …[, t, onsite]) or (values=(a_1, …, a_k)[, t, onsite]) | k (required; k=3 Tribonacci), model, boundary, padding |
These call fibonacci_hamiltonian, metallic_mean_hamiltonian and kbonacci_hamiltonian with cutoff=tol (1e-8 by default, as up to v0.2.0) and maxdim=maxdim; they reject ref_sites.
Preset models (routed through build_hamiltonian and MODEL_REGISTRY)
params is a Number (taken as the first required parameter), a NamedTuple or a Dict; entries beyond the required ones are passed to the builder as keywords, over the MODEL_REGISTRY defaults (which also set tol_quantics, maxbonddim_quantics and, in 2D, cutoff). Extra kwargs: Lx, Ly (2D only), mparams (a "key=value, …" string that params overrides) and ref_sites.
geometry | builder | dim | required params | optional params (default) |
|---|---|---|---|---|
"uniform" | HUniform | 1D | t | v=1e-6, nn=1 |
"ssh" | HSSH | 1D | t, d | nn=1 |
"aah" | HAAH | 1D | V, phi, t | b=(1+√5)/2 |
"square_2d" | HUniform2Dsquare | 2D | t | |
"hex_2d" | HUniform2Dhex | 2D | t | |
"triangular_2d" | HUniform2Dtri | 2D | t | |
"triangular_bravais" | HUniform2Dtri_bravais | 2D | t | |
"chern8" | HChern8 | 2D | V, t | t2=0.2t |
"chernhex" | H2DChernhex | 2D | t, t2, ms | uniformhaldane=false, uniformsemenoff=false |
"qc2dsquare" | HQC2Dsquare | 2D | t |
Multi-atom unit cells (explicit sublattice index)
geometry | params | atoms per cell | Extra kwargs |
|---|---|---|---|
"kagome" | t (a Number, (t=…,) or a Dict) | 3 | Lx, Ly |
"lieb" | t | 3 | Lx, Ly |
"dice" | t | 3 | Lx, Ly |
"honeycomb" | t | 2 | Lx, Ly |
"honeycomb_nnn" | (t, t2) NamedTuple or Dict (t2=0) | 2 | Lx, Ly |
"ssh_sublattice" | t or (t, d) NamedTuple or Dict (t=1, d=0) | 2 | none (1D chain) |
"haldane" is the textbook, C3-symmetric Haldane model ⟨i|H|j⟩ = t2 exp(i phi ν_ij) (Dirac masses -M ± 3√3 t2 sin(phi), see haldane_hoppingf); it refuses an rs whose sites are not on the honeycomb_positions lattice.
For the multi-atom lattices L (= Lx + Ly in 2D) counts only the position qubits; the total atom count is n_sub × 2^L with n_sub the atoms per cell. The sublattice index is stored in H.sublattice_s with H.aux_side = :post. H.geometry returns the full real-space position of each atom (1-indexed over all n_sub × 2^L atoms) and H.geometry_uc the Bravais position of its cell.
Common keyword arguments
L: number of position qubits (2^Lsites or unit cells; the projected spaces keep only their admissible subset)scale: energy half-bandwidth for KPM normalisation: a number (used as given),nothing(default: see "Default KPM scale" below;"custom"requires a scale) or anestimate_scalemethod,:small(dense spectrum of the model at a small size),:geometry(row-sum bound) or:dmrg(DMRG spectral bounds ofH, which also setcenter)tol: relative truncation cutoff of the built MPO; by defaultmin(1e-8, 0.1/D), D the dimension of the site space, which is1e-8(as up to v0.2.0) up to D = 2^23 (see "Large systems" below); the projected spaces keep1e-8. For"custom"and"haldane"a giventolis also the QTCI tolerance (default1e-8). The preset models take their QTCI tolerance fromMODEL_REGISTRY(tol_quantics:1e-8,1e-9for"qc2dsquare"), whichparams/mparamsoverridemaxdim: maximum MPO bond dimension after construction (default15). It can bind:"qc2dsquare"needs bond dimension 16 atL = 8and 17 atL = 10, where the default truncates its MPO (relative error 1.4e-3 and 1.1e-2); pass a largermaxdimfor such modelsref_sites: theLposition qubits to build on (defaultnothing): they replace the MPO's position site indices, so that Hamiltonians built with the sameref_sitesshareIndexobjects; the multi-atom lattices keep their own sublattice index. Any other length or dimension is an error, and the projected spaces rejectref_sites
Default KPM scale
Without scale, "chain_1d", the preset models ("chernhex" excepted) and the 2D multi-atom lattices take max(f, estimate_scale(geometry, params; L, kwargs..., method=:auto)), where f is the geometry's former default (2.5|t| for "chain_1d", "uniform", "ssh"; 1.2(|t| + |V|) for "aah"; 4.4|t|, 4.0|t|, 7|t|, 7|t| for "square_2d", "hex_2d", "triangular_2d", "triangular_bravais"; 6|t| for "chern8", "qc2dsquare"; the builder defaults 4.5|t| for "kagome" and "dice", 2.5|t| for "lieb", 3.5|t| for "honeycomb" and 3.5(|t| + |t2|) for "honeycomb_nnn") and :auto is the padded row-sum bound (:geometry) for the size-scaled "chern8" and "qc2dsquare" and the dense small-size estimate (:small) otherwise. Where f already reaches 1.1 × the row-sum bound, the estimate cannot exceed it and is not computed. Every other geometry keeps its builder's default: the analytic bounds of "haldane", "chernhex", "ssh_sublattice" and the projected spaces. The centre is 0 except for the projected spaces.
Large systems
tol is relative to the squared norm of the MPO, ‖H‖² = D⟨h²⟩ with D the dimension of the site space and ⟨h²⟩ the mean squared norm of a row, so a fixed cutoff drops a term carried by a single matrix element once the system is large enough: an element a survives while the cutoff stays below about |a|²/‖H‖². In a 1D chain the bond across the middle, 2^(L-1) - 1 → 2^(L-1), whose carry flips every qubit, is such a term. With the fixed 1e-8 of v0.2.0 the 1D models lost it at L = 26 ("chain_1d", "uniform", "aah", "ssh_sublattice"; "ssh" at L = 28), and from L = 28 the chain was cut every 2^26 sites; "custom" with nearest-neighbour hops threw, its self-check catching the missing bond. The default is now min(1e-8, 0.1/D). It equals 1e-8 up to D = 2^23 (L = 23 for a spinless chain), so smaller systems build the same MPO as before, and above it keeps every bond with |t|² ≥ ⟨h²⟩/10, such as the hops of a uniform chain (checked up to L = 30).
It does not keep a bond that is weak next to the rest of its rows: beside on-site terms beyond about 4t ("aah" with V ≳ 4t, a large add_onsite! potential) or beside a much stronger bond ("ssh_sublattice" with |t − d| < |t + d|/3). There pass a tol below |t|²/‖H‖²; the fixed 1e-8 lost those bonds as well. An explicit tol above 0.3/D is used as given and warns once. In 2D a long carry repeats along a whole row or column, so D is taken along the longer side: 2D models keep 1e-8 until that side has 2^23 sites.
add_hopping!, add_onsite!, add_spin!, add_zeeman!, add_soc!, add_superconductivity! and the non-Hermitian adders have the same default; with 1e-8 each of them cut the chain again. The 1D kinetic MPOs (kinetic_1d_nn, kineticNNN) summed with a fixed 1e-12, which cut the bond at L = 39 (one direction) and 40; that sum is size-aware too.
Examples
H = get_Hamiltonian("chain_1d", 1.0; L=10)
H = get_Hamiltonian("square_2d", 1.0; L=10, Lx=5) # 32 × 32 sites
rs = honeycomb_positions(10)
H = get_Hamiltonian("haldane", (t2=0.2, phi=π/2, M=0.0); L=10, rs=rs)
H = get_Hamiltonian("custom", (i,j) -> ...; L=10, scale=5.0, geometry=rs)
Ha = get_Hamiltonian("aah", (V=2.0, phi=0.0, t=1.0); L=8)
Hk = get_Hamiltonian("kagome", 1.0; L=6, Lx=3, Ly=3) # 3 × 8 × 8 atoms
Hf = get_Hamiltonian("fibonacci", (A=1.0, B=2.0); L=8, model=:hopping)
Hs = get_Hamiltonian("metallic_mean", (A=1.0, B=2.0); L=8, m=2) # silver mean
Ht = get_Hamiltonian("kbonacci", (A=0.64, B=0.8, C=1.0); L=8, k=3) # TribonacciAfter construction, add further interaction terms with add_hopping! and add_onsite!.
TensorBinding.haldane_hoppingf — Method
haldane_hoppingf(r1, r2, i, j; t2=0.2, phi=pi/2, M=0.0) -> NumberMatrix element ⟨r1|H|r2⟩ of the textbook, C3-symmetric Haldane model H = Σ_ij H_ij c†_i c_j on the honeycomb with bond length 1 laid out as in honeycomb_positions:
- on site:
M σ, withσ = -1on the sublattice of site 1 (x ∈ 1.5ℤ) and+1on the other; - nearest neighbours:
-1; - next-nearest neighbours:
t2 exp(i phi ν), withν = chirality(r1, r2) = sign((d1 × d2)_z)for the pathr1 → k → r2through the common nearest neighbourk.
The Dirac masses are -M ± 3√3 t2 sin(phi), so the model is a Chern insulator for |M| < 3√3 |t2 sin(phi)|. i, j are the site indices of the f(i, j) call pattern (unused).
This is the convention of the manuscript's build_APSOS_hamiltonian: its haldane_phases table, added with add_hopping_2D! on the "honeycomb" preset, gives ⟨i|H|j⟩ = t2 exp(i phi ν_ij) with the same ν_ij, so the same Chern number at the same t2 and phi. It puts +M rather than -M on its sublattice 1, which leaves the Chern number unchanged. Earlier versions gave the four vertical next-nearest bonds -ν, which made the Dirac masses -M ± √3 t2 sin(phi).
TensorBinding.physical_projector — Method
physical_projector(H) -> MPOIdentity operator on the physical position space. For ordinary binary systems this is the full identity; projected encodings specialize this method and return their valid-state projector.
TensorBinding.physical_site_state — Method
physical_site_state(H, x) -> MPSProduct-state probe for 1-indexed physical position x. Auxiliary and two-particle spaces use their dedicated probe constructors.
TensorBinding.site_axis — Method
site_axis(H; ordering=:physical, kwargs...) -> Vector{Int}Return the plotting axis for physical positions or an encoding-defined ordering. kwargs are encoding-specific (for a Fibonacci space: orientation, centered, origin, alignment).
TensorBinding.site_permutation — Method
site_permutation(H; ordering=:physical, kwargs...) -> Vector{Int}Return the 1-based physical-site permutation associated with a plotting ordering. kwargs are as for site_axis.
TensorBinding.truncate! — Method
truncate!(H::TBHamiltonian; cutoff=1e-10, maxdim=nothing) -> HTruncate the Hamiltonian MPO in-place using ITensorMPS.truncate!. Empties all caches (Chebyshev lists, density matrix) and resets scale/center to 0 for a lazy re-estimate; on projected position spaces the window is kept.
Useful after a series of add_hopping! / add_onsite! calls that may have inflated the bond dimension.
Auxiliary Degrees of Freedom
TensorBinding.AuxDOFProjection — Type
AuxDOFProjection(on, sector, index, side)How a spectral method treats one auxiliary DOF: on projects it (the *_proj flag, after _autoenable_proj), sector is the proj_* selector (nothing sums every sector, an integer keeps one), index is its Index on the MPO (nothing when absent) and side the end of the MPO it sits at (:pre first, :post last).
TensorBinding.AuxProjection — Type
AuxProjection(nambu, spin, layer, sublat)The auxiliary projection of a spectral method: one AuxDOFProjection per DOF (the field sublat is the sublattice). Built by _aux_projection(H; …) from the eight public keywords, or by the low-level get_bands from its own.
TensorBinding._autoenable_proj — Method
_autoenable_proj(H, nambu_proj, spin_proj, layer_proj, sublat_proj)
-> (nambu_proj, spin_proj, layer_proj, sublat_proj)Enable projection flags for any auxiliary DOF detected on H, emitting one @info record per auto-enabled flag. Called by _aux_projection (with autoenable=true), which every TBHamiltonian spectral method but the stochastic DOS uses before any aux-index logic runs.
TensorBinding._aux_projection — Method
_aux_projection(H; nambu_proj=false, proj_nambu=nothing, spin_proj=false,
proj_s=nothing, layer_proj=false, proj_layer=nothing,
sublat_proj=false, proj_sl=nothing, autoenable=true)
-> AuxProjectionThe auxiliary projection a spectral method applies to H, from its eight public keywords. With autoenable=true the flag of every DOF present on H is switched on (_autoenable_proj, one @info per flag it enables); the stochastic DOS passes false. Every auxiliary site present on H is located with aux_site, which also gives the side it is projected from (a spin index added with add_spin!(H; position=:post) is :post). An absent DOF gets the side :pre (:post for the sublattice); only the spin fallback sites[1] of get_bands and the GPU methods (spin_proj=true without a spin index) is projected from it.
TensorBinding._aux_setup — Method
_aux_setup(H, nambu_proj, proj_nambu, spin_proj, proj_s,
layer_proj, proj_layer, sublat_proj, proj_sl) -> NamedTupleThe flat view of _aux_projection(H; …, autoenable=false) with the probe ranges. Fields: nambu_s_det, nambu_side_det, spin_s_det, layer_s_det, layer_side_det, sublat_s_det, sublat_side_det (the indices and sides), nambu_range, spin_range, layer_range, sl_range (the sector ranges of _probe_sectors) and any_aux_proj. The package itself now uses the AuxProjection; the KPM golden test pins this view.
TensorBinding._ldos_make_psi0 — Method
_ldos_make_psi0(H, x, σ_n, σ_s, σ_l, σ_sl) -> MPSProduct-state MPS over all H.sites for KPM evaluation in LDOS :mps mode.
- Position sites encode
x-1in big-endian binary (first position site = MSB). - Auxiliary sites are set to 1-based sector indices:
σ_n(nambu),σ_s(spin),σ_l(layer),σ_sl(sublattice). Indices for absent aux dofs are ignored.
TensorBinding._probe_sectors — Method
_probe_sectors(aux) -> VectorThe auxiliary sectors (σ_n, σ_s, σ_l, σ_sl) (Nambu, spin, layer, sublattice) a probe-state method sums over, Nambu outermost and sublattice innermost: for each projected DOF present on H all its sectors (the spin sectors are 1:2) or the selected one, 1 for the others. [nothing] when no DOF is projected: one plain position probe. Each entry is the third argument of probe_state.
TensorBinding._project_aux_block — Method
_project_aux_block(mpo, aux_s, row, col; tag="") -> MPOThe (row, col) block of the aux site aux_s of mpo: that site is contracted with the ComplexF64 projector |row⟩⟨col| and absorbed into a neighbour. The site is the first one that carries aux_s, or an index tagged tag when tag is not empty; it may be anywhere in the MPO. A one-site MPO gives an empty MPO.
TensorBinding._project_aux_sectors — Method
_project_aux_sectors(T, aux; project=project_aux, spin_index=nothing,
sublattice=aux.sublat.on)The projections of the operator T onto every requested auxiliary sector, outermost DOF first: Nambu (sectors 1:2, or proj_nambu), spin (1:2, or proj_s), layer (all its sectors, or proj_layer) and, when sublattice is true, the sublattice (all, or proj_sl). A DOF whose flag is off is left alone. Returns an iterator of (T_proj, s) pairs, s the sublattice sector (1 when the sublattice is not projected), in the order of the four hand-written chains it replaced: the spin step runs over its sectors outermost (a two-dimensional comprehension), the others over their sectors innermost, so the Nambu sector varies fastest across the spin step. The Nambu, spin and layer lists are built when it is called, each sublattice projection when the iteration reaches it.
project(T, index, σ; side)removes one aux site:project_auxon the CPU,_project_aux_gpuon the GPU.spin_indexis the spin Index to project;nothingtakesaux.spin.index, which must then be set (getldosspatial). get_bands and the GPU methods pass their fallback,sites[1]for a Hamiltonian without spin.sublattice: getbands projects the sublattice when `sublatprojis on, the spatial LDOS wheneverH` has a sublattice index.
Each DOF is projected from the side its AuxDOFProjection records. A projected DOF without an Index is an error that names it.
TensorBinding._project_end_site — Method
_project_end_site(W, s, row, col, side; to_device=_on_host, device_type=Float64) -> MPOContract the end site of W that carries s (the first site for side=:pre, the last for any other side) with the one-hot pair ⟨row| on s' and |col⟩ on s, and absorb the link tensor left over into the neighbouring site, as W[neighbour] * block. Returns the MPO without that site. Nothing is checked: the caller guarantees that s sits there (see projectaux, contractnhblock). The one-hot vectors are moved by `todevice(·, devicetype)(seeonhost`; the GPU twin _contractnhblockgpu passes _to_gpu and its dtype).
TensorBinding._project_spin_sector — Method
_project_spin_sector(H, sector) -> TBHamiltonianProject a spinful TBHamiltonian onto spin sector sector (1 = ↑, 2 = ↓) by contracting the spin site tensor with the projector |sector⟩⟨sector|.
The spin index is identified by its "Spin" tag, so the function is robust to whether spin is prepended or postpended, also inside a block of aux sites ([nambu, spin, pos…], [pos…, spin, nambu]). The contracted tensor is absorbed into its neighbour, leaving a valid MPO on every other site of H (the L position qubits when spin is the only aux index).
Returns a new TBHamiltonian with spin_s = nothing and fresh (empty) caches; scale and center are reset to 0.0 so _ensure_scale! will re-estimate them on the first KPM call. All other fields (Lx, interaction_mpo, fock_mpo, position_space, …) are copied from H.
TensorBinding.add_soc! — Method
add_soc!(H, λ; type=:rashba, direction=:z, boundary=:periodic, tol=nothing,
maxdim=200, position=nothing, check=true) -> HAdd spin-orbit coupling to H. Calls add_spin! automatically if needed, placing the spin index at position (default H.aux_side).
type:
:rashba— nearest-neighbour Rashba SOC on the position chain:λ · iσ_y ⊗ (K_u − K_d), whereK_u/K_dare the ±1 shift operators andiσ_y = [0 1; −1 0]is the spin factor:iSy; both factors are anti-Hermitian, so the term is Hermitian for realλ.λmust be a scalar. Breaks SU(2) spin symmetry while preserving time-reversal.boundarysets the bond between the last and the first site::periodic(the default, as before) includes it,:opendrops it; passboundary=:openon an open chain, such as the defaultget_Hamiltonian("chain_1d", t; L). 1D only: on a 2D Hamiltonian (H.Lxset) the term couples neighbours along the linear position index, i.e. along x and across the row ends, with no y bonds, andadd_soc!warns.:ising— diagonal Ising SOCλ(i) · S_z(equivalent to a position-dependent Zeeman along z; useful for Kane–Mele type models).:custom— arbitrary position-space MPOλ_mpotensor-producted with the spin operator given bydirection(:x,:y, or:z).λmay be a Number, a 1-argFunction λ(i), or a 2-argFunction λ(i,j)(the last compressed via TCI and checked againstλon a sample of entries:check=true, seehopping2MPO). For the result to be Hermitian, the position-space matrix must itself be Hermitian:λ(i,j) = conj(λ(j,i)). Diagonal and real-symmetric inputs satisfy this automatically.
boundary (:periodic or :open; :pbc/:obc are accepted too) is read by :rashba only and checked for every type.
tol is the relative cutoff of the sums, by default min(1e-8, 0.1/D), D the dimension of the site space (1e-8 up to D = 2^23; see "Large systems" in get_Hamiltonian); a given tol is also the QTCI tolerance of a two-argument λ (default 1e-8).
Examples
add_soc!(H, 0.05) # Rashba λ=0.05, periodic chain
add_soc!(H, 0.05; boundary=:open) # Rashba on an open chain
add_soc!(H, i -> 0.1*cos(2π*i/H.N); type=:ising)
add_soc!(H, (i,j)->...; type=:custom, direction=:y)TensorBinding.add_spin! — Method
add_spin!(H; cutoff=nothing, maxdim=200, position=:pre) -> HExtend H to a spin-½ degenerate system by adding a spin-½ index in front of (position=:pre) or behind (position=:post) the existing sites. The resulting Hamiltonian is I_spin ⊗ H (both spin sectors identical).
cutoff is the relative cutoff of the final truncation, by default min(1e-8, 0.1/D), D the dimension of the new site space (1e-8 up to D = 2^23; see "Large systems" in get_Hamiltonian).
No-op if H is already spinful (H.spin_s !== nothing). Invalidates all caches.
TensorBinding.add_superconductivity! — Method
add_superconductivity!(H, Δ; type=:swave, tol=nothing, maxdim=200,
position=nothing, check=true) -> HExtend H to a Bogoliubov–de Gennes (BdG) Hamiltonian by prepending (position=:pre) or postpending (position=:post) a Nambu (particle–hole) index; position defaults to H.aux_side.
The BdG structure, in the Nambu basis (c↑, c↓, c†↑, c†↓) (spinless: (c, c†)), is: HBdG = Pp ⊗ H + Ph ⊗ (−H*) + τ+ ⊗ Hpair + τ- ⊗ Hpair† with `Pp,Phthe particle and hole projectors of the Nambu index. For a realHthe first two terms areτz ⊗ H, built as one term; up to v0.2.0 everyHgotτ_z ⊗ H, which is wrong whenHhas imaginary entries (a Zeeman field along y, Peierls phases, complex hoppings).Hmust be Hermitian: for a non-HermitianH(loss, nonreciprocal hopping) the hole block is−Hᵀ`, which is not built.
- Spinless + p-wave (
type=:pwave, or auto-selected when spinless +:swave):H_pair = Δ·(K_forward − K_backward), the antisymmetric nearest-neighbour matrix required by Fermi statistics (Δ(i,j) = −Δ(j,i)). This is the Kitaev chain.Δmust be aNumber. - Spinful + s-wave (
add_spin!called first,type=:swave):H_pair = (i·σ_y)_spin ⊗ Δ(r), the standard BCS singlet Cooper-pair operator. On-site (s-wave) pairing is allowed here because the antisymmetry is carried by the spin singlet factori·σ_y.Δcan be aNumberor 1-argFunction. - Custom (
type=:custom): arbitrary pairing matrix via 2-arg functionΔ(i,j), compressed with TCI and checked againstΔon a sample of entries (check=true, the self-check ofhopping2MPO; a build that passes is kept as it is).
Note on spinless s-wave: on-site pairing is forbidden for spinless fermions (Δ(i,i) = 0 by antisymmetry). Calling with type=:swave on a spinless chain automatically redirects to :pwave (uniform Δ) or errors (spatially varying Δ).
type:
:swave(default) — diagonal pairing for spinful chains; auto-redirects to:pwavefor spinless chains whenΔ isa Number:pwave— antisymmetric NN pairingΔ·(K_f − K_b)for spinless chains;Δmust be aNumber:custom— arbitraryΔ(i,j); pass a 2-arg function
tol is the relative cutoff of the BdG assembly, 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); a given tol is also the QTCI tolerance of type=:custom (default 1e-8).
Errors if BdG has already been applied. Invalidates all caches. The KPM scale becomes |H.center| + H.scale + 1.1‖Δ̂‖ (center 0), with ‖Δ̂‖ = abs(Δ) for s-wave and 2abs(Δ) for p-wave, when H.scale is set and Δ is a Number; otherwise it is reset to 0 and estimated by DMRG on first use.
Examples
add_superconductivity!(H_spinless, 0.1) # auto p-wave (Kitaev chain)
add_superconductivity!(H_spinless, 0.1; type=:pwave) # explicit p-wave
add_superconductivity!(H_spinful, 0.1) # singlet s-wave (spinful required)
add_superconductivity!(H_spinful, i -> i < N÷2 ? 0.1 : 0.0) # spatially varying s-wave
add_superconductivity!(H, (i,j) -> ...; type=:custom) # general pairingTensorBinding.add_zeeman! — Method
add_zeeman!(H, h; direction=:z, tol=nothing, maxdim=200, position=nothing) -> HAdd a Zeeman coupling h · Sα to H. Calls add_spin! automatically if H is not yet spinful, placing the spin index at position (default H.aux_side).
h can be:
- a
Number— uniform field amplitudeh₀ - a
Function— spatially varyingh(i),i ∈ {1, …, N}(1-indexed), compressed by QTCI, which can lose narrow features (seeget_diagonal_mpo) - an
AbstractVector— the valuesh[i](length N), compressed exactly by TT-SVD
direction: :x, :y, or :z (default).
If add_superconductivity! was already called, the Zeeman term Z enters the hole block as −Z*, as required in BdG: τ_z ⊗ Z along x and z, +h·S_y in the hole block along y (up to v0.2.0 every direction got τ_z ⊗ Z, wrong along y).
tol is the relative cutoff of the sums, by default min(1e-8, 0.1/D), D the dimension of the site space (1e-8 up to D = 2^23; see "Large systems" in get_Hamiltonian).
Examples
add_zeeman!(H, 0.1) # uniform h = 0.1 along z
add_zeeman!(H, i -> 0.05 * sin(2π*i/H.N)) # oscillating field
add_zeeman!(H, 0.05; direction=:x) # in-planeTensorBinding.aux_site — Method
aux_site(H, which) -> (Index, Symbol)Return the auxiliary Index and its position side (:pre or :post) for the named auxiliary degree of freedom in H.
which ∈ :spin, :sublattice, :nambu, :layer.
The auxiliary sites sit in a block before (:pre) or after (:post) the position sites of H.sites, e.g. [nambu, spin, pos…] (BdG with spin, both :pre) or [pos…, spin, nambu] (both :post); the side is that of the block holding the index. An index with position sites on both sides is an error.
Useful for passing the correct arguments to project_aux without manually inspecting H.sites.
s, side = aux_site(H, :sublattice)
W_A = project_aux(W, s, 1; side=side) # sublattice-A channelTensorBinding.nambu_index — Method
nambu_index() -> IndexCreate a dim-2 Index tagged "Nambu" (state 1 = particle, state 2 = hole). Pass the result as s to all prepend_nambu / postpend_nambu calls.
TensorBinding.postpend_nambu — Method
postpend_nambu(H, s, op) -> MPOAppend a Nambu operator on the Nambu index s to the end of H. op is a Symbol (same table as prepend_nambu) or an explicit 2×2 matrix. Equivalent to postpend_op(H, s, op).
TensorBinding.postpend_spin — Method
postpend_spin(H, s, op) -> MPOAppend a spin-½ operator on the spin index s to the end of H. op is a Symbol (same table as prepend_spin) or an explicit 2×2 matrix. Equivalent to postpend_op(H, s, op).
TensorBinding.prepend_nambu — Method
prepend_nambu(H, s, op) -> MPOPrepend a Nambu (particle–hole) operator on the Nambu index s (created with nambu_index()). op is a Symbol from the table below or an explicit 2×2 matrix. Equivalent to prepend_op(H, s, op).
| Symbol | Matrix | Typical use |
|---|---|---|
:Id | I₂ | Particle + hole |
:Pp | diag(1,0) | Particle-sector projector |
:Ph | diag(0,1) | Hole-sector projector |
:tz | diag(1,−1) | Kinetic τ_z in BdG |
:tp | |p⟩⟨h| | Pairing amplitude Δ |
:tm | |h⟩⟨p| | Pairing Δ† (h.c.) |
:tx | σ_x | Real pairing (spinless p-wave) |
:ty | σ_y | Imaginary / chiral pairing |
Basis: state 1 = particle, state 2 = hole.
TensorBinding.prepend_op — Method
prepend_op(H_mpo, s, op::Symbol) -> MPO
postpend_op(H_mpo, s, op::Symbol) -> MPOSymbol dispatch for indices tagged "Spin" or "Nambu". Looks up op in the appropriate operator dictionary and calls the matrix-form prepend_op / postpend_op.
Spin ops (index tagged "Spin"): :Id, :Pup, :Pdn, :Sz, :Sp, :Sm, :Sx, :Sy, :iSy, :miSy
Nambu ops (index tagged "Nambu"): :Id, :Pp, :Ph, :tz, :tx, :ty, :tp, :tm
TensorBinding.prepend_spin — Method
prepend_spin(H, s, op) -> MPOPrepend a spin-½ operator on the spin index s (created with spin_index()). op is a Symbol from the table below or an explicit 2×2 matrix. Equivalent to prepend_op(H, s, op).
| Symbol | Matrix | Typical use |
|---|---|---|
:Id | I₂ | Spin-degenerate term |
:Pup | diag(1,0) | Spin-up projector |
:Pdn | diag(0,1) | Spin-down projector |
:Sz | diag(½,−½) | Zeeman / exchange field |
:Sp | |↑⟩⟨↓| | Spin-flip ↓→↑ |
:Sm | |↓⟩⟨↑| | Spin-flip ↑→↓ |
:Sx | ½σ_x | In-plane exchange |
:Sy | ½σ_y | In-plane exchange |
:iSy | i·σ_y = [[0,1],[−1,0]] | Singlet pairing spin factor |
:miSy | −i·σ_y | h.c. of singlet pairing |
Basis: state 1 = ↑, state 2 = ↓.
Mind the factor: :Sx, :Sy and :Sz are spin-½ operators (½σ), but :iSy and :miSy are the full ±iσy, not i·Sy = (i/2)σy. The singlet pairing and the Rashba term of `addsoc!` use them as such.
TensorBinding.probe_state — Function
probe_state(H, x) -> MPS
probe_state(H, x, σ) -> MPSThe probe state |x⟩ of the MPS Chebyshev methods at unit cell x (get_ldos_online, get_ldos_spatial(mode=:mps), the stochastic DOS). With σ = nothing (the default) it is the position probe: physical_site_state(H, x) when H.sites are the H.L position sites, the exciton pair state |x, x⟩ (mpsexciton) when H has more sites. With σ = (σ_n, σ_s, σ_l, σ_sl), an entry of _probe_sectors, it is the binary product state with the auxiliary sites set to those sectors (_ldos_make_psi0).
TensorBinding.project_aux — Method
project_aux(W, aux_s, σ; side=:pre) -> MPORemove an auxiliary site from MPO W by projecting onto state σ.
side=:pre— aux site is at position 1 (prepended, e.g. spin).side=:post— aux site is at the last position (postpended, e.g. sublattice).
Contracts the projector |σ⟩⟨σ| on both bra and ket physical indices of the aux tensor; the resulting dim-1 link is absorbed into the adjacent position site. Returns an (L−1)-site MPO suitable for conjugate_by_qft.
Errors if aux_s is not the site index of that end tensor (aux_site(H, which) returns the side of an auxiliary index of a TBHamiltonian).
TensorBinding.spin_index — Method
spin_index() -> IndexCreate a dim-2 Index tagged "Spin" (state 1 = ↑, state 2 = ↓). Pass the result as s to all prepend_spin / postpend_spin calls.
Model Registry
TensorBinding.MODELS — Constant
MODELS :: Dict{String,ModelEntry}The model registry: one ModelEntry per get_Hamiltonian geometry name.
TensorBinding.MODEL_REGISTRY — Constant
MODEL_REGISTRY :: Dict{String, Tuple{Symbol,Int,Vector{Symbol},NamedTuple}}Preset model name → (builder, dim, required_params, kw_defaults), the view of the preset entries of MODELS that build_hamiltonian reads.
TensorBinding.ModelEntry — Type
ModelEntryOne get_Hamiltonian geometry in the model registry MODELS.
Fields
name: the geometry name.kind::direct("chain_1d","haldane","custom"),:preset(the H* builders reached throughbuild_hamiltonian),:sublattice(the multi-atom unit cells) or:projected(the quasicrystal spaces).dim: spatial dimension (2D models takeLx,Ly).n_sub: atoms per unit cell (dimension of the sublattice index).params: parameter names (for a preset, the required ones, passed positionally).defaults: defaults of the other parameters (for a preset, the builder keywords thatMODEL_REGISTRYlists).builder: name of the function that builds the operator.build:(params, L, N, sites; scale, tol, maxdim, ref_sites, kwargs...) -> TBHamiltonian, called byget_Hamiltonianwith Qubitsites(unused by the presets and multi-atom lattices) ornothing(projected spaces).geometry:Nx -> (i -> position)for the models whose builder takes its geometry closure from the registry ("chain_1d"and the presets that have one).positions: name of the*_positionstable of a multi-atom lattice.legacy_scale:(params, mparams) -> scale, today's default formula when it lives in the registry (_estimate_scalereads it);nothingwhen the builder sets its default scale itself.default_rule::max(default scale =max(today's formula, estimate_scale(:auto))) or:formula(the builder's analytic default, unchanged).auto: the methodestimate_scale(...; method=:auto)uses.rowsum:(params, kwargs) -> bound, the largest absolute row sum (Gershgorin bound) of the builder's terms;nothingwhen there is no such rule.resizable: whether the builder can be run again at a smaller size with the same parameters (whatestimate_scale(...; method=:small)needs above 1024 states).
TensorBinding._chernhex_scale — Method
_chernhex_scale(params, mparams) -> Float64Default "chernhex" scale: the Gershgorin bound of H2DChernhex's terms (see _chernhex_rowsum), padded by 10% and never below the former default 6|t|. The parameters are merged the way buildpreset and build_hamiltonian merge them: the registry defaults, the mparams string, then params on top.
TensorBinding._estimate_scale — Method
_estimate_scale(geometry, params; mparams="") -> Float64Today's default KPM scale formula of geometry (the entry's legacy_scale), 5|t| for a geometry without one. mparams is the parameter string the preset path forwards to buildhamiltonian; only "chernhex" reads it. The default of getHamiltonian is max of this and estimate_scale for the entries with default_rule = :max.
TensorBinding._param — Method
_param(params, name, default; scalar=false) -> valueParameter name of a get_Hamiltonian params argument: the field of a NamedTuple, the entry of an AbstractDict (keyed by Symbol), and default when it has none. A bare Number is the value of the parameter asked for with scalar=true (the shorthand get_Hamiltonian("kagome", 1.0) for t) and gives default otherwise; any other params gives default.
TensorBinding._parse_param_string — Method
_parse_param_string(s) -> Dict{Symbol,Any}Parse "key1=val1, key2=val2, …" into a Dict. Values are auto-typed as Bool, Int, Float64, or String.
TensorBinding._preset_geometry — Method
_preset_geometry(geometry, Nx) -> Union{Function,Nothing}The i -> position closure that get_Hamiltonian stores for geometry (the entry's geometry rule at Nx = 2^Lx columns), nothing for geometries without one.
TensorBinding.build_hamiltonian — Method
build_hamiltonian(model, L; mparams="", mparam_dict=Dict{Symbol,Any}()) -> MPO (1D)
build_hamiltonian(model, Lx, Ly; mparams="", mparam_dict=Dict{Symbol,Any}()) -> MPO (2D)Build a Hamiltonian MPO by model name using the MODELREGISTRY. L, Lx and Ly are qubit counts (2^L sites, or a 2^Lx × 2^Ly grid). The parameters are the mparams string merged with `mparamdict` (which wins); the required ones are passed positionally to the builder, the rest as keywords on top of the registry defaults.
H = build_hamiltonian("aah", 8; mparams="V=2.0, phi=0.0, t=1.0")
H = build_hamiltonian("square_2d", 4, 4; mparams="t=1.0")
H = build_hamiltonian("chernhex", 4, 4; mparam_dict=Dict(:t=>1.0, :t2=>0.3, :ms=>0.0))Known models: aah, chern8, chernhex, hex2d, qc2dsquare, square2d, ssh, triangular2d, triangularbravais, uniform
TensorBinding.estimate_scale — Method
estimate_scale(geometry, params; L, method=:auto, tol=nothing, maxdim=15, kwargs...) -> Float64KPM half-bandwidth estimate (spectral centre 0) for get_Hamiltonian(geometry, params; L, tol, maxdim, kwargs...); kwargs are that call's other keywords (Lx, Ly, mparams, boundary, rs, …).
Methods
:small: exact dense spectrum of the same model with the same parameters and boundary, built at a small size:L_s = min(L, 10)in 1D,Lx_s = min(Lx, 5),Ly_s = min(Ly, 5)in 2D, reduced (the larger side first) until the build has at most 1024 states including its sublattice index. Returns1.1 max(|E_min|, |E_max|)of the Hermitian part. The small build runs from a fixed RNG seed (QTCI draws random pivots) and leaves the caller's RNGs untouched; its estimate is cached per (geometry, params, small sizes,tol,maxdim, other keywords). Withinget_Hamiltonian, a system that is already that small is diagonalised directly."haldane"and"custom", whose builders cannot be run at another size, support it only up to 1024 states.:geometry:1.1 ×the largest absolute row sum (Gershgorin bound) of the builder's terms, with the sup of the amplitude functions over all arguments for the size-scaled"chern8"and"qc2dsquare". Builds nothing. Not available for"custom"and the projected spaces.:dmrg: the DMRG estimate_estimate_spectral_boundsof the full Hamiltonian (the lazyscale=0path, run now); returns its scale and drops the centre it finds (get_Hamiltonian(...; scale=:dmrg)keeps both). Uses the global RNG.:auto: the model's own choice::geometryfor"chern8","qc2dsquare","chernhex"and"haldane",:dmrgfor"custom"and the projected spaces,:smallotherwise.
When scale is not passed, get_Hamiltonian uses max(today's formula, estimate_scale(...; method=:auto)) for "chain_1d", the preset models except "chernhex" and the 2D multi-atom lattices, and the builder's own default for every other geometry (see its docstring).
estimate_scale("aah", (V=0.5, phi=0.2, t=1.0); L=12) # :small, built at L = 10
estimate_scale("qc2dsquare", 1.0; L=12, Lx=6) # :geometry, 10.56
estimate_scale("square_2d", 1.0; L=12, Lx=6, method=:geometry) # 4.4