# DMRG with adaptive number of sweeps

**URL:** <https://itensor.discourse.group/t/dmrg-with-adaptive-number-of-sweeps/723>\
**Category:** ITensor Julia Questions\
**Created:** [March 24, 2023, 9:02am UTC](https://itensor.discourse.group/t/dmrg-with-adaptive-number-of-sweeps/723 "2023-03-24T09:02:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![EmilioRui](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/emiliorui/32/208_2.png) [@EmilioRui](https://itensor.discourse.group/u/EmilioRui)\
**Post date:** [March 24, 2023, 9:02am UTC](https://itensor.discourse.group/t/dmrg-with-adaptive-number-of-sweeps/723/1 "2023-03-24T09:02:16Z")

</div>

Hi!  
Is there a built-in way to run a dmrg simulation not with a fixed number of sweeps, but ending it when it converges up to user need?

As an example, I might need a precision of 10^-5, as soon as a new sweep is not improving the eigenvalue for more than this amount the simulation stops (or within the last 10 or something similar).

Thank you so much!

---

<div class="post-metadata">

**Author:** ![EmilioRui](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/emiliorui/32/208_2.png) [@EmilioRui](https://itensor.discourse.group/u/EmilioRui)\
**Post date:** [March 24, 2023, 5:49pm UTC](https://itensor.discourse.group/t/dmrg-with-adaptive-number-of-sweeps/723/2 "2023-03-24T17:49:13Z")

</div>

Is the question not clear? If so I can try to explain what I mean better

---

<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:** [March 24, 2023, 6:14pm UTC](https://itensor.discourse.group/t/dmrg-with-adaptive-number-of-sweeps/723/3 "2023-03-24T18:14:30Z")

</div>

We have a feature built into our DMRG code called the observer system that lets you both monitor a calculation and stop it early based on any criterion you want. Here’s a walkthrough of how to use it:  
\<  
[https://itensor.github.io/ITensors.jl/stable/Observer.html](https://itensor.github.io/ITensors.jl/stable/Observer.html)\>

Does this give you what you need? For your application you’d need to define a custom checkdone! function.

---

<div class="post-metadata">

**Author:** ![EmilioRui](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/emiliorui/32/208_2.png) [@EmilioRui](https://itensor.discourse.group/u/EmilioRui)\
**Post date:** [March 27, 2023, 3:25pm UTC](https://itensor.discourse.group/t/dmrg-with-adaptive-number-of-sweeps/723/4 "2023-03-27T15:25:10Z")

</div>

Thank you so much!
