
    
1                         S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJ	r	  SSKJ
r
  SSKJr  SS	KJr   " S
 S\	R                  5      r " S S\	R                  5      rSS jrSS jr " S S\5      rg)z'Utilities for dealing with ML jobs API.    )encoding)
list_pager)apis)	arg_utils)
exceptions)
properties)	resources)yamlc                       \ rS rSrSrSrg)NoFieldsSpecifiedError   zEError indicating that no updates were requested in a Patch operation. N__name__
__module____qualname____firstlineno____doc____static_attributes__r       ,lib/googlecloudsdk/api_lib/ml_engine/jobs.pyr   r      s    Mr   r   c                       \ rS rSrSrSrg)NoPackagesSpecifiedError    z>Error that no packages were specified for non-custom training.r   Nr   r   r   r   r   r       s    Fr   r   c                 0    [         R                  " SU 5      $ )Nml)r   GetMessagesModule)versions    r   r   r   $   s    			g	..r   c                 ,    [         R                  " SXS9$ )Nr   )no_http)r   GetClientInstance)r   r    s     r   r!   r!   (   s    			g	??r   c                       \ rS rSrSr  SS jrS r\S 5       rS r	\S 5       r
\S	 5       r\S
 5       rSS jrS rS rS rS r                SS jrS rS r               SS jrSrg)
JobsClient,   z3Client for jobs service in the Cloud ML Engine API.Nc                     U=(       d    [        U5      U l        U=(       d    U R                  R                  U l        X0l        g N)r!   clientMESSAGES_MODULEmessages_short_message_prefix)selfr'   r)   short_message_prefixclient_versions        r   __init__JobsClient.__init__/   s0    =-n=DK; ; ;DM!5r   c                 `    [        U R                  SR                  U R                  US9S 5      $ )Nz{prefix}{name})prefixname)getattrr)   formatr*   )r+   short_message_names     r   GetShortMessageJobsClient.GetShortMessage5   s9    4==#**$2L2L0B + DEIK Kr   c                 B    U R                   R                  R                  $ r&   )r)   GoogleCloudMlV1JobStateValueValuesEnumr+   s    r   
state_enumJobsClient.state_enum:   s    ==++@@@r   c                     U R                   R                  UR                  5       S9n[        R                  " U R
                  R                  USSS9$ )N)parentjobspageSize)fieldbatch_size_attribute)r)   MlProjectsJobsListRequestRelativeNamer   YieldFromListr'   projects_jobs)r+   project_refreqs      r   ListJobsClient.List>   sN    
--
1
1'') 2 +C##!!3f') )r   c                 .    U R                   R                  $ r&   )r)   r9   r;   s    r   	job_classJobsClient.job_classE   s    ==+++r   c                 .    U R                   R                  $ r&   )r)   GoogleCloudMlV1TrainingInputr;   s    r   training_input_classJobsClient.training_input_classI   s    ==555r   c                 .    U R                   R                  $ r&   )r)   GoogleCloudMlV1PredictionInputr;   s    r   prediction_input_class!JobsClient.prediction_input_classM   s    ==777r   c                 6    U R                   R                  UUS9$ )N)r?   googleCloudMlV1Job)r)   MlProjectsJobsCreateRequest)r+   r?   jobs      r   _MakeCreateRequestJobsClient._MakeCreateRequestQ   s$    ==44 5    r   c                     U R                   R                  R                  U R                  UR	                  5       US95      $ )N)r?   rZ   )r'   rG   Creater[   rE   )r+   rH   rZ   s      r   r^   JobsClient.CreateV   sA    ;;$$++++- 	  	 r   c                     U R                   R                  UR                  5       S9nU R                  R                  R                  U5      $ )zCancels given job.r2   )r)   MlProjectsJobsCancelRequestrE   r'   rG   Cancelr+   job_refrI   s      r   rc   JobsClient.Cancel\   s=    
--
3
39M9M9O
3
PC;;$$++C00r   c                     U R                   R                  UR                  5       S9nU R                  R                  R                  U5      $ )Nra   )r)   MlProjectsJobsGetRequestrE   r'   rG   Getrd   s      r   ri   JobsClient.Geta   s=    
--
0
0g6J6J6L
0
MC;;$$((--r   c                 j   U R                  5       n/ nUR                  (       a"  UR                  Ul        UR                  S5        U(       d  [	        S5      eU R
                  R                  UR                  5       USR                  U5      S9nU R                  R                  R                  U5      $ )zUpdate a job.labelszNo updates requested.,)r2   rX   
updateMask)rM   needs_updaterl   appendr   r)   MlProjectsJobsPatchRequestrE   joinr'   rG   Patch)r+   re   labels_updaterZ   update_maskrI   s         r   rs   JobsClient.Patche   s    
..
CK!! ''cj""#:;;
--
2
2!!#88K( 3 C
 ;;$$**3//r   c                 ,   U R                  5       nU(       a>  [        R                  " U5      nU(       a!  [        R                  " UU R                   5      nU(       a  UUl        Ub  UUl        UR                  (       d  U R                  5       Ul        UUUUUUU	U
