diff --git a/Project.toml b/Project.toml index ac7b15424..d6a161380 100644 --- a/Project.toml +++ b/Project.toml @@ -5,7 +5,6 @@ version = "1.0.1-DEV" [deps] CSVFiles = "5d742f6a-9f54-50ce-8119-2520741973ca" Classes = "1a9c1350-211b-5766-99cd-4544d885a0d1" -Compose = "a81c6b42-2e10-5240-aca2-a61377ecd94b" DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" @@ -38,7 +37,6 @@ VegaLite = "112f6efa-9a02-5b7d-90c0-432ed331239a" [compat] CSVFiles = "0.16, 1.0" Classes = "1.2" -Compose = "0.7, 0.8, 0.9" DataFrames = "0.19.1, 0.20, 0.21" DataStructures = "0.17" Distributions = "0.21, 0.22, 0.23" diff --git a/docs/src/figs/plot_comp_graph_example.png b/docs/src/figs/plot_comp_graph_example.png deleted file mode 100644 index 42838fdba..000000000 Binary files a/docs/src/figs/plot_comp_graph_example.png and /dev/null differ diff --git a/docs/src/howto/howto_2.md b/docs/src/howto/howto_2.md index b9d5cf21c..54990946b 100644 --- a/docs/src/howto/howto_2.md +++ b/docs/src/howto/howto_2.md @@ -26,17 +26,9 @@ getdataframe(m, :Component1=>:Var1, :Component2=>:Var2) # request variables from ## Plotting and the Explorer UI -Mimi provides support for plotting using [VegaLite](https://github.com/vega/vega-lite) and [VegaLite.jl](https://github.com/fredo-dedup/VegaLite.jl) within the Mimi Explorer UI and `Mimi.plot` function, and the [LightGraphs](https://github.com/JuliaGraphs/LightGraphs.jl) and [MetaGraphs](https://github.com/JuliaGraphs/MetaGraphs.jl) for the `plot_comp_graph` function described below. +Mimi provides support for plotting using [VegaLite](https://github.com/vega/vega-lite) and [VegaLite.jl](https://github.com/fredo-dedup/VegaLite.jl). -In order to view a DAG representing the component ordering and relationships, use the `plot_comp_graph` function to view a plot and optionally save it to a file. - -```julia -run(m) -plot_comp_graph(m; filename = "MyFilePath.png") -``` -![Plot Component Graph Example](../figs/plot_comp_graph_example.png) - -Other plotting support is provided by the **Explorer UI**, rooted in `VegaLite`. The `explore` function allows the user to view and explore the variables and parameters of a model run. The explorer can be used in two primary ways. +Plotting support is provided by the **Explorer UI**, rooted in `VegaLite`. The `explore` function allows the user to view and explore the variables and parameters of a model run. The explorer can be used in two primary ways. In order to invoke the explorer UI and explore all of the variables and parameters in a model, simply call the function `explore` with the model run as the required argument, and a window title as an optional keyword argument, as shown below. This will produce a new browser window containing a selectable list of parameters and variables, organized by component, each of which produces a graphic. The exception here being that if the parameter or variable is a single scalar value, the value will appear alongside the name in the left-hand list. diff --git a/docs/src/ref/ref_API.md b/docs/src/ref/ref_API.md index 0098a7246..aa06eb240 100644 --- a/docs/src/ref/ref_API.md +++ b/docs/src/ref/ref_API.md @@ -22,7 +22,6 @@ is_last modeldef parameter_names parameter_dimensions -plot_comp_graph replace! set_dimension! set_leftover_params! diff --git a/docs/src/tutorials/tutorial_2.md b/docs/src/tutorials/tutorial_2.md index 1d9de52d8..05dbca3eb 100644 --- a/docs/src/tutorials/tutorial_2.md +++ b/docs/src/tutorials/tutorial_2.md @@ -120,7 +120,7 @@ getdataframe(m, :socioeconomic=>:income)[1:16,:] # results for all regions in fi After running the FUND model, you may also explore the results using plots and graphs. -Mimi provides support for plotting using [VegaLite](https://github.com/vega/vega-lite) and [VegaLite.jl](https://github.com/fredo-dedup/VegaLite.jl) within the Mimi Explorer UI, and the [LightGraphs](https://github.com/JuliaGraphs/LightGraphs.jl) and [MetaGraphs](https://github.com/JuliaGraphs/MetaGraphs.jl) for the [`plot_comp_graph`](@ref) function. +Mimi provides support for plotting using [VegaLite](https://github.com/vega/vega-lite) and [VegaLite.jl](https://github.com/fredo-dedup/VegaLite.jl) within the Mimi Explorer UI. #### Explore @@ -147,15 +147,6 @@ More specifically for our tutorial use of FUND, try: p = Mimi.plot(m, :socioeconomic, :income) save("MyFilePath.svg", p) ``` - -#### Component Graph - -In order to view a DAG representing the component ordering and relationships, use the [`plot_comp_graph`](@ref) function to view a plot and optionally save it to a file. This function returns a plot object displayed in the viewer and showing a graph with components as nodes and component connections as edges. - -```julia -plot_comp_graph(m, "MyFilePath.png") -``` - ---- You're done! Now feel free to move on to the next tutorial, which will go into depth on how to **modify** an existing model such as FUND. diff --git a/src/Mimi.jl b/src/Mimi.jl index eab87c535..a041b8338 100644 --- a/src/Mimi.jl +++ b/src/Mimi.jl @@ -38,7 +38,6 @@ export # parameters, parameter_dimensions, parameter_names, - plot_comp_graph, replace_comp!, set_dimension!, set_leftover_params!, @@ -67,7 +66,6 @@ include("core/references.jl") include("core/time.jl") include("core/time_arrays.jl") include("core/model.jl") -include("core/order.jl") include("core/paths.jl") include("core/show.jl") @@ -77,7 +75,6 @@ include("utils/getdataframe.jl") include("utils/graph.jl") include("utils/lint_helper.jl") include("utils/misc.jl") -include("utils/plotting.jl") # Load built-in components include("components/adder.jl") diff --git a/src/core/connections.jl b/src/core/connections.jl index 35b1e725e..22a71605d 100644 --- a/src/core/connections.jl +++ b/src/core/connections.jl @@ -632,8 +632,5 @@ function add_connector_comps!(obj::AbstractCompositeComponentDef) end end - # Save the sorted component order for processing - # obj.sorted_comps = _topological_sort(obj) - return nothing end diff --git a/src/core/order.jl b/src/core/order.jl deleted file mode 100644 index caca55533..000000000 --- a/src/core/order.jl +++ /dev/null @@ -1,64 +0,0 @@ -# -# Support for automatic ordering of components -# - -""" - dependencies(md::ModelDef, comp_path::ComponentPath) - -Return the set of component names that `comp_path` in `md` depends one, i.e., -sources for which `comp_name` is the destination of an internal connection. -""" -function dependencies(md::ModelDef, comp_path::ComponentPath) - conns = internal_param_conns(md) - # For the purposes of the DAG, we don't treat dependencies on [t-1] as an ordering constraint - deps = Set(c.src_comp_path for c in conns if (c.dst_comp_path == comp_path && c.offset == 0)) - return deps -end - -""" - comp_graph(md::ModelDef) - -Return a MetaGraph containing a directed (LightGraph) graph of the components of -ModelDef `md`. Each vertex has a :name property with its component name. -""" -function comp_graph(md::ModelDef) - comp_paths = [c.comp_path for c in compdefs(md)] - graph = MetaDiGraph() - - for comp_path in comp_paths - add_vertex!(graph, :path, comp_path) - end - - set_indexing_prop!(graph, :path) - - for comp_path in comp_paths - for dep_path in dependencies(md, comp_path) - src = graph[dep_path, :path] - dst = graph[comp_path, :path] - add_edge!(graph, src, dst) - end - end - - #TODO: for now we can allow cycles since we aren't using the offset - # if is_cyclic(graph) - # error("Component graph contains a cycle") - # end - - return graph -end - -""" - _topological_sort(md::ModelDef) - -Build a directed acyclic graph referencing the positions of the components in -the OrderedDict of model `md`, tracing dependencies to create the DAG. -Perform a topological sort on the graph for the given model and return a vector -of component paths in the order that will ensure dependencies are processed -prior to dependent components. -""" -function _topological_sort(md::ModelDef) - graph = comp_graph(md) - ordered = topological_sort_by_dfs(graph) - paths = map(i -> graph[i, :path], ordered) - return paths -end diff --git a/src/utils/plotting.jl b/src/utils/plotting.jl deleted file mode 100644 index 29f764a71..000000000 --- a/src/utils/plotting.jl +++ /dev/null @@ -1,36 +0,0 @@ -using Mimi -using GraphPlot -using Compose - -function _open_file(filename) - if Sys.isapple() - run(`open $(filename)`) - elseif Sys.islinux() - run(`xdg-open $(filename)`) - elseif Sys.iswindows() - run(`$(ENV["COMSPEC"]) /c start $(filename)`) - else - @warn "Showing plots is not supported on $(Sys.KERNEL)" - end -end - -""" - plot_comp_graph(m::Model, filename::Union{Nothing, Symbol} = nothing) - -Plot the DAG of component connections within model `m` and save to `filename`. If -no `filename` is given, plot will simply display. -""" -function plot_comp_graph(m::Model, filename::Union{Nothing, String} = nothing) - - graph = comp_graph(m.md) - paths = map(i -> get_prop(graph, i, :path), vertices(graph)) - names = map(path -> path.names[end], paths) - - plot = gplot(graph, nodelabel=names, nodesize=6, nodelabelsize=6) - if filename !== nothing - draw(PDF(filename, 16cm, 16cm), plot) - return _open_file(filename) - else - return plot - end -end diff --git a/test/runtests.jl b/test/runtests.jl index 3cbf79a21..5c8220abc 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -113,9 +113,6 @@ Electron.prep_test_env() @info("test_explorer_compositecomp.jl") @time include("test_explorer_compositecomp.jl") - @info("test_plotting.jl") - @time include("test_plotting.jl") - @info("mcs/runtests.jl") @time include("mcs/runtests.jl") diff --git a/test/test_plotting.jl b/test/test_plotting.jl deleted file mode 100644 index dcaf6f7a7..000000000 --- a/test/test_plotting.jl +++ /dev/null @@ -1,43 +0,0 @@ -module TestPlotting - -using Mimi -using Test - -using Mimi: plot_comp_graph - -@defcomp LongComponent begin - x = Parameter(index=[time]) - y = Parameter() - z = Variable(index=[time]) - - function run_timestep(p, v, d, ts) - v.z[ts] = p.x[ts] + p.y - end -end - -@defcomp ShortComponent begin - a = Parameter() - b = Variable(index=[time]) - - function run_timestep(p, v, d, ts) - v.b[ts] = p.a * ts.t - end -end - -m = Model() -set_dimension!(m, :time, 2000:3000) -nsteps = Mimi.dim_count(m.md, :time) - -add_comp!(m, ShortComponent) #; first=2100) -add_comp!(m, LongComponent) #; first=2000) - -set_param!(m, :ShortComponent, :a, 2.) -set_param!(m, :LongComponent, :y, 1.) -connect_param!(m, :LongComponent, :x, :ShortComponent, :b, zeros(nsteps)) - -run(m) - -graph = plot_comp_graph(m) -@test typeof(graph) == Mimi.Compose.Context - -end #module \ No newline at end of file