# Errors in the Ground-State Energy in a Next NN 1D Spin Chain

**URL:** https://itensor.discourse.group/t/errors-in-the-ground-state-energy-in-a-next-nn-1d-spin-chain/1051
**Category:** DMRG and Numerical Methods
**Tags:** dmrg, mpo
**Created:** [July 23, 2023, 12:52pm UTC](https://itensor.discourse.group/t/errors-in-the-ground-state-energy-in-a-next-nn-1d-spin-chain/1051 "2023-07-23T12:52:30Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![rafaelsoares](https://avatars.discourse-cdn.com/v4/letter/r/9fc348/32.png) [@rafaelsoares](https://itensor.discourse.group/u/rafaelsoares)
#### Post date: [July 23, 2023, 12:52pm UTC](https://itensor.discourse.group/t/errors-in-the-ground-state-energy-in-a-next-nn-1d-spin-chain/1051/1 "2023-07-23T12:52:30Z")

</div>

Hello,

I was trying to implement this very simple Hamiltonian:

\mathcal{H} = \sum\_{i=1}^{N} \left[J \;S^+\_{2i-1} S^-\_{2i+1} + g \; S^+\_{2i} \left( S^x\_{2i-1} + S^x\_{2i+1} \right) + \text{h.c} \right]

When, I run the g=0 case, I would expect to simply get the ground state energy of an XX chain, which should be 2J/\pi. However, I do not get the correct result, not even in the N=2, where one should get E=-J.

I am using the folllowing code:

```julia
function XXZ(Ncells,J,g):
    
    sites = siteinds("S=1/2",2*Ncells)
    index = 0
    
    
    os = OpSum()
    for i in 1:Ncells-1
        os += J,"S+",2*i-1,"S-",2*i+1
        os += J,"S-",2*i-1,"S+",2*i+1
        os += g,"Sx",2*i-1,"S+",2*i
        os += g,"Sx",2*i-1,"S-",2*i
        os += g,"S+",2*i,"Sx",2*i+1
        os += g,"S-",2*i,"Sx",2*i+1
    end
        
    H = MPO(os,sites)
    psi0 = randomMPS(sites)
    nsweeps = 5
    maxdim = [200,50]
    cutoff = [1E-10]
    energy, psi = dmrg(H,psi0; nsweeps, maxdim, cutoff)
    return energy
end

```

Thank you.

---

<div class="post-metadata">

### Author: ![rafaelsoares](https://avatars.discourse-cdn.com/v4/letter/r/9fc348/32.png) [@rafaelsoares](https://itensor.discourse.group/u/rafaelsoares)
#### Post date: [July 27, 2023, 4:28pm UTC](https://itensor.discourse.group/t/errors-in-the-ground-state-energy-in-a-next-nn-1d-spin-chain/1051/2 "2023-07-27T16:28:14Z")

</div>

Hello!  
Just to add to previous post. I’ve noticed that I get two different results by either doing:

```julia
    sites = siteinds("S=1/2",3)
    os = OpSum()
    os .+= (J,"S+",1,"S-",2)
    os .+= (J,"S-",1,"S+",2)

```

VS

```julia
    sites = siteinds("S=1/2",3)
    os = OpSum()
    os .+= (J,"S+",1,"S-",3)
    os .+= (J,"S-",1,"S+",3)

```

Why should this make a difference?

---

<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: [July 28, 2023, 1:19am UTC](https://itensor.discourse.group/t/errors-in-the-ground-state-energy-in-a-next-nn-1d-spin-chain/1051/3 "2023-07-28T01:19:29Z")

</div>

Regarding your first question, it’s a little hard to say. Are the answers you are getting very different from the exact value or only a little different? Is the exact value for an infinite system? If so, you are simulating a finite-size system so there will be finite-size corrections that make the exact answer from DMRG different from the exact infinite answer. Just as importantly, your DMRG results may not be fully converged.

To diagnose which of the above possibilities could be happening, it’s good that you are considering smaller systems or systems where a completely exact, finite-size solution is known or computable, as you’re doing in your second post.

As to why in your second post you are getting different energies, it almost certainly has to be a lack of convergence of DMRG, since the Hamiltonians should have the same ground state energy. We have an FAQ page of the documentation that gives different ideas for how you can help a DMRG calculation to converge better:  
[https://itensor.github.io/ITensors.jl/dev/faq/DMRG.html](https://itensor.github.io/ITensors.jl/dev/faq/DMRG.html)  
Some that might help you here are using the “noise” parameter (noise term) and trying different initial states.

By the way, the `randomMPS` function accepts a parameter `linkdims` which you can use to make an MPS with larger link or bond dimensions, like this:

```auto
psi0 = randomMPS(sites; linkdims=4)

```

Doing that might help you to have a more ‘general’ initial state which might lead to better convergence, among the other things mentioned in the FAQ.
