qml.gradients.compute_jvp_multi

compute_jvp_multi(tangent, jac)[source]

Convenience function to compute the Jacobian-vector product for a given vector of gradient outputs and a Jacobian for a tape with multiple measurements.

Parameters
  • tangent (tensor_like, list) – tangent vector

  • jac (tensor_like, tuple) – Jacobian matrix

Returns

the Jacobian-vector product

Return type

tensor_like

Examples

  1. For a single parameter and multiple measurements (one without shape and one with shape, e.g. expval and probs):

>>> tangent = np.array([2.0])
>>> jac = tuple([np.array([0.3]), np.array([0.2, 0.5])])
>>> qml.gradients.compute_jvp_multi(tangent, jac)
(array([0.6]), array([0.4, 1. ]))

2. For multiple parameters (in this case 2 parameters) and multiple measurements (one without shape and one with shape, e.g. expval and probs):

>>> tangent = np.array([1.0, 2.0])
>>> jac = tuple([tuple([np.array([0.3]), np.array([0.4])]), tuple([np.array([0.2, 0.5]), np.array([0.3, 0.8])]),])
>>> qml.gradients.compute_jvp_multi(tangent, jac)
(array([1.1]), array([0.8, 2.1]))