Open tanlin2013 opened 3 years ago
Hi @tanlin2013 - the tensor network objects are designed to be picklable so you should be able to use any standard method for saving python objects. quimb
actually has aliases around the disk saving functionality of joblib
which has some special handling of numpy arrays:
import quimb as qu
import quimb.tensor as qtn
peps = qtn.PEPS.rand(Lx=10, Ly=10, max_bond=4)
qu.save_to_disk(peps, 'peps.dmp')
# ['peps.dmp']
qu.load_from_disk('peps.dmp')
# <PEPS(tensors=100, indices=280, Lx=10, Ly=10, max_bond=4)>
see - https://joblib.readthedocs.io/en/latest/generated/joblib.dump.html.
The only thing to note is that saving and loading TNs might break across versions of quimb
since the internal details of the TN implementation change occasionally.
Hi @jcmgray - thanks for the detailed example. This is exactly what I'm looking for. One more silly question, did you ever try HDF5 or other binary file extensions? Just wondering will that make a significant difference in terms of I/O performance?
Hi @tanlin2013 , sorry to have not got back earlier! I think for most of the use cases of quimb
, the size of the actual tensors and tensor networks is very small - all the computational effort is in contracting / optimizing the tensors, so I/O performance I suspect will not be a bottleneck.
However, leaving this issue open in case anyone does have use-cases where I/O is critical and standard pickling etc. is not sufficient.
Just wondering is there a way to save and load 1d and 2d TN state or tensors? thanks!