[docs]classMaxEpisodesTerminationCondition(TerminationCondition):"""Checks whether a maximum number of episodes has been exceeded. This termination condition will only trigger on phase level. It uses the ``episodes`` key in the phase configuration to check whether a maximum number of episodes has been reached. Examples -------- Consider the following experiment phase definition:: schedule: Training: phase_config: mode: train worker: 2 episodes: 100 simulation: conditions: - name: palaestrai.experiment:MaxEpisodesTerminationCondition params: {} name: palaestrai.simulation:TakingTurns run_config: condition: name: palaestrai.experiment:MaxEpisodesTerminationCondition params: {} Then, the phase would end when both workers (``worker: 2``) have reached 100 episodes (``episodes: 100``). """defphase_flow_control(self,run_governor:RunGovernor,message:SimulationControllerTerminationRequest,)->Tuple[SimulationFlowControl,Any]:ifnotisinstance(message,SimulationControllerTerminationRequest):returnSimulationFlowControl.CONTINUE,Noneifrun_governor.experiment_runisNone:LOG.warning("MaxEpisodesTerminationCondition cannot control flow: ""Run governor has no experiment run object!")returnSimulationFlowControl.CONTINUE,Nonetry:max_episodes=run_governor.experiment_run.get_episodes(run_governor.current_phase)exceptKeyError:# If the current phase does not define a phase limit, we can# continue indefinitely.returnSimulationFlowControl.CONTINUE,None# If all SCs have reached the max number of episodes, indicate end of# the phase:ifall(x>=max_episodesforxinrun_governor.current_episode_counts.values()):returnSimulationFlowControl.STOP_PHASE,None# If only the current one, indicate shutdown of the current simulation# controller:sc_uid=message.senderifrun_governor.current_episode_counts[sc_uid]>=max_episodes:returnSimulationFlowControl.STOP_SIMULATION,NonereturnSimulationFlowControl.CONTINUE,None