(player_name: str, path: str)
| 25 | |
| 26 | |
| 27 | def load_policy_module(player_name: str, path: str): |
| 28 | agent_dir = str(Path(path).resolve().parent) |
| 29 | inserted_agent_dir = agent_dir not in sys.path |
| 30 | if inserted_agent_dir: |
| 31 | sys.path.insert(0, agent_dir) |
| 32 | spec = importlib.util.spec_from_file_location(safe_module_name(player_name), path) |
| 33 | if spec is None or spec.loader is None: |
| 34 | raise RuntimeError(f"Could not load module spec from {path}") |
| 35 | module = importlib.util.module_from_spec(spec) |
| 36 | try: |
| 37 | spec.loader.exec_module(module) |
| 38 | finally: |
| 39 | if inserted_agent_dir: |
| 40 | sys.path.remove(agent_dir) |
| 41 | if not hasattr(module, "decide") or not callable(module.decide): |
| 42 | raise RuntimeError(f"{path} must define a callable decide(observation, action_space)") |
| 43 | return module |
| 44 | |
| 45 | |
| 46 | def observation_to_plain(observation): |
no test coverage detected