AI-Planning / pddl

Unquestionable PDDL 3.1 parser
https://ai-planning.github.io/pddl/
MIT License
85 stars 27 forks source link

Unable to pickle or deepcopy Domains, Actions, Problems #79

Closed James-Oswald closed 1 year ago

James-Oswald commented 1 year ago

Subject of the issue

The cache hashing mechanism appears to break my ability to deepcopy or pickle any of the core objects.

Your environment

Steps to reproduce

Minimally reproducible example for domains, same issue with actions and problems

import copy
import pickle
import traceback

from pddl.parser.domain import DomainParser

domain_str = """
    (define (domain test)
        (:requirements :typing)
        (:types t1)
        (:constants c1 - t1)
        (:predicates  (p1 ?v1 - t1))
        (:action a1
        :parameters (?v - t1)
        :effect (c1))
)"""

domain = DomainParser()(domain_str)

#Deep copy domains
try:
    copy.deepcopy(domain)
except Exception:
    print(traceback.format_exc())

#Pickle domains
try:
    pickle.dumps(domain)
except Exception:
    print(traceback.format_exc())

Expected behaviour

I should get a deepcopied/pickled domain/action/problem without any errors occurring.

Actual behaviour

All fails with KeyError: 'hash' in the `d.pop("hash")oncache_hash.py` line 56.

marcofavorito commented 1 year ago

Thank you @James-Oswald for the issue. This is indeed an unintended behaviour.

James-Oswald commented 1 year ago

Thanks for the speedy fix!