CliMA / TurbulenceConvection.jl

A turbulence-convection single column model cloud parameterization.
https://clima.github.io/TurbulenceConvection.jl/dev/
Apache License 2.0
33 stars 5 forks source link

Improve error message when invalid namelist option is used #435

Open haakon-e opened 3 years ago

haakon-e commented 3 years ago

Consider the error message below. The error is an AssertionError, but it is unhelpful. The path provided in output [2] accurately diagnoses the problem, but the verbosity of the line makes debugging somewhat overwhelming.

I propose to update this assertion https://github.com/CliMA/TurbulenceConvection.jl/blob/416bfe27a09c20dbfce76235d6608c4b3427b34b/src/TurbulenceConvection.jl#L60 to something along the lines of

@assert param in valid_options "$param not in $valid_options for dictionary tree $keys"

Error message:

(base) [hervik@login2 TurbulenceConvection.jl]$ srun -t 02:00:00 -n1 --reservation=clima julia --project integration_tests/utils/main.jl Bomex
[ Info: Using default value, 1000.0, for parameter (microphysics, τ_precip).
[ Info: Using default value, 1000.0, for parameter (microphysics, τ_acnv).
[ Info: Using default value, 0.0, for parameter (turbulence, EDMF_PrognosticTKE, stochastic, entr_lognormal_var).
[ Info: Using default value, 0.0, for parameter (turbulence, EDMF_PrognosticTKE, stochastic, detr_lognormal_var).
ERROR: LoadError: AssertionError: param in valid_options
Stacktrace:
 [1] parse_namelist(::Dict{String, Any}, ::String, ::Vararg{String, N} where N; default::String, valid_options::Vector{String})
   @ TurbulenceConvection /central/groups/esm/hervik/calibration/TurbulenceConvection.jl/src/TurbulenceConvection.jl:60
 [2] TurbulenceConvection.EDMF_PrognosticTKE(namelist::Dict{String, Any}, grid::TurbulenceConvection.Grid{Float64, ClimaCore.Spaces.FiniteDifferenceSpace{ClimaCore.Spaces.CellCenter, ClimaCore.Topologies.IntervalTopology{ClimaCore.Meshes.IntervalMesh{Float64, ClimaCore.Domains.IntervalDomain{ClimaCore.Geometry.ZPoint{Float64}, Tuple{Symbol, Symbol}}, LinRange{ClimaCore.Geometry.ZPoint{Float64}}}, NamedTuple{(:bottom, :top), Tuple{Int64, Int64}}}, ClimaCore.DataLayouts.VF{ClimaCore.Geometry.LocalGeometry{ClimaCore.Geometry.ZPoint{Float64}, Float64, ClimaCore.Geometry.AxisTensor{Float64, 2, Tuple{ClimaCore.Geometry.CartesianAxis{(3,)}, ClimaCore.Geometry.CovariantAxis{(3,)}}, StaticArrays.SMatrix{1, 1, Float64, 1}}, ClimaCore.Geometry.AxisTensor{Float64, 2, Tuple{ClimaCore.Geometry.ContravariantAxis{(3,)}, ClimaCore.Geometry.CartesianAxis{(3,)}}, StaticArrays.SMatrix{1, 1, Float64, 1}}}, Matrix{Float64}}}, ClimaCore.Spaces.FiniteDifferenceSpace{ClimaCore.Spaces.CellFace, ClimaCore.Topologies.IntervalTopology{ClimaCore.Meshes.IntervalMesh{Float64, ClimaCore.Domains.IntervalDomain{ClimaCore.Geometry.ZPoint{Float64}, Tuple{Symbol, Symbol}}, LinRange{ClimaCore.Geometry.ZPoint{Float64}}}, NamedTuple{(:bottom, :top), Tuple{Int64, Int64}}}, ClimaCore.DataLayouts.VF{ClimaCore.Geometry.LocalGeometry{ClimaCore.Geometry.ZPoint{Float64}, Float64, ClimaCore.Geometry.AxisTensor{Float64, 2, Tuple{ClimaCore.Geometry.CartesianAxis{(3,)}, ClimaCore.Geometry.CovariantAxis{(3,)}}, StaticArrays.SMatrix{1, 1, Float64, 1}}, ClimaCore.Geometry.AxisTensor{Float64, 2, Tuple{ClimaCore.Geometry.ContravariantAxis{(3,)}, ClimaCore.Geometry.CartesianAxis{(3,)}}, StaticArrays.SMatrix{1, 1, Float64, 1}}}, Matrix{Float64}}}, ClimaCore.Fields.Field{ClimaCore.DataLayouts.VF{ClimaCore.Geometry.ZPoint{Float64}, SubArray{Float64, 2, Matrix{Float64}, Tuple{Base.Slice{Base.OneTo{Int64}}, UnitRange{Int64}}, true}}, ClimaCore.Spaces.FiniteDifferenceSpace{ClimaCore.Spaces.CellCenter, ClimaCore.Topologies.IntervalTopology{ClimaCore.Meshes.IntervalMesh{Float64, ClimaCore.Domains.IntervalDomain{ClimaCore.Geometry.ZPoint{Float64}, Tuple{Symbol, Symbol}}, LinRange{ClimaCore.Geometry.ZPoint{Float64}}}, NamedTuple{(:bottom, :top), Tuple{Int64, Int64}}}, ClimaCore.DataLayouts.VF{ClimaCore.Geometry.LocalGeometry{ClimaCore.Geometry.ZPoint{Float64}, Float64, ClimaCore.Geometry.AxisTensor{Float64, 2, Tuple{ClimaCore.Geometry.CartesianAxis{(3,)}, ClimaCore.Geometry.CovariantAxis{(3,)}}, StaticArrays.SMatrix{1, 1, Float64, 1}}, ClimaCore.Geometry.AxisTensor{Float64, 2, Tuple{ClimaCore.Geometry.ContravariantAxis{(3,)}, ClimaCore.Geometry.CartesianAxis{(3,)}}, StaticArrays.SMatrix{1, 1, Float64, 1}}}, Matrix{Float64}}}}, ClimaCore.Fields.Field{ClimaCore.DataLayouts.VF{ClimaCore.Geometry.ZPoint{Float64}, SubArray{Float64, 2, Matrix{Float64}, Tuple{Base.Slice{Base.OneTo{Int64}}, UnitRange{Int64}}, true}}, ClimaCore.Spaces.FiniteDifferenceSpace{ClimaCore.Spaces.CellFace, ClimaCore.Topologies.IntervalTopology{ClimaCore.Meshes.IntervalMesh{Float64, ClimaCore.Domains.IntervalDomain{ClimaCore.Geometry.ZPoint{Float64}, Tuple{Symbol, Symbol}}, LinRange{ClimaCore.Geometry.ZPoint{Float64}}}, NamedTuple{(:bottom, :top), Tuple{Int64, Int64}}}, ClimaCore.DataLayouts.VF{ClimaCore.Geometry.LocalGeometry{ClimaCore.Geometry.ZPoint{Float64}, Float64, ClimaCore.Geometry.AxisTensor{Float64, 2, Tuple{ClimaCore.Geometry.CartesianAxis{(3,)}, ClimaCore.Geometry.CovariantAxis{(3,)}}, StaticArrays.SMatrix{1, 1, Float64, 1}}, ClimaCore.Geometry.AxisTensor{Float64, 2, Tuple{ClimaCore.Geometry.ContravariantAxis{(3,)}, ClimaCore.Geometry.CartesianAxis{(3,)}}, StaticArrays.SMatrix{1, 1, Float64, 1}}}, Matrix{Float64}}}}}, param_set::EarthParameterSet{NamedTuple{(:MSLP, :cp_d, :cp_v, :R_d, :R_v, :molmass_ratio, :τ_precip, :τ_acnv, :c_ε, :c_div, :α_b, :α_a, :α_d, :H_up_min, :ω_pr, :c_δ, :β, :χ, :c_t, :c_λ, :w_min, :μ_0, :μ, :c_m, :c_d, :c_b, :Pr_n, :smin_ub, :smin_rm, :l_max, :stoch_ε_lognormal_var, :stoch_δ_lognormal_var, :sde_ϵ_θ, :sde_ϵ_σ, :sde_ϵ_μ, :sde_δ_θ, :sde_δ_σ, :sde_δ_μ), NTuple{38, Float64}}})
   @ TurbulenceConvection /central/groups/esm/hervik/calibration/TurbulenceConvection.jl/src/types.jl:728
 [3] Simulation1d(namelist::Dict{String, Any})
   @ Main /central/groups/esm/hervik/calibration/TurbulenceConvection.jl/integration_tests/utils/main.jl:148
 [4] main1d(namelist::Dict{String, Any}; time_run::Bool)
   @ Main /central/groups/esm/hervik/calibration/TurbulenceConvection.jl/integration_tests/utils/main.jl:277
 [5] main1d
   @ /central/groups/esm/hervik/calibration/TurbulenceConvection.jl/integration_tests/utils/main.jl:277 [inlined]
 [6] #main#7
   @ /central/groups/esm/hervik/calibration/TurbulenceConvection.jl/integration_tests/utils/main.jl:273 [inlined]
 [7] main(namelist::Dict{String, Any})
   @ Main /central/groups/esm/hervik/calibration/TurbulenceConvection.jl/integration_tests/utils/main.jl:273
 [8] top-level scope
   @ /central/groups/esm/hervik/calibration/TurbulenceConvection.jl/integration_tests/utils/main.jl:310
in expression starting at /central/groups/esm/hervik/calibration/TurbulenceConvection.jl/integration_tests/utils/main.jl:302
srun: error: hpc-92-37: task 0: Exited with exit code 1
haakon-e commented 3 years ago

@charleskawczynski thoughts?

trontrytel commented 3 years ago

As a side note, we should also change the print statements about using certain parameters:

[ Info: Using default value, 1000.0, for parameter (microphysics, τ_precip).
[ Info: Using default value, 1000.0, for parameter (microphysics, τ_acnv).

The two lines above are misleading. The values of those two parameters are set to something by TC.jl, but only one of those parameters will be used in any given simulation. (One is used by 0-moment scheme and another is used by 1-moment scheme. And you can't use both at the same time).

charleskawczynski commented 3 years ago

Sounds good to me, feel free to open PR(s)!