# qml.transforms.classical_jacobian¶

classical_jacobian(qnode)[source]

Returns a function to extract the Jacobian matrix of the classical part of a QNode.

This transform allows the classical dependence between the QNode arguments and the quantum gate arguments to be extracted.

Parameters

qnode (QNode) – QNode to compute the (classical) Jacobian of

Returns

Function which accepts the same arguments as the QNode. When called, this function will return the Jacobian of the QNode gate arguments with respect to the QNode arguments.

Return type

function

Example

Consider the following QNode:

>>> @qml.qnode(dev)
... def circuit(weights):
...     qml.RX(weights, wires=0)
...     qml.RY(weights, wires=1)
...     qml.RZ(weights ** 2, wires=1)
...     return qml.expval(qml.PauliZ(0))


We can use this transform to extract the relationship $$f: \mathbb{R}^n \rightarrow \mathbb{R}^m$$ between the input QNode arguments $$w$$ and the gate arguments $$g$$, for a given value of the QNode arguments:

>>> cjac_fn = qml.transforms.classical_jacobian(circuit)
>>> weights = np.array([1., 1., 1.], requires_grad=True)
>>> cjac = cjac_fn(weights)
>>> print(cjac)
[[1. 0. 0.]
[1. 0. 0.]
[0. 0. 2.]]


The returned Jacobian has rows corresponding to gate arguments, and columns corresponding to QNode arguments; that is,

$J_{ij} = \frac{\partial}{\partial g_i} f(w_j).$

We can see that:

• The zeroth element of weights is repeated on the first two gates generated by the QNode.

• The second column consisting of all zeros indicates that the generated quantum circuit does not depend on the first element of weights.