diff --git a/src/pruna/config/pre_smash_routines.py b/src/pruna/config/pre_smash_routines.py index 26103d14..cb6bb628 100644 --- a/src/pruna/config/pre_smash_routines.py +++ b/src/pruna/config/pre_smash_routines.py @@ -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 diff --git a/tests/config/test_pre_smash_routines.py b/tests/config/test_pre_smash_routines.py index 57c013f5..a7990dfa 100644 --- a/tests/config/test_pre_smash_routines.py +++ b/tests/config/test_pre_smash_routines.py @@ -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, ) @@ -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