OpIDSum
For some systems, constructing the OpSum can be the bottleneck of MPO construction. OpIDSum plays the same role as OpSum, but in a much more efficient manner. To specify an operator in a term of an OpSum, you provide a string (the operator's name) and a site index. To specify an operator in a term of an OpIDSum, you provide an OpID, which contains an operator index and a site. The operator index is the position of the operator in the provided basis for the site. The remaining metadata about the operator is kept in an OpCacheVec.
ITensorMPOConstruction.OpID — Type
OpID{Ti}Compact identifier for an operator stored in an OpCacheVec.
Type Parameters
Ti: The integer type used to store both the operator ID and site.
Fields:
id: index of the operator within the cache for siten.n: site number on which the operator acts.
The zero value OpID(0, 0) is used internally as padding for unused slots in fixed-width storage.
ITensorMPOConstruction.OpIDSum — Type
OpIDSum{N,C,Ti}Compact, fixed-width storage for sum of products of local operators.
Each stored term has a scalar coefficient and up to N non-identity local operators encoded as OpID{Ti} values. Unused slots are padded with zero(OpID{Ti}). The operator ids are interpreted through op_cache_vec, and terms are stored in increasing site order after insertion.
Type Parameters:
N: maximum number of non-identity onsite operators stored per term.C: scalar coefficient type.Ti: integer type used for operator ids and site numbers.
Fields:
_data: tuple storage backing the reinterpretedtermsmatrix.terms:N x capacitymatrix view of fixed-widthOpIDterm storage.scalars: coefficient storage parallel to columns ofterms.num_terms: atomic count of currently populated terms.op_cache_vec: operator cache defining the meaning of eachOpID.abs_tol: coefficients withabs(scalar) <= abs_tolare dropped byadd!.modify!: callback applied to the nonzero part of a term before storing its scalar.
ITensorMPS.add! — Function
add!(os::OpIDSum, scalar::Number, ops) -> NothingAppend a term (defined by ops) to os. This function is thread-safe.
Identity operators (id == 1) are removed before storage, remaining operators are sorted by site with the appropriate fermionic permutation sign, and the term-modification callback associated with os is applied. Terms below os.abs_tol are skipped. Importantly, the sorting is stable. This does not merge duplicate terms or check capacity; callers must construct os with enough room for all accepted terms.
add!(os::OpIDSum, scalar::Number, ops::OpID...) -> NothingVararg convenience method for add!.
ITensorMPOConstruction.OpInfo — Type
OpInfoCached metadata for a single local operator on a given site.
Fields:
name: operator name used to build the local ITensor operator.matrix: dense matrix representation of the local operator.is_fermionic: whether the operator has odd fermion parity.qn_flux: quantum-number flux carried by the operator, orQN()when the ITensor operator reports no flux.
ITensorMPOConstruction.OpCacheVec — Type
OpCacheVecA per-site operator cache.
OpCacheVec is indexed as op_cache_vec[n][op_id], where n is a site number and op_id is the operator id stored in an OpID. By convention, operator id 1 is the identity on every site.
ITensorMPOConstruction.to_OpCacheVec — Function
to_OpCacheVec(sites::Vector{<:Index}, ops::OpCacheVec) -> OpCacheVecValidate and return a precomputed operator cache.
The number of site caches must match sites, and the first cached operator for every site must be the identity. The input cache is returned unchanged.
to_OpCacheVec(sites::Vector{<:Index}, ops::Vector{Vector{String}}) -> OpCacheVecBuild an OpCacheVec from operator names for each site.
ops[n] is the ordered list of operator names available on site n, and the first entry for every site must be "I", which is reserved for the identity. The returned cache preserves this ordering, so ids in OpID values refer to positions in the corresponding site list.
to_OpCacheVec(sites::Vector{<:Index}, ::Nothing) -> NothingPass through nothing for call sites where an optional operator cache is allowed.
Base.length — Function
length(os::OpIDSum) -> IntReturn the number of terms currently stored in os.
Base.eachindex — Function
eachindex(os::OpIDSum) -> UnitRange{Int}Return the valid term indices of os.
Base.getindex — Function
getindex(os::OpIDSum, i::Integer)Return the pair (scalar, ops) for the ith term of os, where ops is a view into the fixed-width OpID storage for that term.
Base.isless — Function
isless(op1::OpID, op2::OpID) -> BoolOrder OpID values lexicographically by (site, operator id).
ITensors.flux — Function
ITensors.flux(ops::NTuple{N,OpID}, n::Int, op_cache_vec::OpCacheVec) where {N} -> QNReturn the total quantum-number flux contributed by operators in ops on sites >= n, using the cached operator metadata in op_cache_vec.