SciML / ADTypes.jl

Repository for automatic differentiation backend types
https://sciml.github.io/ADTypes.jl/
MIT License
38 stars 11 forks source link

Fix pretty printing and ReverseDiff constructor #67

Closed gdalle closed 3 months ago

gdalle commented 3 months ago

Checklist

Additional context

Fix #65 and #66

Should we test the round-trip-ability of these printings by parsing the string back into an object?

gdalle commented 3 months ago

Code

import ADTypes

struct FakeSparsityDetector <: ADTypes.AbstractSparsityDetector end
struct FakeColoringAlgorithm <: ADTypes.AbstractColoringAlgorithm end

for backend in [
    # dense
    ADTypes.AutoChainRules(; ruleconfig = :rc),
    ADTypes.AutoDiffractor(),
    ADTypes.AutoEnzyme(),
    ADTypes.AutoEnzyme(mode = :forward),
    ADTypes.AutoFastDifferentiation(),
    ADTypes.AutoFiniteDiff(),
    ADTypes.AutoFiniteDiff(fdtype = :fd, fdjtype = :fdj, fdhtype = :fdh),
    ADTypes.AutoFiniteDifferences(; fdm = :fdm),
    ADTypes.AutoForwardDiff(),
    ADTypes.AutoForwardDiff(chunksize = 3, tag = :tag),
    ADTypes.AutoPolyesterForwardDiff(),
    ADTypes.AutoPolyesterForwardDiff(chunksize = 3, tag = :tag),
    ADTypes.AutoReverseDiff(),
    ADTypes.AutoReverseDiff(compile = true),
    ADTypes.AutoSymbolics(),
    ADTypes.AutoTapir(),
    ADTypes.AutoTapir(safe_mode = false),
    ADTypes.AutoTracker(),
    ADTypes.AutoZygote(),
    # sparse
    ADTypes.AutoSparse(ADTypes.AutoForwardDiff()),
    ADTypes.AutoSparse(
        ADTypes.AutoForwardDiff();
        sparsity_detector = FakeSparsityDetector(),
        coloring_algorithm = FakeColoringAlgorithm()
    )
]
    println(backend)
end

Before (1.5.1) (note the unpredictable presence of the package name)

AutoChainRules(ruleconfig=:rc)
ADTypes.AutoDiffractor()
AutoEnzyme()
AutoEnzyme(mode=:forward)
ADTypes.AutoFastDifferentiation()
AutoFiniteDiff()
AutoFiniteDiff(fdtype=:fd, fdjtype=:fdj, fdhtype=:fdh)
AutoFiniteDifferences(fdm=:fdm)
AutoForwardDiff()
AutoForwardDiff(chunksize=3, tag=:tag)
AutoPolyesterForwardDiff()
AutoPolyesterForwardDiff(chunksize=3, tag=:tag)
AutoReverseDiff()
AutoReverseDiff(compile=true)
ADTypes.AutoSymbolics()
AutoTapir()
AutoTapir(safe_mode=false)
ADTypes.AutoTracker()
ADTypes.AutoZygote()
AutoSparse(dense_ad=AutoForwardDiff())
AutoSparse(dense_ad=AutoForwardDiff(), sparsity_detector=FakeSparsityDetector(), coloring_algorithm=FakeColoringAlgorithm()))

After (this PR, 1.5.2)


ADTypes.AutoChainRules(ruleconfig=:rc)
ADTypes.AutoDiffractor()
ADTypes.AutoEnzyme()
ADTypes.AutoEnzyme(mode=:forward)
ADTypes.AutoFastDifferentiation()
ADTypes.AutoFiniteDiff()
ADTypes.AutoFiniteDiff(fdtype=:fd, fdjtype=:fdj, fdhtype=:fdh)
ADTypes.AutoFiniteDifferences(fdm=:fdm)
ADTypes.AutoForwardDiff()
ADTypes.AutoForwardDiff(chunksize=3, tag=:tag)
ADTypes.AutoPolyesterForwardDiff()
ADTypes.AutoPolyesterForwardDiff(chunksize=3, tag=:tag)
ADTypes.AutoReverseDiff()
ADTypes.AutoReverseDiff(compile=true)
ADTypes.AutoSymbolics()
ADTypes.AutoTapir()
ADTypes.AutoTapir(safe_mode=false)
ADTypes.AutoTracker()
ADTypes.AutoZygote()
ADTypes.AutoSparse(dense_ad=ADTypes.AutoForwardDiff())
ADTypes.AutoSparse(dense_ad=ADTypes.AutoForwardDiff(), sparsity_detector=FakeSparsityDetector(), coloring_algorithm=FakeColoringAlgorithm())