About the meaning of "dim" in "siteinds"

I am trying to reproduce the code snippet listed in the C++ Forum: http://itensor.org/support/3295/how-to-construct-bose-hubbard-model?show=3295#q3295
Basically the author is trying to implement the following Bose-Hubbard model:
H = \sum_{j=1}^{L}[-\mu\hat{n}_{j}+\frac{U}{2}\hat{n}_{j}(\hat{n}_j - 1)-J(\hat{a}_{j}\hat{a}_{j+1}^{\dagger}+h.c.)+V\hat{n}_{j}\hat{n}_{j+1}]
In the original author’s code, the author initialized the sites and initial state in the following form

auto sites = Boson(L, {"MaxOcc=", 1, "ConserveQNs", true, "ConserveNb", false});
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);

I assume that to translate the code into Julia ITensor, it will be in the form

sites = siteinds("Boson",N;conserve_number=true,dim=1);
init = ["1" for i in 1:N]
psi0= randomMPS(sites,init);

But running like this it shows an error,

BoundsError: attempt to access 1-element Vector{Float64} at index [2]

So I am wondering what is meaning of dim in siteinds? Does it just equivalent to MaxOcc= in Boson case??

The keyword argument dim is the dimension of the site index. And for the Boson site type, the index values you can set are "0" being the first value, "1" being the second value, "2" being the third value, and so on.

So if you set dim=1 only the value "0" is allowed. We should probably disallow setting dim=1 for Boson since I can’t think of any physically relevant situations where you would want a “Boson” site that cannot have any bosons on it!

Hope that answers your question.

1 Like