edbeeching / godot_rl_agents_plugin

The Godot plugin asset for the Godot RL Agents library
MIT License
121 stars 16 forks source link

Fix inference when action names are not alphabetic #27

Closed Ivan-267 closed 11 months ago

Ivan-267 commented 11 months ago

This is a quick fix that should enable onnx inference to work for environments where the actions are not defined in an alphabetical order by name.

Only briefly tested, I have tried to quickly start training using gdrl and play in Editor.

To do:

For an example action space that is not sorted:

With the applied fix, the action space as Printed from Python was:

action space {'acceleration': {'size': 1, 'action_type': 'continuous'}, '2': {'size': 1, 'action_type': 'continuous'}, '1': {'size': 1, 'action_type': 'continuous'}}
observation space {'obs': {'size': [12], 'space': 'box'}}

(same as the order written in AIController in gdscript)

Without the fix, the order of actions is changed before it reaches Python:

action space {'1': {'action_type': 'continuous', 'size': 1}, '2': {'action_type': 'continuous', 'size': 1}, 'acceleration': {'action_type': 'continuous', 'size': 1}}
observation space {'obs': {'size': [12], 'space': 'box'}}

More info on the issue itself is described in the linked issue.

Ivan-267 commented 11 months ago

Initial test failed, it seems that the received string from var message = stream.get_string() also has alphabetic order of actions rather than the defined order (that may be fine though). Will look into the cause of the issue more closely later.

Edit: It seems that the order of the actions is changed in Python regardless of how Godot sends it on conversion to spaces.Dict. Will experiment a bit with this when I get some time.

Edit2: Added the fix on godot_env side as well, now it should work.