# From exact diagonalization to MPS

**URL:** <https://itensor.discourse.group/t/from-exact-diagonalization-to-mps/2112>\
**Category:** DMRG and Numerical Methods\
**Tags:** julia\
**Created:** [November 8, 2024, 7:26am UTC](https://itensor.discourse.group/t/from-exact-diagonalization-to-mps/2112 "2024-11-08T07:26:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sebastianvromero](https://avatars.discourse-cdn.com/v4/letter/s/dc4da7/32.png) [@sebastianvromero](https://itensor.discourse.group/u/sebastianvromero)\
**Post date:** [November 8, 2024, 7:26am UTC](https://itensor.discourse.group/t/from-exact-diagonalization-to-mps/2112/1 "2024-11-08T07:26:29Z")

</div>

Hi, hope you are doing well.

Given an `op` in the form of `OpSum`, I would like to obtain its whole set of eigenstates and turn them into MPSs to compute separately the overlaps between each eigenstate of `op` with a given MPS `psi`, thus \langle\text{each eigst of op}|\psi\rangle. I have been following different posts regarding exact diagonalization with ITensor

- [Converting the eigenstates obtained from the exact diagonalization to a MPS](https://itensor.discourse.group/t/converting-the-eigenstates-obtained-from-the-exact-diagonalization-to-a-mps/1621)
- [ED with Itensor](https://itensor.discourse.group/t/ed-with-itensor/1088/2)

but, unfortunately, they apparently do not answer my question.

Here there is a snippet of code where the `op` to diagonalize is prepared and exact diagonalized using `eigen`, returning an 2^N\times 2^N matrix `V` for the eigenstates, as expected.

```julia
using ITensors

let
  N = 4 # number of sites

  s = siteinds("Qubit", N)
  op = OpSum()
  for i in 1:N
    op += "σy", i
  end

  cb=combiner(dag(s)...)
  cbp=combiner(s'...)
  H = prod(MPO(op, s))*cb*cbp
  E, V = eigen(H,combinedind(cb),combinedind(cbp), ishermitian=true)

  psi = randomMPS(s;linkdims=2)
  return
end

```

The problem comes when I try to access each individual eigenstate of `V`, since I do not know how to manipulate the `NDTensors.Dense` object. As I said, I would also like to convert them into MPSs to extract each `inner(each eigst of op', psi)`.

Thanks a lot for your time devoted!

---

<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:** [November 8, 2024, 12:23pm UTC](https://itensor.discourse.group/t/from-exact-diagonalization-to-mps/2112/2 "2024-11-08T12:23:29Z")

</div>

First note that we have separated ITensor and ITensorMPS so you’ll need `using ITensorMPS` as well

Unfortunately that snippet isn’t the best way of doing things (and we should really only have one combiner), but with some modification here is how you can do the overlaps

```julia
using ITensors, ITensorMPS

let
  N = 4 # number of sites

  s = siteinds("Qubit", N)
  os = OpSum()
  for i in 1:N
    os += "σy", i
  end

  cb=combiner(dag(s)...)
  H = prod(MPO(os, s))*cb*dag(cb)'
  E, V = eigen(H,ishermitian=true)

  psi = randomMPS(s;linkdims=2)

  psic = prod(conj(psi))*cb # conj psi in case complex
  l = noncommonind(V,psic)
  @assert hastags(l,"eigen")

  # overlap of single vector
  i = 7
  vec = V*onehot(l=>i)
  overlap = (psic*vec)[]
  @show overlap

  # all at once
  overlaps = V*psic
  overlaps = [(overlaps*onehot(l=>i))[] for i=1:2^N]
  @show overlaps
  @show overlap ≈ overlaps[i]
  return
end

```

---

<div class="post-metadata">

**Author:** ![sebastianvromero](https://avatars.discourse-cdn.com/v4/letter/s/dc4da7/32.png) [@sebastianvromero](https://itensor.discourse.group/u/sebastianvromero)\
**Post date:** [November 8, 2024, 4:59pm UTC](https://itensor.discourse.group/t/from-exact-diagonalization-to-mps/2112/3 "2024-11-08T16:59:16Z")

</div>

It works! Thanks a lot 😁

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/itensor/original/1X/d3072b13e047cd06df7f3981547c0917d940dfa4.png) [@system](https://itensor.discourse.group/u/system)\
**Post date:** [November 18, 2024, 4:59pm UTC](https://itensor.discourse.group/t/from-exact-diagonalization-to-mps/2112/4 "2024-11-18T16:59:38Z")

</div>

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
