aiplan4eu / unified-planning

The AIPlan4EU Unified Planning Library
Apache License 2.0
181 stars 39 forks source link

Missing grounded actions. #570

Closed MFaisalZaki closed 6 months ago

MFaisalZaki commented 6 months ago

Describe the bug For some reason, some grounded actions are unavailable when using Pyperplan Grounder.

To Reproduce

from unified_planning.io import PDDLReader
from unified_planning.shortcuts import *

domain  = './domain.pddl'
problem = './problem.pddl'
task = PDDLReader().parse_problem(domain, problem)

with Compiler(problem_kind=task.kind, compilation_kind=CompilationKind.GROUNDING) as grounder:
    print(f'Grounder name: {grounder.name}')
    grounded_problem = grounder.compile(task, compilation_kind=CompilationKind.GROUNDING).problem

grounded_actions = [str(a.name) for a in grounded_problem.actions]

is_action_missing = not 'drive_truck1_distributor0_distributor0'in grounded_actions

with open('grounded_actions.txt', 'w') as f:
    for item in grounded_actions:
        f.write("%s\n" % item)

Screenshots

Screenshot 2024-02-21 at 11 05 30 AM

Additional context instance.zip

alvalentini commented 6 months ago

Hi @MFaisalZaki! The reason is that the grounder removes all the grounded actions that are inapplicable or not useful to solve the problem. The smarter the grounder, the fewer grounded actions are generated.

MFaisalZaki commented 6 months ago

That is so true @alvalentini, but I think this could impact when trying to solve goal recognition as planning tasks since an observation is a grounded action which may not be generated by the grounder. Is there any flag I can set to force the grounder to generate all actions?

alvalentini commented 6 months ago

It is possible using this grounder with the option prune_actions=False.

with Compiler(name='up_grounder', params={'prune_actions':False}) as grounder:
    grounded_problem = grounder.compile(task).problem

or

from unified_planning.engines.compilers.grounder import Grounder
grounder = Grounder(prune_actions=False)
grounded_problem = grounder.compile(task).problem
MFaisalZaki commented 6 months ago

Awesome, thanks @alvalentini.

alvalentini commented 6 months ago

If the issue is solved, can you close the issue? Thanks!