ITensor / ITensorNetworks.jl

A package with general tools for working with higher-dimensional tensor networks based on ITensor.
MIT License
56 stars 12 forks source link

Refactor `sqrt_inv_sqrt` #158

Closed JoeyT1994 closed 5 months ago

JoeyT1994 commented 5 months ago

This PR removes the sqrt_inv_sqrt function in apply.jl in favor of a map_itensor(f::Function, t::ITensors, args...) added in the file itensorsextensions.jl in the new internal module ITensorsExtensions (where src/ITensorsExt/utils.jl is also now moved).

map_itensor(f::Function, A::ITensor, ...) uses the SVD to take a decomposition U, S, V of A and applies f over the diagonal elements of S. This uses the sqrt_decomp function from ITensors.jl (introduced in the PR https://github.com/ITensor/ITensors.jl/pull/1197/files) which correctly handles quantum numbers. The indices of the returned ITensor match those of the input A.

The symmetric_factorize function has been removed entirely from apply.jl as we can just call factorize_svd(A::ITensor; ortho = "none") fromITensors.jl` to do the same thing (again this was introduced in PR https://github.com/ITensor/ITensors.jl/pull/1197/files).

Tests are included. @mtfishman these appear to show the square root / inverse being correctly taken by the SVD backend and I don't see any phase issues cropping up?

A few other changes in this PR: src/tensornetworkoperators.jl and test/test_tnos.jl have been removed and archived as they will be significantly refactored down the line.

codecov-commenter commented 5 months ago

Codecov Report

Attention: Patch coverage is 65.51724% with 10 lines in your changes are missing coverage. Please review.

Project coverage is 82.66%. Comparing base (ae4ad2c) to head (0dc6016). Report is 4 commits behind head on main.

Files Patch % Lines
src/apply.jl 52.38% 10 Missing :warning:

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #158 +/- ## ========================================== + Coverage 81.89% 82.66% +0.77% ========================================== Files 72 72 Lines 3744 3635 -109 ========================================== - Hits 3066 3005 -61 + Misses 678 630 -48 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

mtfishman commented 5 months ago

I have to say that it doesn't sit well with me to use an SVD to perform square roots and inverses of positive semi-definite Hermitian matrices, I think it is safer and more direct (not to mention faster) to use a Hermitian eigendecomposition to ensure the gauge is fixed in the correct way.

mtfishman commented 5 months ago

Looks good, thanks! Good to go back and start cleaning up some of this code.