# Convert co-variance to Hamiltonian matrix

**URL:** <https://discuss.pennylane.ai/t/convert-co-variance-to-hamiltonian-matrix/280>\
**Category:** Strawberry Fields\
**Created:** [November 28, 2019, 5:55pm UTC](https://discuss.pennylane.ai/t/convert-co-variance-to-hamiltonian-matrix/280 "2019-11-28T17:55:25Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![kareem\_essafty](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/kareem_essafty/32/401_2.png) [@kareem\_essafty](https://discuss.pennylane.ai/u/kareem_essafty)\
**Post date:** [December 3, 2019, 9:35pm UTC](https://discuss.pennylane.ai/t/convert-co-variance-to-hamiltonian-matrix/280/6 "2019-12-03T21:35:03Z")

</div>

hey @Nicolas_Quesada, I tried the following:

```
prog = sf.Program(2)
np.random.seed(5)
x = np.random.rand(1)
print(x[0])
with prog.context as q:

    sf.ops.Thermal(n=1e-015) | q[0]
    sf.ops.Thermal(n=1e-015) | q[1]
    #sf.ops.S2gate(r=0.7,phi=0) | q
    #sf.ops.DisplacedSqueezed(alpha=1.,r=.7,p=x[0]) | q[0]
    #sf.ops.DisplacedSqueezed(alpha=2,r=.7,p=x[0]+np.pi) |q[1]
    sf.ops.Sgate(r=0.7,phi=x[0]) | q[0]
    sf.ops.Sgate(r=0.7,phi=x[0]+np.pi/4) | q[1]
    sf.ops.Dgate(7.2) | q[0]
    sf.ops.Dgate(-0.6-0.3j) | q[1]

eng = sf.Engine('gaussian')

result = eng.run(prog)    

cov = result.state.cov()
print(cov)
print(" ")
print(sf.decompositions.covmat_to_hamil(cov)) 

```

the result didn’t include any nan and was perfect except for the fact that the hamiltonian was not symmetric.  
besides that, if i used a displacedsqueezed operation instead of the S and D gates i get nan values

---

_[View the full topic](https://discuss.pennylane.ai/t/convert-co-variance-to-hamiltonian-matrix/280)._
