Add golden toy examples test suite for comprehensive py3plex validation#899
Merged
Add golden toy examples test suite for comprehensive py3plex validation#899
Conversation
Co-authored-by: SkBlaz <10035780+SkBlaz@users.noreply.github.com>
Co-authored-by: SkBlaz <10035780+SkBlaz@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Create pytest module for golden toy examples
Add golden toy examples test suite for comprehensive py3plex validation
Dec 14, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds deterministic test suite with hand-computable expected outputs covering all main py3plex components: core network construction, multiplex coupling semantics, supra-adjacency matrices, statistics, centrality measures, community detection, DSL queries, I/O, and visualization.
Test Coverage
10 tests across key domains:
Q.nodes().from_layers(L["layer1"]).where(degree__gt=1))Example Usage
Implementation Notes
tmp_path, matplotlib uses Agg backendrandom_state=42)Original prompt
This section details on the original issue you should resolve
<issue_title>golden toy tests</issue_title>
<issue_description>You are working in the py3plex repository.
Goal:
Create a new pytest module named: tests/test_golden_toy_examples.py
This module should provide “golden toy examples” (tiny graphs with hand-computable expected outputs) that exercise ALL main parts of py3plex:
Constraints:
Implementation steps:
from py3plex.algorithms.community_detection.multilayer_modularity import louvain_multilayer
If this import path differs in the repo, search for the multilayer Louvain entrypoint used in the 10-minute tutorial and use that.
Fixture A: toy_multilayer_network()
['A','layer1','B','layer1',1],
['B','layer1','C','layer1',1],
['A','layer2','B','layer2',1],
['B','layer2','D','layer2',1]
Fixture B: toy_multiplex_network(tmp_path)
layer 1: A-B, C-D
layer 2: A-B, C-D
net = multinet.multi_layer_network(network_type="multiplex")
net.load_network(str(path), directed=False, input_type="multiplex_edges")
test_golden_multilayer_statistics(toy_multilayer_network):
assert mls.layer_density(net,"layer1") == pytest.approx(2/3, rel=1e-6)
assert mls.layer_density(net,"layer2") == pytest.approx(2/3, rel=1e-6)
assert mls.node_activity(net, node="B") == pytest.approx(1.0)
assert mls.node_activity(net, node="C") == pytest.approx(0.5)
test_golden_supra_adjacency_shape(toy_multilayer_network):
mtx = net.get_supra_adjacency_matrix()
n = len(list(net.get_nodes()))
assert mtx.shape == (n,n)
(Optional robust check) if network is undirected, verify matrix is symmetric (mtx - mtx.T has zero nnz / near-zero norm).
Avoid brittle ordering-dependent checks.
explicit_edges = list(net.get_edges(data=True, multiplex_edges=False))
all_edges = list(net.get_edges(data=True, multiplex_edges=True))
assert len(all_edges) > len(explicit_edges)
coupling_edges = [e for e in all_edges if isinstance(e, tuple) and len(e) >= 3 and e[2].get("type") == "coupling"]
If coupling_edges is non-empty, assert len(coupling_edges) == 4 for 4 physical nodes in 2 layers.
Also assert that explicit_edges contains exactly the 4 within-layer edges (2 per layer).
If the exact API differs, adapt: the key invariant is that coupling edges exist and are filtered out by multiplex_edges=False.
agg = net.aggregate_edges(metric="count", normalize_by="raw")
Ensure you can read weights for edges A-B and C-D.
Assert weight(A,B) == 2 and weight(C,D) == 2.
If agg returns a py3plex network, inspect agg.core_network; if it returns a NetworkX graph, use that directly.
res = execute_query(net, "SELECT nodes WHERE degree > 1")
Assert it returns count == 2 (only ('B','layer1') and ('B','layer2') have degree 2 in the combined core graph).
If the DSL returns a Result object, check re...
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.