qml.gradients.compute_jvp_single

compute_jvp_single(tangent, jac)[source]

Convenience function to compute the Jacobian vector product for a given tangent vector and a Jacobian for a single measurement tape.

Parameters
  • tangent (list, tensor_like) – tangent vector

  • jac (tensor_like, tuple) – Jacobian matrix

Returns

the Jacobian vector product

Return type

tensor_like

Examples

  1. For a single parameter and a single measurement without shape (e.g. expval, var):

>>> tangent = np.array([1.0])
>>> jac = np.array(0.2)
>>> qml.gradients.compute_jvp_single(tangent, jac)
np.array(0.2)
  1. For a single parameter and a single measurment with shape (e.g. probs):

>>> tangent = np.array([2.0])
>>> jac = np.array([0.3, 0.4])
>>> qml.gradients.compute_jvp_single(tangent, jac)
np.array([0.6, 0.8])
  1. For multiple parameters (in this case 2 parameters) and a single measurement without shape (e.g. expval, var):

>>> tangent = np.array([1.0, 2.0])
>>> jac = tuple([np.array(0.1), np.array(0.2)])
>>> qml.gradients.compute_jvp_single(tangent, jac)
np.array(0.5)
  1. For multiple parameters (in this case 2 parameters) and a single measurement with shape (e.g. probs):

>>> tangent = np.array([1.0, 0.5])
>>> jac = tuple([np.array([0.1, 0.3]), np.array([0.2, 0.4])])
>>> qml.gradients.compute_jvp_single(tangent, jac)
np.array([0.2, 0.5])