Skip to content

Commit

Permalink
partial fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Gobbi committed Sep 9, 2024
1 parent 55f619d commit ef9548e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
9 changes: 5 additions & 4 deletions unified_planning/engines/compilers/compilers_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions unified_planning/engines/compilers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions unified_planning/test/test_planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit ef9548e

Please sign in to comment.