LoginSignup
5
5

More than 5 years have passed since last update.

Open AI Gymをインストールする

Last updated at Posted at 2016-09-05

環境:
CPU:Corei7 6700K
GPU:GTX1070
SSD:240GB
HDD:1TB
マザーボード:ASUS H170-pro
OS:Ubuntu14.04 LTS
python:2.7.6
CUDA:8.0 RC
cuDNN:5.1
TensorFlow:0.10.0
など

過去4回で、Ubuntu14.04、CUDA、chainer、dqn、LIS、Tensorflowを順次インストールした。
http://qiita.com/masataka46/items/94417a5974dba810e7b8
http://qiita.com/masataka46/items/fddef236cb211ef3f145
http://qiita.com/masataka46/items/125c7900ec8ca83f6eb2
http://qiita.com/masataka46/items/12fb01f3417bd0791703
ただし、Unityがうまく立ち上がらないため、最後のLIS環境構築は完了していない。

今回はOpen AI Gymをインストールする。まずはここの指示
https://gym.openai.com/docs
に従って進める。

Open AI Gymをインストール

まずGitHubからcloneする。

git clone https://github.com/openai/gym
cd gym

fullインストールする方法もあるが、とりあえずminimumでインストールする。

pip install -e .

サンプルを走らせる

HPの指示に従って、簡単なサンプルを走らせる。

import gym
env = gym.make('CartPole-v0')
env.reset()
for _ in range(1000):
    env.render()
    env.step(env.action_space.sample()) # take a random action

というコードにtest01.pyなど適当な名前を付け、

python test01.py

で走らせる。すると以下のようなエラーが表示された。

[2016-09-05 18:09:35,235] Making new env: CartPole-v0
[2016-09-05 18:09:35,690] You are calling 'step()' even though this environment has already returned done = True. You should always call 'reset()' once you receive 'done = True' -- any further steps are undefined behavior.
Traceback (most recent call last):
  File "test01.py", line 5, in <module>
    env.render()
  File "/home/ohmasa/openAIGym/gym/gym/core.py", line 189, in render
    return self._render(mode=mode, close=close)
  File "/home/ohmasa/openAIGym/gym/gym/envs/classic_control/cartpole.py", line 149, in _render
    return self.viewer.render(return_rgb_array = mode=='rgb_array')
  File "/home/ohmasa/openAIGym/gym/gym/envs/classic_control/rendering.py", line 84, in render
    self.window.dispatch_events()
  File "/usr/local/lib/python2.7/dist-packages/pyglet/window/xlib/__init__.py", line 853, in dispatch_events
    0x1ffffff, byref(e)):
ctypes.ArgumentError: argument 2: <type 'exceptions.TypeError'>: wrong type

しかし、次のサンプル

import gym
env = gym.make('CartPole-v0')
for i_episode in range(20):
    observation = env.reset()
    for t in range(100):
        env.render()
        print(observation)
        action = env.action_space.sample()
        observation, reward, done, info = env.step(action)
        if done:
            print("Episode finished after {} timesteps".format(t+1))
            break

はepisodeを最後まで実行し終了した。場合によってはうまくいくのか?

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5