-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes and improvements in the parsing of typed lists #82
Conversation
The goal was just '(and )', restore the original reachability goal.
This commit adds the parsing utility class "TypesIndex". TypesIndex is an index for PDDL types and PDDL names/variables. It is used to index PDDL names and variables by their types. OrderedDict is used to preserve the order of the types and the names, e.g. for predicate variables. Other types of validations are performed to ensure that the types index is consistent. In this commit, it is used only to parse typed lists of names (not variables).
…ompatible) This commit changes the way typed_list_name rule is parsed. This does not change the parsing behaviour from the user perspective, but it is a non-functional change to improve the performances of the Lark parser. With the previous version of the rule 'typed_list_name: NAME+ TYPE_SEP primitive_type (typed_list_name)', the Lark parser internals would perform a recursive call whenever a typed_list_name is matched. This might cause an arbitrarily long stack of calls whenever the parser got an input like: ``` element1 - t1 element2 - t1 element3 t1 ... ``` The above list of tokens is parsed as: ``` element1 - t1 <typed_list_name> element2 - t1 <typed_list_name> element3 - t1 <typed_list_name> ... ``` For large inputs, this will easily hit the recursion depth limit. With the new approach, the entire list of tokens is parsed at once. This adds some complexity in the parsing function for the typed_list_name rule, but we have more control in how the parsing is performed; in particular, we can parse the tokens *iteratively* rather than *recursively*. Finally, the NAME* pattern is appended at the end of the typed_list_name rule. This is because, according to the syntax specification, the last sublist of names might be non-typed. The implementation exploits the newly added TypesIndex class which handles corner cases and syntax errors (e.g. duplicated entries in the list).
a3b6101
to
ccb5097
Compare
The order is taken from pag. 168 of the PDDL textbook, where colon ':' is ignored in determining the order.
Codecov Report
❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more. @@ Coverage Diff @@
## main #82 +/- ##
==========================================
+ Coverage 89.67% 90.30% +0.62%
==========================================
Files 22 24 +2
Lines 1182 1423 +241
Branches 193 247 +54
==========================================
+ Hits 1060 1285 +225
- Misses 92 102 +10
- Partials 30 36 +6
Flags with carried forward coverage won't be shown. Click here to find out more.
|
662eee9
to
73e4fac
Compare
The value of type dict passed to the Domain constructor in the README is set to None, denoting the fact that the type has no parent type.
37909e9
to
03abf7d
Compare
pddl/parser/domain.py
Outdated
|
||
def typed_list_variable(self, args) -> Dict[str, Set[str]]: | ||
def typed_list_variable(self, args) -> OrderedDictType[name, Set[name]]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OrderedDict
is essential, predicates variables and action parameters require an ordered (possibly typed) list of variables, and the ordering in the PDDL input file must be remembered.
The same cannot be said for forall
/exists
expressions, but having them ordered does not harm.
@@ -21,34 +21,36 @@ | |||
class Symbols(Enum): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1092fae
to
fada331
Compare
4b0ddd6
to
ec8c7d9
Compare
i.e. terms with the same name should have the same type tags.
ec8c7d9
to
3661f64
Compare
@@ -13,7 +13,7 @@ jobs: | |||
strategy: | |||
matrix: | |||
os: [ubuntu-latest] | |||
python-version: [3.7] | |||
python-version: ["3.8"] | |||
|
|||
timeout-minutes: 30 | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we change:
- uses: actions/checkout@master
- uses: actions/setup-python@master
to main
as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes sure, thank you for spotting it
@@ -13,7 +13,7 @@ jobs: | |||
strategy: | |||
matrix: | |||
os: [ubuntu-latest] | |||
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] | |||
python-version: ["3.8", "3.9", "3.10", "3.11"] | |||
|
|||
timeout-minutes: 30 | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here?
hi @francescofuggitti @marcofavorito , I was about to submit a PR to fix the constant section the domain, as they currently do not come with their types. However, I just found this massive PR that seems to deal with related things and will change many things, so don't want to cause conflicts and so I am planning to wait until this is merge. Is it almost done? I think the problem is in
That can be improved I think to do the same as objects in problems... I think. (BTW, great work on this parser, it's very clean!) |
Hi @ssardina , thank you for your appreciation... being useful to the community is the lymph for our work and motivation! Given your message, we will finish the PR very very soon (~hours). We will keep you posted here :) |
- types are now printed correctly in the :constants section - in the :objects section, the objects are grouped by type (as in constants) - minor fixes in how :init and :goal are printed (they are always printed even if empty). The code changes added here are to be considered temporary, since a refactoring of the formatting module is required. Nevertheless, the printing of the typing information of constants will remain.
"""\ | ||
(define (domain my_domain) | ||
(:requirements :typing) | ||
(:types type_2 type_3 - type_1 type_1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(define (domain my_domain) | ||
(:requirements :typing) | ||
(:types type_2 type_3 - type_1 type_1) | ||
(:constants a b c - type_1 d e f - type_2 g h i - type_3 j k l) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the same applies here: first group by type, print groups by type name in alphanumerical order, and then print constants sorted within the group; however, constants with no type must be at the end.
(define (problem problem-1) | ||
(:domain my_domain) | ||
(:requirements :typing) | ||
(:objects a b c - type_1 d e f - type_2 g h i - type_3 j k l) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the same approach used for constants applies here.
(:init ) | ||
(:goal (and)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should decide what to do with empty init and goal sections. The PDDL grammar specifies these sections are mandatory. We will tackle this in a next PR, taking into account formatter refactoring #72
@ssardina this commit edcc295 should solve your request. The formatting issue was planned for another PR, but it is even better that we've added it here. @francescofuggitti, @haz, any concerns? Would you like to give a final review? I have other changes planned (integrate consistency checks, started here), but I think this PR is already too big; so I will continue on another branch/PR. |
Now @marcofavorito , this is related to types and this PR, but maybe you want to handled it later on another thread. It doesn't like a type having two parent types, like in this Storage case: Is this part of PDDL constraints or we are over-checking here: This is the error given in the However, in this PR I get an even more primitive error complaining that area is duplicated: I believe a parent type can indeed be a child type in PDDL and is used in many domains, right? Like here |
Thank you for your reply @ssardina . In this issue #70, there has been a discussion regarding whether we should support them or not. The discussion converged to NOT supporting types with multiple parent types (I think it is summarized by this comment, that cites the PDDL textbook: #70 (comment)) I would be very glad to know your opinion on the topic though! |
Regarding the problem on |
However, in this PR I get an even more primitive error complaining that area is duplicated:
@ssardina I think the problem in this case is that The error message will be changed so to be more informative. |
This should make the error more clear to the user: instead of just saying that the name is "already present" in the list, we clarify that the problem is that not only it occurs, but it is because it occurs (again) as inheriting name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks awesome! Thank you :)
Proposed changes
This PR brings several fixes and improvements in the parsing of typed lists (names/variables).
Fixes
n/a
Types of changes
What types of changes does your code introduce?
Put an
x
in the boxes that applyChecklist
Put an
x
in the boxes that apply.Further comments
n/a