# set "errgoal" and "maxiter" in Davidson algorithm manually

**URL:** <https://itensor.discourse.group/t/set-errgoal-and-maxiter-in-davidson-algorithm-manually/882>\
**Category:** ITensor Julia Questions\
**Created:** [May 18, 2023, 5:52am UTC](https://itensor.discourse.group/t/set-errgoal-and-maxiter-in-davidson-algorithm-manually/882 "2023-05-18T05:52:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![zz123](https://avatars.discourse-cdn.com/v4/letter/z/b5e925/32.png) [@zz123](https://itensor.discourse.group/u/zz123)\
**Post date:** [May 18, 2023, 5:52am UTC](https://itensor.discourse.group/t/set-errgoal-and-maxiter-in-davidson-algorithm-manually/882/1 "2023-05-18T05:52:24Z")

</div>

Dear there,  
I have a maybe naive question about how to set parameters used in Davidson iteration in ITensor. When I do DMRG calculation, I run something like this:

```auto
sweeps= Sweeps(10) 
setmaxdim!(sweeps, 3000)
energy, psi = dmrg(H, psi0, sweeps, observer=obs; write_when_maxdim_exceeds=1000)

```

And I find in **iterativesolvers.jl** in ITensor github, the Davidson function takes some other parameters like maxiter, errgoal etc. The default errgoal is 1E-14, but I want to increase it to larger number in initial sweeps. Could you let me know how to do that? Thank you so much!!

---

<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:** [May 18, 2023, 11:33am UTC](https://itensor.discourse.group/t/set-errgoal-and-maxiter-in-davidson-algorithm-manually/882/2 "2023-05-18T11:33:00Z")

</div>

The current version doesn’t use the `davidson` routine for DMRG but `eigsolve` from [KrylovKit.jl](https://jutho.github.io/KrylovKit.jl/stable/man/eig/#KrylovKit.eigsolve)  
The latest version should have this but the docs for it are in the [`dev` version here](https://itensor.github.io/ITensors.jl/dev/DMRG.html#ITensors.dmrg)  
Check out

- `eigsolve_krylovdim::Int = 3`
- `eigsolve_tol::Number = 1e-14`
- `eigsolve_maxiter::Int = 1`

(If you are using the davidson routine elswhere, then you can simply pass those parameters you mention)

---

<div class="post-metadata">

**Author:** ![zz123](https://avatars.discourse-cdn.com/v4/letter/z/b5e925/32.png) [@zz123](https://itensor.discourse.group/u/zz123)\
**Post date:** [May 20, 2023, 11:25pm UTC](https://itensor.discourse.group/t/set-errgoal-and-maxiter-in-davidson-algorithm-manually/882/3 "2023-05-20T23:25:30Z")

</div>

Thank you!!  
I’ve another naive syntex question… I’m not very sure what’s the difference between using " ; " or  
" , " in `dmrg(H, psi0, other arguments...)` ? For example, before I use:  
`dmrg(H, psi0, sweeps, observer=obs; write_when_maxdim_exceeds=1000)`  
Now I change to use:  
`dmrg(H, psi0, sweeps, observer=obs; eigsolve_tol=1e-6, write_when_maxdim_exceeds=1000)`

Both works perfectly without error, but I’m actually not sure what arguments should be separated by " ; " and what should be separated by " , "…

Also is there a way I can make ITensor print out eigsolve parameters like eigsolve\_tol in each sweep so that I can keep track of the value I set manually?  
Thank you!

---

<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:** [May 21, 2023, 5:57pm UTC](https://itensor.discourse.group/t/set-errgoal-and-maxiter-in-davidson-algorithm-manually/882/4 "2023-05-21T17:57:50Z")

</div>

Hi @zz123,  
For questions about Julia syntax, please use the Julia Discourse ([https://discourse.julialang.org](https://discourse.julialang.org)) and/or consult the Julia docs. Regarding your question about the semicolon, here is the relevant docs page:  
[https://docs.julialang.org/en/v1/manual/functions/#Keyword-Arguments](https://docs.julialang.org/en/v1/manual/functions/#Keyword-Arguments)

For custom printing of variables inside of DMRG, we offer the “Observer” system (see [more info here](https://itensor.github.io/ITensors.jl/dev/Observer.html#observer)). However, currently the parameters like `eigsolve_tol` aren’t passed to the observer object, so we’d have to change that to make them available. I think it’s a good idea to do that, so I’ll modify the code to make sure those are also passed.

Best regards,  
Miles

---

<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:** [May 21, 2023, 6:12pm UTC](https://itensor.discourse.group/t/set-errgoal-and-maxiter-in-davidson-algorithm-manually/882/5 "2023-05-21T18:12:01Z")

</div>

Actually, upon looking at our DMRG code some more, here’s what I’d recommend about printing the `eigsolve_tol` parameter and similar ones. These parameters are kept the same throughout all of the DMRG sweeps, so there isn’t much call to print them every step or every sweep. A good solution for you, if you’d like to print them, is just to print out the keyword arguments you are passing into DMRG, such as `eigsolve_tol`, right before you call DMRG, and then you can be assured it is kept the same inside DMRG.

For parameters you aren’t passing, you can assume they are held fixed to their default values throughout. For these default values, see the [dmrg function documentation here](https://itensor.github.io/ITensors.jl/dev/DMRG.html).

---

<div class="post-metadata">

**Author:** ![zz123](https://avatars.discourse-cdn.com/v4/letter/z/b5e925/32.png) [@zz123](https://itensor.discourse.group/u/zz123)\
**Post date:** [May 21, 2023, 6:52pm UTC](https://itensor.discourse.group/t/set-errgoal-and-maxiter-in-davidson-algorithm-manually/882/6 "2023-05-21T18:52:43Z")

</div>

Got it! Thank you so much!
