Skip to content

Commit 95fcf25

Browse files
Krastanov-agentKrastanovclaude
authored
Silence eccentricity warnings in iFUB diameter test (#491)
The iFUB diameter test generates random sparse Erdos-Renyi graphs that are often disconnected. The naive diameter reference implementation calls eccentricity on every vertex, which emits a "Infinite path length detected" warning per unreachable vertex -- producing ~2300 warnings per test run. Wrap the loop in `with_logger(NullLogger())` to suppress them. Co-authored-by: Stefan Krastanov <stefan@krastanov.org> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 72bcb3b commit 95fcf25

File tree

3 files changed

+37
-31
lines changed

3 files changed

+37
-31
lines changed

test/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
99
Inflate = "d25df0c9-e2be-5dd7-82c8-3ad0b3e990b9"
1010
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
1111
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
12+
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
1213
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
1314
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1415
SharedArrays = "1a1011a3-84de-559e-8e89-a11a2f7dc383"

test/distance.jl

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -81,37 +81,41 @@
8181

8282
NUM_SAMPLES = 50 # Adjust this to change test duration
8383

84-
for i in 1:NUM_SAMPLES
85-
# Random unweighted Graphs
86-
n = rand(10:1000) # Small to Medium size graphs
87-
p = rand() * 0.1 + 0.005 # Sparse to medium density
88-
89-
# Undirected Graphs
90-
g = erdos_renyi(n, p)
91-
@test diameter(g) == diameter_naive(g)
92-
93-
ccs = connected_components(g)
94-
largest_component = ccs[argmax(length.(ccs))]
95-
g_lscc, _ = induced_subgraph(g, largest_component)
96-
97-
if nv(g_lscc) > 1
98-
d_new = @inferred diameter(g_lscc)
99-
d_ref = diameter_naive(g_lscc)
100-
@test d_new == d_ref
101-
end
102-
103-
# Directed Graphs
104-
g_dir = erdos_renyi(n, p, is_directed=true)
105-
@test diameter(g_dir) == diameter_naive(g_dir)
106-
107-
sccs = strongly_connected_components(g_dir)
108-
largest_component_directed = sccs[argmax(length.(sccs))]
109-
g_dir_lscc, _ = induced_subgraph(g_dir, largest_component_directed)
110-
111-
if nv(g_dir_lscc) > 1
112-
d_new_dir = @inferred diameter(g_dir_lscc)
113-
d_ref_dir = diameter_naive(g_dir_lscc)
114-
@test d_new_dir == d_ref_dir
84+
# Silence the many "Infinite path length detected" warnings from
85+
# eccentricity on disconnected random graphs.
86+
with_logger(NullLogger()) do
87+
for i in 1:NUM_SAMPLES
88+
# Random unweighted Graphs
89+
n = rand(10:1000) # Small to Medium size graphs
90+
p = rand() * 0.1 + 0.005 # Sparse to medium density
91+
92+
# Undirected Graphs
93+
g = erdos_renyi(n, p)
94+
@test diameter(g) == diameter_naive(g)
95+
96+
ccs = connected_components(g)
97+
largest_component = ccs[argmax(length.(ccs))]
98+
g_lscc, _ = induced_subgraph(g, largest_component)
99+
100+
if nv(g_lscc) > 1
101+
d_new = @inferred diameter(g_lscc)
102+
d_ref = diameter_naive(g_lscc)
103+
@test d_new == d_ref
104+
end
105+
106+
# Directed Graphs
107+
g_dir = erdos_renyi(n, p, is_directed=true)
108+
@test diameter(g_dir) == diameter_naive(g_dir)
109+
110+
sccs = strongly_connected_components(g_dir)
111+
largest_component_directed = sccs[argmax(length.(sccs))]
112+
g_dir_lscc, _ = induced_subgraph(g_dir, largest_component_directed)
113+
114+
if nv(g_dir_lscc) > 1
115+
d_new_dir = @inferred diameter(g_dir_lscc)
116+
d_ref_dir = diameter_naive(g_dir_lscc)
117+
@test d_new_dir == d_ref_dir
118+
end
115119
end
116120
end
117121
end

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ using LinearAlgebra
1111
using DelimitedFiles
1212
using Base64
1313
using Random
14+
using Logging: NullLogger, with_logger
1415
using Statistics: mean, std
1516
using StableRNGs
1617
using Pkg

0 commit comments

Comments
 (0)