ITensor / ITensor/ITensorMPS.jl

[ENHANCEMENT] Expose `truncerr` in calls to `truncate!`

Open
#96 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Julia
Stars
85
Forks
27
Avg merge
22m
Merged PRs (30d)
1

Description

Hello,

I'd be interested on thoughts here. I think it would be useful to be able to get the truncation error corresponding to a call to truncate!.

Currently truncate! as defined in abstractmps.jl only returns the MPS, but each truncation that is performed is a call to svd which returns the TruncSVD type which contains the truncation error.

Maybe one solution then would be to allocate a small vector with as many elements as there are bonds of the MPS. Then in the right to left sweep just collect the truncation error into each element and have that be optionally returned (could make it a kwarg).

If this functionality is already available then please just disregard and close this feature request.

Here is some psuedocode for what I had in mind (I've not actually tested this to see if it works, just what I was thinking). If this is something that sounds reasonable, I can prepare the pull request. I can make the corresponding updates to truncate as well.

function truncate!(
  ::Algorithm"frobenius", M::AbstractMPS; site_range=1:length(M), return_truncation_error=false, kwargs...
)
  N = length(M)
  truncerr = zeros(N-1)

  # Left-orthogonalize all tensors to make
  # truncations controlled
  orthogonalize!(M, last(site_range))

  # Perform truncations in a right-to-left sweep
  for (idx, j) in enumerate(reverse((first(site_range) + 1):last(site_range)))
    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...)
    truncerr[idx] = spec.truncerr
    M[j] = U
    M[j - 1] *= (S * V)
    setrightlim!(M, j)
  end
  if return_truncation_error
  return M, truncerr 
  else
   return M
   end
end

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in abstractmps.jl with truncate! and trace how each svd call produces a TruncSVD value containing truncerr. Compare the related truncate implementation and determine how an optional return value should preserve the current default behavior. Done means both truncate! and truncate can expose per-bond truncation errors without affecting existing callers.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.