# Index does not contain given QN block

I am receiving this error message upon attempting to construct my Hamiltonian using

auto H = toMPO(ampo);


I can post the code that is constructing the ampo, but I feel it's more likely something is going wrong in my construction of my custom site class. Here it is:

ExcitonSite(Args const& args = Args::global())
{
dim = args.getInt("on_site_dim", 5);
auto ts = TagSet("Site,Exciton");
int n = args.getInt("SiteNumber");
auto v = std::vector<std::pair<QN, long int>>(2 * dim + 1);
int cntr = 0;
for (int j = -dim; j <= dim; ++j)
{
auto q = QN({"Sz",j});
v.emplace_back(q, 1);
}
s = Index(std::move(v),Out,ts);
}


The full error message is
1: 2 QN()
Q = QN({"Sz",-2})

From line 639, file index.cc

Index does not contain given QN block.

Index does not contain given QN block.

Hi, so one thing that jumps out at me is that you already give the vector "v" a size, but then use emplace_back to put things into it, which will put more things at the end, still leaving 2*dim+1 default-initialized pair<QN,long> 's at the beginning.

There may be other issues but this looks like a definite one!

Miles

commented by (350 points)
Gotcha - I replaced the emplace_back line with

v[j + dim] = std::pair(q,1);

but am still running into the same error message unfortunately.
commented by (70.1k points)
Ok then the code looks good to me after that. I could imagine some more issues are:
1. how you define the specific operators you use to build your Hamiltonian
2. how you define your Hamiltonian (does it really conserve the quantum numbers you are specifying?)
commented by (350 points)
I think the specific operators are ok (though of course, I could definitely be wrong). Though the quantum numbers are not conserved, as can be seen in the last two lines of building the Hamiltonian:

auto sites = Exciton(N,{"on_site_dim", dim});
auto ampo = AutoMPO(sites);
for(int j = 1; j <= N; ++j)
{
ampo += + 4. "nsq", j;
}
for(int j = 1; j <= N - 1; ++j)
{
ampo += + 8. , "n", j, "n", j + 1;
ampo += - 10, "gm", j, "gp", j + 1;
ampo += - 10, "gp", j, "gm", j + 1;
}
ampo += + 8. , "n", 1, "n", N;
ampo += - 10, "gm", 1, "gm", N;
ampo += - 10, "gp", 1, "gp", N;

auto H = toMPO(ampo);

where "gp" and "gm" are raising and lowering operators. You believe this is the issue?
commented by (70.1k points)
Yes that's most likely the issue: you cannot use indices which carry quantum numbers in conjunction with a Hamiltonian which does not conserve those quantum numbers.

What were you intending the quantum numbers for? For having extra information available when doing an analysis of the physics?
commented by (350 points)
Got it. No they are totally useless as far as my application is concerned. So then in my custom site class, instead of my for loop there should be something like

s = Index(2*dim+1,ts)

?
commented by (350 points)
Indeed it worked - thank you Miles, you are a wizard.