JuliaML / OpenAIGym.jl

OpenAI's Gym binding for Julia
Other
105 stars 19 forks source link

Speed part 3 #13

Open JobJob opened 6 years ago

JobJob commented 6 years ago

Uses unsafe_gettpl! from https://github.com/JuliaPy/PyCall.jl/pull/486 to get faster access to the elements from the s, r, done, info tuple returned by gym env.step functions in Python.

This is two extra commits on top of #12

Requires

You can test this out by checking out the dev branch on https://github.com/JobJob/PyCall.jl, and the fixes-for-1.0 branch for https://github.com/JobJob/Reinforce.jl, and the branch for this PR - speedierer on https://github.com/JobJob/OpenAIGym.jl

There may be some artifacts in the timing, but speed of stepping the environments in a loop (with random actions) seems slightly faster in Julia than Python for all envs.

Here's the performance vs Python 3 on my machine using the Julia and Python benchmarks the tests:

------------------------------ Begin Julia Speed Check ------------------------------
env.pyenv: PyObject <TimeLimit<AtariEnv<Pong-v4>>> num_eps: 4 t: 2.560144323 steps: 5390
microsecs/step (lower is better): 474.98039387755097
------------------------------
env.pyenv: PyObject <TimeLimit<AtariEnv<PongNoFrameskip-v4>>> num_eps: 4 t: 2.877211298 steps: 14272
microsecs/step (lower is better): 201.59832525224218
------------------------------
env.pyenv: PyObject <TimeLimit<AtariEnv<MsPacman-v4>>> num_eps: 9 t: 2.747953905 steps: 5611
microsecs/step (lower is better): 489.74405720905366
------------------------------
env.pyenv: PyObject <TimeLimit<AtariEnv<MsPacmanNoFrameskip-v4>>> num_eps: 9 t: 3.852006364 steps: 19048
microsecs/step (lower is better): 202.22628958420833
------------------------------
env.pyenv: PyObject <TimeLimit<CartPoleEnv<CartPole-v0>>> num_eps: 5000 t: 0.9092510549999988 steps: 107408
microsecs/step (lower is better): 8.465394151273637
------------------------------
env.pyenv: PyObject <gym.envs.toy_text.blackjack.BlackjackEnv object at 0x127d56be0> num_eps: 30000 t: 0.15676215100000562 steps: 11215
microsecs/step (lower is better): 13.97790022291624
------------------------------
------------------------------ End Julia Speed Check ------------------------------

------------------------------ Begin Python Speed Check ------------------------------
WARN: gym.spaces.Box autodetected dtype as <class 'numpy.float32'>. Please provide explicit dtype.
<TimeLimit<AtariEnv<Pong-v4>>> num_eps: 4 t: 2.288335084915161 steps: 4672
 microsecs/step (lower is better): 489.7977493397177
------------------------------
<TimeLimit<AtariEnv<PongNoFrameskip-v4>>> num_eps: 4 t: 3.096867084503174 steps: 15103
 microsecs/step (lower is better): 205.04979702729085
------------------------------
<TimeLimit<AtariEnv<MsPacman-v4>>> num_eps: 9 t: 2.9955520629882812 steps: 6010
 microsecs/step (lower is better): 498.4279638915609
------------------------------
<TimeLimit<AtariEnv<MsPacmanNoFrameskip-v4>>> num_eps: 9 t: 3.5945401191711426 steps: 17145
 microsecs/step (lower is better): 209.6553000391451
------------------------------
<TimeLimit<CartPoleEnv<CartPole-v0>>> num_eps: 5000 t: 1.1792187690734863 steps: 111920
 microsecs/step (lower is better): 10.536264913094053
------------------------------
<BlackjackEnv<Blackjack-v0>> num_eps: 30000 t: 1.3064210414886475 steps: 41357
 microsecs/step (lower is better): 31.58887350360634
------------------------------
------------------------------ End Python Speed Check ------------------------------