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

WIP: build basic toml format #57

Closed
wants to merge 6 commits into from
Closed

WIP: build basic toml format #57

wants to merge 6 commits into from

Conversation

simonbyrne
Copy link
Member

Basic example:

julia> using CLIMAParameters
[ Info: Precompiling CLIMAParameters [6eacf6c3-8458-43b9-ae03-caf5306d3d53]

julia> paramset = DefaultParameterSet()
DefaultParameterSet()

julia> value(paramset, CLIMAParameters.MolarMassConstant())
8.3144598

@simonbyrne simonbyrne mentioned this pull request Jan 10, 2022
@simonbyrne
Copy link
Member Author

simonbyrne commented Jan 10, 2022

I've added support for getproperty overloading, based on symbols

julia> paramset = DefaultParameterSet()
DefaultParameterSet()

julia> paramset.M_d
0.02897

julia> paramset.R
8.3144598

This means that you can also use @unpack, or in the new Julia property destructuring:

julia> (;M_d, R) = paramset
DefaultParameterSet()

julia> M_d
0.02897

@odunbar
Copy link
Contributor

odunbar commented Feb 9, 2022

Moved to new branch orad/refactor-parameters-v2

bors bot added a commit that referenced this pull request May 18, 2022
62: [WIP] pilot parameter refactor r=odunbar a=odunbar

## Purpose of this PR
Relating to issues #57 
Provides a toml format for other packages to use. Currently see 
- PR [83](CliMA/Thermodynamics.jl#83) on `Clima/Thermodynamics`
- PR [55](CliMA/CloudMicrophysics.jl#55) on `Clima/CloiudMicrophysics` 

Also we can now write **re-readable** log files

## In this PR
- Documentation! See  the latest documentor build below.
- New wrapper ```ParamDict{FT}```around dictionary read from toml. Currently parametric on one type of all the values, provided when it is built (default is `Float64`). Construction:
```julia
create_parameter_struct(override_filepath, default_filepath; dict_type="alias",value_type=Float64) # builds with override and custom default provided
create_parameter_struct(override_filepath ; dict_type="alias",value_type=Float64) # builds, overriding the default from CLIMAParameters
create_parameter_struct(; dict_type="alias",value_type=Float64) # builds using only default in CLIMAParameters
```
- Automated parameter logging on reading parameter values: (can do multiple parameters at once). At the call of this function, the type is enforced on the return values.
```julia 
get_parameter_values!(pd::ParamDict, names, component; log_component=true) #logs component in pd
get_parameter_values(pd::ParamDict,names) # no logging in pd
```
- writing the re-readable log file in `log_parameter_information(pd::ParamDict,filepath)`. Example parameter tested in `CloudMicrophysics.jl`:
```toml
# initial parameter file
[molar_mass_water]
alias = "molmass_water"
value = 0.01801528
type = "float"
```
In this test, a copy of the parameters was created and stored in (1) Thermodynamics, (2) the general CloudMicrophysics, and (3) the specific 1-moment-based Microphysics scheme. Indeed the logfile shows this information below
```toml
# log file
[molar_mass_water]
alias = "molmass_water"
value = 0.01801528
type = "float"
used_in = ["Thermodynamics", "CloudMicrophysicsParameters", "Microphysics_1M_Parameters"]
```
The `log_parameter_information(pd::ParamDict,filepath; warn_else_error="warn")` will also throw warnings if a parameter is in the override file, but unused in the simulation. This works as parameters from the override file are checked for whether they have gained a "used_in" tag, if not found then an this is logged as a warning or error
- From PR #65, reading of array-type parameters
- From PR #68, reading and writing for calibration tools
### TODO
- still using alias based structs
- still based on float, and array-of-float parameters


Co-authored-by: odunbar <[email protected]>
@trontrytel
Copy link
Member

Can we close this one @simonbyrne?

@charleskawczynski
Copy link
Member

Superseded by #62

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.

4 participants