r""" This is the entry point for all processes. The rank 0 is the agent. All other ranks are observers.
(rank, world_size)
| 208 | |
| 209 | |
| 210 | def run_worker(rank, world_size): |
| 211 | r""" |
| 212 | This is the entry point for all processes. The rank 0 is the agent. All |
| 213 | other ranks are observers. |
| 214 | """ |
| 215 | os.environ['MASTER_ADDR'] = 'localhost' |
| 216 | os.environ['MASTER_PORT'] = '29500' |
| 217 | if rank == 0: |
| 218 | # rank0 is the agent |
| 219 | rpc.init_rpc(AGENT_NAME, rank=rank, world_size=world_size) |
| 220 | |
| 221 | agent = Agent(world_size) |
| 222 | for i_episode in count(1): |
| 223 | n_steps = int(TOTAL_EPISODE_STEP / (args.world_size - 1)) |
| 224 | agent.run_episode(n_steps=n_steps) |
| 225 | last_reward = agent.finish_episode() |
| 226 | |
| 227 | if i_episode % args.log_interval == 0: |
| 228 | print('Episode {}\tLast reward: {:.2f}\tAverage reward: {:.2f}'.format( |
| 229 | i_episode, last_reward, agent.running_reward)) |
| 230 | |
| 231 | if agent.running_reward > agent.reward_threshold: |
| 232 | print("Solved! Running reward is now {}!".format(agent.running_reward)) |
| 233 | break |
| 234 | else: |
| 235 | # other ranks are the observer |
| 236 | rpc.init_rpc(OBSERVER_NAME.format(rank), rank=rank, world_size=world_size) |
| 237 | # observers passively waiting for instructions from agents |
| 238 | rpc.shutdown() |
| 239 | |
| 240 | |
| 241 | def main(): |
nothing calls this directly
no test coverage detected