ITensors.jl
ITensors.jl copied to clipboard
[ITensors] [ENHANCEMENT] Introduce `svd(A, :, (k, l))`
Introduce a syntax for specifying only the right indices of a factorization. On proposal would be:
i, j, k, l = Index.((2, 2, 2, 2))
A = randomITensor(i, j, k, l)
U, S, V = svd(A, :, (k, l))
# Equivalent to:
U, S, V = svd(A, (i, j))
One application is simpler syntax for factorizing an ITensor into an MPS. Currently factorizing from right to left is easy to do just in terms of the site indices:
U, S, A4 = svd(A, (i, j, k))
U, S, A3 = svd(U * S, (i, j))
U, S, A2 = svd(U * S, i)
A1 = U * S
Amps = MPS([A1, A2, A3, A4])
but to do a left-to-right factorization it is a bit more annoying, since you need to make use of the link indices:
A1, S, V = svd(A, i)
u = commonind(A1, S)
A2, S, V = svd(S * V, (u, j))
u = commonind(A2, S)
A3, S, V = svd(S * V, (u, k))
A4 = S * V
Amps = MPS([A1, A2, A3, A4])
(there are other ways to do it but they are similar in that they involve some extra set index logic).
With the new proposal this could be done with:
A1, S, V = svd(A, :, (j, k, l))
A2, S, V = svd(S * V, :, (k, l))
A3, S, V = svd(S * V, :, l)
A4 = S * V
I'm sure there are other places in the code where this could come in handy as well.
Note that we could use the notation:
svd(A, .., (k, l))
which is standardized by the package EllipsisNotation.jl.
Not to be too picky, but in principle one can do this by switching U and V, correct? So like
V,S,U = svd(A, (i,j))
would do the same as
U,S,V = svd(A, :, (i,j))
correct?
That being said, the new version you propose would be easier to understand i.e. more obvious about what one is trying to do and why.
I like either notation (either ":" or "..").
Yes good point, I forgot you can do it that way.