class_docstr: A controller/agent that populates a Launch RunQueue from a hyperparameter sweep.
class_docstr_tok: ["A","controller\/agent","that","populates","a","Launch","RunQueue","from","a","hyperparameter","sweep","."]
docstr: Convert a sweeprun into a launch job then push to runqueue.
docstr_tok: ["Convert","a","sweeprun","into","a","launch","job","then","push","to","runqueue","."]
code: def _add_to_launch_queue(self, run: SweepRun) -> bool:
      """Convert a sweeprun into a launch job then push to runqueue."""
      # job and image first from CLI args, then from sweep config
      _job = self._kwargs.get("job") or self._sweep_config.get("job")
      _sweep_config_uri = self._sweep_config.get("image_uri")
      _image_uri = self._kwargs.get("image_uri") or _sweep_config_uri
      if _job is None and _image_uri is None:
          raise SchedulerError(
              f"{LOG_PREFIX}No 'job' nor 'image_uri' ({run.id})"
          )
      elif _job is not None and _image_uri is not None:
          raise SchedulerError(
              f"{LOG_PREFIX}Sweep has both 'job' and 'image_uri'"
          )
  
      entry_point, launch_config = self._make_entry_and_launch_config(
          run
      )
      if entry_point:
          wandb.termwarn(
              f"{LOG_PREFIX}Sweep command {entry_point} will override"
              f' {"job" if _job else "image_uri"} entrypoint'
          )
  
      # override resource and args of job
      _job_launch_config = self._wandb_run.config.get("launch") or {}
  
      # default priority is "medium"
      _priority = int(launch_config.get("priority", 2))  # type: ignore
  
      run_id = run.id or generate_id()
      queued_run = launch_add(
          run_id=run_id,
          entry_point=entry_point,
          config=launch_config,
          docker_image=_image_uri,  # TODO(gst): make agnostic (github? run uri?)
          job=_job,
          project=self._project,
          entity=self._entity,
          queue_name=self._kwargs.get("queue"),
          project_queue=self._project_queue,
          resource=_job_launch_config.get("resource"),
          resource_args=_job_launch_config.get("resource_args"),
          author=self._kwargs.get("author"),
          sweep_id=self._sweep_id,
          priority=_priority,
      )
      run.queued_run = queued_run
      # TODO(gst): unify run and queued_run state
      run.state = RunState.RUNNING  # assume it will get picked up
      self._runs[run_id] = run
  
      wandb.termlog(
          f"{LOG_PREFIX}Added run ({run_id}) to queue ({self._kwargs.get('queue')})"
      )
      return True
  
imports: import asyncio
  import base64
  import logging
  import os
  import socket
  import threading
  import time
  import traceback
  from abc import ABC, abstractmethod
  from dataclasses import dataclass
  from enum import Enum
  from typing import TYPE_CHECKING, Any, Dict, Iterator, List, Optional, Tuple, Union
  import click
  import yaml
  import wandb
  from wandb.errors import CommError
  from wandb.sdk.launch._launch_add import launch_add
  from wandb.sdk.launch.errors import LaunchError
  from wandb.sdk.launch.sweeps import SchedulerError
  from wandb.sdk.launch.sweeps.utils import create_sweep_command_args, make_launch_sweep_entrypoint
  from wandb.sdk.launch.utils import event_loop_thread_exec
  from wandb.sdk.lib.runid import generate_id
label_desc: Use image node_id 35 for calling the Scheduler obj's underlying member method code with example usage: obj._add_to_launch_queue(run) and returns: True