openai / universe

Universe: a software platform for measuring and training an AI's general intelligence across the world's supply of games, websites and other applications.
https://universe.openai.com
MIT License
7.47k stars 959 forks source link

AttributeError: 'VNCEnv' object has no attribute 'remote_manager' #110

Closed fatwhale closed 7 years ago

fatwhale commented 7 years ago

(First, please check https://github.com/openai/universe/wiki/Solutions-to-common-problems for solutions to many common problems)

Expected behavior

import gym
import universe
import random

#reinforcement learning step
def determine_turn(turn, observation_n, j, total_sum, prev_total_sum, reward_n):
    #for every 15 iterations, sum the total observations, and take the average
    #if lower than 0, change the direction
    #if we go 15+ iterations and get a reward each step, we're doing something right
    #thats when we turn
    if(j >= 15):
        if(total_sum/ j ) == 0:
            turn = True
        else:
            turn = False

        #reset vars
        total_sum = 0
        j = 0
        prev_total_sum = total_sum
        total_sum = 0

    else:
        turn = False
    if(observation_n != None):
        #increment counter and reward sum
        j+=1
        total_sum += reward_n
    return(turn, j, total_sum, prev_total_sum)

def main():

    #init environment
    env = gym.make('flashgames.CoasterRacer-v0')
    observation_n = env.reset()

    #init variables
    # num of game iterations
    n = 0
    j = 0
    #sum of observations
    total_sum = 0
    prev_total_sum = 0
    turn = False

    #define our turns or keyboard actions
    left = [('KeyEvent', 'ArrowUp', True) ,('KeyEvent', 'ArrowLeft', True), ('KeyEvent', 'ArrowRight', False)]
    right = [('KeyEvent', 'ArrowUp', True) ,('KeyEvent', 'ArrowLeft', False), ('KeyEvent', 'ArrowRight', True)]
    Forward = [('KeyEvent', 'ArrowUp', True) ,('KeyEvent', 'ArrowLeft', False), ('KeyEvent', 'ArrowRight', False)]

    #main logic
    while True:
        #increment a counter for number of iterations
        n+=1

        #if at least one iteration is made, check if turn is needed
        if(n > 1):
            #if at least one iteration, check if a turn
            if(observation_n[0] != None):
                #store the reward in the previous score
                prev_score = reward_n[0]

                #should we turn?
                if(turn):
                    #pick a random event
                    #where to turn? 
                    event = random.choice([left,right])
                    #perform an action
                    action_n = [event for ob in observation_n]
                    #set turn to false
                    turn = False

        elif(~turn):
            #if no turn is needed, go straight
            action_n = [Forward for ob in observation_n]

        #if there is an obseravtion, game has started, check if turn needed
        if(observation_n[0] != None):
            turn, j, total_sum, prev_total_sum = determine_turn(turn, observation_n[0], j, total_sum, prev_total_sum, reward_n[0])

        #save new variables for each iteration
        observation_n, reward_n, done_n, info = env.step(action_n)

        env.render()

if __name__ == '__main__':
    main()  

Actual behavior

Traceback (most recent call last):
  File "uni2.py", line 77, in <module>
    main()
  File "uni2.py", line 28, in main
    observation_n = env.reset()
  File "/Users/alpha/anaconda/envs/ml/lib/python3.5/site-packages/gym/core.py", line 123, in reset
    observation = self._reset()
  File "/Users/alpha/ml/universe/universe/wrappers/timer.py", line 15, in _reset
    return self.env.reset()
  File "/Users/alpha/anaconda/envs/ml/lib/python3.5/site-packages/gym/core.py", line 123, in reset
    observation = self._reset()
  File "/Users/alpha/ml/universe/universe/wrappers/render.py", line 25, in _reset
    observation_n = self.env.reset()
  File "/Users/alpha/anaconda/envs/ml/lib/python3.5/site-packages/gym/core.py", line 123, in reset
    observation = self._reset()
  File "/Users/alpha/ml/universe/universe/wrappers/throttle.py", line 42, in _reset
    observation = self.env.reset()
  File "/Users/alpha/anaconda/envs/ml/lib/python3.5/site-packages/gym/core.py", line 123, in reset
    observation = self._reset()
  File "/Users/alpha/ml/universe/universe/envs/vnc_env.py", line 331, in _reset
    self._handle_connect()
  File "/Users/alpha/ml/universe/universe/envs/vnc_env.py", line 498, in _handle_connect
    for remote in self.remote_manager.pop(n=n):
AttributeError: 'VNCEnv' object has no attribute 'remote_manager'

Versions

Please include the result of running

Name: universe
Version: 0.21.2
Summary: Universe: a software platform for measuring and training an AI's general intelligence across the world's supply of games, websites and other applications.
Home-page: https://github.com/openai/universe
Author: OpenAI
Author-email: universe@openai.com
License: UNKNOWN
Location: /Users/alpha/ml/universe
Requires: autobahn, docker-py, docker-pycreds, fastzbarlight, go-vncdriver, gym, Pillow, PyYAML, six, twisted, ujson
---
Name: gym
Version: 0.7.1
Summary: The OpenAI Gym: A toolkit for developing and comparing your reinforcement learning agents.
Home-page: https://github.com/openai/gym
Author: OpenAI
Author-email: gym@openai.com
License: UNKNOWN
Location: /Users/alpha/anaconda/envs/ml/lib/python3.5/site-packages
Requires: numpy, requests, pyglet, six
---
Name: tensorflow
Version: 0.12.1
Summary: TensorFlow helps the tensors flow
Home-page: http://tensorflow.org/
Author: Google Inc.
Author-email: opensource@google.com
License: Apache 2.0
Location: /Users/alpha/anaconda/envs/ml/lib/python3.5/site-packages
Requires: protobuf, six, numpy, wheel
---
Name: numpy
Version: 1.11.1
Summary: NumPy: array processing for numbers, strings, records, and objects.
Home-page: http://www.numpy.org
Author: NumPy Developers
Author-email: numpy-discussion@scipy.org
License: BSD
Location: /Users/alpha/anaconda/envs/ml/lib/python3.5/site-packages
Requires: 
---
Name: go-vncdriver
Version: 0.4.19
Summary: UNKNOWN
Home-page: UNKNOWN
Author: UNKNOWN
Author-email: UNKNOWN
License: UNKNOWN
Location: /Users/alpha/anaconda/envs/ml/lib/python3.5/site-packages
Requires: numpy
---
Name: Pillow
Version: 3.3.1
Summary: Python Imaging Library (Fork)
Home-page: http://python-pillow.org
Author: Alex Clark (Fork Author)
Author-email: aclark@aclark.net
License: Standard PIL License
Location: /Users/alpha/anaconda/envs/ml/lib/python3.5/site-packages
Requires: 
tlbtlbtlb commented 7 years ago

You have to configure the environment before using it. See example code

tlbtlbtlb commented 7 years ago

@gdb I plan to set metadata['configure.required']=True in VNCEnv to avoid this non-obvious error message when users forget to call configure. That means it'll auto-configure (setting remotes=1 by default). OK?

gdb commented 7 years ago

Sounds good! That was the original and more desirable behavior in any case.

tlbtlbtlb commented 7 years ago

Fixed by https://github.com/openai/universe/commit/90d3e9360713d299dedec475e356ab0a9a6c6a39 (unstable branch)