Skip to content

Add Aqua tests #775

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

Merged
merged 16 commits into from
Mar 13, 2025
Merged

Add Aqua tests #775

merged 16 commits into from
Mar 13, 2025

Conversation

penelopeysm
Copy link
Member

@penelopeysm penelopeysm commented Jan 8, 2025

This PR adds Aqua tests and fixes all the issues flagged by them. Not much else to describe about it, except for one comment on ThreadSafeVarInfo which I put below.

@coveralls
Copy link

coveralls commented Jan 8, 2025

Pull Request Test Coverage Report for Build 13840255339

Details

  • 5 of 16 (31.25%) changed or added relevant lines in 7 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.2%) to 84.489%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/context_implementations.jl 0 1 0.0%
src/contexts.jl 0 1 0.0%
src/distribution_wrappers.jl 0 2 0.0%
src/compiler.jl 0 3 0.0%
src/threadsafe.jl 0 4 0.0%
Files with Coverage Reduction New Missed Lines %
src/compiler.jl 1 93.04%
Totals Coverage Status
Change from base Build 13839594893: -0.2%
Covered Lines: 3241
Relevant Lines: 3836

💛 - Coveralls

Copy link

codecov bot commented Jan 8, 2025

Codecov Report

Attention: Patch coverage is 31.25000% with 11 lines in your changes missing coverage. Please review.

Project coverage is 84.40%. Comparing base (4bc43a4) to head (f1d5003).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/threadsafe.jl 0.00% 4 Missing ⚠️
src/compiler.jl 0.00% 3 Missing ⚠️
src/distribution_wrappers.jl 0.00% 2 Missing ⚠️
src/context_implementations.jl 0.00% 1 Missing ⚠️
src/contexts.jl 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #775      +/-   ##
==========================================
- Coverage   84.56%   84.40%   -0.17%     
==========================================
  Files          34       34              
  Lines        3830     3840      +10     
==========================================
+ Hits         3239     3241       +2     
- Misses        591      599       +8     

☔ 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.

@penelopeysm penelopeysm force-pushed the py/aqua branch 2 times, most recently from d648df0 to 7146c32 Compare March 9, 2025 02:00
@TuringLang TuringLang deleted a comment from github-actions bot Mar 9, 2025
@TuringLang TuringLang deleted a comment from github-actions bot Mar 9, 2025
Comment on lines +118 to +129
# These two StaticTransformation methods needed to resolve ambiguities
function link!!(
t::StaticTransformation{<:Bijectors.Transform}, vi::ThreadSafeVarInfo, model::Model
)
return Accessors.@set vi.varinfo = link!!(t, vi.varinfo, model)
end

function invlink!!(
t::StaticTransformation{<:Bijectors.Transform}, vi::ThreadSafeVarInfo, model::Model
)
return Accessors.@set vi.varinfo = invlink!!(t, vi.varinfo, model)
end
Copy link
Member Author

@penelopeysm penelopeysm Mar 9, 2025

Choose a reason for hiding this comment

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

Most of the method ambiguity fixes in this PR are really straightforward, but it took me a long time to figure out what to do here.

Firstly, note that this method is only ever invoked in a very specific situation, where we have (1) multithreaded evaluation hence ThreadSafeVarInfo, (2) a StaticTransformation, and (3) the nested varinfo is e.g. a SimpleVarInfo and specifically not a VarInfo, because the ThreadSafeVarInfo{VarInfo} methods are overridden in varinfo.jl.

The DynamicPPL test suite does not ever call this method (if it did, it would have failed with a method ambiguity), and since this has never been reported before, one might justifiably assume that no user has ever called it too.

To be fully honest, while I can't see any reason why this would be wrong, I also can't convince myself 100% that this is the correct behaviour. However, looking at the lines directly above this, it seems clear enough to me that the intent of that code was to suggest that all AbstractTransformations should behave that way, except that DynamicTransformation was to be special-cased. So I figured that it would suffice to duplicate the general AbstractTransformation implementation here.

@penelopeysm penelopeysm marked this pull request as ready for review March 10, 2025 11:53
@penelopeysm
Copy link
Member Author

@mhauru I'm still investigating the Aqua failure on 1.10, but I think the code changes can be reviewed.

@penelopeysm penelopeysm requested a review from mhauru March 10, 2025 11:54
@penelopeysm
Copy link
Member Author

penelopeysm commented Mar 12, 2025

@mhauru The benchmarks are failing because of a numerically inaccurate Cholesky link/invlink. Fun times

TuringLang/Bijectors.jl#356
TuringLang/Bijectors.jl#357

These should resolve it, but I need to get them merged, and the latter is failing because of something in ChainRules ... which is another reason why I need to learn the AD stuff properly

Copy link
Member

@mhauru mhauru left a comment

Choose a reason for hiding this comment

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

Happy with the code, thanks. Just needs tests to pass.

The benchmarks are failing because of a numerically inaccurate Cholesky link/invlink.

Ergh. Why doesn't StableRNGs and seed-fixing save us?

@penelopeysm
Copy link
Member Author

