Storing sites to HDF5

Hello,

I am doing DMRG with fixed maximum bond dimension (which I would like to report was not achieved by just specifying maxdim in the call of the dmrg function but I had to on top of the latter specify maxdim in the Sweeps object as well, otherwise the maxdim was not obeyed and the maximum bond dimension was going way over what I was trying to restrict it to) and then saving my MPS to give it as an ansatz for the next higher maximum bond dimension.

The problem I am facing is that I generate a new sites object for the Hamiltonian so in the DMRG the ansatz cannot contract with the MPO Hamiltonian.

I thought of storing the sites object of my ansatz to HDF5 along with the ansatz and then reading it in code when I am going into the next higher bond dimension calculation.

Something like:

Julia code

sites = siteinds("S=1/2", 2*N)

f = h5open(mps_file_path, "w")
write(f, "MPS", psi)
write(f, "sites", sites)
close(f)

f = h5open(mps_file_path, "r")
sites_read = read(f, "sites")
close(f)

However I have the following issue that the form of the sites after reading is different:

typeof(sites) = Vector{Index{Int64}} (alias for Array{Index{Int64}, 1})

typeof(sites_read) = Dict{String, Any}

and elements in sites_read look like

“index_7” => Dict{String, Any}(“dim”=>2, “id”=>0x3ea41398b1111aac, “plev”=>0, “tags”=>Dict{String, Any}(“tags”=>“S=1/2,Site,n=7”), “dir”=>0)

Is there a way to do this cleanly?

Thanks in advance!

Ok, I think I can answer my own question here and if I am wrong please do correct me.

When saving the MPS, we are effectively also storing its associated sites object. So one can read the MPS and then get the sites as follows:

Julia code

f = h5open(mps_file_path, "r")
psi = read(f, "MPS", MPS)
sites = siteinds(psi)
close(f)

Hi, yes glad you figured that out. It is the approach I was going to suggest.

For some more detail here, actually an MPS doesn’t store a sites object inside: it’s rather that ITensor can figure out the site indices of an MPS just from inspecting each tensor. The site index is the one that doesn’t connect to any neighboring MPS tensor. (Credit Matt Fishman for realizing this.) So actually siteinds is figuring out the site indices rather than recovering them from memory.