GeezerVison is showing github.com — feat: add get_custom_job and get_hyperparameter_tuning_job samples (#68) · googleapis/python-aiplatform@26da7a7
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboard +36Lines changed: 36 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +# Copyright 2020 Google LLC | | 2 | +# | | 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); | | 4 | +# you may not use this file except in compliance with the License. | | 5 | +# You may obtain a copy of the License at | | 6 | +# | | 7 | +# https://www.apache.org/licenses/LICENSE-2.0 | | 8 | +# | | 9 | +# Unless required by applicable law or agreed to in writing, software | | 10 | +# distributed under the License is distributed on an "AS IS" BASIS, | | 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | | 12 | +# See the License for the specific language governing permissions and | | 13 | +# limitations under the License. | | 14 | + | | 15 | +# [START aiplatform_get_custom_job_sample] | | 16 | +from google.cloud import aiplatform | | 17 | + | | 18 | + | | 19 | +def get_custom_job_sample( | | 20 | + project: str, | | 21 | + custom_job_id: str, | | 22 | + location: str = "us-central1", | | 23 | + api_endpoint: str = "us-central1-aiplatform.googleapis.com", | | 24 | +): | | 25 | + client_options = {"api_endpoint": api_endpoint} | | 26 | + # Initialize client that will be used to create and send requests. | | 27 | + # This client only needs to be created once, and can be reused for multiple requests. | | 28 | + client = aiplatform.gapic.JobServiceClient(client_options=client_options) | | 29 | + name = client.custom_job_path( | | 30 | + project=project, location=location, custom_job=custom_job_id | | 31 | + ) | | 32 | + response = client.get_custom_job(name=name) | | 33 | + print("response:", response) | | 34 | + | | 35 | + | | 36 | +# [END aiplatform_get_custom_job_sample] |
Collapse file Copy file name to clipboard +30Lines changed: 30 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +# Copyright 2020 Google LLC | | 2 | +# | | 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); | | 4 | +# you may not use this file except in compliance with the License. | | 5 | +# You may obtain a copy of the License at | | 6 | +# | | 7 | +# https://www.apache.org/licenses/LICENSE-2.0 | | 8 | +# | | 9 | +# Unless required by applicable law or agreed to in writing, software | | 10 | +# distributed under the License is distributed on an "AS IS" BASIS, | | 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | | 12 | +# See the License for the specific language governing permissions and | | 13 | +# limitations under the License. | | 14 | + | | 15 | +import pytest | | 16 | +import os | | 17 | + | | 18 | +import get_custom_job_sample | | 19 | + | | 20 | +PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") | | 21 | +CUSTOM_JOB_ID = "7980906305281851392" | | 22 | +KNOWN_CUSTOM_JOB = f"/locations/us-central1/customJobs/{CUSTOM_JOB_ID}" | | 23 | + | | 24 | + | | 25 | +def test_ucaip_generated_get_custom_job_sample(capsys): | | 26 | + get_custom_job_sample.get_custom_job_sample( | | 27 | + project=PROJECT_ID, custom_job_id=CUSTOM_JOB_ID | | 28 | + ) | | 29 | + out, _ = capsys.readouterr() | | 30 | + assert KNOWN_CUSTOM_JOB in out |
Collapse file Copy file name to clipboard +38Lines changed: 38 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +# Copyright 2020 Google LLC | | 2 | +# | | 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); | | 4 | +# you may not use this file except in compliance with the License. | | 5 | +# You may obtain a copy of the License at | | 6 | +# | | 7 | +# https://www.apache.org/licenses/LICENSE-2.0 | | 8 | +# | | 9 | +# Unless required by applicable law or agreed to in writing, software | | 10 | +# distributed under the License is distributed on an "AS IS" BASIS, | | 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | | 12 | +# See the License for the specific language governing permissions and | | 13 | +# limitations under the License. | | 14 | + | | 15 | +# [START aiplatform_get_hyperparameter_tuning_job_sample] | | 16 | +from google.cloud import aiplatform | | 17 | + | | 18 | + | | 19 | +def get_hyperparameter_tuning_job_sample( | | 20 | + project: str, | | 21 | + hyperparameter_tuning_job_id: str, | | 22 | + location: str = "us-central1", | | 23 | + api_endpoint: str = "us-central1-aiplatform.googleapis.com", | | 24 | +): | | 25 | + client_options = {"api_endpoint": api_endpoint} | | 26 | + # Initialize client that will be used to create and send requests. | | 27 | + # This client only needs to be created once, and can be reused for multiple requests. | | 28 | + client = aiplatform.gapic.JobServiceClient(client_options=client_options) | | 29 | + name = client.hyperparameter_tuning_job_path( | | 30 | + project=project, | | 31 | + location=location, | | 32 | + hyperparameter_tuning_job=hyperparameter_tuning_job_id, | | 33 | + ) | | 34 | + response = client.get_hyperparameter_tuning_job(name=name) | | 35 | + print("response:", response) | | 36 | + | | 37 | + | | 38 | +# [END aiplatform_get_hyperparameter_tuning_job_sample] |
Collapse file Copy file name to clipboard +32Lines changed: 32 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +# Copyright 2020 Google LLC | | 2 | +# | | 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); | | 4 | +# you may not use this file except in compliance with the License. | | 5 | +# You may obtain a copy of the License at | | 6 | +# | | 7 | +# https://www.apache.org/licenses/LICENSE-2.0 | | 8 | +# | | 9 | +# Unless required by applicable law or agreed to in writing, software | | 10 | +# distributed under the License is distributed on an "AS IS" BASIS, | | 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | | 12 | +# See the License for the specific language governing permissions and | | 13 | +# limitations under the License. | | 14 | + | | 15 | +import pytest | | 16 | +import os | | 17 | + | | 18 | +import get_hyperparameter_tuning_job_sample | | 19 | + | | 20 | +PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") | | 21 | +HYPERPARAMETER_TUNING_JOB_ID = "2216298782247616512" | | 22 | +KNOWN_HYPERPARAMETER_TUNING_JOB = ( | | 23 | + f"/locations/us-central1/hyperparameterTuningJobs/{HYPERPARAMETER_TUNING_JOB_ID}" | | 24 | +) | | 25 | + | | 26 | + | | 27 | +def test_ucaip_generated_get_hyperparameter_tuning_job_sample(capsys): | | 28 | + get_hyperparameter_tuning_job_sample.get_hyperparameter_tuning_job_sample( | | 29 | + project=PROJECT_ID, hyperparameter_tuning_job_id=HYPERPARAMETER_TUNING_JOB_ID | | 30 | + ) | | 31 | + out, _ = capsys.readouterr() | | 32 | + assert KNOWN_HYPERPARAMETER_TUNING_JOB in out |
|