Unity-Technologies / obstacle-tower-env

Obstacle Tower Environment
Apache License 2.0
540 stars 124 forks source link

Environment resets to different seeds after calling env.seed(0) #67

Open PeterZhizhin opened 5 years ago

PeterZhizhin commented 5 years ago

Hello.

Try running this piece of code:

from obstacle_tower_env import ObstacleTowerEnv
import sys
import argparse
import time

def run_episode(env):
    done = False
    reward = 0.0

    total_steps = 0
    last_fps_counter = time.time()
    fps_every = 1.0

    while not done:
        action = env.action_space.sample()
        obs, reward, done, info = env.step(action)
        total_steps += 1
        if last_fps_counter + fps_every < time.time():
            print("Current FPS: ", total_steps / (time.time() - last_fps_counter))
            last_fps_counter = time.time()
            total_steps = 0
    return reward

def run_evaluation(env):
    while not env.done_grading():
        run_episode(env)
        env.reset()

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('environment_filename', default='./ObstacleTower/obstacletower', nargs='?')
    parser.add_argument('--docker_training', action='store_true')
    parser.set_defaults(docker_training=False)
    parser.add_argument('--realtime', action='store_true')
    parser.set_defaults(realtime=False)
    args = parser.parse_args()

    env = ObstacleTowerEnv(args.environment_filename, docker_training=args.docker_training, realtime_mode=args.realtime)
    env.floor(0)
    env.seed(0)
    if env.is_grading():
        episode_reward = run_evaluation(env)
    else:
        while True:
            episode_reward = run_episode(env)
            print("Episode reward: " + str(episode_reward))
            env.floor(0)
            env.seed(0)
            env.reset()

    env.close()

Run with the following command: python run.py --realtime Observe the agent's environment. For me, after each reset, the room's layout is always different (sometimes the door to the next level is on the right, sometimes it is straight ahead).

In the output of the command, I see the following:

WARNING:gym_unity:New seed 0 will apply on next reset.
INFO:mlagents_envs:Academy reset with parameters: floor-number -> 0, tower-seed -> 0

However, this is the output of UnitySDK.log:

Log
Academy resetting
Log
Seed: 9
Log
Seed: 69
Log
Academy resetting
Log
Seed: 98

I have verified that the same happens with seed(1) as well.

awjuliani commented 5 years ago

Hi @PeterZhizhin

Can you confirm that you are running the latest binary available here: https://github.com/Unity-Technologies/obstacle-tower-env#download-the-environment?

PeterZhizhin commented 5 years ago

Hi @awjuliani

Yes, I run this binary. I also figured out that running in headless mode (realtime_mode=False) makes seeds work properly according to UnitySDK.log.

kwea123 commented 5 years ago

For me, it is always floor 0 and seed 0 after each reset. The first run is a completely random seed because you didn't reset it before running (there is no env.reset() before while True: episode_reward = run_episode(env))

So I didn't encounter any bug here. My Unity log outputs this:

3/7/2019 7:40:39 PM

Log
Academy resetting

Log
Seed: 26

Log
Seed: 33

Log
Academy resetting

Log
Seed: 0

Log
Academy resetting

Log
Seed: 0

Which seems totally correct. Are you sure you're running v1.2?