Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/pruna/config/pre_smash_routines.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def check_directional_compatibility_violations(graph: nx.DiGraph, algorithm_orde
for j, alg_after in enumerate(algorithm_order):
# alg_before comes before alg_after in the provided order
# Check if there's an edge from alg_after to alg_before in the graph
if i < j and not graph.has_edge(alg_before, alg_after):
if i < j and graph.has_edge(alg_after, alg_before):
violations.append((alg_before, alg_after))
return violations

Expand Down
12 changes: 12 additions & 0 deletions tests/config/test_pre_smash_routines.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
check_argument_compatibility,
execute_algorithm_pre_smash_hooks,
check_algorithm_cross_compatibility,
check_directional_compatibility_violations,
determine_algorithm_order,
construct_algorithm_directed_graph,
)
Expand Down Expand Up @@ -350,6 +351,17 @@ def test_cross_compatibility_disjointly_compatible_algorithms_incompatible_targe
class TestDetermineAlgorithmOrder:
"""Test suite for determine_algorithm_order function."""

def test_directional_compatibility_allows_independent_algorithms(self):
"""Only a reversed dependency should invalidate an explicit order."""
graph = nx.DiGraph()
graph.add_nodes_from(["algorithm1", "algorithm2", "algorithm3"])
graph.add_edge("algorithm1", "algorithm2")

assert check_directional_compatibility_violations(graph, ["algorithm1", "algorithm2", "algorithm3"]) == []
assert check_directional_compatibility_violations(graph, ["algorithm3", "algorithm2", "algorithm1"]) == [
("algorithm2", "algorithm1")
]

def test_determine_algorithm_order_success(self):
"""Test successful algorithm order determination. Should return topologically sorted algorithm order."""
model = None
Expand Down