class_docstr: A controller/agent that populates a Launch RunQueue from a sweeps RunQueue.
docstr: Called by the main scheduler execution loop.
  
  Expected to return a properly formatted SweepRun if the scheduler
  is alive, or None and set the appropriate scheduler state:
  
  FAILED: self.fail_sweep()
  STOPPED: self.stop_sweep()
docstr_tok: ["Called","by","the","main","scheduler","execution","loop",".","Expected","to","return","a","properly","formatted","SweepRun","if","the","scheduler","is","alive",",","or","None","and","set","the","appropriate","scheduler","state",":","FAILED",":","self.fail_sweep","(",")","STOPPED",":","self.stop_sweep","(",")"]
code: def _get_next_sweep_run(self, worker_id: int) -> Optional[SweepRun]:
      """Called by the main scheduler execution loop.
  
      Expected to return a properly formatted SweepRun if the scheduler
      is alive, or None and set the appropriate scheduler state:
  
      FAILED: self.fail_sweep()
      STOPPED: self.stop_sweep()
      """
      commands: List[Dict[str, Any]] = self._get_sweep_commands(
          worker_id
      )
      for command in commands:
          # The command "type" can be one of "run", "resume", "stop", "exit"
          _type = command.get("type")
          if _type in ["exit", "stop"]:
              self.stop_sweep()
              return None
  
          if _type not in ["run", "resume"]:
              self.fail_sweep(
                  f"AgentHeartbeat unknown command: {_type}"
              )
  
          _run_id: Optional[str] = command.get("run_id")
          if not _run_id:
              self.fail_sweep(
                  f"No run id in agent heartbeat: {command}"
              )
              return None
  
          if _run_id in self._runs:
              wandb.termlog(
                  f"{LOG_PREFIX}Skipping duplicate run: {_run_id}"
              )
              continue
  
          return SweepRun(
              id=_run_id,
              state=RunState.PENDING,
              args=command.get("args", {}),
              logs=command.get("logs", []),
              worker_id=worker_id,
          )
      return None
  
file_path: wandb/wandb/sdk/launch/sweeps/scheduler_sweep.py
imports: import logging
  from pprint import pformat
  from typing import Any, Dict, List, Optional
  import wandb
  from wandb.sdk.launch.sweeps.scheduler import LOG_PREFIX, RunState, Scheduler, SweepRun
label_desc: Use image node_id 2 for calling the SweepScheduler obj's underlying member method code with example usage: obj._get_next_sweep_run(worker_id) and returns: None, SweepRun, None, None