o
    -wi["                  +   @   s  d dl Z d dlZd dlmZmZmZmZmZ d dlZd dl	m
  mZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZmZmZmZ dd	lmZ 	d)d
ededeeef dee dedee defddZ																				d*dee dee deeeef  deeeeeeef f  dee dee dee dee deee  dee dee dee dee deeeef  dee d ee  d!ee d"ee d#ee dee dd$f*d%d&Z!							d+d
edee deeeef  dee dee dee dee dee deee  dee dee dee dee deeeef  dee d ee  d!ee d"ee d#ee dee dd$f*d'd(Z"dS ),    N)AnyDictListOptionalUnion)Api)	CommError)build_image_from_project)LaunchError)LAUNCH_DEFAULT_PROJECT
LOG_PREFIXconstruct_launch_specvalidate_launch_spec_source   )LaunchProjectapi
queue_namelaunch_spectemplate_variablesproject_queuepriorityreturnc                 C   s   |  |||||S N)push_to_run_queue)r   r   r   r   r   r    r   Y/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/wandb/sdk/launch/_launch_add.pypush_to_queue   s   
r   Furijobconfigprojectentityresourceentry_pointnameversiondocker_imageresource_argsrun_idbuild
repositorysweep_idauthorzpublic.QueuedRunc                 C   s6   t  }t||||||||||	|
|||||||||dS )a
  Enqueue a W&B launch experiment. With either a source uri, job or docker_image.

    Arguments:
        uri: URI of experiment to run. A wandb run uri or a Git repository URI.
        job: string reference to a wandb.Job eg: wandb/test/my-job:latest
        config: A dictionary containing the configuration for the run. May also contain
            resource specific arguments under the key "resource_args"
        template_variables: A dictionary containing values of template variables for a run queue.
            Expected format of `{"VAR_NAME": VAR_VALUE}`
        project: Target project to send launched run to
        entity: Target entity to send launched run to
        queue: the name of the queue to enqueue the run to
        priority: the priority level of the job, where 1 is the highest priority
        resource: Execution backend for the run: W&B provides built-in support for "local-container" backend
        entry_point: Entry point to run within the project. Defaults to using the entry point used
            in the original run for wandb URIs, or main.py for git repository URIs.
        name: Name run under which to launch the run.
        version: For Git-based projects, either a commit hash or a branch name.
        docker_image: The name of the docker image to use for the run.
        resource_args: Resource related arguments for launching runs onto a remote backend.
            Will be stored on the constructed launch config under ``resource_args``.
        run_id: optional string indicating the id of the launched run
        build: optional flag defaulting to false, requires queue to be set
            if build, an image is created, creates a job artifact, pushes a reference
                to that job artifact to queue
        repository: optional string to control the name of the remote repository, used when
            pushing images to a registry
        project_queue: optional string to control the name of the project for the queue. Primarily used
            for back compatibility with project scoped queues


    Example:
    ```python
    from wandb.sdk.launch import launch_add

    project_uri = "https://github.com/wandb/examples"
    params = {"alpha": 0.5, "l1_ratio": 0.01}
    # Run W&B project and create a reproducible docker environment
    # on a local host
    api = wandb.apis.internal.Api()
    launch_add(uri=project_uri, parameters=params)
    ```


    Returns:
        an instance of`wandb.api.public.QueuedRun` which gives information about the
        queued run, or if `wait_until_started` or `wait_until_finished` are called, gives access
        to the underlying Run information.

    Raises:
        `wandb.exceptions.LaunchError` if unsuccessful
    )r(   r)   r*   r+   r,   r   )r   _launch_add)r   r   r   r   r    r!   r   r"   r#   r$   r%   r&   r   r'   r(   r)   r*   r+   r,   r   r   r   r   r   
launch_add"   s.   Jr.   c                  C   sr  t d || |	||||||
||||||}|ro|dkrtd|dd ur-td d |d< t|| }tt	|| |p;i }tjpLtj
|d |d dd}|||j}| j}|d  d	|d  d	| }||d< d |d
< |d u rud}|d u r{t}|d}t|tr|d |d u r|}ni ||}t| t| |||||}|d u sd|vrtd|d}|r|dr|d|d< |dr|d|d< |tkrtt d| d ntt d| d	| d tt dt| d t }|d ur'z	|j|dd W n ttfy& } z
td| d| d }~ww ||d |d ||d ||}|S )Nzlocal-processz;Cannot build a docker image for the resource: local-processr   z5Build doesn't support setting a job. Overwriting job.r    r!   
launch_job)r    r!   job_type/r   defaultr   runQueueItemIdzError adding run to queuerunSpecr'   r"   zAdded run to queue .zLaunch spec:

)typezUnable to fetch job with name z: )r   r
   getwandbtermwarnr   	from_specasynciorunr	   init_log_job_artifact_with_imageoverride_argswaitr$   r   
isinstancedictpopr   r   termlogr   pprintpformatpublicr   	_artifact
ValueErrorr   
queued_run) r   r   r   r   r    r!   r   r"   r#   r$   r%   r&   r   r'   r(   r)   r*   r+   r,   r   r   launch_projectdocker_image_urir=   job_artifactjob_namespec_template_varsresupdated_spec
public_apierK   r   r   r   r-      s   









r-   r   )NNNNNNNNNNNNNNNFNNNN)NNFNNNN)#r<   rF   typingr   r   r   r   r   r9   wandb.apis.publicapisrH   wandb.apis.internalr   wandb.errorsr   wandb.sdk.launch.builder.buildr	   wandb.sdk.launch.errorsr
   wandb.sdk.launch.utilsr   r   r   r   _project_specr   strrC   intr   floatboolr.   r-   r   r   r   r   <module>   s   	


	

r
	
