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

Vector convenience functions cause errors on nightly Julia builds #28

Open
dingraha opened this issue Jan 3, 2024 · 4 comments
Open

Comments

@dingraha
Copy link
Collaborator

dingraha commented Jan 3, 2024

When I try to create eg a vector of Section structs with nightly builds of Julia, like this:

(jl_DjwQyJ) pkg> using CCBlade
ERROR: `using` is not a recognized command. Type ? for help with available commands

julia> using CCBlade

julia> radii = range(0.1, 1.0; length=10)
0.1:0.1:1.0

julia> chord = similar(radii)
10-element Vector{Float64}:
 6.9368548214818e-310
 6.9369127073666e-310
 6.93690470785607e-310
 6.93685482148497e-310
 6.9369056525649e-310
 6.93685482148813e-310
 6.9368548214913e-310
 6.93691005160844e-310
 6.9369127073666e-310
 6.9369057171642e-310

julia> theta = similar(radii)
10-element Vector{Float64}:
 5.4e-323
 5.0e-324
 5.0e-323
 4.4e-323
 4.0e-323
 3.5e-323
 2.5e-323
 3.0e-323
 2.0e-323
 1.5e-323

julia> sections = Section.(radii, chord, theta, alpha->(1.0, 1.0))
ERROR: type Section has no field ref
Stacktrace:
  [1] _broadcast_getindex_evalf
    @ ./broadcast.jl:677 [inlined]
  [2] _broadcast_getindex
    @ ./broadcast.jl:650 [inlined]
  [3] getindex
    @ ./broadcast.jl:604 [inlined]
  [4] copy
    @ ./broadcast.jl:910 [inlined]
  [5] materialize
    @ ./broadcast.jl:871 [inlined]
  [6] getproperty(obj::Vector{Section{Float64, var"#7#8"}}, sym::Symbol)
    @ CCBlade ~/.julia/packages/CCBlade/5jTbo/src/CCBlade.jl:91
  [7] dataids(A::Vector{Section{Float64, var"#7#8"}})
    @ Base ./abstractarray.jl:1555
  [8] mightalias
    @ Base ./abstractarray.jl:1530 [inlined]
  [9] unalias
    @ Base ./abstractarray.jl:1495 [inlined]
 [10] broadcast_unalias
    @ Base.Broadcast ./broadcast.jl:945 [inlined]
 [11] preprocess
    @ Base.Broadcast ./broadcast.jl:952 [inlined]
 [12] preprocess_args (repeats 2 times)
    @ Base.Broadcast ./broadcast.jl:954 [inlined]
 [13] preprocess
    @ Base.Broadcast ./broadcast.jl:951 [inlined]
 [14] copyto!
    @ Base.Broadcast ./broadcast.jl:968 [inlined]
 [15] copyto!
    @ Base.Broadcast ./broadcast.jl:924 [inlined]
 [16] copy
    @ Base.Broadcast ./broadcast.jl:896 [inlined]
 [17] materialize(bc::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{1}, Nothing, Type{Section}, Tuple{StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, Vector{Float64}, Vector{Float64}, Base.RefValue{var"#7#8"}}})
    @ Base.Broadcast ./broadcast.jl:871
 [18] top-level scope
    @ REPL[8]:1

