-
-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pretty printing #64
Pretty printing #64
Conversation
Here's a before-after comparison. Code using ADTypes
struct FakeSparsityDetector <: ADTypes.AbstractSparsityDetector end
struct FakeColoringAlgorithm <: ADTypes.AbstractColoringAlgorithm end
for backend in [
# dense
AutoChainRules(; ruleconfig = :rc),
AutoDiffractor(),
AutoEnzyme(),
AutoEnzyme(mode = :forward),
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),
AutoSymbolics(),
AutoTapir(),
AutoTapir(safe_mode = false),
AutoTracker(),
AutoZygote(),
# sparse
AutoSparse(AutoForwardDiff()),
AutoSparse(
AutoForwardDiff();
sparsity_detector = FakeSparsityDetector(),
coloring_algorithm = FakeColoringAlgorithm()
)
]
println(backend)
end Before AutoChainRules{Symbol}(:rc)
AutoDiffractor()
AutoEnzyme{Nothing}(nothing)
AutoEnzyme{Symbol}(:forward)
AutoFastDifferentiation()
AutoFiniteDiff{Val{:forward}, Val{:forward}, Val{:hcentral}}(Val{:forward}(), Val{:forward}(), Val{:hcentral}())
AutoFiniteDiff{Symbol, Symbol, Symbol}(:fd, :fdj, :fdh)
AutoFiniteDifferences{Symbol}(:fdm)
AutoForwardDiff{nothing, Nothing}(nothing)
AutoForwardDiff{3, Symbol}(:tag)
AutoPolyesterForwardDiff{nothing, Nothing}(nothing)
AutoPolyesterForwardDiff{3, Symbol}(:tag)
AutoReverseDiff{false}(false)
AutoReverseDiff{true}(true)
AutoSymbolics()
AutoTapir(true)
AutoTapir(false)
AutoTracker()
AutoZygote()
AutoSparse{AutoForwardDiff{nothing, Nothing}, ADTypes.NoSparsityDetector, ADTypes.NoColoringAlgorithm}(AutoForwardDiff{nothing, Nothing}(nothing), ADTypes.NoSparsityDetector(), ADTypes.NoColoringAlgorithm())
AutoSparse{AutoForwardDiff{nothing, Nothing}, FakeSparsityDetector, FakeColoringAlgorithm}(AutoForwardDiff{nothing, Nothing}(nothing), FakeSparsityDetector(), FakeColoringAlgorithm()) After AutoChainRules(ruleconfig=rc)
AutoDiffractor()
AutoEnzyme()
AutoEnzyme(mode=forward)
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)
AutoSymbolics()
AutoTapir()
AutoTapir(safe_mode=false)
AutoTracker()
AutoZygote()
AutoSparse(dense_ad=AutoForwardDiff())
AutoSparse(dense_ad=AutoForwardDiff(), sparsity_detector=FakeSparsityDetector(), coloring_algorithm=FakeColoringAlgorithm())) |
The two argument |
You're right, that's an artefact of |
Directly use the roundtrip property of show, i.e. instead of trying to build a string and printing, do julia> a = :s; b = :r;
julia> show(a); print(a)
:ss
julia> print("MyFunction(a = "); show(a); print(")")
MyFunction(a = :s) |
The string building is useful to remove useless commas at the end. I found another workaround using AutoChainRules(ruleconfig=:rc)
AutoDiffractor()
AutoEnzyme()
AutoEnzyme(mode=:forward)
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)
AutoSymbolics()
AutoTapir()
AutoTapir(safe_mode=false)
AutoTracker()
AutoZygote()
AutoSparse(dense_ad=AutoForwardDiff())
AutoSparse(dense_ad=AutoForwardDiff(), sparsity_detector=FakeSparsityDetector(), coloring_algorithm=FakeColoringAlgorithm())) |
Yes |
Shit I had just realized this won't round-trip properly because you need to re-wrap the symbols in Vals. |
In the example printing case I didn't provide Val's to the constructor so they're not showing up. I'll check tomorrow but I think we're good? |
Checklist
contributor guidelines, in particular the SciML Style Guide and
COLPRAC.
Additional context
Right now every backend type is printed with its type parameters, which yields very long strings (especially with
AutoSparse
). Since I use those strings in DifferentiationInterface (e.g. as@testset
names), I figured it would be nice to make them more user-friendly.Base.show
for every parametric backend type, in a way that is coherent with the keyword-based constructor. The idea is that users can almost copy-pastestring(backend)
to construct it.