# declaration of the variable

reopened

Hello!

If I write

  for(int i = L-1; i >= 1; --i)
{
auto g = Gate(sites,i,i+1,Gate::tReal,tstep/2.,hterm);
gates.push_back(g);
}


it is OK, but if I write

for(int i = L-1; i >= 1; --i)
{
if (i % 2 == 0)
{
}

else
{
}

auto g = Gate(sites,i,i+1,Gate::tReal,tstep/2.,hterm);
gates.push_back(g);
}


It says
error: no declaration of the variable «hterm»
auto g = Gate(sites,i,i+1,Gate::tReal,tstep/2.,hterm);

But the following snippet gives "ITensorT::operator+=: different index structure
"

  for(int i = L-1; i >= 1; --i)
{
if (i % 2 == 0)
{
auto g = Gate(sites,i,i+1,Gate::tReal,tstep/2.,hterm);
gates.push_back(g);
}

else
{
auto g = Gate(sites,i,i+1,Gate::tReal,tstep/2.,hterm);
gates.push_back(g);
}


How one can curcumvent this issue? I need different hamiltonians for even and odd i

+1 vote
selected

Hello,

In your first code, you just have to initialize hterm before the if statement:

for(int i = L-1; i >= 1; --i)
{
IQTensor hterm;
if (i % 2 == 0)
{
}
else
{
}
auto g = Gate(sites,i,i+1,Gate::tReal,tstep/2.,hterm);
gates.push_back(g);
}


(assuming you are using QNs, otherwise you need to initialize with ITensor hterm).

In your second code, it looks like there is just a small mistake in the code. Instead of:

 auto hterm =  sites.op("Adag",i)*sites.op("A",i+1);


it should be:

 auto hterm =  sites.op("Adag",i)*sites.op("A",i+1);