# DMRG: using N site result as a starting guess for N+2 site computation

**URL:** <https://itensor.discourse.group/t/dmrg-using-n-site-result-as-a-starting-guess-for-n-2-site-computation/2190>\
**Category:** ITensor Julia Questions\
**Created:** [January 2, 2025, 4:01pm UTC](https://itensor.discourse.group/t/dmrg-using-n-site-result-as-a-starting-guess-for-n-2-site-computation/2190 "2025-01-02T16:01:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bernardo](https://avatars.discourse-cdn.com/v4/letter/b/c0e974/32.png) [@Bernardo](https://itensor.discourse.group/u/Bernardo)\
**Post date:** [January 2, 2025, 4:01pm UTC](https://itensor.discourse.group/t/dmrg-using-n-site-result-as-a-starting-guess-for-n-2-site-computation/2190/1 "2025-01-02T16:01:29Z")

</div>

Hello!

As the title, I would like to compute the ground state energy, using finite size DMRG, of some Hamiltonian with N sites. After that is done, I would also like to repeat the same computation for the Hamiltonian on a few more sites, let’s say N+2.

I know how to do this starting from some random guess, but I am interested in the case where N is already largish, say for example N=100. I expect such a system to be already large enough so that the matrices living in the bulk of the state don’t change that much.  
This means that if the state (writing only the physical indices explicitly)  
|\psi\rangle = \sum\_{\{\sigma\_i\}} A\_1^{\sigma\_1}\ldots A\_{N}^{\sigma\_{N}} |\sigma\_1 \ldots \sigma\_{N} \rangle  
is a good approximation of the ground state for N sites, I expect  
|\psi'\rangle = \sum\_{\{\sigma\_i\}} A\_1^{\sigma\_1}\ldots A\_{N/2}^{\sigma\_{N/2}}A\_{N/2}^{\sigma\_{N/2+1}}A\_{N/2+1}^{\sigma\_{N/2+2}}A\_{N/2+1}^{\sigma\_{N/2+3}}\ldots A\_{N}^{\sigma\_{N+2}} |\sigma\_1 \ldots \sigma\_{N+2} \rangle  
to be not too far from the ground state for N+2 sites. What I’m doing is just taking the central two sites for the N case, and inserting them in the center of the spin chain to grow it by two sites. After I’ve done this, I would run the dmrg for N+2 with |\psi'\rangle as a starting state

How does one build |\psi'\rangle in ITensors?

I’ve tried and failed by doing the following

```
N = 4
NHalf = div(N,2)
s = siteinds("S=1/2", N; conserve_qns=true)
psi1 = randomMPS(s, n -> isodd(n) ? "Up" : "Dn"; linkdims=4)

println(dot(psi1,psi1))

psi2 = MPS(N+2)

for i=1:NHalf
    psi2[i] = psi1[i]
    psi2[N+2-i] = psi1[N-i]
end

psi2[NHalf+1] = psi1[NHalf]
psi2[NHalf+2] = psi1[NHalf+1]

println(dot(psi2,psi2))

```

But I get an “access to undefined reference” error on the last line

---

<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:** [January 2, 2025, 5:34pm UTC](https://itensor.discourse.group/t/dmrg-using-n-site-result-as-a-starting-guess-for-n-2-site-computation/2190/2 "2025-01-02T17:34:48Z")

</div>

Did you check that the integers going into the brackets for `psi2` are all “in bounds”, i.e. between [1,N+2]?

The other things about the strategy you’re using here (unrelated to the error message you’re getting) are that:

1. you will need to make sure the “virtual” or link indices of the MPS connect up properly when you make `psi2`. Otherwise you will get an error later if you try to use `psi2` in an algorithm like DMRG. To check this, you can print out `psi2` and look at the indices (the id numbers of the indices) to see if they link up properly or not.
2. to actually make it so that `psi2` has similar properties to `psi1`, there is an ansatz for this (unfortunately a bit technical) by Ian McCulloch (in [this paper](https://arxiv.org/abs/0804.2509)) also covered by Uli Schollwoeck in his [“DMRG in the Age of Matrix Product States” paper](https://arxiv.org/abs/1008.3477) that explains a way to “grow” an MPS to have similar local properties as the original MPS.
