File size: 1,413 Bytes
05c9ac2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import argparse
import numpy as np

from mlagents_envs.environment import UnityEnvironment

EPSILON = 0.001


def test_run_environment(env_name):
    """
    Run the low-level API test of compressed sensors using the specified environment
    :param env_name: Name of the Unity environment binary to launch
    """
    env = UnityEnvironment(
        file_name=env_name, no_graphics=True, additional_args=["-logFile", "-"]
    )

    try:
        # Reset the environment
        env.reset()

        env.step()

        # Set the default brain to work with
        group_name = list(env.behavior_specs.keys())[0]

        # Get the state of the agents
        decision_steps, _ = env.get_steps(group_name)

        # One observation comes from compressed sensor while the other comes
        # from an uncompressed sensor
        obs_1 = decision_steps.obs[0][0, :, :, :]
        obs_2 = decision_steps.obs[0][1, :, :, :]

        diff = np.abs(obs_1 - obs_2)

        # make sure both are identical
        assert np.max(diff) < EPSILON

        # make sure an actual observation was collected
        assert np.max(obs_1) > EPSILON

        print("Observations were identical")

    finally:
        env.close()


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--env", default="artifacts/testPlayer")
    args = parser.parse_args()
    test_run_environment(args.env)