aiplan4eu / unified-planning

The AIPlan4EU Unified Planning Library
Apache License 2.0
193 stars 41 forks source link

Crash of `aries` engine integration code when adding timed effects #536

Closed nicola-gigante closed 11 months ago

nicola-gigante commented 11 months ago

Describe the bug The aries engine integration crashes when a timed effect is added to a problem.

To Reproduce Run the following:

import unified_planning as up
from unified_planning.shortcuts import *
from unified_planning.model.htn import *

problem = HierarchicalProblem()

done = Fluent('done', BoolType())
problem.add_fluent(done)
problem.set_initial_value(done, False)

problem.add_timed_effect(
    Timing(60, Timepoint(TimepointKind.GLOBAL_START)), done, True
)

print(problem.timed_effects)

with OneshotPlanner(name='aries') as planner:
    res = planner.solve(problem)
    print(res)

The output is the following:

{start + 60: [done := true]}
Traceback (most recent call last):
  File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/ngigante/projects/telaio/backend/planning/models/issue.py", line 19, in <module>
    res = planner.solve(problem)
  File "/home/ngigante/projects/telaio/.venv/lib/python3.9/site-packages/unified_planning/engines/mixins/oneshot_planner.py", line 80, in solve
    return self._solve(problem, heuristic, timeout, output_stream)
  File "/home/ngigante/projects/telaio/.venv/lib/python3.9/site-packages/up_aries/solver.py", line 347, in _solve
    server, req = self._prepare_solving(problem, heuristic, timeout, output_stream)
  File "/home/ngigante/projects/telaio/.venv/lib/python3.9/site-packages/up_aries/solver.py", line 310, in _prepare_solving
    proto_problem = self._writer.convert(problem)
  File "/home/ngigante/projects/telaio/.venv/lib/python3.9/site-packages/unified_planning/grpc/converter.py", line 37, in convert
    return f(element, *args)
  File "/home/ngigante/projects/telaio/.venv/lib/python3.9/site-packages/unified_planning/grpc/proto_writer.py", line 587, in _convert_problem
    return proto.Problem(
TypeError: Parameter to MergeFrom() must be instance of same class: expected <class 'unified_planning_pb2.TimedEffect'> got <class 'unified_planning_pb2.Timing'>.

Since MergeFrom is a protobuf function and the aries integration uses protobuf to communicate to the backend, I suspect this is a problem in the conversion of the UP Problem class to the unified_planning.grpc.generated.unified_planning_pb2.Problem class.

Note that the fact that I'm creating a HierarchicalProblem here is irrelevant. The same happens if I create a simple Problem.

Expected behavior I would expect to get whatever result the planning problem has, instead of an exception.

Additional context I'm on Python 3.9 on Debian Linux.

mikand commented 11 months ago

@arbimo FYK

Framba-Luca commented 11 months ago

@nicola-gigante The bug you are experiencing comes from the UP.

It should be fixed in the pr #538.

nicola-gigante commented 11 months ago

Thanks! Is there a timeframe for the PR to be merged into a release of the UP?

Edit: I didn't realize the PR was brand new! You have been super fast! Thank you!