Returns a function that maps all substituent PauliTerms and sums them into a program. NOTE: Use
    this function with care. Substituent PauliTerms should commute.

    :param PauliSum pauli_sum: PauliSum to exponentiate.
    :returns: A function that parametrizes the exponential.
    :rtype: function

def exponentiate_commuting_pauli_sum(pauli_sum):
    """
    Returns a function that maps all substituent PauliTerms and sums them into a program. NOTE: Use
    this function with care. Substituent PauliTerms should commute.

    :param PauliSum pauli_sum: PauliSum to exponentiate.
    :returns: A function that parametrizes the exponential.
    :rtype: function
    """
    if not isinstance(pauli_sum, PauliSum):
        raise TypeError("Argument 'pauli_sum' must be a PauliSum.")

    fns = [exponential_map(term) for term in pauli_sum]

    def combined_exp_wrap(param):
        return Program([f(param) for f in fns])

    return combined_exp_wrap