From d49dfa50048633eaa04ea40dbc8a0a1b7cad329d Mon Sep 17 00:00:00 2001 From: Leonardo Lamanna Date: Fri, 3 Apr 2026 18:18:00 +0200 Subject: [PATCH] create a local copy of empty_domain function from amlgym --- main.py | 2 +- olam/util/util.py | 28 ++++++++++++++++++++++++++++ pyproject.toml | 2 +- requirements.txt | 5 +++-- tests/test_results.py | 2 +- 5 files changed, 34 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 30cf536..2b27d40 100644 --- a/main.py +++ b/main.py @@ -10,7 +10,7 @@ import numpy as np import unified_planning from amlgym.metrics import syntactic_precision, syntactic_recall -from amlgym.util.util import empty_domain +from olam.util.util import empty_domain from unified_planning.io import PDDLReader, PDDLWriter from unified_planning.shortcuts import SequentialSimulator diff --git a/olam/util/util.py b/olam/util/util.py index 61528c0..5c77bfd 100644 --- a/olam/util/util.py +++ b/olam/util/util.py @@ -1,5 +1,7 @@ import itertools +import re +from unified_planning.io import PDDLReader, PDDLWriter from unified_planning.model import Fluent, Object, Problem from unified_planning.plans import ActionInstance from unified_planning.shortcuts import BoolType @@ -7,6 +9,32 @@ from olam.modeling.symbolic_observation import SymbolicObservation +def empty_domain(domain_path: str, empty_domain_path: str = 'empty.pddl'): + pddl_domain = PDDLReader().parse_problem(domain_path) + + # Loop through all actions and remove preconditions and effects + for action in pddl_domain.actions: + action.clear_preconditions() + action.clear_effects() + + domain_str = PDDLWriter(pddl_domain).get_domain() + pattern = re.compile( + r"(:action[\s\S]*?:parameters\s*\([^)]*\))\)", + re.MULTILINE + ) + + replacement = r"\1\n :precondition (and )\n :effect (and ))\n" + + # TODO: open issue in up + domain_str = domain_str.replace(f"(domain {pddl_domain.name}-domain)", + f"(domain {pddl_domain.name})") + + with open(empty_domain_path, 'w') as f: + f.write(pattern.sub(replacement, domain_str)) + + return empty_domain_path + + def ground_lifted_atoms(action_instance: ActionInstance, lifted_atoms): grounded_atoms = set() for atom in lifted_atoms: diff --git a/pyproject.toml b/pyproject.toml index 1765c88..432fb6c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,7 +22,7 @@ addopts = "--ignore=tests/heavy" [project] name = "olam" -version = "1.0.1" +version = "1.0.2" dynamic = ["dependencies"] requires-python = ">=3.10" maintainers = [ diff --git a/requirements.txt b/requirements.txt index d550880..5478d0a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,9 @@ unified-planning == 1.3.0 up-fast-downward == 0.5.2 clingo == 5.8.0 -amlgym == 1.0.7 +scikit-learn ruff pytest pandas -gymnasium \ No newline at end of file +gymnasium +amlgym \ No newline at end of file diff --git a/tests/test_results.py b/tests/test_results.py index c95548f..1c221c3 100644 --- a/tests/test_results.py +++ b/tests/test_results.py @@ -4,7 +4,7 @@ import pandas as pd import pytest from amlgym.metrics import syntactic_precision, syntactic_recall -from amlgym.util.util import empty_domain +from olam.util.util import empty_domain from unified_planning.io import PDDLReader from unified_planning.shortcuts import SequentialSimulator