Library


Additional methods for Base and LinearAlgebra

SpinGlassPEPS.SpinGlassTensors.kernel_batch_size — Function

Power-of-two batch size for kernel intermediates of element type T costing per_item elements per batched item. Scales with sizeof(T), so Float32 gets twice the batch of Float64.

The byte budget for intermediates is a quarter of the memory this task is entitled to:

  • if a DEVICE_MEMORY_BUDGET is in scope (set per task by the parallel sweep driver), a quarter of that reservation. This is what makes concurrent solves safe: without it, every concurrently running solve measures the same shared free pool and they all size their batches as if they owned it.
  • otherwise a quarter of the currently free device memory (so it shrinks when other allocations are live, rather than overcommitting against total capacity), floored at a sixteenth of total memory so a busy pool can't collapse the batch to a pathologically small value.

On CPU the budget is 4 GiB.

source

MPS

Compresions and Contractions

Projectors

SpinGlassPEPS.SpinGlassTensors.PoolOfProjectors — Type

PoolOfProjectors is a data structure for managing projectors associated with Ising model sites. It allows efficient storage and retrieval of projectors based on their indices and provides support for different computational devices.

Fields:

  • data::Dict{Symbol, Dict{Int, Proj{T}}}: A dictionary that stores projectors associated with different

computational devices (:CPU, :GPU, etc.). The inner dictionary maps site indices to projectors.

  • default_device::Symbol: A symbol representing the default computational device for projectors in the pool.
  • sizes::Dict{Int, Int}: A dictionary that maps site indices to the maximum projector size for each site.

Constructors:

  • PoolOfProjectors(data::Dict{Int, Dict{Int, Vector{T}}}) where T: Create a PoolOfProjectors with initial data for projectors.

The data is provided as a dictionary that maps site indices to projectors stored in different computational devices. The sizes dictionary is automatically populated based on the maximum projector size for each site.

  • PoolOfProjectors{T}() where T: Create an empty PoolOfProjectors with no projectors initially stored.
source
SpinGlassPEPS.SpinGlassTensors.get_projector! — Function
get_projector!(
    lp::PoolOfProjectors{T<:Integer},
    index::Int64,
    device::Symbol
) -> Union{Vector{T}, CUDA.CuVector{T}, CUDA.DenseCuVector{T}} where T<:Integer

TODO This is version for only one GPU

Retrieve or create a projector from the PoolOfProjectors associated with a specific device.

This function retrieves a projector from the PoolOfProjectors if it already exists. If the projector does not exist in the pool, it creates a new one and stores it for future use on the specified computational device.

Arguments:

  • lp::PoolOfProjectors{T}: The PoolOfProjectors object containing projectors.
  • index::Int: The index of the projector to retrieve or create.
  • device::Symbol: The computational device on which the projector should be stored or retrieved (e.g., :CPU, :GPU).

Returns:

  • Proj{T}: The projector of type T associated with the specified index and device.
source
SpinGlassPEPS.SpinGlassTensors.add_projector! — Function
add_projector!(
    lp::PoolOfProjectors{T<:Integer},
    p::Union{Vector{T}, CUDA.CuArray{T, 1}} where T
) -> Int64

Add a projector to the PoolOfProjectors and associate it with an index.

This function adds a projector p to the PoolOfProjectors. The PoolOfProjectors stores projectors based on their computational device (e.g., CPU or GPU) and assigns a unique index to each projector. The index can be used to retrieve the projector later using get_projector!.

Arguments:

  • lp::PoolOfProjectors{T}: The PoolOfProjectors object to which the projector should be added.
  • p::Proj: The projector to be added to the pool. The type of the projector Proj should match the type T specified in the PoolOfProjectors.

Returns:

  • Int: The unique index associated with the added projector in the pool.
source
Base.empty! — Method
empty!(
    lp::PoolOfProjectors,
    device::Symbol
) -> PoolOfProjectors

Empty the pool of projectors associated with a specific computational device.

This function removes all projectors stored on the specified computational device, freeing up memory resources.

Arguments:

  • lp::PoolOfProjectors: The PoolOfProjectors object containing projectors.
  • device::Symbol: The computational device for which projectors should be emptied (e.g., :CPU, :GPU).
source
Base.copy — Method
copy(lp::PoolOfProjectors)

Create an independent projector workspace. The default-device dictionary is copied while its projector vectors are shared as read-only definitions; derived device data and contraction caches start empty. This lets separate PEPS networks share the same Hamiltonian without duplicating potentially large definition vectors, racing on mutable caches, or clearing one another's GPU data.

source

Task-scoped execution context

Internals backing the device-memory governor and the truncation-error reporting described under Concurrent sweeps and error control. Both quantities are dynamically scoped per task so that concurrently running solves see their own values without threading them through every kernel signature.

SpinGlassPEPS.SpinGlassTensors.NEGLIGIBLE_DISCARD — Constant

Relative discarded weight (‖Σ_dropped‖² / ‖Σ‖²) below which a bond-capped truncation is not counted as saturated: the dropped singular values are deliberately ignored, so no change from raising the bond dimension is expected at the reported precision. Sits above the ~1e-14 weights observed in a reference contraction and below the smallest weight a genuinely bond-limited truncation has been observed to drop (~1e-10 on the shipped 128-spin fixture).

source
SpinGlassPEPS.SpinGlassTensors.record_truncation! — Function
record_truncation!(
    discarded::Real,
    kept::Integer,
    offered::Integer,
    saturated::Bool
)

Record one truncating factorization that kept kept of offered singular values, discarding relative weight discarded (‖Σdropped‖²/‖Σ‖²). saturated marks a truncation forced by the bond-dimension bound rather than by the singular-value tolerance, and that discarded more than numerically negligible weight (callers combine the bond-bound test with [`NEGLIGIBLEDISCARD`](@ref)).

A no-op when no TRUNCATION_LOG is installed in the current task.

source
Base.empty! — Method
empty!(log::TruncationLog) -> TruncationLog

Zero a truncation log in place, so it can be reused for the next phase.

source
SpinGlassPEPS.SpinGlassTensors.DevicePeak — Type

Tracks how much device memory a solve actually used, as a high-water mark over samples of CUDA.available_memory() relative to a baseline taken at construction.

CUDA.jl 5.x allocates through its own caching allocator rather than the CUDA stream-ordered pool, so the driver's MEMPOOL_ATTR_USED_MEM_HIGH watermark stays at zero and cannot be used. Sampling free memory does track the caching allocator (verified), so peak usage is reconstructed from samples taken by two independent samplers:

  • a watchdog task polling on a timer, which catches transients inside a row but needs a second thread to be scheduled reliably;
  • probe_device_peak! calls placed at natural synchronization points in the solve (row boundaries), which are deterministic and work even in a single-threaded session.

Both feed the same tracker, so the reported peak is the max over both.

Only meaningful while the tracked solve runs alone on the device — concurrent work would be attributed to it. This is why the sweep driver calibrates on a solo run before admitting any concurrency.

source
SpinGlassPEPS.SpinGlassTensors.probe_device_peak! — Function
probe_device_peak!()

Take one device-memory sample for the peak tracker installed in the current task, if any. A no-op when no tracker is in scope or CUDA is unavailable, so it is safe to call unconditionally from hot-ish code such as a row transition.

source