Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Change new kwarg name to `truncation_errors!` from `truncation_errors`
Remove usage of `enumerate`
Update docstring

Co-authored-by: Matt Fishman <[email protected]>
  • Loading branch information
NuclearPowerNerd and mtfishman authored Jan 13, 2025
1 parent 00f1764 commit 4a29839
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/abstractmps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1672,7 +1672,7 @@ provided as keyword arguments.
Keyword arguments:
* `site_range`=1:N - only truncate the MPS bonds between these sites
* `truncation_errors` - if provided, will store the truncation error from each SVD performed in a single call to `truncate!`. This should be a `Ref` type, for example `truncation_errors = Ref{Vector{Float64}}()`. It should be initialized to some value (likely 0.0, e.g., `truncation_errors[] = zeros(nbonds)`).
* `truncation_errors!` - if provided, will store the truncation error from each SVD performed in a single call to `truncate!`. This should be a `Ref` type, for example `truncation_errors! = Ref{Vector{Float64}}()`, which will be overwritten in the function.
"""
function truncate!(M::AbstractMPS; alg="frobenius", kwargs...)
return truncate!(Algorithm(alg), M; kwargs...)
Expand All @@ -1682,7 +1682,7 @@ function truncate!(
::Algorithm"frobenius",
M::AbstractMPS;
site_range=1:length(M),
truncation_errors=nothing,
(truncation_errors!)=nothing,
kwargs...,
)
N = length(M)
Expand All @@ -1692,7 +1692,9 @@ function truncate!(
orthogonalize!(M, last(site_range))

# Perform truncations in a right-to-left sweep
for (i,j) in enumerate(reverse((first(site_range) + 1):last(site_range)))
js = reverse((first(site_range) + 1):last(site_range))
for i in eachindex(js)
j = js[i]
rinds = uniqueinds(M[j], M[j - 1])
ltags = tags(commonind(M[j], M[j - 1]))
U, S, V, spec = svd(M[j], rinds; lefttags=ltags, kwargs...)
Expand Down

0 comments on commit 4a29839

Please sign in to comment.