From 72edcd16bdeac6372d6539c7206fbdfc5a267b48 Mon Sep 17 00:00:00 2001 From: Samuel Gobbi Date: Fri, 27 Sep 2024 10:07:28 +0200 Subject: [PATCH] fix(interpreted functions): fixed wrong function for IF in numeric assignment, added tests, removed comments --- unified_planning/engines/parallel.py | 40 +++----------------- unified_planning/model/problem_kind.py | 2 - unified_planning/test/examples/minimals.py | 10 ++++- unified_planning/test/test_plan_validator.py | 9 +++++ unified_planning/test/test_problem.py | 1 + 5 files changed, 23 insertions(+), 39 deletions(-) diff --git a/unified_planning/engines/parallel.py b/unified_planning/engines/parallel.py index 964d4d5ce..475eeaaed 100644 --- a/unified_planning/engines/parallel.py +++ b/unified_planning/engines/parallel.py @@ -13,7 +13,6 @@ # limitations under the License. # -import time import warnings import unified_planning as up import unified_planning.engines as engines @@ -97,26 +96,18 @@ def _run_parallel(self, fname, *args) -> List[Result]: ) processes.append(_p) _p.start() - # print ("\n\n!?!?!?!?!?!?!?!?!?!\n\n") - # print (processes) processes_alive = len(processes) results: List[Result] = [] definitive_result_found: bool = False - # print ("------------msg---------------") - # print ("parent process queue is:") - # print (signaling_queue) - # print ("parent going to sleep") - time.sleep(5) - # print ("parent waking up") while True: if processes_alive == 0: # Every planner gave a result break # deadlock line ----------------------------------------------------------------------------------------- - # print ("about to read") + (idx, res) = signaling_queue.get( block=False ) # (idx, res) = signaling_queue.get(block=True) # deadlock line - # print ("after read") + # deadlock line ----------------------------------------------------------------------------------------- # callables can't be pickled ? processes_alive -= 1 @@ -223,35 +214,14 @@ def _run( *args, ): EngineClass = factory.engine(engine_name) - # print ("------------msg---------------") - # print ("Hello I am") - # print (idx) with EngineClass(**options) as s: s.skip_checks = skip_checks s.error_on_failed_checks = error_on_failed_checks try: - # print ("------------msg---------------") - # print (idx) - # print ("trying to do the thing") local_res = getattr(s, fname)(*args) except Exception as ex: - # print ("------------msg---------------") - # print (idx) - # print ("found an exception") signaling_queue.put((idx, ex)) return - # print ("------------msg---------------") - # print (idx) - # print ("trying to put on the queue:") - # print ("queue:") - # print (signaling_queue) - # print ("local res:") - # print (local_res) - signaling_queue.put((idx, local_res)) - # print ("------------msg---------------") - # print (idx) - # print ("after putting on queue :") - # print ("queue empty result:") - # print (signaling_queue.empty()) - # print ("queue size result:") - # print (signaling_queue.qsize()) + signaling_queue.put( + (idx, local_res) + ) # seems that after this queue.empty still says that queue is empty ? diff --git a/unified_planning/model/problem_kind.py b/unified_planning/model/problem_kind.py index a1a2cfee1..7f1b880e4 100644 --- a/unified_planning/model/problem_kind.py +++ b/unified_planning/model/problem_kind.py @@ -173,8 +173,6 @@ def _set(self, feature, possible_features): self._features.add(feature) def _unset(self, feature, possible_features): - print(feature) - print(possible_features) assert feature in possible_features self._features.discard(feature) diff --git a/unified_planning/test/examples/minimals.py b/unified_planning/test/examples/minimals.py index 66a04285b..18483e688 100644 --- a/unified_planning/test/examples/minimals.py +++ b/unified_planning/test/examples/minimals.py @@ -784,7 +784,7 @@ def i_f_go_home_duration( def i_f_simple_int(inputone, inputtwo): if inputone % 2 == 0: return inputone - return inputtwo + inputone + return inputtwo * inputone funx = InterpretedFunction("funx", IntType(), signatureConditionF, i_f_simple_int) @@ -808,7 +808,13 @@ def i_f_simple_int(inputone, inputtwo): ifproblem = TestCase( problem=problem, - solvable=False, # should be true but can't be handled by UP yet + solvable=True, + valid_plans=[ + up.plans.SequentialPlan([apply_i_f_assignment()]), + ], + invalid_plans=[ + up.plans.SequentialPlan([]), + ], ) problems["interpreted_functions_in_numeric_assignment"] = ifproblem diff --git a/unified_planning/test/test_plan_validator.py b/unified_planning/test/test_plan_validator.py index 52a4faec4..ae468108e 100644 --- a/unified_planning/test/test_plan_validator.py +++ b/unified_planning/test/test_plan_validator.py @@ -177,3 +177,12 @@ def test_with_interpreted_functions(self): for plan in p.invalid_plans: validation_result = spv.validate(problem, plan) self.assertEqual(validation_result.status, ValidationResultStatus.INVALID) + + p = self.problems["interpreted_functions_in_numeric_assignment"] + problem = p.problem + for plan in p.valid_plans: + validation_result = spv.validate(problem, plan) + self.assertEqual(validation_result.status, ValidationResultStatus.VALID) + for plan in p.invalid_plans: + validation_result = spv.validate(problem, plan) + self.assertEqual(validation_result.status, ValidationResultStatus.INVALID) diff --git a/unified_planning/test/test_problem.py b/unified_planning/test/test_problem.py index 0cfbc80f9..128ab4a81 100644 --- a/unified_planning/test/test_problem.py +++ b/unified_planning/test/test_problem.py @@ -607,6 +607,7 @@ def test_undefined_initial_state(self): def test_interpreted_functions_simple(self): problem = self.problems["interpreted_functions_in_conditions"].problem + print(problem) # this is just to test repr of IFs self.assertTrue(problem.kind.has_interpreted_functions_in_conditions()) self.assertFalse(problem.kind.has_simple_numeric_planning()) problem = self.problems[