trackmania-rl / tmrl

Reinforcement Learning for real-time applications - host of the TrackMania Roborace League
https://pypi.org/project/tmrl
MIT License
501 stars 68 forks source link

No response for Trackmania/Openplanet #38

Closed Medatur76 closed 1 year ago

Medatur76 commented 1 year ago

Hello! I am fairly new to python so I don't have much knowledge on it. I am getting a consistent error where after ten seconds of pressing e when setting up the rewards system for a new bot/AI I get this error: AssertionError: OpenPlanet stopped sending data since more than 10.0s. Traceback: Traceback (most recent call last): File "C:\Users\Omar\AppData\Local\Programs\Python\Python310\Lib\runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Users\Omar\AppData\Local\Programs\Python\Python310\Lib\runpy.py", line 86, in _run_code exec(code, run_globals) File "C:\Users\Omar\AppData\Local\Programs\Python\Python310\lib\site-packages\tmrl\__main__.py", line 82, in <module> main(arguments) File "C:\Users\Omar\AppData\Local\Programs\Python\Python310\lib\site-packages\tmrl\__main__.py", line 58, in main record_reward_dist(path_reward=cfg.REWARD_PATH) File "C:\Users\Omar\AppData\Local\Programs\Python\Python310\lib\site-packages\tmrl\tools\record.py", line 30, in record_reward_dist data = client.retrieve_data(sleep_if_empty=0.01) # we need many points to build a smooth curve File "C:\Users\Omar\AppData\Local\Programs\Python\Python310\lib\site-packages\tmrl\custom\utils\tools.py", line 72, in retrieve_data assert t_now - t_start < timeout, f"OpenPlanet stopped sending data since more than {timeout}s." What was printed before trackback: INFO:root:Namespace(server=False, trainer=False, worker=False, test=False, benchmark=False, record_reward=True, check_env=False, no_wandb=False, config={}) INFO:root:start recording This happens even after I reload Trackmania, reload the plugin, and switch out the Script folder in OpenplanetNext with the one in TmrlData. Please help! Thanks in advance! :)

yannbouteiller commented 1 year ago

Hello, this is very strange, sounds like this issue ?

The message you are seeing is a safety net in case the OpenPlanet script crashes and the tmrl Gym environment stops receiving data from it for more than 10 seconds, not sure why you get it though...

yannbouteiller commented 1 year ago

I just tried a clean install with python 3.11 on my laptop, and got something similar to your error, but that was because the TMRL grab data plugin was not activated. I had to do F3 > Developer > Load plugin > TMRL grab data

When you do this (or Reload plugin > TMRL grab data if it is loaded already), you can then go to Openplanet > Log and you should see a message like "Waiting for incoming connection..."

Then when you are in a track and launch the python command in your python terminal, if you leave the logs open you should see a bunch of other messages like "Socket can read", "Accepted incoming connection", "Socket can write", "Connected!"

Maybe when you start recording a reward the plugin crashes for some reason? (If so, an error would probably appear in the OpenPlanet Log).

For me it seems to work as expected.

Medatur76 commented 1 year ago

There was an error that appeared after it says connected: `Script exception: Null pointer access C:/Users/{user}/OpenplanetNext/Scripts/Plugin_GrabData_0_1.as (line 46, column 4)

0 void Main() (C:/Users/{user}/OpenplanetNext/Scripts/Plugin_GrabData_0_1.as line 46)`

Before this I does say: Waiting for incoming connection and when I connect Socket can read Accepted incoming connection Socket can write Connected! Then I get the error at the top.

Medatur76 commented 1 year ago

Hello, this is very strange, sounds like this issue ?

The message you are seeing is a safety net in case the OpenPlanet script crashes and the tmrl Gym environment stops receiving data from it for more than 10 seconds, not sure why you get it though...

This is not the same error as I am recording rewards but he is testing

Medatur76 commented 1 year ago

If it helps, I cant use python 3.11 so I'm using python 3.10 to run this code

yannbouteiller commented 1 year ago

Hmm I use python 3.10 all the time without issues.

The line that crashed on your machine in the OpenPlanet script is the last one in this code snippet:

CTrackMania@ app = cast<CTrackMania>(GetApp());
CSmArenaClient@ playground = cast<CSmArenaClient>(app.CurrentPlayground);
CSmArena@ arena = cast<CSmArena>(playground.Arena);

I am not sure why, though...

Also, when you just do

python -m tmrl --test

instead of

python -m tmrl --record-reward

it works?

This would be very very strange, because both commands use the same script, so I don't see why one would make it crash and not the other?

My guess would be that you tried to launch --record-reward while not on a track or something like that maybe? Note that this OpenPlanet script is not doing any sanity check atm, if something connects to it while not on a track it will crash.

Medatur76 commented 1 year ago

Turns out you need to run python -m tmrl --record-reward after you load the track you want to record

yannbouteiller commented 1 year ago

Ah yes, indeed :)

I'll make that clearer in the doc