Skip to content

Commit 111a747

Browse files
vertex-sdk-botcopybara-github
authored andcommitted
docs(samples): add sample for experiment run state update.
PiperOrigin-RevId: 521002287
1 parent 91d8459 commit 111a747

File tree

4 files changed

+75
-0
lines changed

4 files changed

+75
-0
lines changed

samples/model-builder/conftest.py

+7
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,13 @@ def mock_register_model(mock_experiment_model, mock_model):
10341034
yield mock_register_model
10351035

10361036

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+
10371044
"""
10381045
----------------------------------------------------------------------------
10391046
Model Versioning Fixtures
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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)

samples/model-builder/test_constants.py

+1
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@
279279
METADATA = {}
280280

281281
EXPERIMENT_RUN_NAME = "my-run"
282+
EXPERIMENT_RUN_STATE = aiplatform.gapic.Execution.State.RUNNING
282283

283284
METRICS = {"accuracy": 0.1}
284285
PARAMS = {"learning_rate": 0.1}

0 commit comments

Comments
 (0)