google / TensorNetwork

A library for easy and efficient manipulation of tensor networks.
Apache License 2.0
1.81k stars 356 forks source link

Serialization for Tensor #916

Open tanlin2013 opened 3 years ago

tanlin2013 commented 3 years ago

In numpy, this can be acheived with .npy or .npz extension. Just wonder, given all supported backends in TensorNetwork, is there a unified way to save a bunch of tensors in a compressed and binary format file?

I have read the documentation for a while, but still couldn't find the saving functionality. Or perhaps I miss it somewhere :)

thanks!

mganahl commented 3 years ago

Hi @tanlin2013 , unfortunately this is currently not supported. The Node class supports serialization to HDF5 format using h5py. You could initialize a Node using the data-array in Tensor and save that, if this helps.

mganahl commented 3 years ago

If you are interested in contributing, PRs are always welcome!!

tanlin2013 commented 3 years ago

Sounds nice! I would love to.

I have a small repo tnpy that is built on top of TensorNetwork. I'm actaully about to implement TDVP and DMT for real-time evo. That's why I need to store MPS generated by DMRG.

mganahl commented 3 years ago

nice! Let us know of any additional missing functionality, and we'll try to add it.

jacksonwb commented 3 years ago

There is serialization support that exports networks to json, with array formats stored in their backend specified format. Currently the only backend that currently implements the the serialize/deserialize_tensor methods is the numpy backend, but this can be very easily added to other backends.

824

thanujkumar1999 commented 3 years ago

tf.io.serialize_tensor( tensor, name=None )