o
    xi!                     @  s   d dl mZ d dlZd dlZd dl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 	d5d6ddZ																				d7d8d1d2Z							d9d:d3d4ZdS );    )annotationsN)Any)Api)	CommError)build_image_from_project)LaunchError)LAUNCH_DEFAULT_PROJECT
LOG_PREFIXconstruct_launch_specvalidate_launch_spec_source   )LaunchProjectapir   
queue_namestrlaunch_specdict[str, Any]template_variablesdict | Noneproject_queuepriority
int | Nonereturnr   c                 C  s   |  |||||S N)push_to_run_queue)r   r   r   r   r   r    r   P/home/ubuntu/.local/lib/python3.10/site-packages/wandb/sdk/launch/_launch_add.pypush_to_queue   s   
r   Furi
str | Nonejobconfigdict[str, Any] | None#dict[str, float | int | str] | Noneprojectentityresourceentry_pointlist[str] | Nonenameversiondocker_imageresource_argsrun_idbuildbool | None
repositorysweep_idauthor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.   r0   r1   r2   r   )r   _launch_add)r   r    r!   r   r$   r%   r   r&   r'   r)   r*   r+   r   r,   r-   r.   r0   r1   r2   r   r   r   r   r   
launch_add$   s.   Jr5   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.   r0   r1   r2   r   r   launch_projectdocker_image_urirD   job_artifactjob_namespec_template_varsresupdated_spec
public_apierR   r   r   r   r4      s   









r4   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   )NNNNNNNNNNNNNNNFNNNN)*r   r   r    r   r!   r"   r   r#   r$   r   r%   r   r   r   r&   r   r'   r(   r)   r   r*   r   r+   r   r   r   r,   r"   r-   r   r.   r/   r0   r   r1   r   r2   r   r   r   r   r3   )NNFNNNN)*r   r   r    r   r!   r"   r   r   r$   r   r%   r   r   r   r&   r   r'   r(   r)   r   r*   r   r+   r   r   r   r,   r"   r-   r   r.   r/   r0   r   r1   r   r2   r   r   r   r   r3   )
__future__r   rC   rM   typingr   r@   wandb.apis.publicapisrO   wandb.apis.internalr   wandb.errorsr   wandb.sdk.launch.builder.buildr   wandb.sdk.launch.errorsr   wandb.sdk.launch.utilsr   r	   r
   r   _project_specr   r   r5   r4   r   r   r   r   <module>   sV    	r