# Define a new type of sites in mixed space

**URL:** <https://itensor.discourse.group/t/define-a-new-type-of-sites-in-mixed-space/1375>\
**Category:** ITensor Julia Questions\
**Tags:** julia\
**Created:** [December 24, 2023, 2:37pm UTC](https://itensor.discourse.group/t/define-a-new-type-of-sites-in-mixed-space/1375 "2023-12-24T14:37:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wenqi](https://avatars.discourse-cdn.com/v4/letter/w/46a35a/32.png) [@Wenqi](https://itensor.discourse.group/u/Wenqi)\
**Post date:** [December 24, 2023, 2:37pm UTC](https://itensor.discourse.group/t/define-a-new-type-of-sites-in-mixed-space/1375/1 "2023-12-24T14:37:09Z")

</div>

Hello,

I want to do DMRG calculation in the mixed space: In x-dirction, it is in real-space. While in y-direction, it is in k-space. I define a new type of site, Fermionk. The total momentum in y direction and the total particle number are the good quantum numbers. Here are the codes:

“”“julia  
import ITensors: space, state, op!, has\_fermion\_string  
function ITensors.space(  
::SiteType"Fermionk”,  
n::Int;  
conserve\_qns=false,  
conserve\_nf = conserve\_qns,  
conserve\_nfparity = conserve\_qns,  
conserve\_ky=false,  
qnname\_nf = “Nf”,  
qnname\_nfparity = “NfParity”,  
qnname\_ky=“Ky”,  
# qnname\_sz=“Sz”,  
# conserve\_sz=true,  
modulus\_ky,  
)  
if conserve\_nf && conserve\_ky  
mod = (n-1) % modulus\_ky  
# mod = n % modulus\_ky  
return [  
QN((qnname\_nf,0,-1),(qnname\_ky,0,modulus\_ky))=\>1  
QN((qnname\_nf,1,-1),(qnname\_ky,mod,modulus\_ky))=\>1  
]  
elseif conserve\_ky  
error(“Cannot conserve ky without conserving nf”)  
elseif conserve\_nf  
return [  
QN(qnname\_nf,0,-1)=\>1  
QN(qnname\_nf,1,-1)=\>1  
]  
elseif conserve\_nfparity  
return [  
QN(qnname\_nfparity,0,-2)=\>1  
QN(qnname\_nfparity,1,-2)=\>1  
]  
end  
return 2  
end  
#define vals  
ITensors.val(::ValName"Emp",::SiteType"Fermionk") = 1  
ITensors.val(::ValName"Occ",::SiteType"Fermionk") = 2  
ITensors.val(::ValName"0",st::SiteType"Fermionk") = val(ValName(“Emp”),st)  
ITensors.val(::ValName"1",st::SiteType"Fermionk") = val(ValName(“Occ”),st)  
#define states  
ITensors.state(::StateName"Emp",::SiteType"Fermionk") = [1.0 0.0]  
ITensors.state(::StateName"Occ",::SiteType"Fermionk") = [0.0 1.0]  
ITensors.state(::StateName"0",st::SiteType"Fermionk") = state(StateName(“Emp”),st)  
ITensors.state(::StateName"1",st::SiteType"Fermionk") = state(StateName(“Occ”),st)

## occupation operator definition

function ITensors.op!(Op::ITensor,::OpName"N",::SiteType"Fermionk",s::Index)  
return Op[s’=\>2,s=\>2] = 1.0  
end  
function ITensors.op!(Op::ITensor,on::OpName"n",st::SiteType"Fermionk",s::Index)  
return ITensors.op!(Op,alias(on),st,s)  
end

## anhilation operator definition

function ITensors.op!(Op::ITensor,::OpName"C",::SiteType"Fermionk",s::Index)  
return Op[s’ =\> 1,s =\> 2] = 1.0  
end  
function ITensors.op!(Op::ITensor,on::OpName"c",st::SiteType"Fermionk",s::Index)  
return ITensors.op!(Op,alias(on),st,s)  
end  
#creation opertor  
function ITensors.op!(Op::ITensor, ::OpName"Cdag", ::SiteType"Fermionk", s::Index)  
return Op[s’ =\> 2, s =\> 1] = 1.0  
end  
function ITensors.op!(Op::ITensor, on::OpName"c†“, st::SiteType"Fermionk”, s::Index)  
return ITensors.op!(Op, alias(on), st, s)  
end  
function ITensors.op!(Op::ITensor, on::OpName"cdag", st::SiteType"Fermionk", s::Index)  
return ITensors.op!(Op, alias(on), st, s)  
end  
#F operator  
function ITensors.op!(Op::ITensor, ::OpName"F", ::SiteType"Fermionk", s::Index)  
Op[s’ =\> 1, s =\> 1] = +1.0  
return Op[s’ =\> 2, s =\> 2] = -1.0  
end

has\_fermion\_string(::OpName"C", ::SiteType"Fermionk") = true  
has\_fermion\_string(::OpName"Cdag", ::SiteType"Fermionk") = true

“”"

However, when I try to use the new type of sites to get a MPS with specific quantum number and linkdim,

‘’’  
itensor\_rng = Xoshiro()  
Random.seed!(itensor\_rng,1234)  
Nx = 8  
Ny = 4  
N = Nx\*Ny  
sites = siteinds(“Fermionk”,N;conserve\_qns=true,conserve\_ky=true,modulus\_ky = Ny)  
state = Array{String}(undef, N)  
for i = 1:Nx  
for j = 1:Ny  
if isodd(i)  
state[(i-1)\*Ny+j]=isodd(j) ? “Emp” : “Occ”  
else  
state[(i-1)\*Ny+j]=isodd(j) ? “Occ” : “Emp”  
end  
end  
end  
psi0 = randomMPS(itensor\_rng,sites,state;linkdims = 10)  
‘’’  
I get the warning  
‘’’  
Warning: MPS center bond dimension is less than requested (you requested 10, but in practice it is 1. This is likely due to technicalities of truncating quantum number sectors.  
‘’’  
It seems that every time I set “conserve\_ky=true”, the linkdim of the MPS is always equal to 1, and I cannot get the correct result of DMRG calculation. If I set “conserve\_ky=false”, the DMRG calculation result is right. But, the aim of doing DMRG calculation in the mixed space is making use of the momentum conservation to enhance the calculation efficiency. Could you please tell me how to deal with this problem? Thank you very much!

Best wishes,  
Wenqi

---

<div class="post-metadata">

**Author:** ![miles](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/miles/32/6_2.png) [@miles](https://itensor.discourse.group/u/miles)\
**Post date:** [December 26, 2023, 9:34pm UTC](https://itensor.discourse.group/t/define-a-new-type-of-sites-in-mixed-space/1375/2 "2023-12-26T21:34:28Z")

</div>

Hi Wenqi,  
Thanks for providing a lot of helpful information. Could you please make sure your code above is formatted properly for the forum? The way to do that is to use three backtick symbols at the beginning and end (so not quotation marks but like backwards apostrophe symbols like these: ```). If you need help, I could edit and format your post – just let me know.

Regarding your questions:

1. I wouldn’t worry too much about the warning about the MPS center bond dimension. It’s a weakness of our current implementation of the `randomMPS` function and it should only slightly affect your initial state, but shouldn’t affect any other parts of your calculation (i.e. you should still find that the total quantum number is ok and if you do enough sweeps of DMRG it won’t affect what answer you obtain at the end).

2. It’s a little difficult to know or immediately guess why you are getting only bond dimension 1 for the linkdims when you try to conserve ky.

Are you using the `noise` parameter (noise term) when you are running your DMRG calculations?
