Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error for graphs with self loops #41

Closed
mtfishman opened this issue Sep 17, 2021 · 5 comments
Closed

Error for graphs with self loops #41

mtfishman opened this issue Sep 17, 2021 · 5 comments

Comments

@mtfishman
Copy link

mtfishman commented Sep 17, 2021

Minimal example:

julia> using LightGraphs, NetworkLayout

julia> g = Graph(Edge.([1 => 2, 2 => 3]))
{3, 2} undirected simple Int64 graph

julia> Spring()(g)
3-element Vector{GeometryBasics.Point2{Float64}}:
 [-3.127142160281595, -0.30807599829163085]
 [-0.6142712514773444, -1.155509538576658]
 [1.8599722110838215, -1.9899164671852727]

julia> add_edge!(g, 1 => 1)
true

julia> Spring()(g)
ERROR: ArgumentError: Illegal buffers for SparseMatrixCSC construction 3 [1, 3, 5, 6] [1, 2, 1, 3, 2] [1, 1, 1, 1, 1, 1]
Stacktrace:
 [1] SparseMatrixCSC
   @ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.7/SparseArrays/src/sparsematrix.jl:29 [inlined]
 [2] SparseArrays.SparseMatrixCSC(m::Int64, n::Int64, colptr::Vector{Int64}, rowval::Vector{Int64}, nzval::Vector{Int64})
   @ SparseArrays /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.7/SparseArrays/src/sparsematrix.jl:44
 [3] _adjacency_matrix(g::SimpleGraph{Int64}, T::DataType, neighborfn::typeof(inneighbors), nzmult::Int64)
   @ LightGraphs.LinAlg ~/.julia/packages/LightGraphs/IgJif/src/linalg/spectral.jl:63
 [4] #adjacency_matrix#2
   @ ~/.julia/packages/LightGraphs/IgJif/src/linalg/spectral.jl:25 [inlined]
 [5] adjacency_matrix (repeats 2 times)
   @ ~/.julia/packages/LightGraphs/IgJif/src/linalg/spectral.jl:20 [inlined]
 [6] layout
   @ ~/.julia/packages/NetworkLayout/TxHy6/src/NetworkLayout.jl:91 [inlined]
 [7] (::Spring{2, Float64})(adj_matrix::SimpleGraph{Int64})
   @ NetworkLayout ~/.julia/packages/NetworkLayout/TxHy6/src/NetworkLayout.jl:34
 [8] top-level scope
   @ REPL[19]:1

EDIT: This appears to be specific to Julia 1.7, see sbromberger/LightGraphs.jl#1594.

@mtfishman
Copy link
Author

I guess this is actually a LightGraphs issue:

julia> using LightGraphs

julia> g = Graph(Edge.([1 => 2, 2 => 3]))
{3, 2} undirected simple Int64 graph

julia> adjacency_matrix(g)
3×3 SparseArrays.SparseMatrixCSC{Int64, Int64} with 4 stored entries:
   1  
 1    1
   1  

julia> add_edge!(g, 1 => 1)
true

julia> adjacency_matrix(g)
ERROR: ArgumentError: Illegal buffers for SparseMatrixCSC construction 3 [1, 3, 5, 6] [1, 2, 1, 3, 2] [1, 1, 1, 1, 1, 1]
Stacktrace:
 [1] SparseMatrixCSC
   @ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.7/SparseArrays/src/sparsematrix.jl:29 [inlined]
 [2] SparseArrays.SparseMatrixCSC(m::Int64, n::Int64, colptr::Vector{Int64}, rowval::Vector{Int64}, nzval::Vector{Int64})
   @ SparseArrays /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.7/SparseArrays/src/sparsematrix.jl:44
 [3] _adjacency_matrix(g::SimpleGraph{Int64}, T::DataType, neighborfn::typeof(inneighbors), nzmult::Int64)
   @ LightGraphs.LinAlg ~/.julia/packages/LightGraphs/IgJif/src/linalg/spectral.jl:63
 [4] #adjacency_matrix#2
   @ ~/.julia/packages/LightGraphs/IgJif/src/linalg/spectral.jl:25 [inlined]
 [5] adjacency_matrix (repeats 2 times)
   @ ~/.julia/packages/LightGraphs/IgJif/src/linalg/spectral.jl:20 [inlined]
 [6] top-level scope
   @ REPL[28]:1

@hexaeder
Copy link
Collaborator

hexaeder commented Sep 17, 2021

Interesting I've been using self edges in GraphMakie without a problem http://juliaplots.org/GraphMakie.jl/stable/generated/plots/#Self-edges

Edit: Ah you allready mentioned that it works well on 1.6

@mtfishman
Copy link
Author

See: sbromberger/LightGraphs.jl#1594 it looks like it is specific to Julia 1.7.

@mtfishman
Copy link
Author

@hexaeder on a separate note, GraphMakie looks great! I built my own interactive graph visualization tool here: https://github.com/ITensor/ITensorsVisualization.jl (specific to visualizing tensor networks, but it would pretty be easy to generalize). However it has become pretty outdated from that latest Makie versions, I will try out using your package as a backend.

@hexaeder
Copy link
Collaborator

hexaeder commented Jan 9, 2022

Your upstream fix was released in [email protected] :)

@hexaeder hexaeder closed this as completed Jan 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants