# MPS initialization through state vector

**URL:** <https://itensor.discourse.group/t/mps-initialization-through-state-vector/668>\
**Category:** ITensor Julia Questions\
**Created:** [February 27, 2023, 5:14pm UTC](https://itensor.discourse.group/t/mps-initialization-through-state-vector/668 "2023-02-27T17:14:22Z")\
**Posts on this page:** 5\
**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:** [February 27, 2023, 5:14pm UTC](https://itensor.discourse.group/t/mps-initialization-through-state-vector/668/1 "2023-02-27T17:14:22Z")

</div>

Is there a way to initialize an MPS by the statevector.

As an example, considering the GHZ state N qubits:

\ket{GHZ} = \frac{1}{\sqrt{2}} \ket{00...0} + \ket{11...1}

with state vector with 2^N elements

\frac{1}{\sqrt{2}} [1 0 0 ... 1]

How do I initialize the MPS?

(surely this is an easy example, but I would like to do it with any initial state vector)

---

<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:** [February 27, 2023, 7:12pm UTC](https://itensor.discourse.group/t/mps-initialization-through-state-vector/668/2 "2023-02-27T19:12:14Z")

</div>

Hi Emilio,  
Does this code example answer your question?  
[https://itensor.github.io/ITensors.jl/stable/examples/MPSandMPO.html#Creating-an-MPS-from-a-Tensor](https://itensor.github.io/ITensors.jl/stable/examples/MPSandMPO.html#Creating-an-MPS-from-a-Tensor)

Here the tensor `T` would be your state vector, reshaped as a tensor with N dimensions (N indices).

---

<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:** [February 28, 2023, 9:06am UTC](https://itensor.discourse.group/t/mps-initialization-through-state-vector/668/3 "2023-02-28T09:06:32Z")

</div>

My problem is actually how to initialize an Itensor from a State Vector.

So how to initialize T if all I have is a vector of 2^N elements

---

<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:** [February 28, 2023, 9:21am UTC](https://itensor.discourse.group/t/mps-initialization-through-state-vector/668/4 "2023-02-28T09:21:18Z")

</div>

Oops sorry, you can do it straightforward as said in [ITensor · ITensors.jl](https://itensor.github.io/ITensors.jl/stable/ITensorType.html#Description)

It was not working for other reasons related to my inexperience.  
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:** [February 28, 2023, 1:14pm UTC](https://itensor.discourse.group/t/mps-initialization-through-state-vector/668/5 "2023-02-28T13:14:41Z")

</div>

Glad you figured it out!
