About a realization of Bose-Hubbard model

I am trying to reproduce the same code on the odd C++ forum: http://itensor.org/support/3295/how-to-construct-bose-hubbard-model?show=3295#q3295
When I copy paste exactly the same code

int L = 2;
auto sites = Boson(L, {"MaxOcc=", 1, "ConserveQNs", true, "ConserveNb", false});
auto sweeps = Sweeps(8);
sweeps.maxdim() = 40, 80, 400, 400, 800, 800, 1000, 1000;
sweeps.cutoff() = 1E-16;

Real miu = 1.0;
Real U = 1.0;
Real J = 1.0;
Real V = 1.0;

auto ampo = AutoMPO(sites);
for (int i = 1; i < L; i += 1)
{
    ampo += -miu - U / 2, "N", i;
    ampo += U / 2, "N", i, "N", i;
    ampo += -J, "A", i, "Adag", i + 1;
    ampo += -J, "Adag", i, "A", i + 1;
    ampo += V, "N", i, "N", i + 1;
}
ampo += -J, "A", 1, "Adag", L;
ampo += -J, "Adag", 1, "A", L;
ampo += V, "N", 1, "N", L;
auto H = toMPO(ampo);

auto state = InitState(sites);
for (int i : range1(L))
{
    if (i % 2 == 1)
        state.set(i, "1");
    else
        state.set(i, "1");
}
auto psi = randomMPS(state);

auto [energy, psi0] = dmrg(H, psi, sweeps, "Quiet");
return 0;

And trying to run it, there is an error

LocalOp is default constructed

The code itself looks legitimate, so I don’t quite understand where goes wrong. What does this error usually indicate??

I believe the reason is the size of the system being L=2, which is such a small system that the DMRG algorithm isn’t needed to solve it. Can you please try a larger system size?

1 Like

Hi Miles! Thanks for your answer. Yes, increase the system size solved the problem.

1 Like