Skip to content

Commit

Permalink
fix(interpreted functions): fixed wrong function for IF in numeric as…
Browse files Browse the repository at this point in the history
…signment, added tests, removed comments
  • Loading branch information
Samuel Gobbi committed Sep 27, 2024
1 parent 4f56652 commit 72edcd1
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 39 deletions.
40 changes: 5 additions & 35 deletions unified_planning/engines/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# limitations under the License.
#

import time
import warnings
import unified_planning as up
import unified_planning.engines as engines
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 ?
2 changes: 0 additions & 2 deletions unified_planning/model/problem_kind.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
10 changes: 8 additions & 2 deletions unified_planning/test/examples/minimals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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

Expand Down
9 changes: 9 additions & 0 deletions unified_planning/test/test_plan_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 1 addition & 0 deletions unified_planning/test/test_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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[
Expand Down

0 comments on commit 72edcd1

Please sign in to comment.