Commit f8fccea4 authored by Benjamin's avatar Benjamin
Browse files

replace camera width/height with single resolution + add env tutial pynb

parent 47464ae7
......@@ -60,7 +60,7 @@ We offer two packages:
<!--In case you wish to create a conda environment you can do so by running the below command from the `animalai` folder:
```
conda env create -f conda_isntall.yaml
```-->
```-->ni
- We also provide a package that can be used as a starting point for training, and which is required to run most of the
example scripts found in the `examples/` folder. It contains an extension of
......
import json
import jsonpickle
import yaml
import copy
from typing import List
from animalai.communicator_objects import (
......
......@@ -39,15 +39,12 @@ class AnimalAIEnvironment(UnityEnvironment):
play: bool = False,
arenas_configurations: ArenaConfig = None,
inference: bool = False,
camera_width: int = None,
camera_height: int = None,
resolution: int = None,
grayscale: bool = False,
side_channels: Optional[List[SideChannel]] = None,
):
args = self.executable_args(
n_arenas, play, camera_height, camera_width, grayscale
)
args = self.executable_args(n_arenas, play, resolution, grayscale)
self.play = play
self.inference = inference
self.timeout = 10 if play else 60
......@@ -126,7 +123,8 @@ class AnimalAIEnvironment(UnityEnvironment):
def close(self):
if self.play:
self.communicator.close()
self.proc1.kill()
if self.proc1:
self.proc1.kill()
else:
super().close()
......@@ -134,8 +132,7 @@ class AnimalAIEnvironment(UnityEnvironment):
def executable_args(
n_arenas: int = 1,
play: bool = False,
camera_height: int = 84,
camera_width: int = 84,
resolution: int = 84,
grayscale: bool = False,
) -> List[str]:
args = ["--playerMode"]
......@@ -145,12 +142,9 @@ class AnimalAIEnvironment(UnityEnvironment):
args.append("0")
args.append("--numberOfArenas")
args.append(str(n_arenas))
if camera_width:
args.append("--cameraWidth")
args.append(str(camera_width))
if camera_height:
args.append("--cameraHeight")
args.append(str(camera_height))
if resolution:
args.append("--resolution")
args.append(str(resolution))
if grayscale:
args.append("--grayscale")
return args
......@@ -32,9 +32,7 @@ def test_basic_initialization(mock_communicator, mock_launcher, mock_reset):
discrete_action=True, visual_inputs=1, num_agents=32, vec_obs_size=2
)
env = AnimalAIEnvironment(
file_name=" ", n_arenas=32, camera_height=126, camera_width=512
)
env = AnimalAIEnvironment(file_name=" ", n_arenas=32, resolution=126,)
assert env.get_agent_groups() == ["RealFakeBrain"]
mock_launcher.assert_called_once()
launcher_args, _ = mock_launcher.call_args
......@@ -44,9 +42,7 @@ def test_basic_initialization(mock_communicator, mock_launcher, mock_reset):
"0",
"--numberOfArenas",
"32",
"--cameraWidth",
"512",
"--cameraHeight",
"--resolution",
"126",
]
env.close()
......
......@@ -18,8 +18,7 @@ def create_environment_factory_aai(
start_port: int,
n_arenas_per_env: int,
arenas_configurations: ArenaConfig,
camera_width: Optional[int],
camera_height: Optional[int],
resolution: Optional[int],
) -> Callable[[int, List[SideChannel]], BaseEnv]:
if env_path is not None:
launch_string = AnimalAIEnvironment.validate_environment_path(env_path)
......@@ -53,8 +52,7 @@ def create_environment_factory_aai(
# docker_training=docker_training,
n_arenas=n_arenas_per_env,
arenas_configurations=arenas_configurations,
camera_width=camera_width,
camera_height=camera_height,
resolution=resolution,
side_channels=side_channels,
)
......
......@@ -23,8 +23,7 @@ class RunOptionsAAI(NamedTuple):
height: int = 84
n_arenas_per_env: int = 1
arena_config: ArenaConfig = None
camera_width: int = 84
camera_height: int = 84
resolution: int = 84
"""
trainer_config: Hyperparameters for your training model
......@@ -46,6 +45,5 @@ class RunOptionsAAI(NamedTuple):
height: The height of the executable window of the environment(s)
n_arenas_per_env: Number of arenas (number of agents) per env environment instance
arena_config: Configuration file for the training arenas
camera_width: Width for the visual observation camera of the agent
camera_height: Height for the visual observation camera of the agent
resolution: Resolution for the visual observation camera of the agent (NxN if resolution=N)
"""
......@@ -60,8 +60,7 @@ def run_training_aai(run_seed: int, options: RunOptionsAAI) -> None:
port,
options.n_arenas_per_env,
options.arena_config,
options.camera_width,
options.camera_height,
options.resolution,
)
engine_config = EngineConfig(
options.width,
......
!ArenaConfig
arenas:
0: !Arena
pass_mark: -0.5
t: 250
items:
- !Item
name: Agent
positions:
- !Vector3 {x: 1, y: 0, z: 1}
rotations: [225]
- !Item
name: GoodGoalMulti
positions:
- !Vector3 {x: 39, y: 0, z: 39}
sizes:
- !Vector3 {x: .5, y: .5, z: .5}
\ No newline at end of file
!ArenaConfig
arenas:
0: !Arena
pass_mark: 4
t: 250
items:
- !Item
name: GoodGoalMulti
positions:
sizes:
- !Vector3 {x: 1, y: 1, z: 1}
- !Vector3 {x: 1, y: 1, z: 1}
- !Vector3 {x: 1, y: 1, z: 1}
- !Vector3 {x: 1, y: 1, z: 1}
- !Vector3 {x: 1, y: 1, z: 1}
\ No newline at end of file
!ArenaConfig
arenas:
0: !Arena
pass_mark: 0
t: 250
items:
- !Item
name: Agent
positions:
- !Vector3 {x: 20, y: 0, z: 5}
rotations: [0]
- !Item
name: Wall
positions:
- !Vector3 {x: 10, y: 0, z: 10.25}
- !Vector3 {x: 30, y: 0, z: 10.25}
- !Vector3 {x: 17.78, y: 0, z: 30}
- !Vector3 {x: 22.22, y: 0, z: 30}
rotations: [45, 135, 258.7, 101.3]
colors:
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
sizes:
- !Vector3 {x: 27.75, y: 5, z: .5}
- !Vector3 {x: 27.75, y: 5, z: .5}
- !Vector3 {x: 20, y: 5, z: .5}
- !Vector3 {x: 20, y: 5, z: .5}
- !Item
name: GoodGoal
positions:
- !Vector3 {x: 10, y: 0, z: 30}
sizes:
- !Vector3 {x: 1, y: 1, z: 1}
- !Item
name: BadGoal
positions:
- !Vector3 {x: 30, y: 0, z: 30}
sizes:
- !Vector3 {x: 1, y: 1, z: 1}
\ No newline at end of file
!ArenaConfig
arenas:
0: !Arena
pass_mark: 0
t: 250
items:
- !Item
name: Wall
positions:
- !Vector3 {x: 9.5, y: 0, z: 19}
- !Vector3 {x: 30.5, y: 0, z: 19}
rotations: [0,0]
sizes:
- !Vector3 {x: 19, y: 3, z: 38}
- !Vector3 {x: 19, y: 3, z: 38}
colors:
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !Item
name: GoodGoal
positions:
- !Vector3 {x: 1, y: 0, z: 39}
sizes:
- !Vector3 {x: 1, y: 1, z: 1}
- !Item
name: Agent
positions:
- !Vector3 {x: 20, y: 0, z: 1}
\ No newline at end of file
!ArenaConfig
arenas:
0: !Arena
pass_mark: 1
t: 500
items:
- !Item
name: Wall #Non-diag arms
positions:
- !Vector3 {x: 18, y: 0, z: 7.5}
- !Vector3 {x: 22, y: 0, z: 7.5}
- !Vector3 {x: 18, y: 0, z: 32.5}
- !Vector3 {x: 22, y: 0, z: 32.5}
- !Vector3 {x: 7.5, y: 0, z: 18}
- !Vector3 {x: 7.5, y: 0, z: 22}
- !Vector3 {x: 32.5, y: 0, z: 18}
- !Vector3 {x: 32.5, y: 0, z: 22}
rotations: [0,0,0,0,0,0,0,0]
sizes:
- !Vector3 {x: 0.1, y: 3, z: 15}
- !Vector3 {x: 0.1, y: 3, z: 15}
- !Vector3 {x: 0.1, y: 3, z: 15}
- !Vector3 {x: 0.1, y: 3, z: 15}
- !Vector3 {x: 15, y: 3, z: 0.1}
- !Vector3 {x: 15, y: 3, z: 0.1}
- !Vector3 {x: 15, y: 3, z: 0.1}
- !Vector3 {x: 15, y: 3, z: 0.1}
colors:
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !Item
name: Wall #Non-diag backplates
positions:
- !Vector3 {x: 20, y: 0, z: 25.5}
- !Vector3 {x: 20, y: 0, z: 14.5}
- !Vector3 {x: 0.5, y: 0, z: 20}
- !Vector3 {x: 20, y: 0, z: 0.5}
- !Vector3 {x: 20, y: 0, z: 39.5}
- !Vector3 {x: 39.5, y: 0, z: 20}
rotations: [0,0,90,0,0,90]
sizes:
- !Vector3 {x: 3.9, y: 3, z: 1}
- !Vector3 {x: 3.9, y: 3, z: 1}
- !Vector3 {x: 3.9, y: 3, z: 1}
- !Vector3 {x: 3.9, y: 3, z: 1}
- !Vector3 {x: 3.9, y: 3, z: 1}
- !Vector3 {x: 3.9, y: 3, z: 1}
colors:
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !Item
name: Wall #Diag arms
positions:
- !Vector3 {x: 12.61, y: 0, z: 30.4}
- !Vector3 {x: 9.7, y: 0, z: 27.39}
- !Vector3 {x: 30.3, y: 0, z: 12.61}
- !Vector3 {x: 27.39, y: 0, z: 9.6}
- !Vector3 {x: 12.61, y: 0, z: 9.6}
- !Vector3 {x: 9.7, y: 0, z: 12.61}
- !Vector3 {x: 27.39, y: 0, z: 30.4}
- !Vector3 {x: 30.3, y: 0, z: 27.39}
rotations: [135,135,135,135,45,45,45,45]
sizes:
- !Vector3 {x: 0.1, y: 3, z: 15}
- !Vector3 {x: 0.1, y: 3, z: 15}
- !Vector3 {x: 0.1, y: 3, z: 15}
- !Vector3 {x: 0.1, y: 3, z: 15}
- !Vector3 {x: 0.1, y: 3, z: 15}
- !Vector3 {x: 0.1, y: 3, z: 15}
- !Vector3 {x: 0.1, y: 3, z: 15}
- !Vector3 {x: 0.1, y: 3, z: 15}
colors:
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !Item
name: Wall #Diag Blocks
positions:
- !Vector3 {x: 16.045, y: 0, z: 24.005}
- !Vector3 {x: 23.955, y: 0, z: 15.995}
- !Vector3 {x: 16.045, y: 0, z: 15.995}
- !Vector3 {x: 23.955, y: 0, z: 24.005}
rotations: [135,315,45,225]
sizes:
- !Vector3 {x: 4, y: 3, z: 1}
- !Vector3 {x: 4, y: 3, z: 1}
- !Vector3 {x: 4, y: 3, z: 1}
- !Vector3 {x: 4, y: 3, z: 1}
colors:
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !Item
name: Wall #Diag backplates
positions:
- !Vector3 {x: 6, y: 0, z: 6}
- !Vector3 {x: 34, y: 0, z: 6}
- !Vector3 {x: 6, y: 0, z: 34}
- !Vector3 {x: 34, y: 0, z: 34}
rotations: [45,135,134,45]
sizes:
- !Vector3 {x: 4, y: 3, z: 1}
- !Vector3 {x: 4, y: 3, z: 1}
- !Vector3 {x: 4, y: 3, z: 1}
- !Vector3 {x: 4, y: 3, z: 1}
colors:
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !RGB {r: 153, g: 153, b: 153}
- !Item
name: GoodGoalMulti
positions:
- !Vector3 {x: 2, y: 0, z: 20}
- !Vector3 {x: 38, y: 0, z: 20}
sizes:
- !Vector3 {x: 1, y: 1, z: 1}
- !Vector3 {x: 1, y: 1, z: 1}
- !Item
name: Agent
positions:
- !Vector3 {x: 20, y: 0, z: 20}
\ No newline at end of file
!ArenaConfig
arenas:
0: !Arena
pass_mark: 2
t: 500
items:
- !Item
name: Wall
positions:
- !Vector3 {x: 20, y: 0, z: 22.5}
rotations: [0]
sizes:
- !Vector3 {x: 40, y: .6, z: 35}
colors:
- !RGB {r: 0, g: 0, b: 255}
- !Item
name: Ramp
positions:
- !Vector3 {x: 20, y: .6, z: 22.5}
rotations: [180]
sizes:
- !Vector3 {x: 40, y: 2, z: 35}
colors:
- !RGB {r: 255, g: 0, b: 255}
- !Item
name: Agent
positions:
- !Vector3 {x: 5, y: 0, z: 2.5}
rotations: [60]
- !Item
name: GoodGoal
positions:
- !Vector3 {x: 19, y: 3, z: 9}
sizes:
- !Vector3 {x: 3, y: 3, z: 3}
- !Item
name: GoodGoal
positions:
- !Vector3 {x: 38, y: 0, z: 2.5}
sizes:
- !Vector3 {x: 1, y: 1, z: 1}
!ArenaConfig
arenas:
0: !Arena
pass_mark: 0
t: 250
items:
- !Item
name: CylinderTunnelTransparent
positions:
- !Vector3 {x: 20, y: 0, z: 20}
- !Vector3 {x: 30, y: 0, z: 20}
- !Vector3 {x: 10, y: 0, z: 20}
rotations: [90,90,90]
sizes:
- !Vector3 {x: 10, y: 10, z: 10}
- !Vector3 {x: 10, y: 10, z: 10}
- !Vector3 {x: 10, y: 10, z: 10}
- !Item
name: GoodGoal
positions:
- !Vector3 {x: 20, y: 0, z: 20}
sizes:
- !Vector3 {x: 1, y: 1, z: 1}
- !Item
name: Agent
positions:
- !Vector3 {x: 20, y: 0, z: 1}
rotations: [0]
\ No newline at end of file
!ArenaConfig
arenas:
0: !Arena
pass_mark: 0
t: 250
items:
- !Item
name: Wall
positions:
- !Vector3 {x: 20, y: 0, z: 30}
rotations: [0]
sizes:
- !Vector3 {x: 40, y: 0.5, z: 20}
colors:
- !RGB {r: 0, g: 0, b: 255}
- !Item
name: Ramp
positions:
- !Vector3 {x: 35, y: 0, z: 18}
sizes:
- !Vector3 {x: 4, y: 0.5, z: 4}
rotations: [180]
colors:
- !RGB {r: 255, g: 0, b: 255}
- !Item
name: GoodGoal
positions:
- !Vector3 {x: 20, y: 0.5, z: 35}
sizes:
- !Vector3 {x: 1, y: 1, z: 1}
- !Item
name: Agent
positions:
- !Vector3 {x: 5, y: 0, z: 5}
rotations: [45]
\ No newline at end of file
!ArenaConfig
arenas:
0: !Arena
pass_mark: 0
t: 250
items:
- !Item
name: Cardbox1
positions:
- !Vector3 {x: 20, y: 0, z: 2.5}
- !Vector3 {x: 20, y: 0, z: 7.5}
- !Vector3 {x: 20, y: 0, z: 12.5}
- !Vector3 {x: 20, y: 0, z: 17.5}
- !Vector3 {x: 20, y: 0, z: 22.5}
- !Vector3 {x: 20, y: 0, z: 27.5}
- !Vector3 {x: 20, y: 0, z: 32.5}
- !Vector3 {x: 20, y: 0, z: 37.5}
rotations: [0,0,0,0,0,0,0,0]
sizes:
- !Vector3 {x: 1, y: 1, z: 5}
- !Vector3 {x: 1, y: 1, z: 5}
- !Vector3 {x: 1, y: 1, z: 5}
- !Vector3 {x: 1, y: 1, z: 5}
- !Vector3 {x: 1, y: 1, z: 5}
- !Vector3 {x: 1, y: 1, z: 5}
- !Vector3 {x: 1, y: 1, z: 5}
- !Vector3 {x: 1, y: 1, z: 5}
- !Item
name: GoodGoal
positions:
- !Vector3 {x: 35, y: 0, z: 5}
sizes:
- !Vector3 {x: 1, y: 1, z: 1}
- !Item
name: Agent
positions:
- !Vector3 {x: 5, y: 0, z: 20}
rotations: [90]
\ No newline at end of file
!ArenaConfig
arenas:
0: !Arena
pass_mark: 0
t: 250
items:
- !Item
name: Wall
positions:
- !Vector3 {x: 20, y: 0, z: 20}
- !Vector3 {x: 22, y: 0, z: 24.5}
- !Vector3 {x: 24, y: 0, z: 19}
- !Vector3 {x: 21, y: 0, z: 12.5}
- !Vector3 {x: 17, y: 0, z: 19.5}
- !Vector3 {x: 19, y: 0, z: 28.75}
rotations: [0,0,0,0,0,60]
sizes:
- !Vector3 {x: 1, y: 3, z: 10}
- !Vector3 {x: 3, y: 3, z: 1}
- !Vector3 {x: 1, y: 3, z: 12}
- !Vector3 {x: 7, y: 3, z: 1}
- !Vector3 {x: 1, y: 3, z: 15}
- !Vector3 {x: 1, y