Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add get_custom_job and get_hyperparameter_tuning_job samples (#68)
* feat: add get_custom_job and get_hyperparameter_tuning_job samples
- Loading branch information
Showing
4 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
32
samples/snippets/get_hyperparameter_tuning_job_sample_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |