You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fails to precompile with ChainRules 1.74.11: non-boolean Symbolics.Num in the tanh rule #113
TaylorDiff 0.3.5 fails to precompile with ChainRules 1.74.11, the latest release:
julia>import Pkg; Pkg.activate(temp =true)
julia> Pkg.add("TaylorDiff"); Pkg.add(name ="ChainRules", version ="1.74.11")
julia>using TaylorDiff
ERROR: LoadError: TypeError: non-boolean (Symbolics.Num) used in boolean context
A symbolic expression appeared in a Boolean context. [...]
@ ChainRules ~/.julia/packages/ChainRules/.../src/rulesets/Base/fastmath_able.jl:42
@ TaylorDiff ~/.julia/packages/TaylorDiff/.../src/utils.jl:56
With ChainRules 1.74.10 it loads fine.
Cause
get_term_raiser in src/utils.jl evaluates the frule of each scalar function on the symbolic variable COMMON_Z while the package is being precompiled. ChainRules 1.74.11 (JuliaDiff/ChainRules.jl#864) changed the derivative of tanh to
to avoid cancellation for large |x|. The ternary needs a Bool, and abs(real(z)) < 1 on a Symbolics.Num is symbolic, hence the error. Any rule that branches on its argument would do the same.
Possible fixes: skip (or special-case) functions whose frule cannot be evaluated symbolically, for instance by catching the error in get_term_raiser and falling back to the generic path, or define the tanh recurrence directly from 1 - tanh², which is exact for truncated series.
Versions
TaylorDiff 0.3.5, ChainRules 1.74.11, Symbolics 7.48.0, SymbolicUtils 4.55.0, Julia 1.10 and 1.13 (Linux and Windows).
Found in the CI of FinancialToolbox.jl, which caps ChainRules at 1.74.10 in its test environment in the meantime.
Activity
Take higher-order derivative expressions from DiffRules