Skip to content

Commit

Permalink
JuliaGraphs_interop: remove MetaGraphsNext
Browse files Browse the repository at this point in the history
closes #35
  • Loading branch information
tfiers committed Jan 5, 2023
1 parent fc2b03a commit a1e6bd5
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 143 deletions.
33 changes: 18 additions & 15 deletions docs/src/bg/related-work.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,31 +46,39 @@ PkgGraph does not depend on any of the packages from [JuliaGraphs](https://julia
However, you can easily convert the list of package dependencies to a type that supports
the [graph interface]. You are then able to use the ecosystem's powerful set of graph analysis tools.

See [`PkgGraph.depgraph`](@ref) and [`PkgGraph.vertices`](@ref) for how to obtain the graph edges and vertices, respectively.
Use [`PkgGraph.depgraph`](@ref) and [`PkgGraph.vertices`](@ref) to obtain the graph edges and vertices, respectively.

For an example of using Graphs.jl functions on a package dependency DAG, see
[`PkgGraph.jl/test/JuliaGraphs_interop.jl`][gh], where we analyze the dependency graph
[`test/JuliaGraphs_interop.jl`][gh], where we analyze the dependency graph
of `Tests`:

```@raw html
<img width=400
src="https://github.com/tfiers/PkgGraph.jl/main/docs/img/Test-deps.svg">
```

Some excerpts from that script:
A distillation of that script:
```julia
edges = PkgGraph.depgraph(:Test)
using Graphs

edges = PkgGraph.depgraph("Test")
packages = PkgGraph.vertices(edges)

g = MetaGraph(DiGraph())
g = DiGraph(length(packages))

# Graphs.jl needs nodes to be integers
nodes = Dict(pkg => i for (i, pkg) in enumerate(packages))
node(pkg) = nodes[pkg]

# [..adding nodes and edges to `g`..]
for (pkg, dep) in edges
add_edge!(g, node(pkg), node(dep))
end

@test outdegree(g, node(:Test)) == 4
@test indegree(g, node(:Test)) == 0
@test outdegree(g, node("Test")) == 4
@test indegree(g, node("Test")) == 0

ds = dijkstra_shortest_paths(g, node(:Test))
# [..plus some wrangling & formatting, and..]
ds = dijkstra_shortest_paths(g, node("Test"))
# ..plus some wrangling & formatting, and we get:
"""
Distance from Test to …
Test: 0
Expand All @@ -84,13 +92,8 @@ Distance from Test to …
"""
```

Note that we use [MetaGraphsNext.jl] in the script to construct our graph. The
`SimpleDiGraph` from the main package, Graphs.jl, requires nodes to be integers; and we
want text labels.

[graph interface]: https://juliagraphs.org/Graphs.jl/dev/ecosystem/interface/
[gh]: https://github.com/tfiers/PkgGraph.jl/blob/main/test/JuliaGraphs_interop.jl
[MetaGraphsNext.jl]: https://github.com/JuliaGraphs/MetaGraphsNext.jl



Expand Down
36 changes: 18 additions & 18 deletions test/JuliaGraphs_interop.jl
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@

"""
NOTE: When updating this script, make sure the distillation in
docs/related-work.md is up-to-date too.
"""

using PkgGraph
using Test

print("Loading Graphs, MetaGraphsNext … ")
using Graphs, MetaGraphsNext
println("done")

edges = PkgGraph.depgraph(:Test)
println("Loading Graphs")
using Graphs
println(" … done")

edges = PkgGraph.depgraph("Test")
packages = PkgGraph.vertices(edges)

g = MetaGraph(DiGraph())
g = DiGraph(length(packages))

# Nodes must be created before edges can be added
for pkg in packages
g[Symbol(pkg)] = nothing
end
# Graphs.jl needs nodes to be integers
nodes = Dict(pkg => i for (i, pkg) in enumerate(packages))
node(pkg) = nodes[pkg]

for (pkg, dep) in edges
g[Symbol(pkg), Symbol(dep)] = nothing
add_edge!(g, node(pkg), node(dep))
end

node(s) = code_for(g, s)

@test outdegree(g, node(:Test)) == 4
@test indegree(g, node(:Test)) == 0
@test outdegree(g, node("Test")) == 4
@test indegree(g, node("Test")) == 0

ds = dijkstra_shortest_paths(g, node(:Test))
ds = dijkstra_shortest_paths(g, node("Test"))

io = IOBuffer()
println(io, "Distance from Test to …")
for i in Graphs.vertices(g)
pkg = label_for(g, i)
for (i, pkg) in enumerate(packages)
dist = ds.dists[i]
print(io, lpad(pkg, maximum(length, packages) + 2))
println(io, ": ", Int(dist))
Expand Down
110 changes: 1 addition & 109 deletions test/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

julia_version = "1.8.1"
manifest_format = "2.0"
project_hash = "87ca144b73c6489f5e49b800c4a5f502a5ace02f"

[[deps.ArgTools]]
uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f"
version = "1.1.1"
project_hash = "382fb7ba25925cf6d43b4dfab8acc992dab7b0c0"

[[deps.ArnoldiMethod]]
deps = ["LinearAlgebra", "Random", "StaticArrays"]
Expand Down Expand Up @@ -45,20 +41,6 @@ uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
deps = ["Random", "Serialization", "Sockets"]
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"

[[deps.Downloads]]
deps = ["ArgTools", "FileWatching", "LibCURL", "NetworkOptions"]
uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
version = "1.6.0"

[[deps.FileIO]]
deps = ["Pkg", "Requires", "UUIDs"]
git-tree-sha1 = "7be5f99f7d15578798f338f5433b6c432ea8037b"
uuid = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
version = "1.16.0"

[[deps.FileWatching]]
uuid = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee"

[[deps.Graphs]]
deps = ["ArnoldiMethod", "Compat", "DataStructures", "Distributed", "Inflate", "LinearAlgebra", "Random", "SharedArrays", "SimpleTraits", "SparseArrays", "Statistics"]
git-tree-sha1 = "ba2d094a88b6b287bd25cfa86f301e7693ffae2f"
Expand All @@ -74,31 +56,6 @@ version = "0.1.3"
deps = ["Markdown"]
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

[[deps.JLD2]]
deps = ["FileIO", "MacroTools", "Mmap", "OrderedCollections", "Pkg", "Printf", "Reexport", "TranscodingStreams", "UUIDs"]
git-tree-sha1 = "ec8a9c9f0ecb1c687e34c1fda2699de4d054672a"
uuid = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
version = "0.4.29"

[[deps.LibCURL]]
deps = ["LibCURL_jll", "MozillaCACerts_jll"]
uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21"
version = "0.6.3"

[[deps.LibCURL_jll]]
deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"]
uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0"
version = "7.84.0+0"

[[deps.LibGit2]]
deps = ["Base64", "NetworkOptions", "Printf", "SHA"]
uuid = "76f85450-5226-5b5a-8eaa-529ad045b433"

[[deps.LibSSH2_jll]]
deps = ["Artifacts", "Libdl", "MbedTLS_jll"]
uuid = "29816b5a-b9ab-546f-933c-edad1886dfa8"
version = "1.10.2+0"

[[deps.Libdl]]
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"

Expand All @@ -119,28 +76,9 @@ version = "0.5.10"
deps = ["Base64"]
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"

[[deps.MbedTLS_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1"
version = "2.28.0+0"

[[deps.MetaGraphsNext]]
deps = ["Graphs", "JLD2"]
git-tree-sha1 = "46f9e8e3e27ee71026751fa015ab9c441ba7d51d"
uuid = "fa8bd995-216d-47f1-8a91-f3b68fbeb377"
version = "0.4.0"

[[deps.Mmap]]
uuid = "a63ad114-7e13-5084-954f-fe012c677804"

[[deps.MozillaCACerts_jll]]
uuid = "14a3606d-f60d-562e-9121-12d972cd8159"
version = "2022.2.1"

[[deps.NetworkOptions]]
uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908"
version = "1.2.0"

[[deps.OpenBLAS_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "Libdl"]
uuid = "4536629a-c528-5b80-bd46-f80d51c5b363"
Expand All @@ -151,34 +89,14 @@ git-tree-sha1 = "85f8e6578bf1f9ee0d11e7bb1b1456435479d47c"
uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
version = "1.4.1"

[[deps.Pkg]]
deps = ["Artifacts", "Dates", "Downloads", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"]
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
version = "1.8.0"

[[deps.Printf]]
deps = ["Unicode"]
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"

[[deps.REPL]]
deps = ["InteractiveUtils", "Markdown", "Sockets", "Unicode"]
uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"

[[deps.Random]]
deps = ["SHA", "Serialization"]
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[[deps.Reexport]]
git-tree-sha1 = "45e428421666073eab6f2da5c9d310d99bb12f9b"
uuid = "189a3867-3050-52da-a836-e630ba90ab69"
version = "1.2.2"

[[deps.Requires]]
deps = ["UUIDs"]
git-tree-sha1 = "838a3a4188e2ded87a4f9f184b4b0d78a1e91cb7"
uuid = "ae029012-a4dd-5104-9daa-d747884805df"
version = "1.3.0"

[[deps.SHA]]
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
version = "0.7.0"
Expand Down Expand Up @@ -223,21 +141,10 @@ deps = ["Dates"]
uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
version = "1.0.0"

[[deps.Tar]]
deps = ["ArgTools", "SHA"]
uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e"
version = "1.10.0"

[[deps.Test]]
deps = ["InteractiveUtils", "Logging", "Random", "Serialization"]
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[[deps.TranscodingStreams]]
deps = ["Random", "Test"]
git-tree-sha1 = "e4bdc63f5c6d62e80eb1c0043fcc0360d5950ff7"
uuid = "3bb67fe8-82b1-5028-8e26-92a6c54297fa"
version = "0.9.10"

[[deps.URIs]]
git-tree-sha1 = "ac00576f90d8a259f2c9d823e91d1de3fd44d348"
uuid = "5c2747f8-b7ea-4ff2-ba2e-563bfd36b1d4"
Expand All @@ -250,22 +157,7 @@ uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
[[deps.Unicode]]
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"

[[deps.Zlib_jll]]
deps = ["Libdl"]
uuid = "83775a58-1f1d-513f-b197-d71354ab007a"
version = "1.2.12+3"

[[deps.libblastrampoline_jll]]
deps = ["Artifacts", "Libdl", "OpenBLAS_jll"]
uuid = "8e850b90-86db-534c-a0d3-1478176c7d93"
version = "5.1.1+0"

[[deps.nghttp2_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d"
version = "1.48.0+0"

[[deps.p7zip_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0"
version = "17.4.0+0"
1 change: 0 additions & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[deps]
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
MetaGraphsNext = "fa8bd995-216d-47f1-8a91-f3b68fbeb377"
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
URIs = "5c2747f8-b7ea-4ff2-ba2e-563bfd36b1d4"

0 comments on commit a1e6bd5

Please sign in to comment.