0 votes
asked by (160 points)

Hi!

The issue I have is similar to one found here. It looks like it's still there.

I want to calculate few excited states for spin-1/2 XY model.
Since total Sz is conserved, I want to restrict myself to a sector with fixed nonzero Sz (equal to SzSector in the code below). I do so by picking InitState which belongs to this sector, and putting ConserveQNs=true.

However, I still can catch the segfault, with the following error message:

div(T1)=QN({"Sz",-2}) must equal div(T2)=QN() when adding T1+T2

While for SzSector=+1 I get:

div(T1)=QN({"Sz",2}) must equal div(T2)=QN({"Sz",0}) when adding T1+T2

The minimal (non-)working example code is following:

#include "itensor/all.h"

using namespace itensor;

int main(int argc, char* argv[]) {
    int N = 20;
    int SzSector = -1;
    int nstates = 2;
    // Building Hamiltonian
    auto sites = SpinHalf(N, {"ConserveQNs=", true});
    auto ampo = AutoMPO(sites);
    for (int x = 1; x <= N-1; x++) {
        ampo += -1,"S+",x,"S-",x+1;
        ampo += -1,"S-",x,"S+",x+1;
    }
    MPO H = toMPO(ampo);
    // Preparing random initial state
    InitState state(sites);
    for (int i = 1; i <= N; i++) {
        state.set(i, i <= N/2 + SzSector ? "Up" : "Dn");
    }
    //MPS psi0 = randomMPS(state);
    MPS psi0(state);
    // Initializing sweep parameters
    auto sweeps = Sweeps(5);
    sweeps.maxdim() = 200;
    sweeps.cutoff() = 1e-9;
    sweeps.niter() = 2;
    sweeps.noise() = 1e-9;
    // DMRG
    std::vector<MPS> states;
    std::vector<double> energies;
    for (int i = 0; i < nstates; i++) {
        auto [energy,psi] = dmrg(H, states, psi0, sweeps, {"Quiet=", true, "Weight=", 20.0});
        states.push_back(psi);
        energies.push_back(energy);
    }
    return 0;
}

The code with randomMPS(state) doesn't work as well.

commented by (70.1k points)
Hi, thanks for reporting this. I was able to reproduce your error but it's a tricky one to track down (though I think I've got it cornered). I'm working on it and will post an answer when I push a fix. Thanks for your patience. - Miles
commented by (160 points)
Hi! Thanks for your work!
Any news on that?

1 Answer

+2 votes
answered by (70.1k points)
selected by
 
Best answer

Hi, sorry for the long delay on this, but I just merged a pull request that I believe fixes this bug. If you are still encountering it, or have your code above, please check that the latest v3 branch of ITensor fixes this issue. Thanks!

https://github.com/ITensor/ITensor/pull/341

Best regards,
Miles

commented by (160 points)
Hi Miles,
I can confirm I no longer experience the crash, neither with the MWE from the question, nor with my own original code.
Thank you for fixing this and for dropping a note here!
commented by (70.1k points)
Great! Thanks so much for checking even though it's been a while.
Welcome to ITensor Support Q&A, where you can ask questions and receive answers from other members of the community.

Formatting Tips:
  • To format code, indent by four spaces
  • To format inline LaTeX, surround it by @@ on both sides
  • To format LaTeX on its own line, surround it by $$ above and below
  • For LaTeX, it may be necessary to backslash-escape underscore characters to obtain proper formatting. So for example writing \sum\_i to represent a sum over i.
If you cannot register due to firewall issues (e.g. you cannot see the capcha box) please email Miles Stoudenmire to ask for an account.

To report ITensor bugs, please use the issue tracker.

Categories

...