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

Remove alias field and AliasParamDict functionality, replace with name mapping #154

Merged
merged 5 commits into from
Jan 16, 2024

Conversation

nefrathenrici
Copy link
Member

@nefrathenrici nefrathenrici commented Nov 30, 2023

Purpose

This is part of the larger SDI #144 . The alias field in the TOML dictionary is overly restrictive, but the core functionality of mapping long parameter names to code variable names needs to be maintained.

Content

This PR introduces name maps, which are essentially a dictionary that maps from long parameter names found in the TOML file to short variable names found in code.
This is mainly used in get_parameter_values, which can now take a name map instead of a list of parameter names. get_parameter_values uses the name mapping to find the correct parameters and returns their short names and values in a namedtuple.
Example:

name_map = Dict(
    "gravitational_acceleration" => "g",
    "angular_velocity_planet_rotation" => "omega"
)
params = CP.get_parameter_values(toml_dict, name_map)
params.g
params.omega

A name map does not strictly need to be a Dict. It can be a Vector, Tuple, or Varargs of Pairs.

This replaces the short name alias functionality and makes naming conventions local to specific repositories/modules. The downside here is that each package will have to declare their own name map if they want to use short names for parameter variables effectively.

Here is how I see it being used:

Base.@kwdef struct GrachevParams{FT} <: AbstractUniversalFunctionParameters{FT}
    Pr_0::FT
    a_m::FT
    a_h::FT
    b_m::FT
    b_h::FT
    c_h::FT
    ζ_a::FT
    γ::FT
end

GrachevNameMap = Dict(
    :prandtl_number_0_grachev => :Pr_0,
    :coefficient_a_m_grachev => :a_m,
    :coefficient_a_h_grachev => :a_h,
    :coefficient_b_m_grachev => :b_m,
    :coefficient_b_h_grachev => :b_h,
    :coefficient_c_h_grachev => :c_h,
    :most_stability_parameter_grachev => :ζ_a,
    :most_stability_exponent_grachev => ,
)

UF.GrachevParams(; CP.get_parameter_values(toml_dict, UF.GrachevNameMap)...)

Additional Changes

create_parameter_struct(struct_type, toml_dict; name_map) is a generalized constructor for parameter structs. This already exists in ClimaAtmos, but needs to be moved to ClimaParameters and made a bit less restrictive.

Tests for name maps

alias field removed from the default TOML

Rename docs/src/toml_dict.md to docs/src/param_retrieval.md and add more information. The docs will be improved in a future PR.

Removes get_parameter_values! - logging can still be done via get_parameter_values


  • I have read and checked the items on the review checklist.

Copy link

codecov bot commented Nov 30, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (a780310) 94.73% compared to head (3c03d95) 98.46%.
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #154      +/-   ##
==========================================
+ Coverage   94.73%   98.46%   +3.72%     
==========================================
  Files           1        1              
  Lines         171      130      -41     
==========================================
- Hits          162      128      -34     
+ Misses          9        2       -7     

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

@nefrathenrici nefrathenrici marked this pull request as ready for review November 30, 2023 19:14
@nefrathenrici nefrathenrici changed the title Remove alias field and AliasParamDict functionality, replace with ParameterNameMap Remove alias field and AliasParamDict functionality, replace with name mapping Dec 12, 2023
@nefrathenrici nefrathenrici force-pushed the ne/name_map branch 2 times, most recently from 21b9566 to 6fee7f5 Compare December 13, 2023 20:08
Copy link
Contributor

@odunbar odunbar left a comment

Choose a reason for hiding this comment

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

Hi @nefrathenrici

Looks great! Please merge after addressing the docs comments - I'm glad we finally got to removing the aliases.

docs/src/param_retrieval.md Outdated Show resolved Hide resolved
docs/src/param_retrieval.md Outdated Show resolved Hide resolved
docs/src/param_retrieval.md Outdated Show resolved Hide resolved
docs/src/param_retrieval.md Outdated Show resolved Hide resolved
docs/src/param_retrieval.md Show resolved Hide resolved
docs/src/param_retrieval.md Outdated Show resolved Hide resolved
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