Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
PeterZhizhin opened this issue Mar 6, 2019 · 3 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@PeterZhizhin
Copy link

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
Copy link
Contributor

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?

@awjuliani awjuliani self-assigned this Mar 6, 2019
@awjuliani awjuliani added the bug Something isn't working label Mar 6, 2019
@PeterZhizhin
Copy link
Author

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
Copy link

kwea123 commented Mar 7, 2019

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants