# Storing sites to HDF5

**URL:** https://itensor.discourse.group/t/storing-sites-to-hdf5/348
**Category:** ITensor Julia Questions
**Tags:** dmrg, julia
**Created:** [August 15, 2022, 1:52pm UTC](https://itensor.discourse.group/t/storing-sites-to-hdf5/348 "2022-08-15T13:52:57Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![TakisAngelides](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/takisangelides/32/133_2.png) [@TakisAngelides](https://itensor.discourse.group/u/TakisAngelides)
#### Post date: [August 15, 2022, 1:52pm UTC](https://itensor.discourse.group/t/storing-sites-to-hdf5/348/1 "2022-08-15T13:52:57Z")

</div>

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

```auto
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!

---

<div class="post-metadata">

### Author: ![TakisAngelides](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/takisangelides/32/133_2.png) [@TakisAngelides](https://itensor.discourse.group/u/TakisAngelides)
#### Post date: [August 15, 2022, 2:16pm UTC](https://itensor.discourse.group/t/storing-sites-to-hdf5/348/2 "2022-08-15T14:16:53Z")

</div>

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

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

```

---

<div class="post-metadata">

### Author: ![miles](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/miles/32/6_2.png) [@miles](https://itensor.discourse.group/u/miles)
#### Post date: [August 15, 2022, 7:48pm UTC](https://itensor.discourse.group/t/storing-sites-to-hdf5/348/3 "2022-08-15T19:48:48Z")

</div>

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.
