Commit 862bf387 authored by Benjamin Beyret's avatar Benjamin Beyret
Browse files

add submission code and documentation

parent 1f40d683
env/*
!env/README.md
examples/submission/test_submission/env/*
!examples/submission/test_submission/env/README.md
models/
summaries/
/.idea
......@@ -11,4 +13,4 @@ venv/
build/
dist/
*.egg-info*
*.eggs*
\ No newline at end of file
*.eggs*
from animalai.envs.brain import BrainInfo
class Agent(object):
def __init__(self):
"""
Load your agent here and initialize anything needed
WARNING: any path to files you wish to access on the docker should be ABSOLUTE PATHS
"""
pass
......@@ -16,16 +14,24 @@ class Agent(object):
:param t the number of timesteps in the episode
"""
def step(self, brain_info: BrainInfo) -> list[float]:
def step(self, obs, reward, done, info):
"""
A single step the agent should take based on the current
:param brain_info: a single BrainInfo containing the observations and reward for a single step for one agent
:return: a list of actions to execute (of size 2)
A single step the agent should take based on the current state of the environment
We will run the Gym environment (AnimalAIEnv) and pass the arguments returned by env.step() to
the agent.
Note that should if you prefer using the BrainInfo object that is usually returned by the Unity
environment, it can be accessed from info['brain_info'].
:param obs: agent's observation of the current environment
:param reward: amount of reward returned after previous action
:param done: whether the episode has ended.
:param info: contains auxiliary diagnostic information, including BrainInfo.
:return: the action to take, a list or size 2
"""
action = [0, 0]
self.action = [0, 0]
return self.action
return action
def destroy(self):
pass
#Submission
In order to participate to the competition you will need to upload a [docker container](https://docs.docker.com/get-started/)
containing your trained agent that should interface with the `animalai` library. We details the steps for participating
below.
##Create an EvalAI account
The competition is kindly hosted by EvalAI, head over to [the website](https://evalai.cloudcv.org/), create an account
and enroll your team in the AnimalAI challenge _add link_.
**Any question related to the evaluation process should go to the EvalAI forum** _add link_
##Link your account to your identity
Due to the rules of the competition you will need to register your personal details to be eligible for prizes. _Explain
linking of EvalAI account_
##Install Docker
If you are unfamiliar with Docker, it offers a containerized platform for running applications in a closed environment.
Consequently it is a great tool for you to setup all the libraries your agent will require, and for us to directly run
code as it would run on your local machine without any addition.
Take the time to read the [Docker documentation](https://docs.docker.com/get-started/) and follow the install process.
##Adding CUDA capabilities to Docker (optional)
As part of the evaluation we offer GPU compute on an AWS
[p2.xlarge instance](https://aws.amazon.com/ec2/instance-types/p2/). These compute instances will run an Amazon
[Deep Learning Base AMI](https://aws.amazon.com/marketplace/pp/B077GCZ4GR) with several CUDA libraries installed. The
native docker engine does not provide a pass-through to these libraries, rendering any use of GPU capable libraries (such
as `tensorflow-gpu`) impossible.
To overcome this issue, NVIDIA provides a specific version of docker. We can recommend
[this tutorial](https://marmelab.com/blog/2018/03/21/using-nvidia-gpu-within-docker-container.html#installing-nvidia-docker)
for installing this version, note we will not provide help with installing these.
##Create a submission docker
Once you have docker up and running, you can start building your submission. Head over to the examples provided _add link_
and have a look at the `Dockerfile`. We install all the requirements for the environment to run on the docker, we do not
recommend editing anything outside of the commented block saying `YOUR COMMANDS GO HERE`.
For example, if your submission requires the `animalai-train` library to run, you can just build the docker by running:
```
dcoerk build --tag=submission .
```
You can give your docker the name you want, it does not have to be `submission`. Note that the Dockerfile creates two
folders `/aaio` and `/aaio/data` at the root of the container, and copies the agent and associated data from your local
machine onto the container. Your submission requires to keep this architecture and any reference to these folders in
your code **should use absolute paths** (see the example agent provided _add link_).
##Test your docker
As uploading and evaluating containers take a while, it is recommended to ensure your docker runs properly before submitting.
Moreover, in case your docker fails during submission, **you will only get curated outputs** which may not be enough to
debug on your own (this is done to prevent cheating). If this happens, you will need to raise a question on the forum
and we will investigate for you (which might take time).
Bottom line: let's test your submission!
First, place the AnimalAI linux environment (and folder) in `examples/submission/test_submission/env`. We will now run
the container by mounting the `test_submission` folder and its content as a volume, and execute the `testDocker.py`
script. To do so, from the `submission` folder, run:
```
docker run -v "$PWD"/test_submission:/aaio/test submission python /aaio/test/testDocker.py
```
If your container and agent are set properly, you should not get any error, and the script should conclude with `SUCCESS`
##Submit your docker
You can now submit your docker for evaluation
\ No newline at end of file
......@@ -24,10 +24,23 @@ ENV PATH /opt/conda/envs/python36/bin:/opt/conda/envs/bin:$PATH
RUN pip install animalai
COPY agent.py /aaio/agent.py
COPY data /aaio/data
ENV HTTP_PROXY ""
ENV HTTPS_PROXY ""
ENV http_proxy ""
ENV https_proxy ""
########################################################################################################################
# YOUR COMMANDS GO HERE
# For example, if your agent requires the animalai-train library
# you can add the following (remove if not needed):
RUN pip install animalai-train
########################################################################################################################
CMD ["/bin/bash"]
import yaml
from animalai_train.trainers.ppo.policy import PPOPolicy
from animalai.envs.brain import BrainParameters
class Agent(object):
def __init__(self):
"""
Load your agent here and initialize anything needed
"""
# Load the configuration and model using ABSOLUTE PATHS
self.configuration_file = '/aaio/data/trainer_config.yaml'
self.model_path = '/aaio/data/1-Food/Learner'
self.brain = BrainParameters(brain_name='Learner',
camera_resolutions=[{'height': 84, 'width': 84, 'blackAndWhite': False}],
num_stacked_vector_observations=1,
vector_action_descriptions=['', ''],
vector_action_space_size=[3, 3],
vector_action_space_type=0, # corresponds to discrete
vector_observation_space_size=3
)
self.trainer_params = yaml.load(open(self.configuration_file))['Learner']
self.trainer_params['keep_checkpoints'] = 0
self.trainer_params['model_path'] = self.model_path
self.trainer_params['use_recurrent'] = False
self.policy = PPOPolicy(brain=self.brain,
seed=0,
trainer_params=self.trainer_params,
is_training=False,
load=True)
def reset(self, t=250):
"""
Reset is called before each episode begins
Leave blank if nothing needs to happen there
:param t the number of timesteps in the episode
"""
def step(self, obs, reward, done, info):
"""
A single step the agent should take based on the current
:param brain_info: a single BrainInfo containing the observations and reward for a single step for one agent
:return: a list of actions to execute (of size 2)
"""
brain_info = info['brain_info']
action = self.policy.evaluate(brain_info=brain_info)['action']
return action
def destroy(self):
pass
model_checkpoint_path: "model-58856.cptk"
all_model_checkpoint_paths: "model-5000.cptk"
all_model_checkpoint_paths: "model-10000.cptk"
all_model_checkpoint_paths: "model-15000.cptk"
all_model_checkpoint_paths: "model-20000.cptk"
all_model_checkpoint_paths: "model-25000.cptk"
all_model_checkpoint_paths: "model-30000.cptk"
all_model_checkpoint_paths: "model-35000.cptk"
all_model_checkpoint_paths: "model-40000.cptk"
all_model_checkpoint_paths: "model-45000.cptk"
all_model_checkpoint_paths: "model-50000.cptk"
all_model_checkpoint_paths: "model-55000.cptk"
all_model_checkpoint_paths: "model-58856.cptk"
Learner:
trainer: ppo
epsilon: 0.2
gamma: 0.99
lambd: 0.95
learning_rate: 3.0e-4
memory_size: 256
normalize: false
sequence_length: 64
summary_freq: 1000
use_recurrent: false
use_curiosity: true
curiosity_strength: 0.01
curiosity_enc_size: 256
time_horizon: 128
batch_size: 64
buffer_size: 2024
hidden_units: 256
num_layers: 1
beta: 1.0e-2
max_steps: 5.0e6
num_epoch: 3
!ArenaConfig
arenas:
0: !Arena
t: 250
items:
- !Item
name: GoodGoal
Place the **Linux** environment here to test your docker
\ No newline at end of file
import sys
import importlib.util
import signal
import traceback
from os import listdir
from animalai.envs.gym.environment import AnimalAIEnv
from animalai.envs.arena_config import ArenaConfig
def main():
# Load the agent from the submission
print('Loading your agent')
try:
spec = importlib.util.spec_from_file_location('agent_module', '/aaio/agent.py')
agent_module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(agent_module)
submitted_agent = agent_module.Agent()
except Exception as e:
print('Your agent could not be loaded, make sure all the paths are absolute, error thrown:')
raise e
print('Agent successfully loaded')
arena_config_in = ArenaConfig('/aaio/test/1-Food.yaml')
print('Resetting your agent')
try:
submitted_agent.reset(t=arena_config_in.arenas[0].t)
except Exception as e:
print('Your agent could not be reset:')
raise e
env = AnimalAIEnv(
environment_filename='/aaio/test/env/AnimalAI',
# seed=0,
retro=False,
n_arenas=1,
worker_id=1,
docker_training=True,
)
env.reset(arenas_configurations=arena_config_in)
obs, reward, done, info = env.step([0, 0])
print('Running 5 episodes')
for k in range(5):
cumulated_reward = 0
print('Episode {} starting'.format(k))
try:
for i in range(arena_config_in.arenas[0].t):
action = submitted_agent.step(obs, reward, done, info)
obs, reward, done, info = env.step(action)
cumulated_reward += reward
if done:
break
except Exception as e:
print('Episode {} failed'.format(k))
raise e
print('Episode {0} completed, reward {1}'.format(k, cumulated_reward))
print('SUCCESS')
if __name__ == '__main__':
main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment