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.