# Prepare Gaussianstate

**URL:** <https://discuss.pennylane.ai/t/prepare-gaussianstate/993>\
**Category:** PennyLane Strawberry Fields\
**Created:** [April 22, 2021, 4:16pm UTC](https://discuss.pennylane.ai/t/prepare-gaussianstate/993 "2021-04-22T16:16:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alice\_Wong](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/alice_wong/32/505_2.png) [@Alice\_Wong](https://discuss.pennylane.ai/u/Alice_Wong)\
**Post date:** [April 22, 2021, 4:16pm UTC](https://discuss.pennylane.ai/t/prepare-gaussianstate/993/1 "2021-04-22T16:16:05Z")

</div>

I want to feed two-qubit gaussian states with covariance matrix into CVNeuralNetLayers. However, it returned error that " The input matrix is not square".

```python
> dev = qml.device('strawberryfields.fock', wires=2, cutoff_dim=10) 
@qml.qnode(dev)
def quantum_neural_net(pars,cm):
    mean_vector=np.array([[0.0],
                                              [0.0],
                                              [0.0],
                                             [0.0]])
    cm=cm.reshape((4,4))
    qml.GaussianState(mean_vector,cm,wires=range(2))
    CVNeuralNetLayers(*pars,wires=range(2))
    return qml.expval(qml.X(0))
#random pick a column with 16 elements in training dataset 
cm_test=xtr[89]
result=quantum_neural_net(init_pars,cm_test))
ValueError: The input matrix is not square

```

I directly used sf.ops.Gaussian(cm\_test) to check, which worked.

```python
> import strawberryfields as sf
cm_test=xtr[89].reshape((4,4))
result=sf.ops.Gaussian(cm_test)
print("returned gaussian state",result)
Out: returned gaussian state Gaussian([[68.4229 0. 68.5705 0.]
 [0. 68.4229 0. -68.5705]
 [68.5705 0. 68.9229 0.]
 [0. -68.5705 0. 68.9229]], [0. 0. 0. 0.])
```

---

<div class="post-metadata">

**Author:** ![glassnotes](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/glassnotes/32/327_2.png) [@glassnotes](https://discuss.pennylane.ai/u/glassnotes)\
**Post date:** [April 22, 2021, 7:59pm UTC](https://discuss.pennylane.ai/t/prepare-gaussianstate/993/2 "2021-04-22T19:59:35Z")

</div>

Hi @Alice_Wong,

Welcome to the forum!

One thing to note is the required shape of `mean_vector`. The documentation specifies that it should be an array of length `2N` (4 in this case), while the array in the code snippet is shape `(4, 1)`. However I tested even with the correct shape (`mean_vector = np.array([0,0,0,0])`) and received a different error which will require some looking into.

I’ve created a [bug report](https://github.com/PennyLaneAI/pennylane-sf/issues/67) in the PennyLane-SF plugin repository. Feel free to check that out for the extra details, and follow the progress on that issue.

Thanks for uncovering this!

---

<div class="post-metadata">

**Author:** ![glassnotes](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/glassnotes/32/327_2.png) [@glassnotes](https://discuss.pennylane.ai/u/glassnotes)\
**Post date:** [April 22, 2021, 8:47pm UTC](https://discuss.pennylane.ai/t/prepare-gaussianstate/993/3 "2021-04-22T20:47:08Z")

</div>

Quick update: we believe the source of the error is in the order of the parameters in `GaussianState`. In addition to changing the shape of `mean_vector`, try swapping the order of `mean_vector` and `cm` in the `qml.GaussianState` function. Let us know if it works 🙂

---

<div class="post-metadata">

**Author:** ![Alice\_Wong](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/alice_wong/32/505_2.png) [@Alice\_Wong](https://discuss.pennylane.ai/u/Alice_Wong)\
**Post date:** [April 22, 2021, 8:54pm UTC](https://discuss.pennylane.ai/t/prepare-gaussianstate/993/4 "2021-04-22T20:54:17Z")

</div>

Thanks.  
It works now.

---

<div class="post-metadata">

**Author:** ![glassnotes](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/glassnotes/32/327_2.png) [@glassnotes](https://discuss.pennylane.ai/u/glassnotes)\
**Post date:** [April 22, 2021, 8:59pm UTC](https://discuss.pennylane.ai/t/prepare-gaussianstate/993/5 "2021-04-22T20:59:28Z")

</div>

Awesome - thanks for letting us know!
