diff --git a/Project.toml b/Project.toml index 6b5906a57..371cf2c36 100644 --- a/Project.toml +++ b/Project.toml @@ -14,6 +14,7 @@ Electron = "a1bb12fb-d4d1-54b4-b10a-ee7951ef7ad3" FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" FilePaths = "8fc22ac5-c921-52a6-82fd-178b2807b824" GlobalSensitivityAnalysis = "1b10255b-6da3-57ce-9089-d24e8517b87e" +InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" IterTools = "c8e1da08-722c-5040-9ed9-7db0dc04731e" IteratorInterfaceExtensions = "82899510-4779-5014-852e-03e436cf321d" JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" diff --git a/src/Mimi.jl b/src/Mimi.jl index 2aab7ec92..a8a0d2c39 100644 --- a/src/Mimi.jl +++ b/src/Mimi.jl @@ -8,6 +8,7 @@ using Electron using JSON using NamedArrays using StringBuilders +import InteractiveUtils export @defcomp, @@ -77,6 +78,7 @@ include("explorer/explore.jl") include("utils/getdataframe.jl") include("utils/graph.jl") include("utils/misc.jl") +include("utils/diagnostics.jl") # Load built-in components include("components/adder.jl") diff --git a/src/utils/diagnostics.jl b/src/utils/diagnostics.jl new file mode 100644 index 000000000..c0389a2b8 --- /dev/null +++ b/src/utils/diagnostics.jl @@ -0,0 +1,19 @@ +function find_type_instabilities(m, comp, tool=InteractiveUtils.code_warntype) + m.mi===nothing && error("Model must be built.") + + mi = m.mi + + time_keys::Vector{Int} = dim_keys(mi.md, :time) + clock = Clock(time_keys) + + dim_dict_keys = collect(keys(getproperty(mi.comps_dict[comp].comp_id.module_obj, mi.comps_dict[comp].comp_id.comp_name).dim_dict)) + dim_dict = OrderedDict([k => m.md.dim_dict[k] for k in dim_dict_keys]) + + f = mi.comps_dict[comp].run_timestep + v = typeof(mi.comps_dict[comp].variables) + p = typeof(mi.comps_dict[comp].parameters) + d = typeof(NamedTuple(name => (name == :time ? timesteps(clock) : collect(values(dim))) for (name, dim) in dim_dict)) + t = typeof(clock.ts) + + tool(f, (p, v, d, t)) +end