julia> versioninfo()
Julia Version 1.11.0-DEV.1187
Commit ca0a266e4f6 (2024-01-03 13:34 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 12 × Intel(R) Core(TM) i7-10850H CPU @ 2.70GHz
  WORD_SIZE: 64
  LLVM: libLLVM-15.0.7 (ORCJIT, skylake)
Threads: 1 default, 0 interactive, 1 GC (on 12 virtual cores)
Environment:
  JULIA_PKG_SERVER = us-east.pkg.julialang.org

(jl_DjwQyJ) pkg> st
Status `/tmp/jl_DjwQyJ/Project.toml`
  [e1828068] CCBlade v0.2.5

(jl_DjwQyJ) pkg> 

I get an error that appears to be related to the convenience functions used to access individual fields of a Vector{<:Section}:

function Base.getproperty(obj::AbstractVector{<:Section}, sym::Symbol)

If I remove that function, then the error goes away:

shell> nvr ./dev/CCBlade/src/CCBlade.jl # Remove Base.getproperty(obj::AbstractVector{<:Section}, sym::Symbol)

julia> using CCBlade
Precompiling CCBlade
  1 dependency successfully precompiled in 3 seconds. 59 already precompiled.

julia> radii = range(0.1, 1.0; length=10)
0.1:0.1:1.0

julia> chord = similar(radii)
10-element Vector{Float64}:
 6.9321471006254e-310
 6.9321549093946e-310
 6.93215490939933e-310
 6.93215490940407e-310
 6.9321471855873e-310
 6.93214830413057e-310
 6.93215490940723e-310
 6.9321549094104e-310
 6.93215490941356e-310
 6.9321549094167e-310

julia> theta = similar(radii)
10-element Vector{Float64}:
 0.0
 1.390671161567e-309
 0.0
 0.0
 1.390671161567e-309
 0.0
 0.0
 1.265e-321
 0.0
 0.0

julia> sections = Section.(radii, chord, theta, alpha->(1.0, 1.0))
10-element Vector{Section{Float64, var"#7#8"}}:
 Section{Float64, var"#7#8"}(0.1, 6.9321471006254e-310, 0.0, var"#7#8"())
 Section{Float64, var"#7#8"}(0.2, 6.9321549093946e-310, 1.390671161567e-309, var"#7#8"())
 Section{Float64, var"#7#8"}(0.3, 6.93215490939933e-310, 0.0, var"#7#8"())
 Section{Float64, var"#7#8"}(0.4, 6.93215490940407e-310, 0.0, var"#7#8"())
 Section{Float64, var"#7#8"}(0.5, 6.9321471855873e-310, 1.390671161567e-309, var"#7#8"())
 Section{Float64, var"#7#8"}(0.6, 6.93214830413057e-310, 0.0, var"#7#8"())
 Section{Float64, var"#7#8"}(0.7, 6.93215490940723e-310, 0.0, var"#7#8"())
 Section{Float64, var"#7#8"}(0.8, 6.9321549094104e-310, 1.265e-321, var"#7#8"())
 Section{Float64, var"#7#8"}(0.9, 6.93215490941356e-310, 0.0, var"#7#8"())
 Section{Float64, var"#7#8"}(1.0, 6.9321549094167e-310, 0.0, var"#7#8"())

julia> versioninfo()
Julia Version 1.11.0-DEV.1187
Commit ca0a266e4f6 (2024-01-03 13:34 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 12 × Intel(R) Core(TM) i7-10850H CPU @ 2.70GHz
  WORD_SIZE: 64
  LLVM: libLLVM-15.0.7 (ORCJIT, skylake)
Threads: 1 default, 0 interactive, 1 GC (on 12 virtual cores)
Environment:
  JULIA_PKG_SERVER = us-east.pkg.julialang.org

julia> 

I know CCBlade doesn't use Julia nightly builds for testing, but I recently ran into this and thought I'd bring it up. The error doesn't occur with any of the stable Julia builds—I checked 1.9.4 and 1.10.0 today.

@dingraha
Copy link
Collaborator Author

Looks like this is happening with stable Julia now, FWIW:

julia> versioninfo()
Julia Version 1.11.2
Commit 5e9a32e7af2 (2024-12-01 20:02 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 12 × Intel(R) Core(TM) i7-10850H CPU @ 2.70GHz
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, skylake)
Threads: 1 default, 0 interactive, 1 GC (on 12 virtual cores)
Environment:
  JULIA_PKG_SERVER = us-east.pkg.julialang.org
  JULIA_PROJECT = /home/dingraha/projects/tcritchfield_bergmann_2024_questions

julia> using CCBlade

julia> radii = range(0.1, 1.0; length=10)
0.1:0.1:1.0

julia> chord = similar(radii)
10-element Vector{Float64}:
 0.0
 5.0e-324
 1.0e-323
 1.5e-323
 2.0e-323
 2.5e-323
 3.0e-323
 3.5e-323
 4.0e-323
 4.4e-323

julia> theta = similar(radii)
10-element Vector{Float64}:
 5.4e-323
 5.0e-323
 4.4e-323
 4.0e-323
 3.5e-323
 3.0e-323
 2.5e-323
 2.0e-323
 1.5e-323
 1.0e-323

julia> sections = Section.(radii, chord, theta, alpha->(1.0, 1.0))
ERROR: type Section has no field ref
Stacktrace:
  [1] _broadcast_getindex_evalf
    @ ./broadcast.jl:673 [inlined]
  [2] _broadcast_getindex
    @ ./broadcast.jl:646 [inlined]
  [3] getindex
    @ ./broadcast.jl:605 [inlined]
  [4] copy
    @ ./broadcast.jl:906 [inlined]
  [5] materialize
    @ ./broadcast.jl:867 [inlined]
  [6] getproperty(obj::Vector{Section{Float64, var"#5#6"}}, sym::Symbol)
    @ CCBlade ~/projects/tcritchfield_bergmann_2024_questions/dev/Bergmann2024RotorPredictions.jl/dev/AcousticAnalogies/dev/CCBlade/src/CCBlade.jl:91
  [7] dataids(A::Vector{Section{Float64, var"#5#6"}})
    @ Base ./abstractarray.jl:1562
  [8] mightalias
    @ ./abstractarray.jl:1537 [inlined]
  [9] unalias
    @ ./abstractarray.jl:1500 [inlined]
 [10] broadcast_unalias
    @ ./broadcast.jl:941 [inlined]
 [11] preprocess
    @ ./broadcast.jl:948 [inlined]
 [12] preprocess_args (repeats 2 times)
    @ ./broadcast.jl:950 [inlined]
 [13] preprocess
    @ ./broadcast.jl:947 [inlined]
 [14] copyto!
    @ ./broadcast.jl:964 [inlined]
 [15] copyto!
    @ ./broadcast.jl:920 [inlined]
 [16] copy
    @ ./broadcast.jl:892 [inlined]
 [17] materialize(bc::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{1}, Nothing, Type{Section}, Tuple{StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, Vector{Float64}, Vector{Float64}, Base.RefValue{var"#5#6"}}})
    @ Base.Broadcast ./broadcast.jl:867
 [18] top-level scope
    @ REPL[50]:1

julia> 

@cibinjoseph
Copy link

cibinjoseph commented Jan 18, 2025

Removing these convenience functions will break outputs.Np and outputs.Tp in the thrusttorque function

CCBlade.jl/src/CCBlade.jl

Lines 646 to 647 in b5e9514

Npfull = [0.0; outputs.Np; 0.0]
Tpfull = [0.0; outputs.Tp; 0.0]

To fix that, something like this would work:

Npfull = zeros(length(outputs)+2)
Tpfull = zeros(length(outputs)+2)
Npfull[2:end-1] .= [output.Np for output in outputs]
Tpfull[2:end-1] .= [output.Tp for output in outputs]

@dingraha
Copy link
Collaborator Author

True! The PR linked above addresses that.

@cibinjoseph
Copy link

@dingraha gotcha! Didn't notice you had made other changes too.

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

No branches or pull requests

2 participants