store ground state in h5 file

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”.

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:

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

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

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)

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