|
3 | 3 | """Launches trainers for each External Brains in a Unity Environment.""" |
4 | 4 |
|
5 | 5 | import os |
| 6 | +import glob |
6 | 7 | import logging |
| 8 | +import shutil |
7 | 9 |
|
8 | 10 | import yaml |
9 | 11 | import re |
@@ -71,8 +73,16 @@ def __init__(self, env_path, run_id, save_freq, curriculum_folder, |
71 | 73 | docker_target_name=docker_target_name, |
72 | 74 | run_id=run_id) |
73 | 75 | if env_path is not None: |
74 | | - env_path = '/{docker_target_name}/{env_name}'.format( |
75 | | - docker_target_name=docker_target_name, env_name=env_path) |
| 76 | + """ |
| 77 | + Comments for future maintenance: |
| 78 | + Some OS/VM instances (e.g. COS GCP Image) mount filesystems |
| 79 | + with COS flag which prevents execution of the Unity scene, |
| 80 | + to get around this, we will copy the executable into the |
| 81 | + container. |
| 82 | + """ |
| 83 | + # Navigate in docker path and find env_path and copy it. |
| 84 | + env_path = self._prepare_for_docker_run(docker_target_name, |
| 85 | + env_path) |
76 | 86 | if curriculum_folder is not None: |
77 | 87 | self.curriculum_folder = \ |
78 | 88 | '/{docker_target_name}/{curriculum_folder}'.format( |
@@ -124,6 +134,26 @@ def __init__(self, env_path, run_id, save_freq, curriculum_folder, |
124 | 134 | 'name as the Brain ' |
125 | 135 | 'whose curriculum it defines.') |
126 | 136 |
|
| 137 | + def _prepare_for_docker_run(self, docker_target_name, env_path): |
| 138 | + for f in glob.glob('/{docker_target_name}/*'.format( |
| 139 | + docker_target_name=docker_target_name)): |
| 140 | + if env_path in f: |
| 141 | + try: |
| 142 | + b = os.path.basename(f) |
| 143 | + if os.path.isdir(f): |
| 144 | + shutil.copytree(f, |
| 145 | + '/ml-agents/{b}'.format(b=b)) |
| 146 | + else: |
| 147 | + src_f = '/{docker_target_name}/{b}'.format( |
| 148 | + docker_target_name=docker_target_name, b=b) |
| 149 | + dst_f = '/ml-agents/{b}'.format(b=b) |
| 150 | + shutil.copyfile(src_f, dst_f) |
| 151 | + os.chmod(dst_f, 0o775) # Make executable |
| 152 | + except Exception as e: |
| 153 | + self.logger.info(e) |
| 154 | + env_path = '/ml-agents/{env_name}'.format(env_name=env_path) |
| 155 | + return env_path |
| 156 | + |
127 | 157 | def _get_measure_vals(self): |
128 | 158 | if self.meta_curriculum: |
129 | 159 | brain_names_to_measure_vals = {} |
|
0 commit comments