# Initialising MPS or MPO manually

+1 vote

Dear ITensor team,

this is a kind of follow-up of my previous question on manually constructing MPOs in ITensor v3 c++. It appears to me that it is not well documented the general way to construct generic MPS, and it would be really useful to have it written somewhere. :)

Say one wants to generate an MPS

psi = A^sigma1{b1} A{b1,b2}^sigma2 A{b2,b3}^sigma_3 ....

with b1,b2 indices of dimension = dim and sigma local site indices and A{bi,bi+1}^sigmai matrices we know. The main problem to me is to assign correct indices that are correctly contracted and properly represent the MPS (or MPO, it's the same). The way I do it is the following:

psi = MPS(sites)
auto comInd = Index(dim,"Link"); // define a common index

for(int n = 1; n <= N; n ++){ // run over the chain of size N

auto sigma = sites(n);

if(n==1){

auto A = ITensor(sigma,i);
// here set the values of the matrix elements of A
psi.set(n,A);
comInd = j; // set the common index to the right index of A
}

if(n>1 && n< N){
auto i = comInd;
auto A = ITensor(sigma,i,j);
// here set the values of the matrix elements of A
psi.set(n,A);
comInd = j; // set the common index to the right index of A
}

if(n==N){
auto i=comInd;
auto A = ITensor(sigma,i);
// here set the values of the matrix elements of A
psi.set(n,A);
}

} // end of for over sites


I would like to know if this is the correct way to do it or if there are other ways or simpler methods!

Thanks a lot!
All the best,
Jacopo.