Giter VIP home page Giter VIP logo

Comments (6)

mtfishman avatar mtfishman commented on June 16, 2024

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 flux returns nothing.

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 BlockSparse storage (instead of Empty storage), I was considering a notation like:

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...)

from itensor.

mtfishman avatar mtfishman commented on June 16, 2024

So I would lean towards it being an error to try to make the tensor randomITensor(QN("Sz", 1), s...) in the first place, since probably it is a mistake to do that and if you want an ITensor with empty blocks, you should use a different constructor.

from itensor.

emstoudenmire avatar emstoudenmire commented on June 16, 2024

I agree. There is the small issue that randomITensor works by calling a specific, fairly general-purpose QDense constructor so it could interfere with other functions that call that constructor and rely on it to just silently create a QDense with no blocks. But I think we'll just have to run the tests we have and if those pass then assume it's not breaking any other code and/or wait for a user to raise an issue if it errors in theirs.

from itensor.

mtfishman avatar mtfishman commented on June 16, 2024

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, emptyITensor, and in C++, I guess the plain ITensor constructor with no QNs specified?).

from itensor.

mtfishman avatar mtfishman commented on June 16, 2024

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 randomITensor and ITensor (where we just run the QDense constructor, and if it ends up with no blocks then we throw an error), as opposed to actually in the QDense constructor itself.

from itensor.

emstoudenmire avatar emstoudenmire commented on June 16, 2024

Ok that's the right solution of course!

from itensor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.