UUUS.nUR                  5        H"  u  nnUc  M  [        UR                  UU5        M$     U(       a  [        R                  " USU5        U(       Ga^  UR                  5       R                  5        GH;  u  nnUc  M  UR                  S5      (       Ga  UR                  S5      (       d  US   (       a*  [        R                  " USR                  U5      US   5        US   S   (       a-  [        R                  " US	R                  U5      US   S   5        US   S
   (       a-  [        R                  " USR                  U5      US   S
   5        US:X  a:  US   (       a-  [        R                  " USR                  U5      US   5        GM  GM!  GM$  [        UR                  UU5        GM>     U R!                  U5      (       d!  U R#                  U5      (       d  [%        S5      eU$ )a  Builds a Cloud ML Engine Job from a config file and/or flag values.

Args:
    path: path to a yaml configuration file
    module_name: value to set for moduleName field (overrides yaml file)
    job_name: value to set for jobName field (overrides yaml file)
    trainer_uri: List of values to set for trainerUri field (overrides yaml
      file)
    region: compute region in which to run the job (overrides yaml file)
    job_dir: Cloud Storage working directory for the job (overrides yaml
      file)
    scale_tier: ScaleTierValueValuesEnum the scale tier for the job
      (overrides yaml file)
    user_args: [str]. A list of arguments to pass through to the job.
    (overrides yaml file)
    runtime_version: the runtime version in which to run the job (overrides
      yaml file)
    python_version: the Python version in which to run the job (overrides
      yaml file)
    network: user network to which the job should be peered with (overrides
      yaml file)
    service_account: A service account (email address string) to use for the
      job.
    labels: Job.LabelsValue, the Cloud labels for the job
    kms_key: A customer-managed encryption key to use for the job.
    custom_train_server_config: jobs_util.CustomTrainingInputServerConfig,
      configuration object for custom server parameters.
    enable_web_access: whether to enable the interactive shell for the job.
Raises:
  NoPackagesSpecifiedError: if a non-custom job was specified without any
    trainer_uris.
Returns:
    A constructed Job object.
)pythonModuleargspackageUrisregionjobDir	scaleTierruntimeVersionpythonVersionnetworkserviceAccountenableWebAccessz)trainingInput.encryptionConfig.kmsKeyNameConfigTfConfigimageUriztrainingInput.{}.imageUriacceleratorConfigtypez'trainingInput.{}.acceleratorConfig.typecountz(trainingInput.{}.acceleratorConfig.countworkerConfigtpuTfVersionztrainingInput.{}.tpuTfVersionz#Non-custom jobs must have packages.)rM   r
   	load_pathr   DictToMessagejobIdrl   trainingInputrQ   itemssetattrr   SetFieldInMessageGetFieldMapendswithr4   HasPackageURIsIsCustomContainerTrainingr   )r+   pathmodule_namejob_nametrainer_urir{   job_dir
scale_tier	user_argsruntime_versionpython_versionr   service_accountrl   kms_keycustom_train_server_configenable_web_accessrZ   dataadditional_fields
field_namevalues                         r   BuildTrainingJobJobsClient.BuildTrainingJobu   se   f ..
C ^^D!d	$$T4>>:cicj335c#")'), /446
E		!!:u5 7 !!#"M")+ "9EEGMMO
*e!!(++%%j11Z ))-44Z@
#% ()&1));BB:N+,V46 ()'2))<CCJO+,W57 ^+n0E))188D') 1F+ C%%z593  P6 s##D,J,J3,O,O$%JKKJr   c                 @    [        UR                  R                  5      $ r&   )boolr   rz   r+   rZ   s     r   r   JobsClient.HasPackageURIs   s    !!--..r   c                     [        UR                  R                  =(       a     UR                  R                  R                  5      $ r&   )r   r   masterConfigr   r   s     r   r   $JobsClient.IsCustomContainerTraining   s7    !!.. 8!!..779 9r   c           
      F   [         R                  R                  R                  R	                  5       nU(       a  U R                  S5      nU" UUS9nOSnU R                  UUUU	U
UUS9nUR                  U5      Ul        U(       a  UUl	        OuU(       a8  [        R                  R                  USUUS.S9nUR                  5       Ul        O6[        R                  R                  USS	U0S9nUR                  5       Ul        U(       a  UUl        U R#                  UUUS
9$ )a"  Builds a Cloud ML Engine Job for batch prediction from flag values.

Args:
    job_name: value to set for jobName field
    model_dir: str, Google Cloud Storage location of the model files
    model_name: str, value to set for modelName field
    version_name: str, value to set for versionName field
    input_paths: list of input files
    data_format: format of the input files
    output_path: single value for the output location
    region: compute region in which to run the job
    runtime_version: the runtime version in which to run the job
    max_worker_count: int, the maximum number of workers to use
    batch_size: int, the number of records per batch sent to Tensorflow
    signature_name: str, name of input/output signature in the TF meta graph
    labels: Job.LabelsValue, the Cloud labels for the job
    accelerator_count: int, The number of accelerators to attach to the
       machines
   accelerator_type: AcceleratorsValueListEntryValuesEnum, The type of
       accelerator to add to machine.
Returns:
    A constructed Job object.
AcceleratorConfig)r   r   N)
inputPaths
outputPathr{   r~   maxWorkerCount	batchSizeacceleratorzml.projects.models.versions)modelsId
projectsId)
collectionparamszml.projects.modelsr   )r   predictionInputrl   )r   VALUEScoreproject	GetOrFailr6   rU   DataFormatValueValuesEnum
dataFormaturir	   REGISTRYParserE   versionName	modelNamesignatureNamerM   )r+   r   	model_dir
model_nameversion_nameinput_pathsdata_formatoutput_pathr{   r   max_worker_count
batch_sizesignature_namerl   accelerator_countaccelerator_type
project_idaccelerator_config_msgaccelerator_configprediction_inputversion_ref	model_refs                         r   BuildBatchPredictionJob"JobsClient.BuildBatchPredictionJob   sM   N ""''//99;J#334GH18I7GI  22&'& 3  #3"L"L#&	&&,,
#@(
C - Ek &1%=%=%?"$$**
!5
+ + -i $-#9#9#; '5$>>(   r   )r*   r'   r)   )NNGoogleCloudMlV1v1)NN)NNNNNNNNNNNNNNNN)NNNNNNNNNNNNNNN)r   r   r   r   r   r.   r6   propertyr<   rJ   rM   rQ   rU   r[   r^   rc   ri   rs   r   r   r   r   r   r   r   r   r#   r#   ,   s    ;+/FJ6K
 A A) , , 6 6 8 8 
1
.0" !#' $#'"#"&!%'+&*#'+"#26)-!xt/9
 (,(,)-+/*.*.*.%).2/3)--1%)04/3Pr   r#   N)r   )r   F)r   apitools.base.pyr   r   googlecloudsdk.api_lib.utilr   $googlecloudsdk.command_lib.util.apisr   googlecloudsdk.corer   r   r	   r
   Errorr   r   r   r!   objectr#   r   r   r   <module>r      se    . & ' , : * * ) $NZ-- NGz// G/@Z Zr   