forked from giuse/DNE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgym_test.rb
35 lines (31 loc) · 883 Bytes
/
gym_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
def test_pycall_gym
ENV["PYTHON"] = `which python3`.strip # set python3 path for PyCall
require 'pycall/import' # https://github.com/mrkn/pycall.rb/
include PyCall::Import
pyimport :gym
env = gym.make('CartPole-v1')
nsteps = 100
env.reset
env.render
nsteps.times do |i|
selected_action = env.action_space.sample
env.step(selected_action)
env.render
end
end
puts "Choose your test: [a,b]"
case gets.strip
when 'a'
puts "The test works fine by itself"
test_pycall_gym
puts "and if I later require `numo/narray`, everything is fine"
require 'numo/narray'
puts "I can run the test again with no problem"
test_pycall_gym
when 'b'
puts "Requiring `'numo/narray'` before the first `pyimport :gym` makes PyCall crash"
require 'numo/narray'
test_pycall_gym
else
puts "Please choose between 'a' and 'b' next time."
end