# How to write MPS to disk

+1 vote
edited

HI,
I want to write an IQMPS to disk to a format that I can process further. Namely given usual A-representation of an MPS state which is a family of matrices indexed by site index and local hilbert space index, I want to write the A tensors to disk in the text form. I wanted to figure that out from documentation but I reached self-contradictionary information.

1) Is this simple enough that someone could provide a code snippet?

2) What actually psi.A(sitenumber) for psi being an IQMPS does? Here (http://itensor.org/docs.cgi?page=classes/mps) it is written that it provides a local IQTensor, on the other hand somewhere else I noticed that psi.A(sitenumber) changes orthogonality center of an MPS (just like psi.position). This is suggested here: http://itensor.org/docs.cgi?page=tutorials/MPS

3) is there a way to access a site tensor without modifying it? It seems that psi.A(sitenumber) is not that method.

Best,
Mateusz Łącki

Hi Mateusz,
First of all, to answer your questions 2 and 3, the page tutorials/MPS you reached had some incorrect information on it. I just updated that page to now have the correct information.

So the correct information about psi.A(j) is that it just provides read-only access to the MPS tensor at site j, without modifying that tensor in any way. If you do want to modify the tensor at site j you can call psi.Aref(j). Neither of these changes the MPS gauge. To move the MPS gauge center to some site i call psi.position(i);

Finally, about writing the tensor elements to a text file, there isn't a facility in ITensor right now to do this automatically. But you could write a short code yourself to do this. The main thing to know is that you will need a local copy of the MPS indices to access elements. To get these you can use the linkInd method.

So let's say you want to get the elements of the third MPS tensor psi.A(3). Here is some sample code for doing that:

auto ll = linkInd(psi,2);

The code above will give you the 4,2,7 element of the tensor A(3). You can get the sizes of each of the indices ll, rl, and s by calling ll.m(), rl.m() etc. and then looping over all of the values of the tensor and printing them to a file.