We need to find a seed that doesn't fail 😅
It's actually Bijectors#357 that will fix it 'for good', unfortunately that's a more involved one

@penelopeysm
Copy link
Member Author

(But the tl;dr is that inv/linking LKJCholesky is numerically quite unstable, even for what might be considered 'sensible' inputs. If you're really curious it's explained in those PRs)

Copy link
Contributor

github-actions bot commented Mar 12, 2025

Benchmark Report for Commit fcad3763ea3fe9c495af5b2665b2779f40952b3d

Computer Information

Julia Version 1.11.4
Commit 8561cc3d68d (2025-03-10 11:36 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 4 × AMD EPYC 7763 64-Core Processor
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, znver3)
Threads: 1 default, 0 interactive, 1 GC (on 4 virtual cores)

Benchmark Results

|                 Model | Dimension |  AD Backend |      VarInfo Type | Linked | Eval Time / Ref Time | AD Time / Eval Time |
|-----------------------|-----------|-------------|-------------------|--------|----------------------|---------------------|
| Simple assume observe |         1 | forwarddiff |             typed |  false |                  9.6 |                 1.6 |
|           Smorgasbord |       201 | forwarddiff |             typed |  false |                621.0 |                42.6 |
|           Smorgasbord |       201 | forwarddiff | simple_namedtuple |   true |                425.4 |                47.7 |
|           Smorgasbord |       201 | forwarddiff |           untyped |   true |               1245.9 |                28.0 |
|           Smorgasbord |       201 | forwarddiff |       simple_dict |   true |               3750.4 |                21.2 |
|           Smorgasbord |       201 | reversediff |             typed |   true |               1479.2 |                29.8 |
|           Smorgasbord |       201 |    mooncake |             typed |   true |                948.5 |                 5.4 |
|    Loop univariate 1k |      1000 |    mooncake |             typed |   true |               5633.2 |                 5.2 |
|       Multivariate 1k |      1000 |    mooncake |             typed |   true |               1127.9 |                 8.4 |
|   Loop univariate 10k |     10000 |    mooncake |             typed |   true |              62119.6 |                 4.6 |
|      Multivariate 10k |     10000 |    mooncake |             typed |   true |               9277.7 |                 9.5 |
|               Dynamic |        10 |    mooncake |             typed |   true |                129.0 |                12.9 |
|              Submodel |         1 |    mooncake |             typed |   true |                 25.8 |                 7.7 |
|                   LDA |        12 | reversediff |             typed |   true |                452.8 |                 4.8 |

@penelopeysm
Copy link
Member Author

penelopeysm commented Mar 12, 2025

@mhauru I fixed the benchmarks by adding more StableRNGs. As for the failing tests, the error message points to a Julia 1.10.0 bug (our CI is being run on 'min', which resolves to the lowest possible version).

Internal error: encountered unexpected error in runtime:
MethodError(f=Core.Compiler.widenconst, args=(Base.ComposedFunction{typeof(Base.identity), Base.Fix1{Type{Base.MappingRF{F, T} where T where F}, typeof(Aqua.aspkgid)}}(outer=typeof(Base.identity)(), inner=Base.Fix1{Type{Base.MappingRF{F, T} where T where F}, typeof(Aqua.aspkgid)}(f=Base.MappingRF{F, T} where T where F, x=typeof(Aqua.aspkgid)())),), world=0x00000000000015a8)
jl_method_error_bare at /cache/build/builder-amdci4-6/julialang/julia-release-1-dot-10/src/gf.c:2208
jl_method_error at /cache/build/builder-amdci4-6/julialang/julia-release-1-dot-10/src/gf.c:2226
jl_lookup_generic_ at /cache/build/builder-amdci4-6/julialang/julia-release-1-dot-10/src/gf.c:3057 [inlined]
ijl_apply_generic at /cache/build/builder-amdci4-6/julialang/julia-release-1-dot-10/src/gf.c:3072

There must be some bug on there that does not let Aqua run properly. When I test locally with 1.10.9, it runs just fine. (Edit: actually when I test locally with 1.10.0 it runs fine too, so the bug is presumably restricted to the CI runner, maybe Linux)

So there are a couple of options:

  1. Bump the julia compat in Project.toml to the minimum patch version of 1.10 that lets Aqua run on CI. This seems a bit unnecessary because DPPL itself still works just fine on 1.10.0.
  2. Skip Aqua tests on 1.10 and assume that passing on 1.11 is a good enough indicator

Of these options, I think I prefer (2). What say you?

Copy link
Member

@mhauru mhauru left a comment

Choose a reason for hiding this comment

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

Of these options, I think I prefer (2). What say you?

Agreed. Would be a shame to bump compat just because of a silly testing thing.

@penelopeysm penelopeysm enabled auto-merge March 13, 2025 16:56
@penelopeysm penelopeysm added this pull request to the merge queue Mar 13, 2025
Merged via the queue into main with commit b0818b9 Mar 13, 2025
16 of 19 checks passed
@penelopeysm penelopeysm deleted the py/aqua branch March 13, 2025 17:52
@penelopeysm penelopeysm mentioned this pull request Mar 14, 2025
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.

3 participants