Skip to content

Commit 0cd1739

Browse files
committed
switch LightGraphs to Graphs
1 parent 9bf38dd commit 0cd1739

File tree

9 files changed

+28
-28
lines changed

9 files changed

+28
-28
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
1616
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
1717
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
1818
DomainSets = "5b8099bc-c8ec-5219-889f-1d9e522a28bf"
19+
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
1920
IfElse = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173"
2021
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
2122
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
2223
LabelledArrays = "2ee39098-c373-598a-b85f-a56591580800"
2324
Latexify = "23fbe1c1-3f47-55db-b15f-69d7ec21a316"
2425
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
25-
LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d"
2626
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
2727
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
2828
NaNMath = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
@@ -55,11 +55,11 @@ DiffRules = "0.1, 1.0"
5555
Distributions = "0.23, 0.24, 0.25"
5656
DocStringExtensions = "0.7, 0.8"
5757
DomainSets = "0.5"
58+
Graphs = "1.4"
5859
IfElse = "0.1"
5960
JuliaFormatter = "0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18"
6061
LabelledArrays = "1.3"
6162
Latexify = "0.11, 0.12, 0.13, 0.14, 0.15"
62-
LightGraphs = "1.3"
6363
MacroTools = "0.5"
6464
NaNMath = "0.3"
6565
NonlinearSolve = "0.3.8"

src/ModelingToolkit.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ import Symbolics: rename, get_variables!, _solve, hessian_sparsity,
5656

5757
import DiffEqBase: @add_kwonly
5858

59-
import LightGraphs: SimpleDiGraph, add_edge!, incidence_matrix
59+
import Graphs: SimpleDiGraph, add_edge!, incidence_matrix
6060

6161
using Requires
6262

src/bipartite_graph.jl

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ export 𝑠vertices, 𝑑vertices, has_𝑠vertex, has_𝑑vertex, 𝑠neighbors
88
using DocStringExtensions
99
using UnPack
1010
using SparseArrays
11-
using LightGraphs
11+
using Graphs
1212
using Setfield
1313

1414
###
1515
### Edges & Vertex
1616
###
1717
@enum VertType SRC DST ALL
1818

19-
struct BipartiteEdge{I<:Integer} <: LightGraphs.AbstractEdge{I}
19+
struct BipartiteEdge{I<:Integer} <: Graphs.AbstractEdge{I}
2020
src::I
2121
dst::I
2222
function BipartiteEdge(src::I, dst::V) where {I,V}
@@ -25,8 +25,8 @@ struct BipartiteEdge{I<:Integer} <: LightGraphs.AbstractEdge{I}
2525
end
2626
end
2727

28-
LightGraphs.src(edge::BipartiteEdge) = edge.src
29-
LightGraphs.dst(edge::BipartiteEdge) = edge.dst
28+
Graphs.src(edge::BipartiteEdge) = edge.src
29+
Graphs.dst(edge::BipartiteEdge) = edge.dst
3030

3131
function Base.show(io::IO, edge::BipartiteEdge)
3232
@unpack src, dst = edge
@@ -65,7 +65,7 @@ badjlist = [[1,2,5,6],[3,4,6]]
6565
bg = BipartiteGraph(7, fadjlist, badjlist)
6666
```
6767
"""
68-
mutable struct BipartiteGraph{I<:Integer,F<:Vector{Vector{I}},B<:Union{Vector{Vector{I}},I},M} <: LightGraphs.AbstractGraph{I}
68+
mutable struct BipartiteGraph{I<:Integer,F<:Vector{Vector{I}},B<:Union{Vector{Vector{I}},I},M} <: Graphs.AbstractGraph{I}
6969
ne::Int
7070
fadjlist::F # `fadjlist[src] => dsts`
7171
badjlist::B # `badjlist[dst] => srcs` or `ndsts`
@@ -112,11 +112,11 @@ Base.length(::BipartiteGraph) = error("length is not well defined! Use `ne` or `
112112

113113
@noinline throw_no_back_edges() = throw(ArgumentError("The graph has no back edges."))
114114

