-
Notifications
You must be signed in to change notification settings - Fork 80
Remove implicit broadcast for Grad
#1458
Conversation
We want to disallow the following: ```julia using StaticArrays using ClimateMachine.VariableTemplates function vs(FT) @vars begin a::FT end end FT = Float64 arr = fill!(MArray{Tuple{3, 1}, FT}(undef), 0) g = Grad{vs(FT)}(arr) g.a = 4 # changes arr to [4 4 4] g.a = [5] # changes arr to [5 5 5] ```
bors try |
1 similar comment
bors try |
tryAlready running a review |
So this didn't break anything... |
Not sure if anyone has any better solutions / suggestions cc: @vchuravy, @kpamnany, @simonbyrne, @jakebolewski, @leios |
I read the issue and your presentation of the options was clear. I think the proposed choice was the best of the options -- unintended behavior is a terrible thing. Good find! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be great to merge 👍
I just realized that I'm getting an error with these changes in the EDMF branch: function flux_first_order!(
turbconv::EDMF{FT},
m::AtmosModel{FT},
flux::Grad,
state::Vars,
aux::Vars,
t::Real,
) where {FT}
up_f = flux.turbconv.updraft
...
for i in 1:N_up
ρa_i = enforce_unit_bounds(up[i].ρa)
up_f[i].ρa .= up[i].ρaw # <-------line 855 in edmf_kernels.jl
end Stack trace:
Ah, but this is precisely the issue. Let me see if I can wrap the RHS with |
I thought that this was the bug we wanted to avoid? |
Yes, it is. The PR is fine and does fix the problem. I was just confused at first by the error 😄 |
Cool. I'm fine with this being merged unless @simonbyrne wants to comment. |
bors r+ |
1537: Use static range in Grad setproperty! r=mwarusz a=mwarusz # Description After #1458 I noticed a slowdown. This PR proposes a fix. Running ```julia --project=. experiments/AtmosLES/bomex_les.jl --monitor-timestep-duration 100steps``` I get Before: ``` ┌ Info: Wall-clock time per time-step (statistics across MPI ranks) │ maximum (s) = 1.5273617989999998e-02 │ minimum (s) = 1.5273617989999998e-02 │ median (s) = 1.5273617989999998e-02 └ std (s) = NaN ``` After: ``` Info: Wall-clock time per time-step (statistics across MPI ranks) │ maximum (s) = 1.1554147779999999e-02 │ minimum (s) = 1.1554147779999999e-02 │ median (s) = 1.1554147779999999e-02 └ std (s) = NaN ``` The fix relies on unexported `StaticArrays` API but JuliaArrays/StaticArrays.jl#474 makes me think that this is ok. 1538: Rename step (intrinsic func) r=charleskawczynski a=charleskawczynski # Description Closes #95. Co-authored-by: Maciej Waruszewski <[email protected]> Co-authored-by: Charles Kawczynski <[email protected]>
1537: Use static range in Grad setproperty! r=mwarusz a=mwarusz # Description After #1458 I noticed a slowdown. This PR proposes a fix. Running ```julia --project=. experiments/AtmosLES/bomex_les.jl --monitor-timestep-duration 100steps``` I get Before: ``` ┌ Info: Wall-clock time per time-step (statistics across MPI ranks) │ maximum (s) = 1.5273617989999998e-02 │ minimum (s) = 1.5273617989999998e-02 │ median (s) = 1.5273617989999998e-02 └ std (s) = NaN ``` After: ``` Info: Wall-clock time per time-step (statistics across MPI ranks) │ maximum (s) = 1.1554147779999999e-02 │ minimum (s) = 1.1554147779999999e-02 │ median (s) = 1.1554147779999999e-02 └ std (s) = NaN ``` The fix relies on unexported `StaticArrays` API but JuliaArrays/StaticArrays.jl#474 makes me think that this is ok. Co-authored-by: Maciej Waruszewski <[email protected]>
We want to disallow the following:
This is not a perfect solution though, because it will result in the sort of unclear error:
close #1457