Skip to content

Add SmallTag type for more compact Dual types #748

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

topolarity
Copy link

This is largely to improve printing and reduce visual noise for packages with large function types (e.g. SciML)

Compare tag = :small:

ForwardDiff.Dual{ForwardDiff.SmallTag{0x39f35d61d979c3d1}, Float64, 3}

to tag = :default:

ForwardDiff.Dual{ForwardDiff.Tag{var"#f#1"{DAEProblem{Vector{Float64}, Vector{Float64}, Tuple{Float64, Float64}, false, Vector{Float64}, DAEFunction{false, SciMLBase.FullSpecialize, typeof(f), Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing, Nothing}, @Kwargs{}, Vector{Bool}}, BrownFullBasicInit{Float64, Nothing}, DFBDF{5, 0, ADTypes.AutoForwardDiff{nothing, Nothing}, Nothing, OrdinaryDiffEqNonlinearSolve.NLNewton{Rational{Int64}, Rational{Int64}, Rational{Int64}, Rational{Int64}}, typeof(OrdinaryDiffEqCore.DEFAULT_PRECS), Val{:forward}(), true, nothing, Nothing, Nothing}}, Float64}, Float64, 3}

@topolarity topolarity changed the title Add SmallTag type for more compute Dual types Add SmallTag type for more compact Dual types Apr 23, 2025
Copy link

codecov bot commented Apr 23, 2025

Codecov Report

Attention: Patch coverage is 86.36364% with 9 lines in your changes missing coverage. Please review.

Project coverage is 86.92%. Comparing base (c310fb5) to head (d88bf58).
Report is 21 commits behind head on master.

Files with missing lines Patch % Lines
src/config.jl 86.36% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #748      +/-   ##
==========================================
- Coverage   89.57%   86.92%   -2.66%     
==========================================
  Files          11       10       -1     
  Lines         969     1025      +56     
==========================================
+ Hits          868      891      +23     
- Misses        101      134      +33     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mcabbott
Copy link
Member

We could also revive #572, closed it was thought that SciML printing problems were solved in Base.

Can you comment on the comparison?

@topolarity
Copy link
Author

topolarity commented Apr 23, 2025

We could also revive #572, closed it was thought that SciML printing problems were solved in Base.

Base has type-folding now that helps many stack traces, but you still sometimes need a repr(...) of a type that you can copy-and-paste, which disables folding

Can you comment on the comparison?

The main difference is that debugging perturbation issues without the actual function / array types can be very confusing, so it seems useful to keep the original functionality around. Other than that, the implementation should be mostly equivalent (the hash is based in many cases on the objectid)

Also it's worth mentioning that tag = short does not allow the Dual / Config type to be inferred on 1.10 sadly, since hash(::Type) is only const-eval-able on 1.11+ (see JuliaLang/julia#52427 (comment))

This is an alternative to `Tag` that provides largely the same
functionality, but carries around only the hash of the function
/ array types instead of the full types themselves.

This can make these types much less bulky to print and easier to
visually scan for.
This provides a convenient interface to ask for a SmallTag.
Latest patch release seems to have tightened this up.
This old version of Julia doesn't have call-site `@inline` / `@noinline`
so version-guard against this trick for now.
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.

2 participants