# store ground state in h5 file

**URL:** <https://itensor.discourse.group/t/store-ground-state-in-h5-file/551>\
**Category:** ITensor Julia Questions\
**Created:** [December 6, 2022, 4:01am UTC](https://itensor.discourse.group/t/store-ground-state-in-h5-file/551 "2022-12-06T04:01:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kristin](https://avatars.discourse-cdn.com/v4/letter/k/2bfe46/32.png) [@Kristin](https://itensor.discourse.group/u/Kristin)\
**Post date:** [December 6, 2022, 4:01am UTC](https://itensor.discourse.group/t/store-ground-state-in-h5-file/551/1 "2022-12-06T04:01:05Z")

</div>

Hello,  
I have a quick question about saving the ground state I got in a h5 file (I’ve done this before, and I just ran a new calculation and save my ground state in the same way, but got some error currently…)  
My code is as below, besically I just give it an initial psi0 and get a psi\_tem1, and save it in file f as “PGS”.

```julia
energy, psi_tem1 = dmrg(H, psi0, sweeps_tem)
f = h5open("mu$(mu)U$(U)V$(V)_$(N)sites—tem.h5","w")
write(f,"PGS",psi_tem1)
close(f)
println("finish 3tem sweeps in total")

```

But then when I try to read it as below:

```julia
f = h5open("mu$(mu)U$(U)V$(V)_$(N)sites—tem.h5","w")
psi_tem1 = read(f,"PGS",MPS)
close(f)
psi_tem1 = replace_siteinds(psi_tem1,sites)

```

The error message says “PGS” doesn’t exist.  
Could you help to see why this happen? Thank you so much!

(The whole error message:)  
HDF5-DIAG: Error detected in HDF5 (1.12.1) thread 1:  
#000: H5G.c line 510 in H5Gopen2(): unable to open group  
major: Symbol table  
minor: Can’t open object  
#001: H5VLcallback.c line 4187 in H5VL\_group\_open(): group open failed  
major: Virtual Object Layer  
minor: Can’t open object  
#002: H5VLcallback.c line 4154 in H5VL\_\_group\_open(): group open failed  
major: Virtual Object Layer  
minor: Can’t open object  
#003: H5VLnative\_group.c line 123 in H5VL\_\_native\_group\_open(): unable to open group  
major: Symbol table  
minor: Can’t open object  
#004: H5Gint.c line 270 in H5G\_\_open\_name(): group not found  
major: Symbol table  
minor: Object not found  
#005: H5Gloc.c line 442 in H5G\_loc\_find(): can’t find object  
major: Symbol table  
minor: Object not found  
#006: H5Gtraverse.c line 837 in H5G\_traverse(): internal path traversal failed  
major: Symbol table  
minor: Object not found  
#007: H5Gtraverse.c line 613 in H5G\_\_traverse\_real(): traversal operator failed  
major: Symbol table  
minor: Callback failed  
#008: H5Gloc.c line 399 in H5G\_\_loc\_find\_cb(): object ‘PGS’ doesn’t exist  
major: Symbol table  
minor: Object not found  
ERROR: LoadError: Error opening group //PGS

---

<div class="post-metadata">

**Author:** ![ryanlevy](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/ryanlevy/32/150_2.png) [@ryanlevy](https://itensor.discourse.group/u/ryanlevy)\
**Post date:** [December 7, 2022, 1:18pm UTC](https://itensor.discourse.group/t/store-ground-state-in-h5-file/551/2 "2022-12-07T13:18:15Z")

</div>

> [@Kristin](#):
>
> ```auto
> f = h5open("mu$(mu)U$(U)V$(V)_$(N)sites—tem.h5","w")
> 
> ```

Any chance it works if you change `"w"` to `"r"` (or “r+” if you want to read/write)? The original data will be probably gone though since `"w"` = “read-write, destroying any existing contents (if any)”.

* * *

Also I recommend doing something like

```julia
psi_tem1 = h5open("data.h5", "r") do f
      read(f,"PGS",MPS)
end

```

this method will always close the file so you can open it again later (but won’t prevent the “w” problem)

---

<div class="post-metadata">

**Author:** ![Kristin](https://avatars.discourse-cdn.com/v4/letter/k/2bfe46/32.png) [@Kristin](https://itensor.discourse.group/u/Kristin)\
**Post date:** [December 8, 2022, 6:52am UTC](https://itensor.discourse.group/t/store-ground-state-in-h5-file/551/3 "2022-12-08T06:52:11Z")

</div>

Thank you! Let me run my code again and try this!
