# Using HDF5 in DMRG.jl

**URL:** <https://itensor.discourse.group/t/using-hdf5-in-dmrg-jl/1926>\
**Category:** ITensor Julia Questions\
**Created:** [August 14, 2024, 5:02pm UTC](https://itensor.discourse.group/t/using-hdf5-in-dmrg-jl/1926 "2024-08-14T17:02:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cfengno1](https://avatars.discourse-cdn.com/v4/letter/c/7feea3/32.png) [@cfengno1](https://itensor.discourse.group/u/cfengno1)\
**Post date:** [August 14, 2024, 5:02pm UTC](https://itensor.discourse.group/t/using-hdf5-in-dmrg-jl/1926/1 "2024-08-14T17:02:32Z")

</div>

Hi there,

I am trying to add a few lines of code that saves the psi to .h5 file during the DMRG sweeps. I add the following line to the top of dmrg.jl file:  
`using HDF5`

but it reports the following error

```auto
  **ERROR:** LoadError: ArgumentError: Package ITensors does not have HDF5 in its dependencies:
- You may have a partially installed environment. Try `Pkg.instantiate()` to ensure all packages in the environment are installed.
- Or, if you have ITensors checked out for development and have added HDF5 as a dependency but haven't updated your primary environment's manifest file, try `Pkg.resolve()`.
- Otherwise you may need to report an issue with ITensors

```

Then, I tried to add HDF5 to the dependence of ITensor by running:

```auto
Pkg.activate("/home/cfengno1/.julia/dev/ITensors/")
Pkg.add("HDF5")
using ITensors

```

It gives the following error:

```auto
  **Warning:** The project dependencies or compat requirements have changed since the manifest was last resolved.
 It is recommended to `Pkg.resolve()` or consider `Pkg.update()` if necessary.
@ Pkg.API ~/.julia/juliaup/julia1.10.4+0.x64.linux.gnu/share/julia/stdlib/v1.10/Pkg/src/API.jl:1807

  **Precompiling** ITensors
  1 dependency successfully precompiled in 9 seconds. 91 already precompiled.

  **Warning:** The project dependencies or compat requirements have changed since the manifest was last resolved. It is recommended to `Pkg.resolve()` or consider `Pkg.update()` if necessary.@ Pkg.API ~/.julia/juliaup/julia-1.10.4+0.x64.linux.gnu/share/julia/stdlib/v1.10/Pkg/src/API.jl:1807

  **Info:** Precompiling ITensorsVectorInterfaceExt [2f1fcacd-197e-560a-aa0f-27cf761d5e85]

**Warning:** Module ITensorsVectorInterfaceExt with build ID ffffffff-ffff-ffff-00d9-4bce33645c6f is missing from the cache. This may mean ITensorsVectorInterfaceExt [2f1fcacd-197e-560a-aa0f-27cf761d5e85] does not support precompilation but is imported by a module that does.
 @ Base loading.jl:1948

  **Error:** Error during loading of extension ITensorsVectorInterfaceExt of ITensors, use `Base.retry_load_extensions()` to retry.
 exception =
1-element ExceptionStack:
Declaring __precompile__ (false) is not allowed in files that are being precompiled.

```

Can you help me to save the state psi to file in the middle of the DMRG sweeps?

Best,  
Feng Chen

---

<div class="post-metadata">

**Author:** ![kmp5](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/kmp5/32/251_2.png) [@kmp5](https://itensor.discourse.group/u/kmp5)\
**Post date:** [August 15, 2024, 5:02pm UTC](https://itensor.discourse.group/t/using-hdf5-in-dmrg-jl/1926/2 "2024-08-15T17:02:08Z")

</div>

Hi Feng,

I think it would be much safer to not modify the `Project.toml` of ITensor. Potentially a better idea is to make a custom `Observer` object which captures `psi` during a DMRG computations and writes it to disk there. That way your `Observer` code will interface with HDF5 and you will not need HDF5 in ITensors explicitly.  
Additionally, I have found much better luck with using the `JLD2` package over `HDF5` for writing ITensors to disk.

All the best,  
Karl

---

<div class="post-metadata">

**Author:** ![cfengno1](https://avatars.discourse-cdn.com/v4/letter/c/7feea3/32.png) [@cfengno1](https://itensor.discourse.group/u/cfengno1)\
**Post date:** [August 16, 2024, 1:50pm UTC](https://itensor.discourse.group/t/using-hdf5-in-dmrg-jl/1926/3 "2024-08-16T13:50:30Z")

</div>

Thank you very much Karl!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/itensor/original/1X/d3072b13e047cd06df7f3981547c0917d940dfa4.png) [@system](https://itensor.discourse.group/u/system)\
**Post date:** [August 26, 2024, 1:51pm UTC](https://itensor.discourse.group/t/using-hdf5-in-dmrg-jl/1926/4 "2024-08-26T13:51:10Z")

</div>

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
