Skip to content

Commit

Permalink
Assert atmos to not have UnionAll types
Browse files Browse the repository at this point in the history
  • Loading branch information
charleskawczynski committed Dec 15, 2023
1 parent 06a3da7 commit a0ccabd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/ClimaAtmos.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ include(joinpath("parameters", "Parameters.jl"))
import .Parameters as CAP

include(joinpath("utils", "abbreviations.jl"))
include(joinpath("utils", "gpu_compat.jl"))
include(joinpath("utils", "common_spaces.jl"))
include(joinpath("solver", "types.jl"))
include(joinpath("solver", "cli_options.jl"))
Expand Down
1 change: 1 addition & 0 deletions src/solver/type_getters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ function get_atmos(config::AtmosConfig, params)
surface_model = get_surface_model(parsed_args),
numerics = get_numerics(parsed_args),
)
@assert !@any_reltype(atmos, (UnionAll,))

@info "AtmosModel: \n$(summary(atmos))"
return atmos
Expand Down
30 changes: 30 additions & 0 deletions src/utils/gpu_compat.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""
@any_reltype(::Any, t::Tuple, warn=true)
Returns a Bool (and prints warnings) if the given
data structure has an instance of any types in `t`.
"""
function any_reltype(found, obj, name, ets, pc = (); warn = true)
for pn in propertynames(obj)
prop = getproperty(obj, pn)
pc_full = (pc..., ".", pn)
pc_string = name * string(join(pc_full))
for et in ets
if prop isa et
warn && @warn "$pc_string::$(typeof(prop)) is a DataType"
found = true
end
end
found = found || any_reltype(found, prop, name, ets, pc_full; warn)
end
return found
end
macro any_reltype(obj, ets, warn = true)
return :(any_reltype(
false,
$(esc(obj)),
$(string(obj)),
$(esc(ets));
warn = $(esc(warn)),
))
end

0 comments on commit a0ccabd

Please sign in to comment.