## Writing objects to files

• writeToFile(string filename, T const& obj)

Opens a file with the name filename and writes the object obj to it. The type T of the object is deduced automatically.

This function is defined in the file itensor/util/readwrite.h.

Click to Show Example
auto i = Index(2,"Site");
writeToFile("ifile",i);
writeToFile("jfile",j);

auto T = randomTensor(i,j);
writeToFile("Tfile",T);


• readFromFile<T>(string filename) -> T

Opens a file with the name filename, read an object of type T, and return that object.

This function is defined in the file itensor/util/readwrite.h.

Click to Show Example
auto T = readFromFile<ITensor>("tensor_file");

//Initialize MPS with SiteSet "sites" before reading from file:

• readFromFile(string filename, T & obj)

Opens a file with the name filename and read an object of type T to the variable obj. The type T is automatically deduced.

This function is defined in the file itensor/util/readwrite.h.

Click to Show Example
ITensor T;

MPS psi;

• readFromFile<T>(string filename, InitArgs&&... iargs) -> T

Opens a file with the name filename, read an object of type T, and return that object.

This version of the readFromFile function takes an arbitrary number of additional arguments which are passed to the constructor of the type T before reading the object from the file. This can be useful for cases where you want to construct the class before its .read method is called. A key example is the MPS or IQMPS class which can optionally be constructed with a SiteSet before calling its .read method to read in its tensors.

This function is defined in the file itensor/util/readwrite.h.

Click to Show Example
//Initialize MPS with SiteSet "sites" before reading from file: