Skip to content
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

Suspect formatting bug with Type Hierarchy #115

Closed
marcofavorito opened this issue May 8, 2024 · 6 comments
Closed

Suspect formatting bug with Type Hierarchy #115

marcofavorito opened this issue May 8, 2024 · 6 comments

Comments

@marcofavorito
Copy link
Member

Subject of the issue

This issue has been created to investigate more on several issue the user @fenjenahwe is experiencing with the library. Some of the issues the user encountered have been reported in the comments of issue #98, and they are about the formatting of domains with a non-flat hierarchy of types.

The user reported in this comment that the following code:

from pddl.core import Domain, Requirements
from pddl.formatter import domain_to_string

requirements = [Requirements.STRIPS, Requirements.TYPING, Requirements.NEG_PRECONDITION]
domain = Domain("dining-general",
    requirements=requirements,
    types={
        "objects": "world",
        "location": "world",
        "hypothesis": "world",
        "agent": "objects",
        "furniture": "objects",
        "consumable": "objects",
    })
print(domain_to_string(domain))

Prints:

(define (domain dining-general)
    (:requirements :negative-preconditions :strips :typing)
    (:types agent consumable furniture hypothesis location objects)

Whereas the expected behaviour is something like:

(define (domain dining-general)
    (:requirements :negative-preconditions :strips :typing)
    (:types agent consumable furniture - objects hypothesis location objects - world)
)
@marcofavorito
Copy link
Member Author

Hi @fenjenahwe, I tried to install the library in a fresh virtual environment (Python 3.10.12). I installed pddl at the latest version at the time of writing, which is 0.4.0.

The above code gave me the expected outcome, follows a screenshot:
image

Please, @fenjenahwe, can you provide more details on your environment (i.e., operating system, Python version, pddl version...) ? It would be greatly appreciated to better understand the issue you are having.

@marcofavorito
Copy link
Member Author

Also, the result can be parsed correctly:

from pathlib import Path
from pddl.core import Domain, Requirements
from pddl.formatter import domain_to_string
from pddl import parse_domain

requirements = [Requirements.STRIPS, Requirements.TYPING, Requirements.NEG_PRECONDITION]
types = {
        "A": "B",
        "B": "C",
        "C": None
    }
domain = Domain("example",
    requirements=requirements,
    types=types
)

# write domain to file
Path("example.pddl").write_text(domain_to_string(domain))

# parse the domaion
actual_domain = parse_domain(Path("example.pddl"))

print(domain_to_string(actual_domain))

print("Original domain types:")
print(types)
print("Parsed domain types:")
print(actual_domain.types)

The output of the above code snippet is:

(define (domain example)
    (:requirements :negative-preconditions :strips :typing)
    (:types A - B B - C C)
)
Original domain types:
{'A': 'B', 'B': 'C', 'C': None}
Parsed domain types:
{'A': 'B', 'B': 'C', 'C': None}

@fenjenahwe
Copy link

Thanks @marcofavorito

My environment details are:
OS: Ubuntu 22.04.4
Python version: 3.10.12

While reinstalling the library in a new environment, I noticed I had been installing pddl version 0.2.0
This must be the reason, my apologies.
I will try with the newest library version and report back if it doesn't solve it.

@marcofavorito
Copy link
Member Author

Perfect, thank you so much! If you don't mind, please let us know when you tried so we can be sure it is not an issue.

@fenjenahwe
Copy link

I confirm! This solved it.
Thanks a lot for helping so quickly and sorry for the oversight.

@marcofavorito
Copy link
Member Author

Perfect! No worries :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants