-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should QDense constructor error if zero blocks? #383
Comments
Good question. The way this is handled in the Julia version right now is: using ITensors
s = siteinds("S=1/2", 4)
T = randomITensor(QN("Sz", 1), s...)
@assert store(T) isa NDTensors.BlockSparse
@assert iszero(nnzblocks(T))
@assert isnothing(flux(T)) so it handles it in a similar way (makes an ITensor with no blocks), however for that case Perhaps trying to make that ITensor should error (or at least give a warning), since likely it is a mistake to try to make it in the first place. At least in Julia, the "correct" way to make an ITensor with no blocks is: T = emptyITensor(s...)
@assert store(T) isa NDTensors.Empty but I forget if there is an equivalent thing in the C++ version. On a related note, to explicitly make an ITensor with zero blocks but with an actual T = ITensor(Block[], s...) which would generalize to being able to specify a list of flux-consistent nonzero blocks, i.e.: T = ITensor([Block(2, 2, 1, 1), Block(1, 1, 2, 2)], s...) |
So I would lean towards it being an error to try to make the tensor |
I agree. There is the small issue that |
Yeah. I think in terms of it being a breaking change, I would say that right now it is ill-defined behavior so it is ok to break it. We can also have the error message point users to the "correct" way to make a QN ITensor with no blocks (so in Julia, |
Oh I see what you are saying. I guess it depends on where we implement it. We could just implement this at the level of |
Ok that's the right solution of course! |
The QDense storage constructor taking an IndexSet and a QN sometimes results in a storage with zero blocks, in the case that the requested QN is not compatible with any settings of the indices. This is ok, but the current behavior is that the constructor just makes no blocks (empty list of blocks) and goes on. As a result, calling
flux
on the resulting ITensor givesQN()
which is interpreted as a zero QN. Then calling something likeT.generate
inside of a function likerandomITensor
now will generate blocks corresponding to a zero-flux ITensor. So the final QN ends up different from the one requested.Where should we throw an error to prevent this? Is it reasonable for the QDense constructor to error? It's probably an easy change, but we just need to be sure of the right design.
Example to reproduce:
The text was updated successfully, but these errors were encountered: