Ignore_derivatives of entire module with ChainRules.jl

The hacky “lets not think about this” way is to do some code generation.
You can use something like

for name in names(MyModule; all=true)
    func = getfield(MyModule, name)
    !isempty(methods(func)) && continue  # not actually a function
    
    println("@non_differentiable $name(args...; kwargs...)")
end

to create a nice file with them all filled in.
Though probably you just need to define it for some of the functions.


@ignore_derivatives can only be applied to function calls. Not to modules or function definitions.
You could use MacroTools or MLStyle.jl to recursively match your code AST looking for calls.
But it is definately not trivial.
Could be good excuse to use the 2 argument form of include though.

1 Like