pyrddlgym-project / pyRDDLGym-gurobi

Gurobi compilation of RDDL description files to mixed-integer programs, and optimization tools.
https://pyrddlgym.readthedocs.io/en/latest/gurobi.html
MIT License
0 stars 0 forks source link

pyRDDLGym-gurobi not working on Quadcopter domain whereas pyRDDLGym-jax can #2

Closed fteicht closed 5 months ago

fteicht commented 6 months ago

Hi,

First of all, thanks a lot for the great and helpful work on the pyrddlgym-project and all the dependent domains and solvers!

I tried to run pyRDDLGym-gurobi on the Quadcopter domain from rddlrepository.archive.standalone.Quadcopter using the following command:

python -m pyRDDLGym_gurobi.examples.run_plan Quadcopter 1 5

I get the following exception which seems to indicate an issue with the RDDL parser or the grounder:

Traceback (most recent call last):
  File "/opt/homebrew/Cellar/python@3.10/3.10.14/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/opt/homebrew/Cellar/python@3.10/3.10.14/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/Users/teichteil_fl/pyRDDLGym-gurobi/pyRDDLGym_gurobi/examples/run_plan.py", line 42, in <module>
    main(domain, instance, horizon)
  File "/Users/teichteil_fl/pyRDDLGym-gurobi/pyRDDLGym_gurobi/examples/run_plan.py", line 26, in main
    controller = GurobiOnlineController(rddl=env.model,
  File "/Users/teichteil_fl/pyRDDLGym-gurobi/pyRDDLGym_gurobi/core/planner.py", line 772, in __init__
    self.compiler = GurobiRDDLCompiler(rddl=rddl, plan=plan, **compiler_kwargs)
  File "/Users/teichteil_fl/pyRDDLGym-gurobi/pyRDDLGym_gurobi/core/compiler.py", line 87, in __init__
    self.rddl = RDDLGrounder(deepcopy(rddl.ast)).ground()
  File "/Users/teichteil_fl/pyRDDLGym-gurobi/.env/lib/python3.10/site-packages/pyRDDLGym/core/grounder.py", line 88, in ground
    self._ground_pvariables_and_cpf()
  File "/Users/teichteil_fl/pyRDDLGym-gurobi/.env/lib/python3.10/site-packages/pyRDDLGym/core/grounder.py", line 200, in _ground_pvariables_and_cpf
    variations = list(self._ground_objects(pvariable.param_types))
  File "/Users/teichteil_fl/pyRDDLGym-gurobi/.env/lib/python3.10/site-packages/pyRDDLGym/core/grounder.py", line 151, in _ground_objects
    raise RDDLTypeError(
pyRDDLGym.core.debug.exception.RDDLTypeError: Object type <propeller> is not defined, should be one of <{'drone'}>.

Please note that the exact same domain just works fine with pyRDDLGym-jax, which is strange to me because I thought that pyRDDLGym-gurobi and pyRDLLGym-jax use the same parser and grounder.

Thanks for your help! Best, Florent

mike-gimelfarb commented 6 months ago

Hi Florent,

Thanks for your bug report.

"I get the following exception which seems to indicate an issue with the RDDL parser or the grounder"

Indeed, this is not actually a bug with the grounder, so much as it is a feature limitation. Currently, the grounder we've implemented only supports the original RDDL syntax "pre-enum", so it will not support enums and everything added to the language afterwards and explains why the grounder is crashing (note the message only lists "drone" as a valid type, whereas "propeller" is an enum type). I think we should definitely document that better.

You could get it to work if you replace the propeller type with a proper object type, but I don't remember how much exactly you'd have to change in the CPF definitions to make it work correctly. We are hoping to update the grounder support in the future, but there are some syntax features that we do not have an idea how to support, so we want to make sure enums can be properly handled during grounding when we decide to ahead with it (you are, of course, welcome to submit a PR if you are this ambitious :) )

"Please note that the exact same domain just works fine with pyRDDLGym-jax"

The JAX planner does not ground the domain because it represents all the pvariables using numpy/jax tensors, which allows it to scale quite well in practice thanks to vectorization. The JAX planner is indeed designed to solve continuous domains like this and does it optimally I believe, though you may get some mileage with the RL package too.

mike-gimelfarb commented 6 months ago

Hi again, It seems adding enum support was not that hard for the grounder (as enum objects are treated almost the same way as regular objects). I've added this feature to the latest (github) version of pyRDDLGym, along with a few other fixes and error handling of unsupported operations. If you have further problems with the grounder, please let me know. Thanks.

fteicht commented 5 months ago

Sorry Mike for not having answered earlier! I haven't had time to give it another try following your updates, but I'm glad you found an elegant working solution! Best, Florent

mike-gimelfarb commented 4 months ago

Hi Florent, Apologies for my very late replies as well. If you have any further issues with pyRDDLGym or other packages, we'll be glad to help. Best, Mike