def operation_derivative(operation) -> np.ndarray:
    'Calculate the derivative of an operation.\n\n    For an operation :math:`e^{i \\hat{H} \\phi t}`, this function returns the matrix representation\n    in the standard basis of its derivative with respect to :math:`t`, i.e.,\n\n    .. math:: \\frac{d \\, e^{i \\hat{H} \\phi t}}{dt} = i \\phi \\hat{H} e^{i \\hat{H} \\phi t},\n\n    where :math:`\\phi` is a real constant.\n\n    Args:\n        operation (.Operation): The operation to be differentiated.\n\n    Returns:\n        array: the derivative of the operation as a matrix in the standard basis\n\n    Raises:\n        ValueError: if the operation does not have a generator or is not composed of a single\n            trainable parameter\n    '
    (generator, prefactor) = operation.generator
    if (generator is None):
        raise ValueError(f'Operation {operation.name} does not have a generator')
    if (operation.num_params != 1):
        raise ValueError(f'Operation {operation.name} is not written in terms of a single parameter')
    if (not isinstance(generator, np.ndarray)):
        generator = generator.matrix
    if operation.inverse:
        prefactor *= (- 1)
        generator = generator.conj().T
    return (((1j * prefactor) * generator) @ operation.matrix)
Calculate the derivative of an operation.

For an operation :math:`e^{i \hat{H} \phi t}`, this function returns the matrix representation
in the standard basis of its derivative with respect to :math:`t`, i.e.,

.. math:: \frac{d \, e^{i \hat{H} \phi t}}{dt} = i \phi \hat{H} e^{i \hat{H} \phi t},

where :math:`\phi` is a real constant.

Args:
    operation (.Operation): The operation to be differentiated.

Returns:
    array: the derivative of the operation as a matrix in the standard basis

Raises:
    ValueError: if the operation does not have a generator or is not composed of a single
        trainable parameter
def operation_derivative(operation) -> np.ndarray:
    'Calculate the derivative of an operation.\n\n    For an operation :math:`e^{i \\hat{H} \\phi t}`, this function returns the matrix representation\n    in the standard basis of its derivative with respect to :math:`t`, i.e.,\n\n    .. math:: \\frac{d \\, e^{i \\hat{H} \\phi t}}{dt} = i \\phi \\hat{H} e^{i \\hat{H} \\phi t},\n\n    where :math:`\\phi` is a real constant.\n\n    Args:\n        operation (.Operation): The operation to be differentiated.\n\n    Returns:\n        array: the derivative of the operation as a matrix in the standard basis\n\n    Raises:\n        ValueError: if the operation does not have a generator or is not composed of a single\n            trainable parameter\n    '
    (generator, prefactor) = operation.generator
    if (generator is None):
        raise ValueError(f'Operation {operation.name} does not have a generator')
    if (operation.num_params != 1):
        raise ValueError(f'Operation {operation.name} is not written in terms of a single parameter')
    if (not isinstance(generator, np.ndarray)):
        generator = generator.matrix
    if operation.inverse:
        prefactor *= (- 1)
        generator = generator.conj().T
    return (((1j * prefactor) * generator) @ operation.matrix)