[WIP] [ITensors] add kwarg to truncate! to return RankFactorization.Spectru… #1518
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The purpose of this commit is to allow the truncation error from an operation to be returned. This is the first step envisioned for that functionality.
The spectrum and truncation error from calling svd() on ITensors is not accessible from calls to truncate! and truncate. This allows the Spectrum type (which contains the spectrum and the error) to be optionally returned. This required importing RankFactorization.Spectrum in ITensors (so an added import in imports.jl) and then slightly refactoring the definition of truncate! and truncate.
This commit makes a named tuple with each element being "bond_n" where n is
1
toN-1
bonds and each element of the named tuple corresponds to the Spectrum returned from the call to svd as the bonds are swept over during the call to truncate.All tests were run with 92979 passing and 73 broken. Total tests were 93052.
Implements ITensor/ITensorMPS.jl#96
If practical and applicable, please include a minimal demonstration of the previous behavior and new behavior below.
Minimal demonstration of previous behavior
Minimal demonstration of new behavior
Additional Remark
I limited the scope of these changes to just
truncate!
andtruncate
. But looking forward, it would be nice to be able to get truncation error returned for any operation. For example, something like thisI wasn't sure if those changes should be implemented as part of this pull request or be made in a separate pull request. So I'd appreciate feedback on what the preference there is.
How Has This Been Tested?
I verified its behavior in the MWE above. If I need to add a dedicated test let me know. I didn't see an existing one for
truncate!
in/ITensors.jl/src/lib/ITensorMPS/test/base/
.Checklist:
using JuliaFormatter; format(".")
in the base directory of the repository (~/.julia/dev/ITensors
) to format your code according to our style guidelines.