Repository navigation
Expand file tree
/
Copy pathtest_snap_shell.py
More file actions
559 lines (482 loc) · 21.9 KB
/
Copy pathtest_snap_shell.py
File metadata and controls
559 lines (482 loc) · 21.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
import importlib
import shutil
from types import SimpleNamespace
from unittest.mock import Mock
import pytest
import numpy as np
from binsparse.conversions import to_numpy, to_scipy, to_sparse
from saps.benchmark import Generator
from saps.benchmarks.bfs import (
BFSDataset,
BFSSNAPGenerator,
)
from saps.benchmarks.snap import (
_MAX_DEGREES,
NUM_SNAP_SOURCES,
SNAPGraphGenerator,
SNAPGraphShellBenchmark,
fetch_snap_graph,
seeded_source_vertices,
select_source_vertices,
)
from saps.benchmarks.suitesparse import (
SuiteSparseMatrixGenerator,
fetch_suitesparse_matrix,
)
from saps.downloaders import suitesparse as downloader
from saps.metadata import _benchmark_instances
from saps.storage import LocalStorageBackend
_CONSUMERS = [
("bfs", "BFSSNAPGenerator"),
("bellman_ford", "BellmanFordSNAPGenerator"),
("betweenness_centrality", "BetweennessCentralitySNAPGenerator"),
("connected_components", "ConnectedComponentsSNAPGenerator"),
("fastsv", "FastSVSNAPGenerator"),
("four_clique_counting", "FourCliqueCountingSNAPGenerator"),
("pagerank", "PageRankSNAPGenerator"),
("transitive_closure", "TransitiveClosureSNAPGenerator"),
("floyd_warshall", "FloydWarshallSNAPGenerator"),
("triangle_counting", "TriangleCountingSNAPGenerator"),
("transitive_reduction", "TransitiveReductionSNAPGenerator"),
("mssp", "MSSPSNAPGenerator"),
("msbfs", "MSBFSSNAPGenerator"),
("mcl", "MCLSNAPGenerator"),
]
_MULTI_SOURCE = {"mssp", "msbfs"}
def _seeded_sources(graph):
"""Source k of a SNAP shell graph: the first draw of seed k."""
return [
int(select_source_vertices(graph, seed=seed)[0])
for seed in range(NUM_SNAP_SOURCES)
]
def test_snap_max_degrees_cover_exactly_the_declared_graphs():
datasets = SNAPGraphGenerator().datasets
assert set(_MAX_DEGREES) == {d.source_name for d in datasets}
assert all(d.max_degree == _MAX_DEGREES[d.source_name] > 0 for d in datasets)
def test_snap_shell_inventory_covers_consumers():
generator = SNAPGraphGenerator()
declared = {d.name for d in generator.datasets}
assert len(declared) == len(generator.datasets) == 68
assert {"soc-Slashdot0902", "as-735", "as-caida"} <= declared
assert (
not {
"facebook_combined",
"soc-Slashdot0922",
"as-733",
"as-Caida",
"Deezer Ego-nets",
"GitHub Stargazers",
"Reddit Threads",
"Ego-Nets",
"ERC20-stablecoins",
}
& declared
)
assert SNAPGraphShellBenchmark().name == "snap_graph_shell"
assert not generator.cacheable
consumed = set()
for benchmark in _benchmark_instances():
for consumer in benchmark.generators:
for dataset in consumer.datasets:
if (
type(consumer).__name__.endswith("SNAPGenerator")
or consumer.name == "snap_graph"
):
name = getattr(dataset, "source_name", dataset.name).removeprefix(
"SNAP/"
)
assert name in declared
if consumer.name != generator.name:
assert not consumer.cacheable
consumed.add(name)
assert consumed <= declared
assert consumed == declared
@pytest.mark.parametrize("name", ["soc-Slashdot0902", "as-735", "as-caida"])
def test_snap_shell_preserves_suitesparse_matrix_and_discards_extras(
monkeypatch, tmp_path, name
):
backend = LocalStorageBackend(
tmp_path / "remote", tmp_path / "manifest.json", tmp_path / "cache"
)
monkeypatch.setattr(Generator, "backend", property(lambda _: backend))
matrix_dir = tmp_path / name
matrix_dir.mkdir()
# Preserve signed values, Matrix Market symmetry, and isolated vertices.
(matrix_dir / f"{name}.mtx").write_text(
"%%MatrixMarket matrix coordinate real symmetric\n4 4 2\n2 1 -2\n4 2 3\n"
)
(matrix_dir / f"{name}_b.mtx").write_text(
"%%MatrixMarket matrix array real general\n4 1\n1\n2\n3\n4\n"
)
download = Mock(return_value=(matrix_dir, SimpleNamespace(group="SNAP", name=name)))
monkeypatch.setattr(downloader, "download_suitesparse_matrix", download)
generator = SNAPGraphGenerator()
dataset = next(d for d in generator.datasets if d.name == name)
shell = SuiteSparseMatrixGenerator()
source = next(d for d in shell.datasets if d.source_name == dataset.source_name)
assert backend.upload_dataset(shell, source)
download.assert_called_once_with(f"SNAP/{name}", data_dir=None)
download.side_effect = AssertionError("Unexpected source download")
problem = generator.cached_generate(dataset)
assert len(problem.inputs) == 1
np.testing.assert_array_equal(
to_scipy(problem.inputs[0]).toarray(),
[[0, -2, 0, 0], [-2, 0, 0, 3], [0, 0, 0, 0], [0, 3, 0, 0]],
)
assert problem.meta == {
"max_degree": _MAX_DEGREES[f"SNAP/{name}"],
"sources": _seeded_sources(problem.inputs[0]),
}
assert problem.ref_outputs is None
assert problem.ref_meta is None
# Dropping the extras for graph benchmarks leaves the shared source intact.
shared = fetch_suitesparse_matrix(dataset.source_name)
assert len(shared.inputs) == 2
assert shared.meta["has_b_file"]
np.testing.assert_array_equal(to_numpy(shared.inputs[1]), [1, 2, 3, 4])
@pytest.mark.parametrize(("module_name", "class_name"), _CONSUMERS)
def test_snap_consumer_reads_shared_remote_graph_without_source_download(
monkeypatch, tmp_path, module_name, class_name
):
backend = LocalStorageBackend(
tmp_path / "remote", tmp_path / "manifest.json", tmp_path / "cache"
)
monkeypatch.setattr(Generator, "backend", property(lambda _: backend))
monkeypatch.delenv("SAPS_CACHE_DATASETS", raising=False)
module = importlib.import_module(f"saps.benchmarks.{module_name}")
consumer = getattr(module, class_name)()
dataset = consumer.datasets[0]
shell = SuiteSparseMatrixGenerator()
slug = getattr(dataset, "source_name", dataset.name).removeprefix("SNAP/")
source = next(d for d in shell.datasets if d.source_name == f"SNAP/{slug}")
path = backend.cache_dir / "suitesparse" / "SNAP" / slug / f"{slug}.mtx"
path.parent.mkdir(parents=True)
path.write_text(
"%%MatrixMarket matrix coordinate pattern general\n3 3 3\n1 2\n2 3\n3 3\n"
)
source_download = Mock(
return_value=(path.parent, SimpleNamespace(group="SNAP", name=slug))
)
monkeypatch.setattr(downloader, "download_suitesparse_matrix", source_download)
assert backend.upload_dataset(shell, source)
source_download.assert_called_once_with(f"SNAP/{slug}", data_dir=None)
# Simulate another worker with only the manifest and remote prepared object.
shutil.rmtree(backend.cache_dir)
forbidden = Mock(side_effect=AssertionError("Unexpected source download"))
monkeypatch.setattr(downloader, "download_suitesparse_matrix", forbidden)
monkeypatch.setattr(
"saps.benchmarks.suitesparse.load_suitesparse_matrix", forbidden
)
monkeypatch.setattr(backend, "upload_dataset", forbidden)
download = Mock(wraps=backend.download_file)
monkeypatch.setattr(backend, "download_file", download)
manifest = backend.manifest_path.read_bytes()
problem = consumer.cached_generate(dataset)
assert len(problem.inputs) == (2 if module_name in _MULTI_SOURCE else 1)
if getattr(dataset, "source_seed", None) is not None:
assert problem.meta["seed"] == 0
assert problem.meta["src"] == int(
select_source_vertices(fetch_snap_graph(slug).inputs[0], seed=0)[0]
)
elif module_name in _MULTI_SOURCE:
assert problem.meta == {
"sources": sorted(set(_seeded_sources(fetch_snap_graph(slug).inputs[0])))
}
elif module_name == "mcl":
assert problem.meta == {}
else:
expected_meta = {
"max_degree": _MAX_DEGREES[f"SNAP/{slug}"],
"sources": _seeded_sources(fetch_snap_graph(slug).inputs[0]),
}
if module_name in {"transitive_closure", "floyd_warshall"}:
expected_meta["max_squarings"] = 0
assert problem.meta == expected_meta
if module_name in {"bellman_ford", "mssp", "floyd_warshall"}:
expected = np.array([[0, 1, np.inf], [np.inf, 0, 1], [np.inf, np.inf, 0]])
np.testing.assert_array_equal(to_sparse(problem.inputs[0]).todense(), expected)
assert problem.inputs[0].fill_value == np.inf
assert problem.inputs[0].number_of_stored_values == 5
elif module_name == "transitive_reduction":
expected = np.array(
[[np.inf, 1, np.inf], [np.inf, np.inf, 1], [np.inf, np.inf, np.inf]]
)
np.testing.assert_array_equal(to_sparse(problem.inputs[0]).todense(), expected)
assert problem.inputs[0].number_of_stored_values == 2
else:
np.testing.assert_array_equal(
to_scipy(problem.inputs[0]).toarray(), [[0, 1, 0], [0, 0, 1], [0, 0, 1]]
)
# Subsequent users read the local shared shell object, not per-consumer caches.
raw = fetch_snap_graph(slug)
assert to_scipy(raw.inputs[0]).toarray()[2, 2] == 1
if getattr(dataset, "source_seed", None) is not None:
seeded = [d for d in consumer.datasets if d.source_name == slug]
assert [d.source_seed for d in seeded] == list(range(10))
from scipy.sparse.csgraph import shortest_path
from frameworks.saps_numpy import NumpyFramework
xp = NumpyFramework()
benchmark = (
module.BFSBenchmark()
if module_name == "bfs"
else module.BellmanFordBenchmark()
)
for variant in seeded:
actual = consumer.cached_generate(variant)
distances = shortest_path(
to_scipy(raw.inputs[0]).toarray(),
directed=True,
unweighted=True,
indices=actual.meta["src"],
)
expected_output = (
np.where(np.isfinite(distances), distances + 1, 0)
if module_name == "bfs"
else distances
)
output = benchmark.benchmark(
xp, [xp.from_binsparse(actual.inputs[0])], actual.meta
)[0]
np.testing.assert_array_equal(output, expected_output)
assert actual.meta["src"] == int(
select_source_vertices(raw.inputs[0], seed=variant.source_seed)[0]
)
assert len(raw.inputs) == 1
assert raw.meta == {
"max_degree": _MAX_DEGREES[f"SNAP/{slug}"],
"sources": _seeded_sources(raw.inputs[0]),
}
download.assert_called_once()
assert download.call_args.args[0].startswith(f"suitesparse_matrix/SNAP/{slug}/")
forbidden.assert_not_called()
assert backend.manifest_path.read_bytes() == manifest
assert len(list(backend.cache_dir.rglob("*.bsp.h5"))) == 1
def test_each_gap_graph_problem_has_an_explicit_snap_generator():
problems = []
for benchmark in _benchmark_instances():
generators = benchmark.generators
if not any(type(g).__name__.endswith("GAPGenerator") for g in generators):
continue
problems.append(benchmark.name)
snap = [g for g in generators if type(g).__name__.endswith("SNAPGenerator")]
assert len(snap) == 1, benchmark.name
assert "SNAP" in snap[0].pretty_name
assert snap[0].name.endswith("_snap")
assert not snap[0].cacheable
assert len(problems) == 14
def test_snap_transitive_reduction_removes_redundant_edge(monkeypatch):
from scipy.sparse import coo_array
from binsparse.conversions import from_scipy
from frameworks.saps_numpy import NumpyFramework
from saps.benchmark import DataInstance
from saps.benchmarks import transitive_reduction as reduction
adjacency = from_scipy(coo_array([[0, 1, 1], [0, 0, 1], [0, 0, 0]]))
raw = DataInstance(inputs=[adjacency], meta={})
monkeypatch.setattr(reduction, "fetch_snap_graph", lambda _: raw)
generator = reduction.TransitiveReductionSNAPGenerator()
problem = generator.generate(generator.datasets[0])
xp = NumpyFramework()
actual = reduction.TransitiveReductionBenchmark().benchmark(
xp, [xp.from_binsparse(problem.inputs[0])], problem.meta
)[0]
np.testing.assert_array_equal(
actual, [[np.inf, 1, np.inf], [np.inf, np.inf, 1], [np.inf, np.inf, np.inf]]
)
np.testing.assert_array_equal(
to_scipy(adjacency).toarray(), [[0, 1, 1], [0, 0, 1], [0, 0, 0]]
)
def test_snap_catalog_metadata_and_group_concepts():
from xml.etree import ElementTree as ET
datasets = SNAPGraphGenerator().datasets
for dataset in datasets:
metadata = dataset.metadata
assert metadata["source_name"] == f"SNAP/{dataset.name}"
assert metadata["max_degree"] == _MAX_DEGREES[dataset.source_name]
assert metadata["types"] == dataset.types
assert metadata["description"] == dataset.description
assert metadata["nodes"] == dataset.nodes
assert metadata["edges"] == dataset.edges
assert metadata["groups"] == dataset.groups
assert ET.fromstring(dataset.concepts).findtext("concept/concept_id")
assert dataset.topics
by_name = {d.name: d for d in datasets}
rfa = by_name["wiki-RfA"]
assert len(rfa.groups) == 3
concepts = ET.fromstring(rfa.concepts).findall("concept/concept_id")
assert len(concepts) == len({c.text for c in concepts}) == 3
assert by_name["as-735"].nodes == "103-6,474"
assert by_name["com-Amazon"].communities == 75149
assert by_name["email-Eu-core-temporal"].static_edges == 24929
def test_source_selection_samples_nonzero_edge_starts_reproducibly():
from scipy.sparse import coo_array
from binsparse import COORMatrix
from saps.benchmarks.snap import select_source_vertices
# Row 0 has an explicit zero; row 3 cancels to zero; row 5 is isolated.
adjacency = coo_array(
([0, 1, 1, 1, 1, -1], ([0, 1, 1, 4, 3, 3], [2, 2, 4, 4, 2, 2])),
shape=(6, 6),
)
graph = COORMatrix(
adjacency.shape,
adjacency.nnz,
indices_0=adjacency.row,
indices_1=adjacency.col,
values=adjacency.data,
)
expected = np.array([1, 1, 4])[np.random.default_rng(42).integers(3, size=100)]
actual = select_source_vertices(graph, 100, seed=42)
np.testing.assert_array_equal(actual, expected)
np.testing.assert_array_equal(select_source_vertices(graph, 100, seed=42), actual)
assert set(actual) == {1, 4}
# Coalescing takes place on a copy, leaving the input unchanged.
assert to_scipy(graph).nnz == 6
def test_source_selection_stays_sparse_and_preserves_global_rng():
from scipy.sparse import coo_array
from binsparse.conversions import from_scipy
from saps.benchmarks.snap import select_source_vertices
graph = from_scipy(coo_array(([1], ([999999], [2])), shape=(1000000, 1000000)))
state = np.random.get_state() # noqa: NPY002 - verify legacy global state is untouched
np.testing.assert_array_equal(select_source_vertices(graph, 3), [999999] * 3)
after = np.random.get_state() # noqa: NPY002 - verify legacy global state is untouched
assert state[0] == after[0]
np.testing.assert_array_equal(state[1], after[1])
assert state[2:] == after[2:]
@pytest.mark.parametrize(
("shape", "values", "count", "message"),
[
((3, 3), [], 1, "without nonzero edges"),
((3, 3), [0], 1, "without nonzero edges"),
((3, 2), [1], 1, "square"),
((3, 3), [1], 0, "positive"),
],
)
def test_source_selection_rejects_invalid_inputs(shape, values, count, message):
from scipy.sparse import coo_array
from binsparse.conversions import from_scipy
from saps.benchmarks.snap import select_source_vertices
indices = np.zeros(len(values), dtype=int)
graph = from_scipy(coo_array((values, (indices, indices)), shape=shape))
with pytest.raises(ValueError, match=message):
select_source_vertices(graph, count)
@pytest.mark.parametrize(
("module_name", "test_class", "benchmark_class"),
[
("bfs", "BFSTestGenerator", "BFSBenchmark"),
("bellman_ford", "BellmanFordTestGenerator", "BellmanFordBenchmark"),
],
)
@pytest.mark.parametrize("seed", range(10))
def test_seeded_source_test_suite_problems(
module_name, test_class, benchmark_class, seed
):
from frameworks.saps_numpy import NumpyFramework
module = importlib.import_module(f"saps.benchmarks.{module_name}")
generator = getattr(module, test_class)()
dataset = next(d for d in generator.datasets if d.source_seed == seed)
assert "test" in dataset.suites
problem = generator.generate(dataset)
src = problem.meta["src"]
assert src in (1, 2) # Never the isolated vertex or the sink.
assert problem.meta["seed"] == seed
xp = NumpyFramework()
result = getattr(module, benchmark_class)().benchmark(
xp, [xp.from_binsparse(problem.inputs[0])], problem.meta
)[0]
expected = (
{1: [0, 1, 2, 3], 2: [0, 0, 1, 2]}
if module_name == "bfs"
else {1: [np.inf, 0, 1, 2], 2: [np.inf, np.inf, 0, 1]}
)[src]
np.testing.assert_array_equal(result, expected)
np.testing.assert_array_equal(to_numpy(problem.ref_outputs[0]), expected)
def test_all_snap_sources_have_ten_seeded_cases():
from saps.benchmarks.bellman_ford import BellmanFordSNAPGenerator
from saps.benchmarks.bfs import BFSSNAPGenerator
graphs = SNAPGraphGenerator().datasets
for generator in (BFSSNAPGenerator(), BellmanFordSNAPGenerator()):
datasets = generator.datasets
assert len(datasets) == len({d.name for d in datasets}) == len(graphs) * 10
assert {(d.source_name, d.source_seed) for d in datasets} == {
(g.name, seed) for g in graphs for seed in range(10)
}
assert all("standard" in d.suites for d in datasets)
def test_snap_with_suites_does_not_mutate_shared_graphs():
graph = SNAPGraphGenerator().datasets[0]
selected = graph.with_suites(["standard", "trace"])
assert selected.suites == ["standard", "trace"]
assert graph.suites == []
assert all(dataset.suites == [] for dataset in SNAPGraphGenerator().datasets)
selected.suites.append("test")
assert graph.with_suites(["standard", "trace"]).suites == ["standard", "trace"]
def test_snap_source_trace_selection_is_seed_specific():
graph = SNAPGraphGenerator().datasets[0]
selected = BFSDataset(
"selected", source_name=graph.name, source_seed=0, suites=["trace"]
)
other = BFSDataset("other", source_name=graph.name, source_seed=1)
assert selected.suites == ["trace"]
assert other.suites == []
assert graph.suites == []
@pytest.mark.parametrize("seed", range(5))
def test_seeded_sources_match_one_selection_per_seed(seed):
from scipy.sparse import random as sparse_random
from binsparse.conversions import from_scipy
graph = from_scipy(
sparse_random(50, 50, density=0.05, format="coo", random_state=seed)
)
assert seeded_source_vertices(graph, 20) == [
int(select_source_vertices(graph, seed=k)[0]) for k in range(20)
]
@pytest.mark.parametrize("seed", [-1, NUM_SNAP_SOURCES])
def test_snap_generator_rejects_seeds_without_a_source(monkeypatch, seed):
from saps.benchmark import DataInstance
from saps.benchmarks import bfs
raw = DataInstance(
inputs=[object()], meta={"sources": list(range(NUM_SNAP_SOURCES))}
)
monkeypatch.setattr(bfs, "fetch_snap_graph", lambda _: raw)
dataset = BFSDataset("invalid", source_name="soc-Epinions1", source_seed=seed)
with pytest.raises(ValueError, match="Source seed"):
BFSSNAPGenerator().generate(dataset)
def test_snap_source_graph_picks_source_from_shell_sources(monkeypatch):
from scipy.sparse import coo_array
from binsparse.conversions import from_scipy
from saps.benchmark import DataInstance
from saps.benchmarks import bfs
sources = list(range(100, 100 + NUM_SNAP_SOURCES))
adjacency = from_scipy(coo_array([[0, 1], [0, 0]]))
raw = DataInstance(inputs=[adjacency], meta={"max_degree": 3, "sources": sources})
monkeypatch.setattr(bfs, "fetch_snap_graph", lambda _: raw)
dataset = BFSDataset("seed-seven", source_name="soc-Epinions1", source_seed=7)
problem = BFSSNAPGenerator().generate(dataset)
assert problem.meta == {**raw.meta, "src": 107, "seed": 7}
assert raw.meta == {"max_degree": 3, "sources": sources}
def test_multi_source_snap_problems_use_deduplicated_shell_sources(monkeypatch):
from scipy.sparse import coo_array
from binsparse.conversions import from_scipy
from saps.benchmark import DataInstance
from saps.benchmarks import mssp
adjacency = from_scipy(coo_array([[0, 1, 0], [0, 0, 1], [1, 0, 0]]))
raw = DataInstance(inputs=[adjacency], meta={"sources": [2, 0, 2, 0, 1]})
monkeypatch.setattr(mssp, "fetch_snap_graph", lambda _: raw)
generator = mssp.MSSPSNAPGenerator()
problem = generator.generate(generator.datasets[0])
assert problem.meta == {"sources": [0, 1, 2]}
assert problem.inputs[1].shape == (3, 3)
def test_msbfs_snap_problems_use_deduplicated_shell_sources_and_edge_pattern(
monkeypatch,
):
from scipy.sparse import coo_array
from binsparse.conversions import from_scipy
from saps.benchmark import DataInstance
from saps.benchmarks import msbfs
adjacency = from_scipy(coo_array([[0, 2, 0], [0, 0, -1], [1, 0, 0]]))
raw = DataInstance(inputs=[adjacency], meta={"sources": [2, 0, 2, 0, 1]})
monkeypatch.setattr(msbfs, "fetch_snap_graph", lambda _: raw)
generator = msbfs.MSBFSSNAPGenerator()
problem = generator.generate(generator.datasets[0])
assert problem.meta == {"sources": [0, 1, 2]}
edges = to_sparse(problem.inputs[0]).todense()
assert edges.dtype == bool
np.testing.assert_array_equal(edges, [[0, 1, 0], [0, 0, 1], [1, 0, 0]])
np.testing.assert_array_equal(to_sparse(problem.inputs[1]).todense(), np.eye(3))