Skip to content

Commit

Permalink
Updating plotting references along with adjusting unit tests to Julia…
Browse files Browse the repository at this point in the history
… 1.5 (#42)

* plottin refs

* update randomized tests for newer Julia vers

* tests
  • Loading branch information
pszufe authored Sep 21, 2020
1 parent a283323 commit fe923e4
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 37 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SimpleHypergraphs"
uuid = "aa4a32ff-dd5d-5357-90e3-e7a9512f0501"
authors = ["Przemysław Szufel <[email protected]>", "Bogumił Kamiński <[email protected]>", "Carmine Spagnuolo <[email protected]>", "Alessia Antelmi <[email protected]>"]
version = "0.1.12"
version = "0.1.13"

[deps]
Conda = "8f4d0f93-b110-5947-807f-2305c1781a2d"
Expand All @@ -23,6 +23,6 @@ JSON3 = "1.0.1"
LightGraphs = "1.3"
PyCall = "1.91.2"
PyPlot = "2.8.2"
StatsBase = "0.33"
StatsBase = "0.33.0"
StructTypes = "1.0.1"
julia = "1.0.0"
36 changes: 19 additions & 17 deletions src/SimpleHypergraphs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,31 +41,33 @@ export distance
export HyperNetX, GraphBased
export draw

const hnx = PyNULL()
const hnx = PyNULL()
const nx = PyNULL()
const pynull = PyNULL()
const has_plotting = Ref(false)


function __init__()
plot_ok = true
has_networkx = false
has_hypernetx = false
try
copy!(nx, pyimport("networkx"))
catch e
@warn "Python networkx not found. Plotting functionality of HyperNetX will not work."
plot_ok = false
end
try
copy!(hnx, pyimport("hypernetx"))
catch e
@warn "Python HyperNetX not found. Plotting functionality will not work."
plot_ok = false
end
copy!(nx, pyimport("networkx"))
has_networkx = true
catch e; end
try
copy!(hnx, pyimport("hypernetx"))
has_hypernetx = true
catch e; end
has_plotting[] = has_networkx && has_hypernetx
if !has_plotting[]
@warn "The plotting functionality of HyperNetX will not work!\n"*
(has_networkx ? "" : "Conda Python networkx not found.\n")*
(has_hypernetx ? "" : "Conda Python HyperNetX not found.\n")*
"To test your installation try running `using PyCall;pyimport(\"networkx\");pyimport(\"hypernetx\")`"
end
end

function support_hypernetx()
return ((SimpleHypergraphs.nx != SimpleHypergraphs.pynull) &&
(SimpleHypergraphs.hnx != SimpleHypergraphs.pynull))

return has_plotting[]
end


Expand Down
9 changes: 4 additions & 5 deletions src/viz/drawing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@ function draw(
with_node_labels::Bool=true,
label_alpha::Float64=.35
)
if (!SimpleHypergraphs.support_hypernetx())
throw("HyperNetX is not installed in Python used by this Julia. Install HyperNetX and reload SimpleHypergraphs.jl")
end
if (!SimpleHypergraphs.support_hypernetx())
throw("HyperNetX is not installed in Python used by this Julia. Install HyperNetX and reload SimpleHypergraphs.jl")
end
h_hnx = _convert_to_hnx(h;
node_labels=node_labels,
edge_labels=edge_labels
Expand Down Expand Up @@ -261,7 +261,6 @@ function _convert_to_hnx(h::Hypergraph;
node_labels::Union{Dict{Int, String}, Nothing}=nothing,
edge_labels::Union{Dict{Int, String}, Nothing}=nothing,
)

h_hnx = hnx.Hypergraph()

for he=1:nhe(h)
Expand Down
27 changes: 14 additions & 13 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,13 @@ end;

cfmr = CFModularityRandom(3,10000)

@test findcommunities(hg,cfmr) ==
(bp = Set.([[4, 5, 9], [1, 3, 6, 7], [2, 8, 10]]), bm = 0.21505688117829677)
@test findcommunities(hg,cfmr).bm 0.21505688117829677
@test modularity(hg, Set.([1:10])) == 0.0
Random.seed!(1234);
@test randompartition(hg, 2) == Set.([[1, 5, 6, 7, 9], [2, 3, 4, 8, 10]])

@test typeof(randompartition(hg, 2)) == Vector{Set{Int}}
@test length(randompartition(hg, 2)) == 2
@test sort(vcat(collect.(randompartition(hg, 2))...))==1:nhv(hg)

hh = Hypergraph{Bool}(7,4)
hh[1,1] = true
hh[2,1:2] .= true
Expand All @@ -336,17 +337,17 @@ end;
@test cfmr.reps == 10000
@test findcommunities(hh,cfmr).bm 16/81
Random.seed!(1234);
cnm = CFModularityCNMLike(100)
@test cnm.reps == 100
cnm = CFModularityCNMLike(1000)
@test cnm.reps == 1000
@test findcommunities(hh, CFModularityRandom(4,10000)).bm findcommunities(hh, cnm).bm
Random.seed!(0);
@test findcommunities(hh, cnm).bm 223/972
@test any(isapprox.(findcommunities(hh, cnm).bm, [16/81, 223/972]))
end;


@testset "SimpleHypergraphs randomized tests " begin
Random.seed!(0)
N = 100
N = 500
res = Vector{Bool}(undef, N)
for i in 1:N
m1 = CFModularityCNMLike(100)
Expand All @@ -357,7 +358,7 @@ end;
bm2 = findcommunities(hh, m2).bm
res[i] = (bm1 > bm2)
end
@test sum(res) >= N*0.80
@test sum(res) >= N*0.75
end


Expand Down Expand Up @@ -426,10 +427,10 @@ end

@testset "SimpleHypergraphs hypernetx bridge " begin

if (!SimpleHypergraphs.support_hypernetx())
@warn "HyperNetX is not installed. Skipping hypernetx tests"
return
end
if (!SimpleHypergraphs.support_hypernetx())
@warn "HyperNetX is not installed. Skipping hypernetx tests"
return
end

h_hnx = SimpleHypergraphs._convert_to_hnx(h1)
data = Dict{String, Array{Int, 1}}(
Expand Down

2 comments on commit fe923e4

@pszufe
Copy link
Owner Author

@pszufe pszufe commented on fe923e4 Sep 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/21743

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.13 -m "<description of version>" fe923e488fc24f7a88b278ad36934d7d25b906ff
git push origin v0.1.13

Please sign in to comment.