Skip to content

New autodiff rule from DifferentiateWith #804

@yebai

Description

@yebai

As explored in discussions (e.g., #68), we can introduce a flexible "rule switch" mechanism into DifferentiationInterface.jl (DI) by generalising the existing DifferentiateWith functionality.

The central concept is a macro that allows for the dynamic generation of differentiation rules:

Targtypes = (typeof(x), typeof(y), Constant{typeof(z)}, Cache{typeof(c)})
Tfunc_sig =Tuple{typeof(f), Targtypes...}
@rule_from_DifferentiateWith(AutoTargetAD, ::Tfunc_sig, backend_to_use::AbstractADType)

In this definition:

  • @rule_from_DifferentiateWith is a macro designed to generate new differentiation rules.
  • AutoTargetAD specifies the automatic differentiation (AD) package for which the new rule is being created (e.g., AutoChainRules).
  • func_sig represents the signature of the function f along with its argument types (argtypes...) for which the rule is being defined.
  • backend_to_use indicates another AD package (the "backend") whose capabilities will be leveraged to define the rule for AutoTargetAD.

This approach provides a powerful and general way to establish a "rule switch mechanism." It avoids imposing strict assumptions on the rule interface, unlike systems such as ChainRules, offering greater flexibility.

After #806, we could also do

dw = DifferentiateWith(Tfunc_sig, backend_to_use::AbstractADType)
@rule_from_DifferentiateWith(AutoTargetAD, dw)

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendRelated to one or more autodiff backendscoreRelated to the core utilities of the package

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions