code: def create_or_load_study(
      project_id: Text,
      region: Text,
      study_id: Text,
      study_config: Optional[Dict[Text, Any]] = None,
  ) -> _VizierClient:
      """Factory method for creating or loading a Vizier client.
  
      Given an Vizier study_config, this will either create or open the
      specified study. It will create it if it doesn't already exist, and open
      it if someone has already created it.
  
      Note that once a study is created, you CANNOT modify it with this function.
  
      This function is designed for use in a distributed system, where many jobs
      call create_or_load_study() nearly simultaneously with the same
      `study_config`. In that situation, all clients will end up pointing nicely
      to the same study.
  
      Args:
          project_id: A GCP project id.
          region: A GCP region. e.g. 'us-central1'.
          study_id: An identifier of the study. If not supplied, system-determined
              unique ID is given. The full study name will be
              projects/{project_id}/locations/{region}/studies/{study_id}.
              And the full trial name will be {study name}/trials/{trial_id}.
          study_config: Study configuration for Vizier service. If not
              supplied, it will be assumed that the study with the given study_id
              already exists, and will try to retrieve that study.
  
      Returns:
          An _VizierClient object with the specified study created or loaded.
  
      Raises:
          RuntimeError: Indicates that study_config is supplied but CreateStudy
              failed and GetStudy did not succeed after
              constants.MAX_NUM_TRIES_FOR_STUDIES tries.
          ValueError: Indicates that study_config is not supplied and the study
              with the given study_id does not exist.
      """
      # Build the API client
      # Note that Vizier service is exposed as a regional endpoint. As such,
      # an API client needs to be created separately from the default.
      with open(constants.OPTIMIZER_API_DOCUMENT_FILE) as f:
          service_client = discovery.build_from_document(
              service=json.load(f),
              requestBuilder=google_api_client.TFCloudHttpRequest,
          )
  
      # Creates or loads a study.
      study_parent = "projects/{}/locations/{}".format(
          project_id, region
      )
  
      if study_config is None:
          # If study config is unspecified, assume that the study already exists.
          _get_study(
              service_client=service_client,
              study_parent=study_parent,
              study_id=study_id,
              study_should_exist=True,
          )
  
      else:
          request = (
              service_client.projects()
              .locations()
              .studies()
              .create(
                  body={"study_config": study_config},
                  parent=study_parent,
                  studyId=study_id,
              )
          )
          try:
              tf.get_logger().info(request.execute())
          except errors.HttpError as e:
              if (
                  e.resp.status != 409
              ):  # 409 implies study exists, handled below
                  raise
  
              _get_study(
                  service_client=service_client,
                  study_parent=study_parent,
                  study_id=study_id,
              )
  
      return _VizierClient(service_client, project_id, region, study_id)
  
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 1 for calling a global function with example usage: create_or_load_study(project_id, region, study_id, study_config) and returns: _VizierClient