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 test error with Turing >= 0.30 #570

Merged
merged 5 commits into from
Jan 22, 2024
Merged

Fix test error with Turing >= 0.30 #570

merged 5 commits into from
Jan 22, 2024

Conversation

devmotion
Copy link
Member

The PR updates the Turing tests for the changes in version 0.30.

I expect that the LKJ tests still fail due to an unfortunate behaviour of LinearAlgebra in Julia 1.10:

julia> using LinearAlgebra

julia> X = convert(Matrix{Real}, rand(2, 2))
2×2 Matrix{Real}:
 0.550882  0.54726
 0.921542  0.647784

julia> typeof(X)
Matrix{Real} (alias for Array{Real, 2})

julia> UpperTriangular(X)' * UpperTriangular(X)
ERROR: InexactError: Int64(0.30147568734789565)
Stacktrace:
 [1] Int64
   @ Base ./float.jl:909 [inlined]
 [2] convert(::Type{Int64}, x::Float64)
   @ Base ./number.jl:7
 [3] setindex!
   @ ./array.jl:1024 [inlined]
 [4] generic_trimatmul!(C::Matrix{…}, uploc::Char, isunitc::Char, tfun::typeof(adjoint), A::Matrix{…}, B::UpperTriangular{…})
   @ LinearAlgebra ~/.asdf/installs/julia/1.10.0/share/julia/stdlib/v1.10/LinearAlgebra/src/triangular.jl:946
 [5] _trimul!
   @ LinearAlgebra ~/.asdf/installs/julia/1.10.0/share/julia/stdlib/v1.10/LinearAlgebra/src/triangular.jl:711 [inlined]
 [6] mul!
   @ LinearAlgebra ~/.asdf/installs/julia/1.10.0/share/julia/stdlib/v1.10/LinearAlgebra/src/triangular.jl:693 [inlined]
 [7] *(A::LowerTriangular{Real, Adjoint{Real, Matrix{Real}}}, B::UpperTriangular{Real, Matrix{Real}})
   @ LinearAlgebra ~/.asdf/installs/julia/1.10.0/share/julia/stdlib/v1.10/LinearAlgebra/src/triangular.jl:1463
 [8] top-level scope
   @ REPL[7]:1
Some type information was truncated. Use `show(err)` to see complete types.

julia> LowerTriangular(X) * LowerTriangular(X)'
ERROR: InexactError: Int64(0.5076607013553399)
Stacktrace:
 [1] Int64
   @ Base ./float.jl:909 [inlined]
 [2] convert(::Type{Int64}, x::Float64)
   @ Base ./number.jl:7
 [3] setindex!
   @ ./array.jl:1024 [inlined]
 [4] generic_trimatmul!(C::Matrix{Int64}, uploc::Char, isunitc::Char, tfun::typeof(identity), A::Matrix{Real}, B::UpperTriangular{Real, Adjoint{Real, Matrix{Real}}})
   @ LinearAlgebra ~/.asdf/installs/julia/1.10.0/share/julia/stdlib/v1.10/LinearAlgebra/src/triangular.jl:958
 [5] _trimul!
   @ LinearAlgebra ~/.asdf/installs/julia/1.10.0/share/julia/stdlib/v1.10/LinearAlgebra/src/triangular.jl:711 [inlined]
 [6] mul!
   @ LinearAlgebra ~/.asdf/installs/julia/1.10.0/share/julia/stdlib/v1.10/LinearAlgebra/src/triangular.jl:693 [inlined]
 [7] *(A::LowerTriangular{Real, Matrix{Real}}, B::UpperTriangular{Real, Adjoint{Real, Matrix{Real}}})
   @ LinearAlgebra ~/.asdf/installs/julia/1.10.0/share/julia/stdlib/v1.10/LinearAlgebra/src/triangular.jl:1463
 [8] top-level scope
   @ REPL[14]:1

julia> versioninfo()
Julia Version 1.10.0
Commit 3120989f39b (2023-12-25 18:01 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (arm64-apple-darwin22.4.0)
  CPU: 10 × Apple M2 Pro
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, apple-m1)
  Threads: 1 on 6 virtual cores
Environment:
  JULIA_PKG_USE_CLI_GIT = true

On previous Julia versions this example worked:

julia> using LinearAlgebra

julia> X = convert(Matrix{Real}, rand(2, 2))
2×2 Matrix{Real}:
 0.811948  0.080013
 0.10377   0.688589

julia> UpperTriangular(X)' * UpperTriangular(X)
2×2 Matrix{Real}:
 0.659259   0.0649664
 0.0649664  0.480556

julia> LowerTriangular(X) * LowerTriangular(X)'
2×2 Matrix{Real}:
 0.659259   0.0842561
 0.0842561  0.484923

julia> versioninfo()
Julia Version 1.9.4
Commit 8e5136fa297 (2023-11-14 08:46 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (arm64-apple-darwin22.4.0)
  CPU: 10 × Apple M2 Pro
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-14.0.6 (ORCJIT, apple-m1)
  Threads: 1 on 6 virtual cores
Environment:
  JULIA_PKG_USE_CLI_GIT = true

On the Julia master branch the problem was fixed (maybe in JuliaLang/julia#52464?) but I wonder if we could make the Vector{Real} that shows up in DynamicPPL and Bijectors in the first place to avoid this problem also on Julia 1.10. Alternatively, we could use Bijectors.pd_upper(X) = collect(UpperTriangular(X)') * collect(UpperTriangular(X)) etc. on Julia 1.10.

test/turing/compiler.jl Outdated Show resolved Hide resolved
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Copy link
Contributor

github-actions bot commented Jan 21, 2024

Pull Request Test Coverage Report for Build 7604303730

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+4.8%) to 84.62%

Totals Coverage Status
Change from base Build 7506113239: 4.8%
Covered Lines: 2674
Relevant Lines: 3160

💛 - Coveralls

Copy link

codecov bot commented Jan 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (c6e3b6b) 79.64% compared to head (bcaf02c) 84.30%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #570      +/-   ##
==========================================
+ Coverage   79.64%   84.30%   +4.65%     
==========================================
  Files          26       26              
  Lines        2938     3172     +234     
==========================================
+ Hits         2340     2674     +334     
+ Misses        598      498     -100     

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

@devmotion devmotion requested a review from torfjelde January 22, 2024 01:06
Copy link
Member

@torfjelde torfjelde left a comment

Choose a reason for hiding this comment

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

LGTM with the one outstanding comment/question: should we bump the version used in CI to work with test/turing?

test/turing/Project.toml Show resolved Hide resolved
@torfjelde
Copy link
Member

Feel free to hit merge whenever!

@devmotion devmotion enabled auto-merge January 22, 2024 15:48
@devmotion devmotion added this pull request to the merge queue Jan 22, 2024
Merged via the queue into master with commit 39751b1 Jan 22, 2024
14 checks passed
@devmotion devmotion deleted the dw/fix_tests branch January 22, 2024 17:31
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