# Way to tell how PennyLane will differentiate a QNode

**URL:** <https://discuss.pennylane.ai/t/way-to-tell-how-pennylane-will-differentiate-a-qnode/1675>\
**Category:** PennyLane Help\
**Created:** [February 17, 2022, 7:20pm UTC](https://discuss.pennylane.ai/t/way-to-tell-how-pennylane-will-differentiate-a-qnode/1675 "2022-02-17T19:20:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cvjjm](https://avatars.discourse-cdn.com/v4/letter/c/96bed5/32.png) [@cvjjm](https://discuss.pennylane.ai/u/cvjjm)\
**Post date:** [February 17, 2022, 7:20pm UTC](https://discuss.pennylane.ai/t/way-to-tell-how-pennylane-will-differentiate-a-qnode/1675/1 "2022-02-17T19:20:14Z")

</div>

In PL v0.21.0 I could, given a `QNode` `circuit` and a device `dev` do for example

```
circuit.get_best_method(dev, circuit.interface)[-1]['method'] == 'numeric'

```

to test whether computing the jacobian on that device would be done with the finite difference method.

I understand that this was never officially supported UI and indeed in the current master this no longer works as `get_best_method()` no longer returns a “human readable” description of the method as its last argument.

Is there a more official way to find out how PL will differentiate a `QNode` on a device?

---

<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 18, 2022, 5:33am UTC](https://discuss.pennylane.ai/t/way-to-tell-how-pennylane-will-differentiate-a-qnode/1675/2 "2022-02-18T05:33:08Z")

</div>

Hey @cvjjm! Ah, this is a consequence of us moving away from ‘string’ identifiers, and towards using gradient transform functions directly.

Currently, the only change is that:

- the `"analytic"` string is now represented by either `qml.gradients.param_shift` or `qml.gradients.param_shift_cv` depending on the device, and

- the `"numeric"` string is now represented by `qml.gradients.finite_diff`.

Here is a quick function that will replicate the behaviour of PL v0.21:

```python
def get_best_method(dev, interface):
    transform = qml.QNode.get_best_method(dev, interface)[0]

    if transform is qml.gradients.finite_diff:
        return "numeric"

    if transform in (qml.gradients.param_shift, qml.gradients.param_shift_cv):
        return "analytic"

    # only other options by this point are "backprop" or "device"
    return transform

```

> Is there a more official way to find out how PL will differentiate a `QNode` on a device?

Not at the moment, but this is good feedback and something we will look at adding (and definitely useful!).

Regarding the heuristics for determining the ‘best’ gradient method; this is functionality we are planning to evolve further down the line, and may even be moved out of the QNode initialization at some point; since we have identified several places where knowing the _circuit structure itself_ — which is not known at QNode initialization, only at execution — can result in better heuristics.

So we may factor out these static methods into utility functions, and make them ‘public’.