115-
if isdefined(LightGraphs, :has_contiguous_vertices)
116-
LightGraphs.has_contiguous_vertices(::Type{<:BipartiteGraph}) = false
115+
if isdefined(Graphs, :has_contiguous_vertices)
116+
Graphs.has_contiguous_vertices(::Type{<:BipartiteGraph}) = false
117117
end
118-
LightGraphs.is_directed(::Type{<:BipartiteGraph}) = false
119-
LightGraphs.vertices(g::BipartiteGraph) = (𝑠vertices(g), 𝑑vertices(g))
118+
Graphs.is_directed(::Type{<:BipartiteGraph}) = false
119+
Graphs.vertices(g::BipartiteGraph) = (𝑠vertices(g), 𝑑vertices(g))
120120
𝑠vertices(g::BipartiteGraph) = axes(g.fadjlist, 1)
121121
𝑑vertices(g::BipartiteGraph) = g.badjlist isa AbstractVector ? axes(g.badjlist, 1) : Base.OneTo(g.badjlist)
122122
has_𝑠vertex(g::BipartiteGraph, v::Integer) = v in 𝑠vertices(g)
@@ -126,14 +126,14 @@ function 𝑑neighbors(g::BipartiteGraph, j::Integer, with_metadata::Val{M}=Val(
126126
g.badjlist isa AbstractVector || throw_no_back_edges()
127127
M ? zip(g.badjlist[j], (g.metadata[i][j] for i in g.badjlist[j])) : g.badjlist[j]
128128
end
129-
LightGraphs.ne(g::BipartiteGraph) = g.ne
130-
LightGraphs.nv(g::BipartiteGraph) = sum(length, vertices(g))
131-
LightGraphs.edgetype(g::BipartiteGraph{I}) where I = BipartiteEdge{I}
129+
Graphs.ne(g::BipartiteGraph) = g.ne
130+
Graphs.nv(g::BipartiteGraph) = sum(length, vertices(g))
131+
Graphs.edgetype(g::BipartiteGraph{I}) where I = BipartiteEdge{I}
132132

133133
nsrcs(g::BipartiteGraph) = length(𝑠vertices(g))
134134
ndsts(g::BipartiteGraph) = length(𝑑vertices(g))
135135

136-
function LightGraphs.has_edge(g::BipartiteGraph, edge::BipartiteEdge)
136+
function Graphs.has_edge(g::BipartiteGraph, edge::BipartiteEdge)
137137
@unpack src, dst = edge
138138
(src in 𝑠vertices(g) && dst in 𝑑vertices(g)) || return false # edge out of bounds
139139
insorted(𝑠neighbors(src), dst)
@@ -146,8 +146,8 @@ struct NoMetadata
146146
end
147147
const NO_METADATA = NoMetadata()
148148

149-
LightGraphs.add_edge!(g::BipartiteGraph, i::Integer, j::Integer, md=NO_METADATA) = add_edge!(g, BipartiteEdge(i, j), md)
150-
function LightGraphs.add_edge!(g::BipartiteGraph, edge::BipartiteEdge, md=NO_METADATA)
149+
Graphs.add_edge!(g::BipartiteGraph, i::Integer, j::Integer, md=NO_METADATA) = add_edge!(g, BipartiteEdge(i, j), md)
150+
function Graphs.add_edge!(g::BipartiteGraph, edge::BipartiteEdge, md=NO_METADATA)
151151
@unpack fadjlist, badjlist = g
152152
s, d = src(edge), dst(edge)
153153
(has_𝑠vertex(g, s) && has_𝑑vertex(g, d)) || error("edge ($edge) out of range.")
@@ -168,7 +168,7 @@ function LightGraphs.add_edge!(g::BipartiteGraph, edge::BipartiteEdge, md=NO_MET
168168
return true # edge successfully added
169169
end
170170

171-
function LightGraphs.add_vertex!(g::BipartiteGraph{T}, type::VertType) where T
171+
function Graphs.add_vertex!(g::BipartiteGraph{T}, type::VertType) where T
172172
if type === DST
173173
if g.badjlist isa AbstractVector
174174
push!(g.badjlist, T[])
@@ -186,11 +186,11 @@ end
186186
###
187187
### Edges iteration
188188
###
189-
LightGraphs.edges(g::BipartiteGraph) = BipartiteEdgeIter(g, Val(ALL))
189+
Graphs.edges(g::BipartiteGraph) = BipartiteEdgeIter(g, Val(ALL))
190190
𝑠edges(g::BipartiteGraph) = BipartiteEdgeIter(g, Val(SRC))
191191
𝑑edges(g::BipartiteGraph) = BipartiteEdgeIter(g, Val(DST))
192192

193-
struct BipartiteEdgeIter{T,G} <: LightGraphs.AbstractEdgeIter
193+
struct BipartiteEdgeIter{T,G} <: Graphs.AbstractEdgeIter
194194
g::G
195195
type::Val{T}
196196
end
@@ -259,7 +259,7 @@ end
259259
###
260260
### Utils
261261
###
262-
function LightGraphs.incidence_matrix(g::BipartiteGraph, val=true)
262+
function Graphs.incidence_matrix(g::BipartiteGraph, val=true)
263263
I = Int[]
264264
J = Int[]
265265
for i in 𝑠vertices(g), n in 𝑠neighbors(g, i)

src/structural_transformation/StructuralTransformations.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ using ModelingToolkit: ODESystem, AbstractSystem,var_from_nested_derivative, Dif
2424
get_postprocess_fbody
2525

2626
using ModelingToolkit.BipartiteGraphs
27-
using LightGraphs
27+
using Graphs
2828
using ModelingToolkit.SystemStructures
2929

3030
using ModelingToolkit.DiffEqBase

src/structural_transformation/codegen.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function torn_system_jacobian_sparsity(sys)
5151
for var in 𝑠neighbors(graph, teq)
5252
# Skip the tearing variables in the current partition, because
5353
# we are computing them from all the other states.
54-
LightGraphs.insorted(var, v_residual) && continue
54+
Graphs.insorted(var, v_residual) && continue
5555
deps = get(avars2dvars, var, nothing)
5656
if deps === nothing # differential variable
5757
@assert !isalgvar(s, var)

src/systems/systemstructure.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import ..ModelingToolkit: isdiffeq, var_from_nested_derivative, vars!, flatten,
99
value, InvalidSystemException, isdifferential, _iszero, isparameter,
1010
independent_variables, isinput
1111
using ..BipartiteGraphs
12-
using LightGraphs
12+
using Graphs
1313
using UnPack
1414
using Setfield
1515
using SparseArrays

test/dep_graphs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using Test
2-
using ModelingToolkit, LightGraphs, DiffEqJump
2+
using ModelingToolkit, Graphs, DiffEqJump
33

44
import ModelingToolkit: value
55

test/structural_transformation/index_reduction.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using ModelingToolkit
2-
using LightGraphs
2+
using Graphs
33
using DiffEqBase
44
using Test
55
using UnPack

test/structural_transformation/utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using Test
22
using ModelingToolkit
3-
using LightGraphs
3+
using Graphs
44
using SparseArrays
55
using UnPack
66

0 commit comments

Comments
 (0)