diff --git a/unified_planning/engines/compilers/compilers_pipeline.py b/unified_planning/engines/compilers/compilers_pipeline.py index 2f4cabb40..0156af98c 100644 --- a/unified_planning/engines/compilers/compilers_pipeline.py +++ b/unified_planning/engines/compilers/compilers_pipeline.py @@ -107,10 +107,11 @@ def _compile( def map_back_action_instance( action: ActionInstance, - map_back_functions: List[Callable[[ActionInstance], ActionInstance]], + map_back_functions: List[Callable[[ActionInstance], Optional[ActionInstance]]], ) -> Optional[ActionInstance]: + tempAction: Optional[ActionInstance] = action for f in map_back_functions: - action = f(action) - if action is None: + tempAction = f(tempAction) + if tempAction is None: break - return action + return tempAction diff --git a/unified_planning/engines/compilers/trajectory_constraints_remover.py b/unified_planning/engines/compilers/trajectory_constraints_remover.py index 81f1a0c0c..e20c8b7b1 100644 --- a/unified_planning/engines/compilers/trajectory_constraints_remover.py +++ b/unified_planning/engines/compilers/trajectory_constraints_remover.py @@ -23,6 +23,7 @@ from unified_planning.model.walkers import ExpressionQuantifiersRemover from unified_planning.model import Problem, ProblemKind, MinimizeActionCosts from unified_planning.model.problem_kind_versioning import LATEST_PROBLEM_KIND_VERSION +from unified_planning.model.expression import Expression from functools import partial from unified_planning.engines.compilers.utils import ( lift_action_instance, @@ -239,14 +240,12 @@ def _compile( for qm in grounded_problem.quality_metrics: if qm.is_minimize_action_costs(): assert isinstance(qm, MinimizeActionCosts) - new_costs = { + new_costs: Dict[Action, Expression] = { na: qm.get_action_cost(grounded_problem.action(na.name)) for na in new_problem.actions } new_problem.add_quality_metric( - MinimizeActionCosts( - new_costs - ) # , environment=new_problem.environment # add_quality_metric does not get the environment as argument + MinimizeActionCosts(new_costs, environment=new_problem.environment) ) else: new_problem.add_quality_metric(qm) diff --git a/unified_planning/engines/compilers/usertype_fluents_remover.py b/unified_planning/engines/compilers/usertype_fluents_remover.py index 50ff630fc..598198a2b 100644 --- a/unified_planning/engines/compilers/usertype_fluents_remover.py +++ b/unified_planning/engines/compilers/usertype_fluents_remover.py @@ -174,7 +174,7 @@ def _compile( tm = env.type_manager em = env.expression_manager - new_to_old: Dict[Action, Action] = {} + new_to_old: Dict[Action, Optional[Action]] = {} new_problem = Problem(f"{self.name}_{problem.name}", env) new_problem.add_objects(problem.all_objects) diff --git a/unified_planning/engines/compilers/utils.py b/unified_planning/engines/compilers/utils.py index e916056e0..01fbb8b3f 100644 --- a/unified_planning/engines/compilers/utils.py +++ b/unified_planning/engines/compilers/utils.py @@ -309,7 +309,7 @@ def add_invariant_condition_apply_function_to_problem_expressions( new_problem: Problem, condition: Optional[FNode] = None, function: Optional[Callable[[FNode], FNode]] = None, -) -> Dict[Action, Action]: +) -> Dict[Action, Optional[Action]]: """ This function takes the original problem, the new problem and adds to the new problem all the fields that involve an expression, applying the given function (the identity if it is None) @@ -336,7 +336,7 @@ def add_invariant_condition_apply_function_to_problem_expressions( assert condition is not None if function is None: function = lambda x: x - new_to_old: Dict[Action, Action] = {} + new_to_old: Dict[Action, Optional[Action]] = {} for constraint in original_problem.trajectory_constraints: new_problem.add_trajectory_constraint(function(constraint)) diff --git a/unified_planning/test/test_planner.py b/unified_planning/test/test_planner.py index 96e672b4b..c6eceec87 100644 --- a/unified_planning/test/test_planner.py +++ b/unified_planning/test/test_planner.py @@ -331,11 +331,11 @@ def name(self): @staticmethod def supports( problem_kind: ProblemKind, - ): # super method requires this to be static with problem_kind as an argument + ) -> bool: return True @staticmethod - def supported_kind() -> ProblemKind: # super method requires this to be static + def supported_kind() -> ProblemKind: return ProblemKind() with self.assertRaises(TypeError):