# Running DMRG with storing the PH and Psi into the Disk instead of RAM and use them via I/O

**URL:** <https://itensor.discourse.group/t/running-dmrg-with-storing-the-ph-and-psi-into-the-disk-instead-of-ram-and-use-them-via-i-o/1486>\
**Category:** DMRG and Numerical Methods\
**Tags:** julia, dmrg, mps\
**Created:** [February 18, 2024, 11:06am UTC](https://itensor.discourse.group/t/running-dmrg-with-storing-the-ph-and-psi-into-the-disk-instead-of-ram-and-use-them-via-i-o/1486 "2024-02-18T11:06:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Minlo](https://avatars.discourse-cdn.com/v4/letter/m/cdc98d/32.png) [@Minlo](https://itensor.discourse.group/u/Minlo)\
**Post date:** [February 18, 2024, 11:06am UTC](https://itensor.discourse.group/t/running-dmrg-with-storing-the-ph-and-psi-into-the-disk-instead-of-ram-and-use-them-via-i-o/1486/1 "2024-02-18T11:06:16Z")

</div>

Dear there,

I checked the space complexity of the DMRG code, and I found that the bottleneck is on the variable PH, especially when I considering a 1D system with long range interaction. Then the bond dimension of MPO will become much large than the physical dimension d.

PH is the projected Hamiltonian, which contain the effective hamiltonian of left and right subsystem. However, when we perform local minimization on sites N, we only need PH.L [n]and one PH.R[n+1]. However, PH.L and PH.R for all sites is stored on the memory thus the memory requirement is very high when the bond dimention is large.

I’m wondering if there is a simple way to store PH and Psi into the Disk and visit them via I/O? This will significantly reduce the memory demand.

Thank you for your help!

Min

---

<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:** [February 18, 2024, 1:55pm UTC](https://itensor.discourse.group/t/running-dmrg-with-storing-the-ph-and-psi-into-the-disk-instead-of-ram-and-use-them-via-i-o/1486/2 "2024-02-18T13:55:46Z")

</div>

Yes, it is a good strategy to save RAM, and fortunately we have exactly this feature built in to ITensor’s DMRG code.

To use it, you pass the keyword `write_when_maxdim_exceeds=M` to our `dmrg` function, where `M` is some number you decide. When the allowed maxdim crosses this value, our code will start writing the PH.L and PH.R “environment” tensors to the hard drive or disk and only reading them back into RAM one at a time, as needed.
