Skip to content
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

Fix pretty printing and ReverseDiff constructor #67

Merged
merged 3 commits into from
Jun 27, 2024
Merged

Conversation

gdalle
Copy link
Collaborator

@gdalle gdalle commented Jun 26, 2024

Checklist

  • Appropriate tests were added
  • Any code changes were done in a way that does not break public API
  • All documentation related to code changes were updated
  • The new code follows the
    contributor guidelines, in particular the SciML Style Guide and
    COLPRAC.
  • Any new documentation only uses public API

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
Copy link
Collaborator Author

gdalle commented Jun 26, 2024

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())

@gdalle gdalle requested review from Vaibhavdixit02 and ChrisRackauckas and removed request for Vaibhavdixit02 June 26, 2024 17:19
Comment on lines +114 to +118
print(io, "fdtype=", repr(backend.fdtype; context = io), ", ")
backend.fdjtype != backend.fdtype &&
print(io, "fdjtype=", repr(backend.fdjtype; context = io), ", ")
backend.fdhtype != Val(:hcentral) &&
print(io, "fdhtype=", repr(backend.fdhtype; context = io))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These don't show the Val?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes they do, there's just no Val in the test case I displayed above. Take a look here:

julia> string(AutoFiniteDiff(fdjtype=Val(:whatever)))
"AutoFiniteDiff(fdjtype=Val{:whatever}(), )"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ChrisRackauckas I think this one is a strict improvement over the current state, what do you say?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@gdalle gdalle merged commit 59ceff3 into main Jun 27, 2024
4 checks passed
@gdalle gdalle deleted the gd/print_other_module branch September 7, 2024 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Broken constructor in v1.5
3 participants