Conversation
|
This change is part of the following stack: Change managed by git-spice. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #700 +/- ##
==========================================
- Coverage 94.98% 92.28% -2.70%
==========================================
Files 53 54 +1
Lines 2371 2269 -102
==========================================
- Hits 2252 2094 -158
- Misses 119 175 +56
🚀 New features to boost your workflow:
|
6b4ed07 to
9215200
Compare
1f4a917 to
7f380dc
Compare
haakon-e
left a comment
There was a problem hiding this comment.
comments to assist review
| # Developer docs | ||
|
|
||
| ```@autodocs | ||
| Modules = [ShowMethods] | ||
| ``` |
There was a problem hiding this comment.
The additional method signatures can be viewed in the doc preview
| CMP.ParametersP3{Float64} | ||
| CMP.ParametersP3(::Float64) | ||
| CMP.ParametersP3(::Parameters.CP.ParamDict) | ||
| CMP.ParametersP3 |
There was a problem hiding this comment.
got some doc errors with this, so simplifying for now, will return improve this in a later PR
|
|
||
|
|
||
| # Temporary fallback until we stop checking eltype from the parameters | ||
| Base.eltype(p::ParametersType) = fieldcount(typeof(p)) > 0 ? eltype(getfield(p, 1)) : Any |
There was a problem hiding this comment.
will remove this method in a future breaking PR
| H2SO4SolutionParameters(::Type{FT}) where {FT <: AbstractFloat} = | ||
| H2SO4SolutionParameters(CP.create_toml_dict(FT)) | ||
|
|
There was a problem hiding this comment.
Definitions such as this is moved to src/parameters/Parameters.jl, which defines this for all subtypes of ParametersType
| FT = CP.float_type(td) | ||
| return H2SO4SolutionParameters{FT}(; parameters...) | ||
| return H2SO4SolutionParameters(; parameters...) |
There was a problem hiding this comment.
Removed these type flags where I could find them as they're unnecessary since all fields returned from CP.get_parameter_values have uniform FT type already.
| # Fields | ||
| $(DocStringExtensions.FIELDS) | ||
| """ | ||
| Base.@kwdef struct H2SO4SolutionParameters{FT} <: ParametersType{FT} |
There was a problem hiding this comment.
@kwdef is always available, no need for Base. prefix. Did a search and replace to remove them.
| ### Create methods that enables the creation of parameter types with a given float type | ||
| ### for all subtypes of `ParametersType` | ||
| ### e.g. `Microphysics1MParams(Float32)` | ||
| import InteractiveUtils |
There was a problem hiding this comment.
InteractiveUtils is already shipped with the julia standard library, so this is not in reality a new dependency. We do need to add it to the Project.toml file though.
| return concrete_types | ||
| end | ||
| for T in get_concrete_subtypes(ParametersType) | ||
| @eval (::Type{$T})(::Type{FT}; kw...) where {FT} = $T(CP.create_toml_dict(FT); kw...) |
There was a problem hiding this comment.
For future reference: The reason I needed to define these in a loop over concrete subtypes of ParametersType as opposed to simply defining the method
(::Type{T}(::Type{FT}; kw...) where {T <: ParametersType, FT} =
T(CP.create_toml_dict(FT); kw...)is that this results in Aqua/Test complaining about ambiguous method definitions for structs with one field. For example,
@kwdef struct NumberAdjustmentHorn2012{FT} <: ParametersType
"Number concentration adjustment timescale [s]"
τ::FT
enddefines the method
(::Type{NumberAdjustmentHorn2012})(τ::Any)Here, the struct is more concrete, while the argument is less concrete. With the method above, the struct is less concrete while the argument (::Type{FT}) is more concrete. In practice, it appears that julia is able to resolve this apparent ambiguity, so it may be a bug in Test/Aqua.
The @eval loop instead defines
(::Type{NumberAdjustmentHorn2012})(::Type{FT}) where {FT} = ...for every subtype of ParametersType, circumventing this potential method ambiguity problem.
e0cb5b6 to
35f69b6
Compare
35f69b6 to
62241f0
Compare
0459d67 to
3bc6212
Compare
|
Amazing! Thank you so much for carrying out for the whole repo. |
trontrytel
left a comment
There was a problem hiding this comment.
Thank you!
I was wondering if we can replace some of the parameter printing here: https://clima.github.io/CloudMicrophysics.jl/dev/guides/literated/Parameters/
with the new show. But I can also do it in a separate PR
|
Is this a breaking release from ClimaAtmos point of view in any way? |
|
Closes #573 |
be4ca3d to
6fa6924
Compare
- add constructor using float type (e.g. Float32)
for all param structs
- remove explicit type declarations where not needed
- clean up some constructors
6fa6924 to
1080882
Compare
1080882 to
c909c1a
Compare
Let's do it separately, since the
I don't think so, but I won't make a release here until the P3 PR is merged anyways, and I have a corresponding PR in Atmos |
Summary
This pull request refactors the type hierarchy and usage of parameterized types throughout the codebase to simplify type signatures and improve code clarity. The main change is the removal of the floating-point type parameter (
FT) from many struct definitions and function signatures, in favor of storing the floating-point type only where necessary (typically as fields rather than in the type itself). This results in shorter, more readable type signatures and reduces the need for repeated type parameters in function definitions. Additionally, some keyword argument usage is improved for clarity.The PR is organized with two commits:
show.jlmethodsContent
Type System Simplification and Refactoring:
ParametersTypeno longer has theFTfield in type space. For backward compatibility, theeltypefunction remains, and recursively looks up the first argument of the concrete struct. Within microphysics parameterizations,FTshould instead be fetched from the state.FT, no longer carry this information in type space.API and Usability Improvements:
SB2006objects in plotting scripts now uses keyword arguments for clarity (is_limited = false), replacing positional boolean arguments. [1] [2] [3]Struct printing
showmethods (seeshow.jl) that structs can use to enable pretty-printing of their contents.ParametersType) with more than 7 elements will be verbosely printed, and otherwise tersely printed. Printing is recursive, as the example below illustrates.Other Minor Improvements:
Base.prefix from@kwdefmacro as it is directly available.