Skip to content

UnityEnvironment seed not working #5297

@julienroyd

Description

@julienroyd

Hi,

Seeding of the environment does not seem to work properly. Two calls to env.action_space.sample() won't give the same result on two different runs.

To Reproduce

Here is the minimal example I used. I first created an executable of the 3DBall environment according to the directions given here: https://github.com/Unity-Technologies/ml-agents/blob/release_12_docs/docs/Learning-Environment-Executable.md.

I then ran this example below (replacing the path to the executable):

import numpy as np
import random
from mlagents_envs.environment import UnityEnvironment
from gym_unity.envs import UnityToGymWrapper

SEED = 123

random.seed(SEED)
np.random.seed(SEED)

exec_path = "/home/user1/Desktop/3DBall/build/3DBall"
unity_env = UnityEnvironment(file_name=exec_path, no_graphics=True, seed=SEED)
env = UnityToGymWrapper(unity_env, uint8_visual=False, flatten_branched=False, allow_multiple_obs=False)

print(env.action_space.sample())

Environment (please complete the following information):

  • Unity Version: 2019.4.19f1
  • OS + version: Ubuntu 20.04
  • ML-Agents version: 1.8.0
  • Torch version: 1.8.1
  • Environment: 3DBall

Metadata

Metadata

Assignees

Labels

bugIssue describes a potential bug in ml-agents.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions