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?
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:
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’.