GeezerVison is showing github.com — docs(samples): add sample for experiment run state update. · googleapis/python-aiplatform@111a747
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 clipboardExpand all lines: samples/model-builder/conftest.py +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1034,6 +1034,13 @@ def mock_register_model(mock_experiment_model, mock_model): | 1034 | 1034 | yield mock_register_model | 1035 | 1035 |
| 1036 | 1036 |
| | 1037 | +@pytest.fixture | | 1038 | +def mock_update_run_state(mock_experiment_run): | | 1039 | + with patch.object(mock_experiment_run, "update_state") as mock_update_run_state: | | 1040 | + mock_update_run_state.return_value = None | | 1041 | + yield mock_update_run_state | | 1042 | + | | 1043 | + | 1037 | 1044 | """ | 1038 | 1045 | ---------------------------------------------------------------------------- | 1039 | 1046 | Model Versioning Fixtures | |
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 2023 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 | +from typing import Union | | 16 | + | | 17 | +from google.cloud import aiplatform | | 18 | + | | 19 | + | | 20 | +# [START aiplatform_sdk_update_experiment_run_state_sample] | | 21 | +def update_experiment_run_state_sample( | | 22 | + run_name: str, | | 23 | + experiment: Union[str, aiplatform.Experiment], | | 24 | + project: str, | | 25 | + location: str, | | 26 | + state: aiplatform.gapic.Execution.State, | | 27 | +) -> None: | | 28 | + experiment_run = aiplatform.ExperimentRun( | | 29 | + run_name=run_name, | | 30 | + experiment=experiment, | | 31 | + project=project, | | 32 | + location=location, | | 33 | + ) | | 34 | + | | 35 | + experiment_run.update_state(state) | | 36 | + | | 37 | + | | 38 | +# [END aiplatform_sdk_update_experiment_run_state_sample] |
Collapse file Copy file name to clipboard +29Lines changed: 29 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +# you may not use this file except in compliance with the License. | | 2 | +# You may obtain a copy of the License at | | 3 | +# | | 4 | +# https://www.apache.org/licenses/LICENSE-2.0 | | 5 | +# | | 6 | +# Unless required by applicable law or agreed to in writing, software | | 7 | +# distributed under the License is distributed on an "AS IS" BASIS, | | 8 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | | 9 | +# See the License for the specific language governing permissions and | | 10 | +# limitations under the License. | | 11 | + | | 12 | +import pytest | | 13 | + | | 14 | +from experiment_tracking import update_experiment_run_state_sample | | 15 | +import test_constants as constants | | 16 | + | | 17 | + | | 18 | +@pytest.mark.usefixtures("mock_get_run") | | 19 | +def test_update_experiment_run_state_sample(mock_update_run_state): | | 20 | + | | 21 | + update_experiment_run_state_sample.update_experiment_run_state_sample( | | 22 | + run_name=constants.EXPERIMENT_RUN_NAME, | | 23 | + experiment=constants.EXPERIMENT_NAME, | | 24 | + project=constants.PROJECT, | | 25 | + location=constants.LOCATION, | | 26 | + state=constants.EXPERIMENT_RUN_STATE, | | 27 | + ) | | 28 | + | | 29 | + mock_update_run_state.assert_called_once_with(constants.EXPERIMENT_RUN_STATE) |
Collapse file Copy file name to clipboardExpand all lines: samples/model-builder/test_constants.py +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 279 | 279 | METADATA = {} | 280 | 280 |
| 281 | 281 | EXPERIMENT_RUN_NAME = "my-run" | | 282 | +EXPERIMENT_RUN_STATE = aiplatform.gapic.Execution.State.RUNNING | 282 | 283 |
| 283 | 284 | METRICS = {"accuracy": 0.1} | 284 | 285 | PARAMS = {"learning_rate": 0.1} | |
|