Skip to content

Commit

Permalink
feat: add get_custom_job and get_hyperparameter_tuning_job samples (#68)
Browse files Browse the repository at this point in the history
* feat: add get_custom_job and get_hyperparameter_tuning_job samples
  • Loading branch information
dizcology committed Nov 16, 2020
1 parent 1eab2be commit 26da7a7
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 0 deletions.
36 changes: 36 additions & 0 deletions samples/snippets/get_custom_job_sample.py
@@ -0,0 +1,36 @@
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# [START aiplatform_get_custom_job_sample]
from google.cloud import aiplatform


def get_custom_job_sample(
project: str,
custom_job_id: str,
location: str = "us-central1",
api_endpoint: str = "us-central1-aiplatform.googleapis.com",
):
client_options = {"api_endpoint": api_endpoint}
# Initialize client that will be used to create and send requests.
# This client only needs to be created once, and can be reused for multiple requests.
client = aiplatform.gapic.JobServiceClient(client_options=client_options)
name = client.custom_job_path(
project=project, location=location, custom_job=custom_job_id
)
response = client.get_custom_job(name=name)
print("response:", response)


# [END aiplatform_get_custom_job_sample]
30 changes: 30 additions & 0 deletions samples/snippets/get_custom_job_sample_test.py
@@ -0,0 +1,30 @@
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import pytest
import os

import get_custom_job_sample

PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT")
CUSTOM_JOB_ID = "7980906305281851392"
KNOWN_CUSTOM_JOB = f"/locations/us-central1/customJobs/{CUSTOM_JOB_ID}"


def test_ucaip_generated_get_custom_job_sample(capsys):
get_custom_job_sample.get_custom_job_sample(
project=PROJECT_ID, custom_job_id=CUSTOM_JOB_ID
)
out, _ = capsys.readouterr()
assert KNOWN_CUSTOM_JOB in out
38 changes: 38 additions & 0 deletions samples/snippets/get_hyperparameter_tuning_job_sample.py
@@ -0,0 +1,38 @@
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# [START aiplatform_get_hyperparameter_tuning_job_sample]
from google.cloud import aiplatform


def get_hyperparameter_tuning_job_sample(
project: str,
hyperparameter_tuning_job_id: str,
location: str = "us-central1",
api_endpoint: str = "us-central1-aiplatform.googleapis.com",
):
client_options = {"api_endpoint": api_endpoint}
# Initialize client that will be used to create and send requests.
# This client only needs to be created once, and can be reused for multiple requests.
client = aiplatform.gapic.JobServiceClient(client_options=client_options)
name = client.hyperparameter_tuning_job_path(
project=project,
location=location,
hyperparameter_tuning_job=hyperparameter_tuning_job_id,
)
response = client.get_hyperparameter_tuning_job(name=name)
print("response:", response)


# [END aiplatform_get_hyperparameter_tuning_job_sample]
32 changes: 32 additions & 0 deletions samples/snippets/get_hyperparameter_tuning_job_sample_test.py
@@ -0,0 +1,32 @@
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import pytest
import os

import get_hyperparameter_tuning_job_sample

PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT")
HYPERPARAMETER_TUNING_JOB_ID = "2216298782247616512"
KNOWN_HYPERPARAMETER_TUNING_JOB = (
f"/locations/us-central1/hyperparameterTuningJobs/{HYPERPARAMETER_TUNING_JOB_ID}"
)


def test_ucaip_generated_get_hyperparameter_tuning_job_sample(capsys):
get_hyperparameter_tuning_job_sample.get_hyperparameter_tuning_job_sample(
project=PROJECT_ID, hyperparameter_tuning_job_id=HYPERPARAMETER_TUNING_JOB_ID
)
out, _ = capsys.readouterr()
assert KNOWN_HYPERPARAMETER_TUNING_JOB in out

0 comments on commit 26da7a7

Please sign in to comment.