# Trouble implementing parameter shift rule on a CV circuit

**URL:** <https://discuss.pennylane.ai/t/trouble-implementing-parameter-shift-rule-on-a-cv-circuit/1687>\
**Category:** PennyLane Help\
**Created:** [February 21, 2022, 11:49am UTC](https://discuss.pennylane.ai/t/trouble-implementing-parameter-shift-rule-on-a-cv-circuit/1687 "2022-02-21T11:49:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jane](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/jane/32/930_2.png) [@Jane](https://discuss.pennylane.ai/u/Jane)\
**Post date:** [February 21, 2022, 11:49am UTC](https://discuss.pennylane.ai/t/trouble-implementing-parameter-shift-rule-on-a-cv-circuit/1687/1 "2022-02-21T11:49:19Z")

</div>

Hello,

I am finding it a little difficult to find the gradient of my simple circuit using parameter shift rule.

```
@qml.qnode(dev_gaussian)

def experiment(r, a, phi, rot):

    qml.Squeezing(r, 0, wires = 0)

    qml.Displacement(a, phi, wires = 0)

    qml.Rotation(rot, wires = 0)

    return qml.expval(qml.X(0))

```

It is a basic squeezed coherent state with a rotation gate applied.  
I find that when I try to find the gradient with respect to the rotation gate, the results by parameter shift rule doesn’t match that by finite differences.  
Can you explain why this behaviour?

Parameter shift rule used as described in documentation:

```
plus = experiment(r,a,phi,rot + np.pi / 2)
minus = experiment(r,a,phi,rot - np.pi / 2)

grad = (0.5 * (plus - minus))
```

---

<div class="post-metadata">

**Author:** ![josh](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/josh/32/100_2.png) [@josh](https://discuss.pennylane.ai/u/josh)\
**Post date:** [February 22, 2022, 7:23am UTC](https://discuss.pennylane.ai/t/trouble-implementing-parameter-shift-rule-on-a-cv-circuit/1687/2 "2022-02-22T07:23:31Z")

</div>

Hi @Jane! The manual parameter-shift rule you have defined appears to work for me. For example, considering the same circuit and parameter, and comparing all three methods:

```python
def experiment(r, a, phi, rot):
   qml.Squeezing(r, 0, wires=0)
   qml.Displacement(a, phi, wires=0)
   qml.Rotation(rot, wires=0)
   return qml.expval(qml.X(0))

rot = np.array(0.56, requires_grad=True)

```

**PennyLane’s finite differences** :

```auto
>>> qnode = qml.QNode(experiment, dev_gaussian, diff_method="finite-diff")
>>> qml.grad(qnode)(1.0, 0.6, 0.76, rot)
-1.162458135861577

```

**PennyLane’s parameter-shift** :

```auto
>>> qnode = qml.QNode(experiment, dev_gaussian, diff_method="parameter-shift")
>>> qml.grad(qnode)(1.0, 0.6, 0.76, rot)
-1.1624581201419182

```

**Manual parameter-shift** :

```python
>>> plus = qnode(1.0, 0.6, 0.76, rot + np.pi / 2)
>>> minus = qnode(1.0, 0.6, 0.76, rot - np.pi / 2)
>>> (0.5 * (plus - minus))
tensor(-1.16245812, requires_grad=True)

```
