Hi! I’ve a quick question about defining three types of sites at different positions. Specifically, I’m trying to have 3N sites, with 1~N as Electron sites, N+1~2N as Spin1/2 sites, and 2N+1~3N also as Spin1/2 sites, because I want to use these to represent three chains. Currently, I only find cases with at most two types of sites, where the example use:
sites=[isodd(n) ? siteind(...) : siteind(...) for n=1:2N]
to separate two types of sites, and I’ve tried things like:
sites=[isless(n-(N+1),0) ? siteind(...) : isless(0,n-N) & isless(n-(2*N+1),0) ?siteind(...) : isless(0,n-2N) & isless(n-(3*N+1),0) ?siteind(...) for n=1:3N] , but it doesn’t work.
Thanks you!
Thanks for the question. I think the key thing to understand about this topic is that all the constructs such as
sites=[isodd(n) ? siteind(...) : siteind(...) for n=1:2N]
are doing is making a Julia array with ITensor Index objects in certain locations. The site type information is just coming from the “tags” that the Index objects have, and siteind is nothing but a convenient way to make an Index object with certain tags (such as “Site,S=1/2”) and the right dimensions.
So my answer is that rather than using an array comprehension, which can get rather complicated for a case like yours, I would suggest just using a for loop, like this:
sites = Vector{Index}(undef,3N)
for j=1:N
sites[j] = siteind("Electron")
end
for j=N+1:2N
sites[j] = siteind("S=1/2")
end
for j=2N+1:3N
sites[j] = siteind("S=1/2")
end
If you want to turn on quantum number conservation, you can just modify the calls to siteind above by passing keyword arguments such as conserve_qns=true.