-
Notifications
You must be signed in to change notification settings - Fork 10
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
Remove overloaded getindex #314
Conversation
We can merge this first #315 and then in this PR, after rebasing, add back in the Aqua piracy test. |
@charleskawczynski could you review this? I cant tag you since it is your PR :) |
@@ -483,9 +483,10 @@ function ClimaLSM.make_update_aux( | |||
) | |||
) / 2 | |||
end | |||
@. β = moisture_stress(ψ[n_stem + n_leaf] * ρ_l * grav, sc, pc) | |||
# We update the fa[n_stem+n_leaf] element once we have computed transpiration, below | |||
i_end = n_stem + n_leaf |
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.
likewise here, and Im not totally clear on the rules around broadcasting -> use $$ but this seemed to give what we want!
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.
Same as above, I think it's fine to add an intermediate if it helps fix this issue.
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.
Do we need to use two $$
if we have a broadcast inside of a loop because the broadcast and loop are each an expression, so we need to interpolate the index value twice? If we have a broadcast outside of a loop, do we use just one $
?
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.
If we broadcast outside of a loop with a known index (like 2), we dont need any dollar signs:
julia> @. ψ.:2 = PlantHydraulics.water_retention_curve(
retention_model,
PlantHydraulics.effective_saturation(ν, ϑ_l.:2),
ν,
S_s,
)
Float64-valued Field:
[203.938]
If we want to index at the result of an expression, it doesnt really work. I think we need to define the intermediate i_end = n_stem+n_leaf.
julia> @. ψ.:$(n_stem+n_leaf) = PlantHydraulics.water_retention_curve(
retention_model,
PlantHydraulics.effective_saturation(ν, ϑ_l.:$(n_stem+n_leaf)),
ν,
S_s,
)
ERROR: syntax: "(n_stem + n_leaf)" is not a valid function argument name around REPL[118]:1
@@ -506,7 +507,7 @@ function ClimaLSM.make_update_aux( | |||
canopy_surface_fluxes(canopy.atmos, canopy, Y, p, t) | |||
transpiration .= canopy_transpiration | |||
# Transpiration is per unit ground area, not leaf area (mult by LAI) | |||
fa[n_stem + n_leaf] .= PlantHydraulics.transpiration_per_ground_area( | |||
fa.:($i_end) .= PlantHydraulics.transpiration_per_ground_area( |
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.
not totally sure why we needed the $ here, either, since this is not in a loop.
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.
We can/should probably document how this is working (with the single vs double $
), but it looks fine to me
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 agree that we should document how the indexing works now, Ill add some comments!
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'm also confused about why we use a $
here - shouldn't it just be fa.:i_end
?
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.
Im not sure. the :i_end
notation says to look for the field associated with the symbol i_end
if I understand correctly, and so it doesnt work here.
julia> i_end = n_stem+n_leaf
11
julia> fa.:i_end
ERROR: Invalid field name i_end for type NTuple{11, Float64}
This doesnt work either:
julia> fa.:($(n_stem+n_leaf))
ERROR: syntax: invalid syntax "fa.((n_stem + n_leaf))" around REPL[104]:1
Stacktrace:
[1] top-level scope
@ REPL[104]:1
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.
The integer needs $
to be interpolated otherwise the symbol (used to call getproperty(fa, ::Symbol)
) is :i_end
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.
Looks good to me!
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.
Looks good! I just had a couple of questions about places that weren't clear to me
@@ -483,9 +483,10 @@ function ClimaLSM.make_update_aux( | |||
) | |||
) / 2 | |||
end | |||
@. β = moisture_stress(ψ[n_stem + n_leaf] * ρ_l * grav, sc, pc) | |||
# We update the fa[n_stem+n_leaf] element once we have computed transpiration, below | |||
i_end = n_stem + n_leaf |
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.
Do we need to use two $$
if we have a broadcast inside of a loop because the broadcast and loop are each an expression, so we need to interpolate the index value twice? If we have a broadcast outside of a loop, do we use just one $
?
@@ -506,7 +507,7 @@ function ClimaLSM.make_update_aux( | |||
canopy_surface_fluxes(canopy.atmos, canopy, Y, p, t) | |||
transpiration .= canopy_transpiration | |||
# Transpiration is per unit ground area, not leaf area (mult by LAI) | |||
fa[n_stem + n_leaf] .= PlantHydraulics.transpiration_per_ground_area( | |||
fa.:($i_end) .= PlantHydraulics.transpiration_per_ground_area( |
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'm also confused about why we use a $
here - shouldn't it just be fa.:i_end
?
Remove setindex/getindex overloading Remove getindex overloading Remove getindex overloading wip, trouble in loops tests pass aqua piracy turned on address two compat updates from compathelper as well made beta use same notation added comments regarding usage of getproperty
bors r+ |
Build succeeded! The publicly hosted instance of bors-ng is deprecated and will go away soon. If you want to self-host your own instance, instructions are here. If you want to switch to GitHub's built-in merge queue, visit their help page. |
314: Remove overloaded getindex r=kmdeck a=charleskawczynski This PR removes the overloading of `getindex` on ClimaCore fields. also closes #317 #312 We access the individual fields within the Field of Tuples using the following rules: Previously, regardless of in a loop or not: ``` field[i] .= .... `@.` field[i] = g(other field) ``` Now: outside of a loop: ``` field.:i .= ... ``` Now: inside of a loop: ``` field.:($i) .= `@.` field.:($$i) = ``` We also need to sometimes access elements that are compute quantities, for example, before, ``` field[n_stem+n_leaf] .= ``` Now, we need to do something like: ``` i_end =n_stem+n_leaf # define intermediate quantity field.:($i_end) .= ``` regardless of if we are in a loop or not. Co-authored-by: Charles Kawczynski <kawczynski.charles@gmail.com>
This PR removes the overloading of
getindex
on ClimaCore fields.also closes #317 #312
We access the individual fields within the Field of Tuples using the following rules:
Previously, regardless of in a loop or not:
Now: outside of a loop:
Now: inside of a loop:
We also need to sometimes access elements that are compute quantities, for example, before,
Now, we need to do something like:
regardless of if we are in a loop or not.