
    =                         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  \R                  4S
 jr " S S\5      rg)z4Utilities for querying hptuning-jobs in AI platform.    )absolute_import)division)unicode_literals)
list_pager)apis)messages)	constants)yamlc                     [         R                  " [        R                  [        R                  U    5      nU [        R
                  :X  a  UR                  R                  $ UR                  R                  $ N)	r   GetMessagesModuler	   AI_PLATFORM_API_NAMEAI_PLATFORM_API_VERSION
GA_VERSION GoogleCloudAiplatformV1StudySpecAlgorithmValueValuesEnum%GoogleCloudAiplatformV1beta1StudySpec)versionr   s     6lib/googlecloudsdk/api_lib/ai/hp_tuning_jobs/client.pyGetAlgorithmEnumr      s[    ##I$B$B$-$E$Eg$NP(	$$$44MMM99RRR    c                   r    \ rS rSrSrS rS rS rS r          SS jr	SS	 jr
SS
 jrSS jrS rSrg)HpTuningJobsClient%   zBClient used for interacting with HyperparameterTuningJob endpoint.c                     [         R                  " [        R                  [        R                  U   5      nUR
                  U l        UR                  U l        Xl	        [        R                  U   U l        g r   )r   GetClientInstancer	   r   r   MESSAGES_MODULE	_messages+projects_locations_hyperparameterTuningJobs_servicer   AI_PLATFORM_MESSAGE_PREFIX_message_prefix)selfr   clients      r   __init__HpTuningJobsClient.__init__(   s[    ##I$B$B$-$E$Eg$NPF++DNFFDML$??HDr   c                 `    [        U R                  SR                  U R                  US9S5      $ )z(Returns the API messsages class by name.z{prefix}{name})prefixnameN)getattrr   formatr"   )r#   message_names     r   _GetMessageHpTuningJobsClient._GetMessage0   s9     t';';%1 	  	348: :r   c                 $    U R                  S5      $ )z5Returns the HyperparameterTuningJob resource message.HyperparameterTuningJob)r-   r#   s    r   HyperparameterTuningJobMessage1HpTuningJobsClient.HyperparameterTuningJobMessage8   s     566r   c                 8    U R                  S5      R                  $ )z,Returns enum message representing Algorithm.	StudySpec)r-   r   r1   s    r   AlgorithmEnum HpTuningJobsClient.AlgorithmEnum=   s     K(AAAr   Nc                    U R                  5       nU(       aA  [        R                  " U5      nU(       a$  [        R                  " XR                  5       5      nUR
                  (       d  U(       d  SUl        OU(       a  XMl        UR                  (       d  U(       d  SUl        OU(       a  X]l        U(       a  XR                  l        U	(       a  XR                  l	        U
(       a  XR                  l
        U(       a  XR                  l        U(       a  X-l        U(       a!  UR                  (       a  XmR                  l        Ub  U R                  S5      " US9Ul        U(       a  Xl        U R$                  [&        R(                  :X  a  U R*                  R-                  UUS9nOU R*                  R-                  UUS9nU R.                  R1                  U5      $ )a  Creates a hyperparameter tuning job with given parameters.

Args:
  config_path: str, the file path of the hyperparameter tuning job
    configuration.
  display_name: str, the display name of the created hyperparameter tuning
    job.
  parent: str, parent of the created hyperparameter tuning job. e.g.
    /projects/xxx/locations/xxx/
  max_trial_count: int, the desired total number of Trials. The default
    value is 1.
  parallel_trial_count: int, the desired number of Trials to run in
    parallel. The default value is 1.
  algorithm: AlgorithmValueValuesEnum, the search algorithm specified for
    the Study.
  kms_key_name: str, A customer-managed encryption key to use for the
    hyperparameter tuning job.
  network: str, user network to which the job should be peered with
    (overrides yaml file)
  service_account: str, A service account (email address string) to use for
    the job.
  enable_web_access: bool, Whether to enable the interactive shell for the
    job.
  enable_dashboard_access: bool, Whether to enable the dashboard defined for
    the job.
  labels: LabelsValues, map-like user-defined metadata to organize the
    hp-tuning jobs.

Returns:
  Created hyperparameter tuning job.
   EncryptionSpec)
kmsKeyName)parent.googleCloudAiplatformV1HyperparameterTuningJob)r<   3googleCloudAiplatformV1beta1HyperparameterTuningJob)r2   r
   	load_pathmessages_utilDictToMessageWithErrorCheckmaxTrialCountparallelTrialCounttrialJobSpecnetworkserviceAccountenableWebAccessenableDashboardAccessdisplayName	studySpec	algorithmr-   encryptionSpeclabelsr   r	   r   r   @AiplatformProjectsLocationsHyperparameterTuningJobsCreateRequestr    Create)r#   config_pathdisplay_namer<   max_trial_countparallel_trial_countrK   kms_key_namerE   service_accountenable_web_accessenable_dashboard_accessrM   job_specdatarequests                   r   rO   HpTuningJobsClient.CreateB   ss   Z 224H^^K(d	 <<5579 !!/ h	.&&/C$%h!	$8!&-#-<*.?+4K1)X''%." $ 0 01A B!!#h o||y+++__9A ` Cg __>F ` Hg ==((r   c                 j    U R                   R                  US9nU R                  R                  U5      $ Nr)   r   =AiplatformProjectsLocationsHyperparameterTuningJobsGetRequestr    Getr#   r)   rZ   s      r   ra   HpTuningJobsClient.Get   s4    nnZZ [ G==W%%r   c                 j    U R                   R                  US9nU R                  R                  U5      $ r]   )r   @AiplatformProjectsLocationsHyperparameterTuningJobsCancelRequestr    Cancelrb   s      r   rf   HpTuningJobsClient.Cancel   s4    nn]] ^ G==((r   c                 t    [         R                  " U R                  U R                  R	                  US9SSUS9$ )N)r<   hyperparameterTuningJobspageSize)fieldbatch_size_attributelimit)r   YieldFromListr    r   >AiplatformProjectsLocationsHyperparameterTuningJobsListRequest)r#   rm   regions      r   ListHpTuningJobsClient.List   s@    ##	G	G 
H 
(' r   c                 |   ^ U R                   R                  US9nU R                  R                  U5      mU4S jnU$ )zReturns a function to decide if log fetcher should continue polling.

Args:
  name: String id of job.

Returns:
  A one-argument function decides if log fetcher should continue.
r^   c                 .   > U S::  a  gTR                   S L $ )Nr9   T)endTime)periods_without_logsresponses    r   ShouldContinue;HpTuningJobsClient.CheckJobComplete.<locals>.ShouldContinue   s    		"%%r   r_   )r#   r)   rZ   rx   rw   s       @r   CheckJobComplete#HpTuningJobsClient.CheckJobComplete   sC     nnZZ [ G}}  )H&
 r   )r"   r   r    r   )
NNNNNNNFFNr   )NN)__name__
__module____qualname____firstlineno____doc__r%   r-   r2   r6   rO   ra   rf   rq   rz   __static_attributes__ r   r   r   r   %   sV    JI:7
B #_)B&
)
r   r   N)r   
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.utilr   r   r@   googlecloudsdk.command_lib.air	   googlecloudsdk.corer
   BETA_VERSIONr   objectr   r   r   r   <module>r      sA    ; &  ' ' , A 3 $ '33 Sd dr   