code: def _get_study(
      service_client: discovery.Resource,
      study_parent: Text,
      study_id: Text,
      study_should_exist: bool = False,
  ):
      """Method for loading a study.
  
      Given the study_parent and the study_id, this method will load the specified
      study, up to constants.MAX_NUM_TRIES_FOR_STUDIES tries.
  
      Args:
          service_client: An API client of Vizier service.
          study_parent: Prefix of the study name. The full study name will be
              {study_parent}/studies/{study_id}.
          study_id: An identifier of the study.
          study_should_exist: Indicates whether it should be assumed that the
              study with the given study_id exists.
      """
      study_name = "{}/studies/{}".format(study_parent, study_id)
      tf.get_logger().info(
          "Study already exists: {}.\nLoad existing study...".format(
              study_name
          )
      )
      num_tries = 0
      while True:
          try:
              service_client.projects().locations().studies().get(
                  name=study_name
              ).execute()
          except errors.HttpError as err:
              num_tries += 1
              if num_tries >= constants.MAX_NUM_TRIES_FOR_STUDIES:
                  if (
                      study_should_exist
                      and err.resp.status
                      == http.HTTPStatus.NOT_FOUND.value
                  ):
                      raise ValueError(
                          "GetStudy failed. Study not found: {}.".format(
                              study_id
                          )
                      )
                  else:
                      raise RuntimeError(
                          "GetStudy failed. Max retries reached: {0!s}".format(
                              err
                          )
                      )
              time.sleep(
                  1
              )  # wait 1 second before trying to get the study again
          else:
              break
  
imports: import datetime
  import http
  import json
  import time
  from typing import Any, Dict, List, Mapping, Optional, Text, Union
  from googleapiclient import discovery
  from googleapiclient import errors
  import tensorflow
  from tensorflow_cloud.tuner import vizier_client_interface
  from tensorflow_cloud.tuner import constants
  from tensorflow_cloud.utils import google_api_client
label_desc: Use image node_id 2 for calling a global function with example usage: _get_study(service_client, study_parent, study_id, study_should_exist) without return types