ITensor / NDTensors.jl

A Julia package for n-dimensional sparse tensors.
Apache License 2.0
27 stars 7 forks source link

small fix to exp - extract parent matrix from Hermitian view #15

Closed orialb closed 4 years ago

orialb commented 4 years ago

Extract the parent matrix from the Hermitian view in exp(T, Linds, Rinds; ishermitian=true), similar to the way it is done in the case of the order 2 tensor exp(T::Hermitian{ElT<:DenseTensor{ElT,2}}). Without this fix one cannot use the ITensor returned from exp.

orialb commented 4 years ago

Looking at the how svd is handled I guess that the method exp(T::DenseTensor, Linds, Rinds) is redundant and the goal would be to rewrite the exp(T::ITensor,...) method in ITensors such that it calls the appropriate method for an order 2 tensor from NDTensors ?

mtfishman commented 4 years ago

Thanks for looking into this, Ori.

Perhaps we should handle this better in general. I had been going back and forth about what Dense should be able to accept and store. Ideally Dense only stores AbstractVector objects, since it is supposed to be a 1-dimensional storage that is indexed based on the inds of the Tensor. So maybe it should be able to accept AbstractMatrix objects, like Matrix and Hermitian, and automatically turn them into a Vector that can be stored by Dense. The case of Hermitian is a bit unfortunate, since it may involve an extra copy beyond using parent as you do here. Anyway, maybe for now we can just handle this particular case as you do here.

But as you guessed, I'm not sure right now what the status of functions like this are. I had thought these would be more natural to get called by ITensors.jl, but realized that most of the time ITensors.jl is already handling the reshape into a matrix, since for QN ITensors it really needs to be done using a combiner (and the combiner requires knowing about the QNs). So we should move this to being like the svd code, where ITensors.jl handles the reshape into an order-2 tensor and just calls exp(::Tensor{ElT,2}).

mtfishman commented 4 years ago

Independent of the question about whether functions like this are useful, I'll merge this fix. Thanks again!

orialb commented 4 years ago

As long as the function is there, there is no harm in making in it work in the hermitian case :)