hc99 commited on
Commit
3193ef1
·
verified ·
1 Parent(s): 1856027

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. testbed/googleapis__python-aiplatform/samples/AUTHORING_GUIDE.md +1 -0
  2. testbed/googleapis__python-aiplatform/samples/CONTRIBUTING.md +1 -0
  3. testbed/googleapis__python-aiplatform/samples/model-builder/automl_image_classification_training_job_sample.py +57 -0
  4. testbed/googleapis__python-aiplatform/samples/model-builder/automl_image_classification_training_job_sample_test.py +56 -0
  5. testbed/googleapis__python-aiplatform/samples/model-builder/batch_create_features_sample.py +46 -0
  6. testbed/googleapis__python-aiplatform/samples/model-builder/batch_create_features_sample_test.py +42 -0
  7. testbed/googleapis__python-aiplatform/samples/model-builder/batch_serve_features_to_bq_sample.py +46 -0
  8. testbed/googleapis__python-aiplatform/samples/model-builder/batch_serve_features_to_bq_sample_test.py +45 -0
  9. testbed/googleapis__python-aiplatform/samples/model-builder/cancel_hyperparameter_tuning_job_sample.py +34 -0
  10. testbed/googleapis__python-aiplatform/samples/model-builder/cancel_hyperparameter_tuning_job_sample_test.py +40 -0
  11. testbed/googleapis__python-aiplatform/samples/model-builder/conftest.py +1471 -0
  12. testbed/googleapis__python-aiplatform/samples/model-builder/create_and_import_dataset_image_sample.py +50 -0
  13. testbed/googleapis__python-aiplatform/samples/model-builder/create_and_import_dataset_image_sample_test.py +41 -0
  14. testbed/googleapis__python-aiplatform/samples/model-builder/create_and_import_dataset_tabular_bigquery_sample.py +40 -0
  15. testbed/googleapis__python-aiplatform/samples/model-builder/create_and_import_dataset_tabular_bigquery_sample_test.py +37 -0
  16. testbed/googleapis__python-aiplatform/samples/model-builder/create_and_import_dataset_tabular_gcs_sample.py +41 -0
  17. testbed/googleapis__python-aiplatform/samples/model-builder/create_and_import_dataset_tabular_gcs_sample_test.py +37 -0
  18. testbed/googleapis__python-aiplatform/samples/model-builder/create_and_import_dataset_text_sample.py +44 -0
  19. testbed/googleapis__python-aiplatform/samples/model-builder/create_and_import_dataset_text_sample_test.py +39 -0
  20. testbed/googleapis__python-aiplatform/samples/model-builder/create_and_import_dataset_time_series_bigquery_sample.py +40 -0
  21. testbed/googleapis__python-aiplatform/samples/model-builder/create_and_import_dataset_time_series_bigquery_sample_test.py +37 -0
  22. testbed/googleapis__python-aiplatform/samples/model-builder/create_and_import_dataset_time_series_gcs_sample.py +41 -0
  23. testbed/googleapis__python-aiplatform/samples/model-builder/create_and_import_dataset_time_series_gcs_sample_test.py +37 -0
  24. testbed/googleapis__python-aiplatform/samples/model-builder/create_and_import_dataset_video_sample.py +44 -0
  25. testbed/googleapis__python-aiplatform/samples/model-builder/create_and_import_dataset_video_sample_test.py +41 -0
  26. testbed/googleapis__python-aiplatform/samples/model-builder/create_batch_prediction_job_bigquery_sample.py +47 -0
  27. testbed/googleapis__python-aiplatform/samples/model-builder/create_batch_prediction_job_bigquery_sample_test.py +42 -0
  28. testbed/googleapis__python-aiplatform/samples/model-builder/create_batch_prediction_job_dedicated_resources_bigquery_sample.py +59 -0
  29. testbed/googleapis__python-aiplatform/samples/model-builder/create_batch_prediction_job_dedicated_resources_sample.py +61 -0
  30. testbed/googleapis__python-aiplatform/samples/model-builder/create_batch_prediction_job_dedicated_resources_sample_bigquery_test.py +55 -0
  31. testbed/googleapis__python-aiplatform/samples/model-builder/create_batch_prediction_job_dedicated_resources_sample_test.py +57 -0
  32. testbed/googleapis__python-aiplatform/samples/model-builder/create_batch_prediction_job_sample.py +55 -0
  33. testbed/googleapis__python-aiplatform/samples/model-builder/create_batch_prediction_job_sample_test.py +42 -0
  34. testbed/googleapis__python-aiplatform/samples/model-builder/create_custom_job_on_persistent_resource_sample.py +57 -0
  35. testbed/googleapis__python-aiplatform/samples/model-builder/create_custom_job_on_persistent_resource_sample_test.py +52 -0
  36. testbed/googleapis__python-aiplatform/samples/model-builder/create_custom_job_psci_sample.py +65 -0
  37. testbed/googleapis__python-aiplatform/samples/model-builder/create_custom_job_psci_sample_test.py +77 -0
  38. testbed/googleapis__python-aiplatform/samples/model-builder/create_custom_job_with_experiment_autologging_sample.py +48 -0
  39. testbed/googleapis__python-aiplatform/samples/model-builder/create_custom_job_with_experiment_autologging_sample_test.py +55 -0
  40. testbed/googleapis__python-aiplatform/samples/model-builder/create_custom_job_with_experiment_sample.py +52 -0
  41. testbed/googleapis__python-aiplatform/samples/model-builder/create_custom_job_with_experiment_sample_test.py +54 -0
  42. testbed/googleapis__python-aiplatform/samples/model-builder/create_endpoint_sample.py +37 -0
  43. testbed/googleapis__python-aiplatform/samples/model-builder/create_endpoint_sample_test.py +36 -0
  44. testbed/googleapis__python-aiplatform/samples/model-builder/create_entity_type_sample.py +38 -0
  45. testbed/googleapis__python-aiplatform/samples/model-builder/create_entity_type_sample_test.py +35 -0
  46. testbed/googleapis__python-aiplatform/samples/model-builder/create_feature_sample.py +43 -0
  47. testbed/googleapis__python-aiplatform/samples/model-builder/create_feature_sample_test.py +39 -0
  48. testbed/googleapis__python-aiplatform/samples/model-builder/create_featurestore_sample.py +41 -0
  49. testbed/googleapis__python-aiplatform/samples/model-builder/create_featurestore_sample_test.py +37 -0
  50. testbed/googleapis__python-aiplatform/samples/model-builder/create_hyperparameter_tuning_job_sample.py +74 -0
testbed/googleapis__python-aiplatform/samples/AUTHORING_GUIDE.md ADDED
@@ -0,0 +1 @@
 
 
1
+ See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/AUTHORING_GUIDE.md
testbed/googleapis__python-aiplatform/samples/CONTRIBUTING.md ADDED
@@ -0,0 +1 @@
 
 
1
+ See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/CONTRIBUTING.md
testbed/googleapis__python-aiplatform/samples/model-builder/automl_image_classification_training_job_sample.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2021 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
+
16
+ from google.cloud import aiplatform
17
+
18
+
19
+ # [START aiplatform_sdk_automl_image_classification_training_job_sample]
20
+ def automl_image_classification_training_job_sample(
21
+ project: str,
22
+ location: str,
23
+ dataset_id: str,
24
+ display_name: str,
25
+ ):
26
+ aiplatform.init(project=project, location=location)
27
+
28
+ dataset = aiplatform.ImageDataset(dataset_id)
29
+
30
+ job = aiplatform.AutoMLImageTrainingJob(
31
+ display_name=display_name,
32
+ prediction_type="classification",
33
+ multi_label=False,
34
+ model_type="CLOUD",
35
+ base_model=None,
36
+ )
37
+
38
+ model = job.run(
39
+ dataset=dataset,
40
+ model_display_name=display_name,
41
+ training_fraction_split=0.6,
42
+ validation_fraction_split=0.2,
43
+ test_fraction_split=0.2,
44
+ budget_milli_node_hours=8000,
45
+ disable_early_stopping=False,
46
+ )
47
+
48
+ print(model.display_name)
49
+ print(model.name)
50
+ print(model.resource_name)
51
+ print(model.description)
52
+ print(model.uri)
53
+
54
+ return model
55
+
56
+
57
+ # [END aiplatform_sdk_automl_image_classification_training_job_sample]
testbed/googleapis__python-aiplatform/samples/model-builder/automl_image_classification_training_job_sample_test.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2021 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
+
16
+ import automl_image_classification_training_job_sample
17
+ import test_constants as constants
18
+
19
+
20
+ def test_automl_image_classification_training_job_sample(
21
+ mock_sdk_init,
22
+ mock_image_dataset,
23
+ mock_get_image_dataset,
24
+ mock_get_automl_image_training_job,
25
+ mock_run_automl_image_training_job,
26
+ ):
27
+ automl_image_classification_training_job_sample.automl_image_classification_training_job_sample(
28
+ project=constants.PROJECT,
29
+ location=constants.LOCATION,
30
+ dataset_id=constants.DATASET_NAME,
31
+ display_name=constants.DISPLAY_NAME,
32
+ )
33
+
34
+ mock_get_image_dataset.assert_called_once_with(constants.DATASET_NAME)
35
+
36
+ mock_sdk_init.assert_called_once_with(
37
+ project=constants.PROJECT, location=constants.LOCATION
38
+ )
39
+
40
+ mock_get_automl_image_training_job.assert_called_once_with(
41
+ display_name=constants.DISPLAY_NAME,
42
+ base_model=None,
43
+ model_type="CLOUD",
44
+ multi_label=False,
45
+ prediction_type="classification",
46
+ )
47
+
48
+ mock_run_automl_image_training_job.assert_called_once_with(
49
+ budget_milli_node_hours=8000,
50
+ disable_early_stopping=False,
51
+ test_fraction_split=0.2,
52
+ training_fraction_split=0.6,
53
+ validation_fraction_split=0.2,
54
+ model_display_name=constants.DISPLAY_NAME,
55
+ dataset=mock_image_dataset,
56
+ )
testbed/googleapis__python-aiplatform/samples/model-builder/batch_create_features_sample.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2022 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
+
16
+ # [START aiplatform_sdk_batch_create_features_sample]
17
+ from google.cloud import aiplatform
18
+
19
+
20
+ def batch_create_features_sample(
21
+ project: str,
22
+ location: str,
23
+ entity_type_id: str,
24
+ featurestore_id: str,
25
+ sync: bool = True,
26
+ ):
27
+
28
+ aiplatform.init(project=project, location=location)
29
+
30
+ my_entity_type = aiplatform.featurestore.EntityType(
31
+ entity_type_name=entity_type_id, featurestore_id=featurestore_id
32
+ )
33
+
34
+ FEATURE_CONFIGS = {
35
+ "age": {"value_type": "INT64", "description": "User age"},
36
+ "gender": {"value_type": "STRING", "description": "User gender"},
37
+ "liked_genres": {
38
+ "value_type": "STRING_ARRAY",
39
+ "description": "An array of genres this user liked",
40
+ },
41
+ }
42
+
43
+ my_entity_type.batch_create_features(feature_configs=FEATURE_CONFIGS, sync=sync)
44
+
45
+
46
+ # [END aiplatform_sdk_batch_create_features_sample]
testbed/googleapis__python-aiplatform/samples/model-builder/batch_create_features_sample_test.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2022 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 batch_create_features_sample
16
+ import test_constants as constants
17
+
18
+
19
+ def test_batch_create_features_sample(
20
+ mock_sdk_init, mock_get_entity_type, mock_batch_create_features
21
+ ):
22
+
23
+ batch_create_features_sample.batch_create_features_sample(
24
+ project=constants.PROJECT,
25
+ location=constants.LOCATION,
26
+ entity_type_id=constants.ENTITY_TYPE_ID,
27
+ featurestore_id=constants.FEATURESTORE_ID,
28
+ sync=constants.SYNC,
29
+ )
30
+
31
+ mock_sdk_init.assert_called_once_with(
32
+ project=constants.PROJECT, location=constants.LOCATION
33
+ )
34
+
35
+ mock_get_entity_type.assert_called_once_with(
36
+ entity_type_name=constants.ENTITY_TYPE_ID,
37
+ featurestore_id=constants.FEATURESTORE_ID,
38
+ )
39
+
40
+ mock_batch_create_features.assert_called_once_with(
41
+ feature_configs=constants.FEATURE_CONFIGS, sync=constants.SYNC
42
+ )
testbed/googleapis__python-aiplatform/samples/model-builder/batch_serve_features_to_bq_sample.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2022 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
+
16
+ # [START aiplatform_sdk_batch_serve_features_to_bq_sample]
17
+ from google.cloud import aiplatform
18
+
19
+
20
+ def batch_serve_features_to_bq_sample(
21
+ project: str,
22
+ location: str,
23
+ featurestore_name: str,
24
+ bq_destination_output_uri: str,
25
+ read_instances_uri: str,
26
+ sync: bool = True,
27
+ ):
28
+
29
+ aiplatform.init(project=project, location=location)
30
+
31
+ fs = aiplatform.featurestore.Featurestore(featurestore_name=featurestore_name)
32
+
33
+ SERVING_FEATURE_IDS = {
34
+ "users": ["age", "gender", "liked_genres"],
35
+ "movies": ["title", "average_rating", "genres"],
36
+ }
37
+
38
+ fs.batch_serve_to_bq(
39
+ bq_destination_output_uri=bq_destination_output_uri,
40
+ serving_feature_ids=SERVING_FEATURE_IDS,
41
+ read_instances_uri=read_instances_uri,
42
+ sync=sync,
43
+ )
44
+
45
+
46
+ # [END aiplatform_sdk_batch_serve_features_to_bq_sample]
testbed/googleapis__python-aiplatform/samples/model-builder/batch_serve_features_to_bq_sample_test.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2022 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 batch_serve_features_to_bq_sample
16
+ import test_constants as constants
17
+
18
+
19
+ def test_batch_serve_features_to_bq_sample(
20
+ mock_sdk_init, mock_get_featurestore, mock_batch_serve_to_bq
21
+ ):
22
+
23
+ batch_serve_features_to_bq_sample.batch_serve_features_to_bq_sample(
24
+ project=constants.PROJECT,
25
+ location=constants.LOCATION,
26
+ featurestore_name=constants.FEATURESTORE_NAME,
27
+ bq_destination_output_uri=constants.BQ_DESTINATION_OUTPUT_URI,
28
+ read_instances_uri=constants.INPUT_CSV_FILE,
29
+ sync=constants.SYNC,
30
+ )
31
+
32
+ mock_sdk_init.assert_called_once_with(
33
+ project=constants.PROJECT, location=constants.LOCATION
34
+ )
35
+
36
+ mock_get_featurestore.assert_called_once_with(
37
+ featurestore_name=constants.FEATURESTORE_NAME
38
+ )
39
+
40
+ mock_batch_serve_to_bq.assert_called_once_with(
41
+ bq_destination_output_uri=constants.BQ_DESTINATION_OUTPUT_URI,
42
+ serving_feature_ids=constants.SERVING_FEATURE_IDS,
43
+ read_instances_uri=constants.INPUT_CSV_FILE,
44
+ sync=constants.SYNC,
45
+ )
testbed/googleapis__python-aiplatform/samples/model-builder/cancel_hyperparameter_tuning_job_sample.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2022 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_sdk_cancel_hyperparameter_tuning_job_sample]
16
+ from google.cloud import aiplatform
17
+
18
+
19
+ def cancel_hyperparameter_tuning_job_sample(
20
+ project: str,
21
+ hyperparameter_tuning_job_id: str,
22
+ location: str = "us-central1",
23
+ ):
24
+
25
+ aiplatform.init(project=project, location=location)
26
+
27
+ hpt_job = aiplatform.HyperparameterTuningJob.get(
28
+ resource_name=hyperparameter_tuning_job_id,
29
+ )
30
+
31
+ hpt_job.cancel()
32
+
33
+
34
+ # [END aiplatform_sdk_cancel_hyperparameter_tuning_job_sample]
testbed/googleapis__python-aiplatform/samples/model-builder/cancel_hyperparameter_tuning_job_sample_test.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2022 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 cancel_hyperparameter_tuning_job_sample
16
+ import test_constants as constants
17
+
18
+
19
+ def test_cancel_hyperparameter_tuning_job_sample(
20
+ mock_sdk_init,
21
+ mock_hyperparameter_tuning_job_get,
22
+ mock_hyperparameter_tuning_job_cancel,
23
+ ):
24
+
25
+ cancel_hyperparameter_tuning_job_sample.cancel_hyperparameter_tuning_job_sample(
26
+ project=constants.PROJECT,
27
+ location=constants.LOCATION,
28
+ hyperparameter_tuning_job_id=constants.HYPERPARAMETER_TUNING_JOB_ID,
29
+ )
30
+
31
+ mock_sdk_init.assert_called_once_with(
32
+ project=constants.PROJECT,
33
+ location=constants.LOCATION,
34
+ )
35
+
36
+ mock_hyperparameter_tuning_job_get.assert_called_once_with(
37
+ resource_name=constants.HYPERPARAMETER_TUNING_JOB_ID,
38
+ )
39
+
40
+ mock_hyperparameter_tuning_job_cancel.assert_called_once_with()
testbed/googleapis__python-aiplatform/samples/model-builder/conftest.py ADDED
@@ -0,0 +1,1471 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2022 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 unittest.mock import MagicMock
16
+ from unittest.mock import patch
17
+
18
+ from google.cloud import aiplatform
19
+ from google.cloud import aiplatform_v1beta1
20
+ import vertexai
21
+ from vertexai.resources import preview as preview_resources
22
+ import pytest
23
+
24
+
25
+ @pytest.fixture
26
+ def mock_sdk_init():
27
+ with patch.object(aiplatform, "init") as mock:
28
+ yield mock
29
+
30
+
31
+ @pytest.fixture
32
+ def mock_vertexai_init():
33
+ with patch.object(vertexai, "init") as mock:
34
+ yield mock
35
+
36
+
37
+ """
38
+ ----------------------------------------------------------------------------
39
+ Dataset Fixtures
40
+ ----------------------------------------------------------------------------
41
+ """
42
+
43
+ """Dataset objects returned by SomeDataset(), create(), import_data(), etc. """
44
+
45
+
46
+ @pytest.fixture
47
+ def mock_image_dataset():
48
+ mock = MagicMock(aiplatform.datasets.ImageDataset)
49
+ yield mock
50
+
51
+
52
+ @pytest.fixture
53
+ def mock_tabular_dataset():
54
+ mock = MagicMock(aiplatform.datasets.TabularDataset)
55
+ yield mock
56
+
57
+
58
+ @pytest.fixture
59
+ def mock_time_series_dataset():
60
+ mock = MagicMock(aiplatform.datasets.TimeSeriesDataset)
61
+ yield mock
62
+
63
+
64
+ @pytest.fixture
65
+ def mock_text_dataset():
66
+ mock = MagicMock(aiplatform.datasets.TextDataset)
67
+ yield mock
68
+
69
+
70
+ @pytest.fixture
71
+ def mock_video_dataset():
72
+ mock = MagicMock(aiplatform.datasets.VideoDataset)
73
+ yield mock
74
+
75
+
76
+ """Mocks for getting an existing Dataset, i.e. ds = aiplatform.ImageDataset(...) """
77
+
78
+
79
+ @pytest.fixture
80
+ def mock_get_image_dataset(mock_image_dataset):
81
+ with patch.object(aiplatform, "ImageDataset") as mock_get_image_dataset:
82
+ mock_get_image_dataset.return_value = mock_image_dataset
83
+ yield mock_get_image_dataset
84
+
85
+
86
+ @pytest.fixture
87
+ def mock_get_tabular_dataset(mock_tabular_dataset):
88
+ with patch.object(aiplatform, "TabularDataset") as mock_get_tabular_dataset:
89
+ mock_get_tabular_dataset.return_value = mock_tabular_dataset
90
+ yield mock_get_tabular_dataset
91
+
92
+
93
+ @pytest.fixture
94
+ def mock_get_time_series_dataset(mock_time_series_dataset):
95
+ with patch.object(aiplatform, "TimeSeriesDataset") as mock_get_time_series_dataset:
96
+ mock_get_time_series_dataset.return_value = mock_time_series_dataset
97
+ yield mock_get_time_series_dataset
98
+
99
+
100
+ @pytest.fixture
101
+ def mock_get_text_dataset(mock_text_dataset):
102
+ with patch.object(aiplatform, "TextDataset") as mock_get_text_dataset:
103
+ mock_get_text_dataset.return_value = mock_text_dataset
104
+ yield mock_get_text_dataset
105
+
106
+
107
+ @pytest.fixture
108
+ def mock_get_video_dataset(mock_video_dataset):
109
+ with patch.object(aiplatform, "VideoDataset") as mock_get_video_dataset:
110
+ mock_get_video_dataset.return_value = mock_video_dataset
111
+ yield mock_get_video_dataset
112
+
113
+
114
+ """Mocks for creating a new Dataset, i.e. aiplatform.ImageDataset.create(...) """
115
+
116
+
117
+ @pytest.fixture
118
+ def mock_create_image_dataset(mock_image_dataset):
119
+ with patch.object(aiplatform.ImageDataset, "create") as mock_create_image_dataset:
120
+ mock_create_image_dataset.return_value = mock_image_dataset
121
+ yield mock_create_image_dataset
122
+
123
+
124
+ @pytest.fixture
125
+ def mock_create_tabular_dataset(mock_tabular_dataset):
126
+ with patch.object(
127
+ aiplatform.TabularDataset, "create"
128
+ ) as mock_create_tabular_dataset:
129
+ mock_create_tabular_dataset.return_value = mock_tabular_dataset
130
+ yield mock_create_tabular_dataset
131
+
132
+
133
+ @pytest.fixture
134
+ def mock_create_time_series_dataset(mock_time_series_dataset):
135
+ with patch.object(
136
+ aiplatform.TimeSeriesDataset, "create"
137
+ ) as mock_create_time_series_dataset:
138
+ mock_create_time_series_dataset.return_value = mock_time_series_dataset
139
+ yield mock_create_time_series_dataset
140
+
141
+
142
+ @pytest.fixture
143
+ def mock_create_text_dataset(mock_text_dataset):
144
+ with patch.object(aiplatform.TextDataset, "create") as mock_create_text_dataset:
145
+ mock_create_text_dataset.return_value = mock_text_dataset
146
+ yield mock_create_text_dataset
147
+
148
+
149
+ @pytest.fixture
150
+ def mock_create_video_dataset(mock_video_dataset):
151
+ with patch.object(aiplatform.VideoDataset, "create") as mock_create_video_dataset:
152
+ mock_create_video_dataset.return_value = mock_video_dataset
153
+ yield mock_create_video_dataset
154
+
155
+
156
+ """Mocks for SomeDataset.import_data() """
157
+
158
+
159
+ @pytest.fixture
160
+ def mock_import_image_dataset(mock_image_dataset):
161
+ with patch.object(mock_image_dataset, "import_data") as mock:
162
+ yield mock
163
+
164
+
165
+ @pytest.fixture
166
+ def mock_import_tabular_dataset(mock_tabular_dataset):
167
+ with patch.object(mock_tabular_dataset, "import_data") as mock:
168
+ yield mock
169
+
170
+
171
+ @pytest.fixture
172
+ def mock_import_text_dataset(mock_text_dataset):
173
+ with patch.object(mock_text_dataset, "import_data") as mock:
174
+ yield mock
175
+
176
+
177
+ @pytest.fixture
178
+ def mock_import_video_data(mock_video_dataset):
179
+ with patch.object(mock_video_dataset, "import_data") as mock:
180
+ yield mock
181
+
182
+
183
+ # ----------------------------------------------------------------------------
184
+ # TrainingJob Fixtures
185
+ # ----------------------------------------------------------------------------
186
+
187
+
188
+ @pytest.fixture
189
+ def mock_custom_training_job():
190
+ mock = MagicMock(aiplatform.training_jobs.CustomTrainingJob)
191
+ yield mock
192
+
193
+
194
+ @pytest.fixture
195
+ def mock_custom_container_training_job():
196
+ mock = MagicMock(aiplatform.training_jobs.CustomContainerTrainingJob)
197
+ yield mock
198
+
199
+
200
+ @pytest.fixture
201
+ def mock_custom_package_training_job():
202
+ mock = MagicMock(aiplatform.training_jobs.CustomPythonPackageTrainingJob)
203
+ yield mock
204
+
205
+
206
+ @pytest.fixture
207
+ def mock_image_training_job():
208
+ mock = MagicMock(aiplatform.training_jobs.AutoMLImageTrainingJob)
209
+ yield mock
210
+
211
+
212
+ @pytest.fixture
213
+ def mock_tabular_training_job():
214
+ mock = MagicMock(aiplatform.training_jobs.AutoMLTabularTrainingJob)
215
+ yield mock
216
+
217
+
218
+ @pytest.fixture
219
+ def mock_forecasting_training_job():
220
+ mock = MagicMock(aiplatform.training_jobs.AutoMLForecastingTrainingJob)
221
+ yield mock
222
+
223
+
224
+ @pytest.fixture
225
+ def mock_text_training_job():
226
+ mock = MagicMock(aiplatform.training_jobs.AutoMLTextTrainingJob)
227
+ yield mock
228
+
229
+
230
+ @pytest.fixture
231
+ def mock_video_training_job():
232
+ mock = MagicMock(aiplatform.training_jobs.AutoMLVideoTrainingJob)
233
+ yield mock
234
+
235
+
236
+ @pytest.fixture
237
+ def mock_get_automl_tabular_training_job(mock_tabular_training_job):
238
+ with patch.object(aiplatform, "AutoMLTabularTrainingJob") as mock:
239
+ mock.return_value = mock_tabular_training_job
240
+ yield mock
241
+
242
+
243
+ @pytest.fixture
244
+ def mock_run_automl_tabular_training_job(mock_tabular_training_job):
245
+ with patch.object(mock_tabular_training_job, "run") as mock:
246
+ yield mock
247
+
248
+
249
+ @pytest.fixture
250
+ def mock_get_automl_forecasting_training_job(mock_forecasting_training_job):
251
+ with patch.object(aiplatform, "AutoMLForecastingTrainingJob") as mock:
252
+ mock.return_value = mock_forecasting_training_job
253
+ yield mock
254
+
255
+
256
+ @pytest.fixture
257
+ def mock_run_automl_forecasting_training_job(mock_forecasting_training_job):
258
+ with patch.object(mock_forecasting_training_job, "run") as mock:
259
+ yield mock
260
+
261
+
262
+ @pytest.fixture
263
+ def mock_get_automl_forecasting_seq2seq_training_job(mock_forecasting_training_job):
264
+ with patch.object(
265
+ aiplatform, "SequenceToSequencePlusForecastingTrainingJob"
266
+ ) as mock:
267
+ mock.return_value = mock_forecasting_training_job
268
+ yield mock
269
+
270
+
271
+ @pytest.fixture
272
+ def mock_run_automl_forecasting_seq2seq_training_job(mock_forecasting_training_job):
273
+ with patch.object(mock_forecasting_training_job, "run") as mock:
274
+ yield mock
275
+
276
+
277
+ @pytest.fixture
278
+ def mock_get_automl_forecasting_tft_training_job(mock_forecasting_training_job):
279
+ with patch.object(
280
+ aiplatform, "TemporalFusionTransformerForecastingTrainingJob"
281
+ ) as mock:
282
+ mock.return_value = mock_forecasting_training_job
283
+ yield mock
284
+
285
+
286
+ @pytest.fixture
287
+ def mock_run_automl_forecasting_tft_training_job(mock_forecasting_training_job):
288
+ with patch.object(mock_forecasting_training_job, "run") as mock:
289
+ yield mock
290
+
291
+
292
+ @pytest.fixture
293
+ def mock_get_automl_forecasting_tide_training_job(mock_forecasting_training_job):
294
+ with patch.object(
295
+ aiplatform, "TimeSeriesDenseEncoderForecastingTrainingJob"
296
+ ) as mock:
297
+ mock.return_value = mock_forecasting_training_job
298
+ yield mock
299
+
300
+
301
+ @pytest.fixture
302
+ def mock_run_automl_forecasting_tide_training_job(mock_forecasting_training_job):
303
+ with patch.object(mock_forecasting_training_job, "run") as mock:
304
+ yield mock
305
+
306
+
307
+ @pytest.fixture
308
+ def mock_get_automl_image_training_job(mock_image_training_job):
309
+ with patch.object(aiplatform, "AutoMLImageTrainingJob") as mock:
310
+ mock.return_value = mock_image_training_job
311
+ yield mock
312
+
313
+
314
+ @pytest.fixture
315
+ def mock_run_automl_image_training_job(mock_image_training_job):
316
+ with patch.object(mock_image_training_job, "run") as mock:
317
+ yield mock
318
+
319
+
320
+ @pytest.fixture
321
+ def mock_get_automl_text_training_job(mock_text_training_job):
322
+ with patch.object(aiplatform, "AutoMLTextTrainingJob") as mock:
323
+ mock.return_value = mock_text_training_job
324
+ yield mock
325
+
326
+
327
+ @pytest.fixture
328
+ def mock_run_automl_text_training_job(mock_text_training_job):
329
+ with patch.object(mock_text_training_job, "run") as mock:
330
+ yield mock
331
+
332
+
333
+ @pytest.fixture
334
+ def mock_get_custom_training_job(mock_custom_training_job):
335
+ with patch.object(aiplatform, "CustomTrainingJob") as mock:
336
+ mock.return_value = mock_custom_training_job
337
+ yield mock
338
+
339
+
340
+ @pytest.fixture
341
+ def mock_get_custom_container_training_job(mock_custom_container_training_job):
342
+ with patch.object(aiplatform, "CustomContainerTrainingJob") as mock:
343
+ mock.return_value = mock_custom_container_training_job
344
+ yield mock
345
+
346
+
347
+ @pytest.fixture
348
+ def mock_get_custom_package_training_job(mock_custom_package_training_job):
349
+ with patch.object(aiplatform, "CustomPythonPackageTrainingJob") as mock:
350
+ mock.return_value = mock_custom_package_training_job
351
+ yield mock
352
+
353
+
354
+ @pytest.fixture
355
+ def mock_run_custom_training_job(mock_custom_training_job):
356
+ with patch.object(mock_custom_training_job, "run") as mock:
357
+ yield mock
358
+
359
+
360
+ @pytest.fixture
361
+ def mock_run_custom_container_training_job(mock_custom_container_training_job):
362
+ with patch.object(mock_custom_container_training_job, "run") as mock:
363
+ yield mock
364
+
365
+
366
+ @pytest.fixture
367
+ def mock_run_custom_package_training_job(mock_custom_package_training_job):
368
+ with patch.object(mock_custom_package_training_job, "run") as mock:
369
+ yield mock
370
+
371
+
372
+ @pytest.fixture
373
+ def mock_job_service_client_v1beta1():
374
+ mock = MagicMock(aiplatform_v1beta1.JobServiceClient)
375
+ yield mock
376
+
377
+
378
+ @pytest.fixture
379
+ def mock_get_job_service_client_v1beta1(mock_job_service_client_v1beta1):
380
+ with patch.object(aiplatform_v1beta1, "JobServiceClient") as mock:
381
+ mock.return_value = mock_job_service_client_v1beta1
382
+ yield mock
383
+
384
+
385
+ @pytest.fixture
386
+ def mock_create_custom_job_v1beta1(mock_job_service_client_v1beta1):
387
+ with patch.object(
388
+ mock_job_service_client_v1beta1, "create_custom_job"
389
+ ) as mock:
390
+ yield mock
391
+
392
+
393
+ @pytest.fixture
394
+ def mock_get_create_custom_job_request_v1beta1():
395
+ with patch.object(aiplatform_v1beta1, "CreateCustomJobRequest") as mock:
396
+ mock.return_value = mock_custom_job
397
+ yield mock
398
+
399
+
400
+ @pytest.fixture
401
+ def mock_custom_job():
402
+ mock = MagicMock(aiplatform.CustomJob)
403
+ yield mock
404
+
405
+
406
+ @pytest.fixture
407
+ def mock_get_custom_job(mock_custom_job):
408
+ with patch.object(aiplatform, "CustomJob") as mock:
409
+ mock.return_value = mock_custom_job
410
+ yield mock
411
+
412
+
413
+ @pytest.fixture
414
+ def mock_get_custom_job_from_local_script(mock_custom_job):
415
+ with patch.object(aiplatform.CustomJob, "from_local_script") as mock:
416
+ mock.return_value = mock_custom_job
417
+ yield mock
418
+
419
+
420
+ @pytest.fixture
421
+ def mock_run_custom_job(mock_custom_job):
422
+ with patch.object(mock_custom_job, "run") as mock:
423
+ yield mock
424
+
425
+
426
+ """
427
+ ----------------------------------------------------------------------------
428
+ Model Fixtures
429
+ ----------------------------------------------------------------------------
430
+ """
431
+
432
+
433
+ @pytest.fixture
434
+ def mock_model():
435
+ mock = MagicMock(aiplatform.models.Model)
436
+ yield mock
437
+
438
+
439
+ @pytest.fixture
440
+ def mock_init_model(mock_model):
441
+ with patch.object(aiplatform, "Model") as mock:
442
+ mock.return_value = mock_model
443
+ yield mock
444
+
445
+
446
+ @pytest.fixture
447
+ def mock_batch_predict_model(mock_model):
448
+ with patch.object(mock_model, "batch_predict") as mock:
449
+ yield mock
450
+
451
+
452
+ @pytest.fixture
453
+ def mock_upload_model(mock_model):
454
+ with patch.object(aiplatform.Model, "upload") as mock:
455
+ mock.return_value = mock_model
456
+ yield mock
457
+
458
+
459
+ @pytest.fixture
460
+ def mock_deploy_model(mock_model, mock_endpoint):
461
+ with patch.object(mock_model, "deploy") as mock:
462
+ mock.return_value = mock_endpoint
463
+ yield mock
464
+
465
+
466
+ """
467
+ ----------------------------------------------------------------------------
468
+ Job Fixtures
469
+ ----------------------------------------------------------------------------
470
+ """
471
+
472
+
473
+ @pytest.fixture
474
+ def mock_create_batch_prediction_job():
475
+ with patch.object(aiplatform.jobs.BatchPredictionJob, "create") as mock:
476
+ yield mock
477
+
478
+
479
+ """
480
+ ----------------------------------------------------------------------------
481
+ Tensorboard Fixtures
482
+ ----------------------------------------------------------------------------
483
+ """
484
+
485
+
486
+ @pytest.fixture
487
+ def mock_tensorboard():
488
+ mock = MagicMock(aiplatform.Tensorboard)
489
+ yield mock
490
+
491
+
492
+ @pytest.fixture
493
+ def mock_TensorBoard_uploaderTracker():
494
+ mock = MagicMock(aiplatform.uploader_tracker)
495
+ yield mock
496
+
497
+
498
+ @pytest.fixture
499
+ def mock_create_tensorboard(mock_tensorboard):
500
+ with patch.object(aiplatform.Tensorboard, "create") as mock:
501
+ mock.return_value = mock_tensorboard
502
+ yield mock
503
+
504
+
505
+ @pytest.fixture
506
+ def mock_get_tensorboard(mock_tensorboard):
507
+ with patch.object(aiplatform, "Tensorboard") as mock_get_tensorboard:
508
+ mock_get_tensorboard.return_value = mock_tensorboard
509
+ yield mock_get_tensorboard
510
+
511
+
512
+ @pytest.fixture
513
+ def mock_tensorboard_delete(mock_tensorboard):
514
+ with patch.object(mock_tensorboard, "delete") as mock_tensorboard_delete:
515
+ yield mock_tensorboard_delete
516
+
517
+
518
+ @pytest.fixture
519
+ def mock_tensorboard_uploader_onetime():
520
+ with patch.object(aiplatform, "upload_tb_log") as mock_tensorboard_uploader_onetime:
521
+ mock_tensorboard_uploader_onetime.return_value = None
522
+ yield mock_tensorboard_uploader_onetime
523
+
524
+
525
+ @pytest.fixture
526
+ def mock_tensorboard_uploader_start():
527
+ with patch.object(
528
+ aiplatform, "start_upload_tb_log"
529
+ ) as mock_tensorboard_uploader_start:
530
+ mock_tensorboard_uploader_start.return_value = None
531
+ yield mock_tensorboard_uploader_start
532
+
533
+
534
+ @pytest.fixture
535
+ def mock_tensorboard_uploader_end():
536
+ with patch.object(aiplatform, "end_upload_tb_log") as mock_tensorboard_uploader_end:
537
+ mock_tensorboard_uploader_end.return_value = None
538
+ yield mock_tensorboard_uploader_end
539
+
540
+
541
+ """
542
+ ----------------------------------------------------------------------------
543
+ Endpoint Fixtures
544
+ ----------------------------------------------------------------------------
545
+ """
546
+
547
+
548
+ @pytest.fixture
549
+ def mock_endpoint():
550
+ mock = MagicMock(aiplatform.models.Endpoint)
551
+ yield mock
552
+
553
+
554
+ @pytest.fixture
555
+ def mock_create_endpoint():
556
+ with patch.object(aiplatform.models.Endpoint, "create") as mock:
557
+ yield mock
558
+
559
+
560
+ @pytest.fixture
561
+ def mock_get_endpoint(mock_endpoint):
562
+ with patch.object(aiplatform, "Endpoint") as mock_get_endpoint:
563
+ mock_get_endpoint.return_value = mock_endpoint
564
+ yield mock_get_endpoint
565
+
566
+
567
+ @pytest.fixture
568
+ def mock_endpoint_predict(mock_endpoint):
569
+ with patch.object(mock_endpoint, "predict") as mock:
570
+ mock.return_value = []
571
+ yield mock
572
+
573
+
574
+ @pytest.fixture
575
+ def mock_endpoint_explain(mock_endpoint):
576
+ with patch.object(mock_endpoint, "explain") as mock_endpoint_explain:
577
+ mock_get_endpoint.return_value = mock_endpoint
578
+ yield mock_endpoint_explain
579
+
580
+
581
+ # ----------------------------------------------------------------------------
582
+ # Hyperparameter Tuning Job Fixtures
583
+ # ----------------------------------------------------------------------------
584
+
585
+
586
+ @pytest.fixture
587
+ def mock_hyperparameter_tuning_job():
588
+ mock = MagicMock(aiplatform.HyperparameterTuningJob)
589
+ yield mock
590
+
591
+
592
+ @pytest.fixture
593
+ def mock_get_hyperparameter_tuning_job(mock_hyperparameter_tuning_job):
594
+ with patch.object(aiplatform, "HyperparameterTuningJob") as mock:
595
+ mock.return_value = mock_hyperparameter_tuning_job
596
+ yield mock
597
+
598
+
599
+ @pytest.fixture
600
+ def mock_run_hyperparameter_tuning_job(mock_hyperparameter_tuning_job):
601
+ with patch.object(mock_hyperparameter_tuning_job, "run") as mock:
602
+ yield mock
603
+
604
+
605
+ @pytest.fixture
606
+ def mock_hyperparameter_tuning_job_get(mock_hyperparameter_tuning_job):
607
+ with patch.object(
608
+ aiplatform.HyperparameterTuningJob, "get"
609
+ ) as mock_hyperparameter_tuning_job_get:
610
+ mock_hyperparameter_tuning_job_get.return_value = mock_hyperparameter_tuning_job
611
+ yield mock_hyperparameter_tuning_job_get
612
+
613
+
614
+ @pytest.fixture
615
+ def mock_hyperparameter_tuning_job_cancel(mock_hyperparameter_tuning_job):
616
+ with patch.object(mock_hyperparameter_tuning_job, "cancel") as mock:
617
+ yield mock
618
+
619
+
620
+ @pytest.fixture
621
+ def mock_hyperparameter_tuning_job_delete(mock_hyperparameter_tuning_job):
622
+ with patch.object(mock_hyperparameter_tuning_job, "delete") as mock:
623
+ yield mock
624
+
625
+
626
+ """
627
+ ----------------------------------------------------------------------------
628
+ Feature Store Fixtures
629
+ ----------------------------------------------------------------------------
630
+ """
631
+
632
+
633
+ @pytest.fixture
634
+ def mock_featurestore():
635
+ mock = MagicMock(aiplatform.featurestore.Featurestore)
636
+ yield mock
637
+
638
+
639
+ @pytest.fixture
640
+ def mock_entity_type():
641
+ mock = MagicMock(aiplatform.featurestore.EntityType)
642
+ yield mock
643
+
644
+
645
+ @pytest.fixture
646
+ def mock_feature():
647
+ mock = MagicMock(aiplatform.featurestore.Feature)
648
+ yield mock
649
+
650
+
651
+ @pytest.fixture
652
+ def mock_get_featurestore(mock_featurestore):
653
+ with patch.object(aiplatform.featurestore, "Featurestore") as mock_get_featurestore:
654
+ mock_get_featurestore.return_value = mock_featurestore
655
+ yield mock_get_featurestore
656
+
657
+
658
+ @pytest.fixture
659
+ def mock_get_entity_type(mock_entity_type):
660
+ with patch.object(aiplatform.featurestore, "EntityType") as mock_get_entity_type:
661
+ mock_get_entity_type.return_value = mock_entity_type
662
+ yield mock_get_entity_type
663
+
664
+
665
+ @pytest.fixture
666
+ def mock_create_featurestore(mock_featurestore):
667
+ with patch.object(
668
+ aiplatform.featurestore.Featurestore, "create"
669
+ ) as mock_create_featurestore:
670
+ mock_create_featurestore.return_value = mock_featurestore
671
+ yield mock_create_featurestore
672
+
673
+
674
+ @pytest.fixture
675
+ def mock_create_entity_type(mock_entity_type):
676
+ with patch.object(
677
+ aiplatform.featurestore.EntityType, "create"
678
+ ) as mock_create_entity_type:
679
+ mock_create_entity_type.return_value = mock_entity_type
680
+ yield mock_create_entity_type
681
+
682
+
683
+ @pytest.fixture
684
+ def mock_create_feature(mock_feature):
685
+ with patch.object(aiplatform.featurestore.Feature, "create") as mock_create_feature:
686
+ mock_create_feature.return_value = mock_feature
687
+ yield mock_create_feature
688
+
689
+
690
+ @pytest.fixture
691
+ def mock_delete_featurestore(mock_featurestore):
692
+ with patch.object(mock_featurestore, "delete") as mock_delete_featurestore:
693
+ yield mock_delete_featurestore
694
+
695
+
696
+ @pytest.fixture
697
+ def mock_batch_serve_to_bq(mock_featurestore):
698
+ with patch.object(mock_featurestore, "batch_serve_to_bq") as mock_batch_serve_to_bq:
699
+ yield mock_batch_serve_to_bq
700
+
701
+
702
+ @pytest.fixture
703
+ def mock_batch_create_features(mock_entity_type):
704
+ with patch.object(
705
+ mock_entity_type, "batch_create_features"
706
+ ) as mock_batch_create_features:
707
+ yield mock_batch_create_features
708
+
709
+
710
+ @pytest.fixture
711
+ def mock_read_feature_values(mock_entity_type):
712
+ with patch.object(mock_entity_type, "read") as mock_read_feature_values:
713
+ yield mock_read_feature_values
714
+
715
+
716
+ @pytest.fixture
717
+ def mock_import_feature_values(mock_entity_type):
718
+ with patch.object(
719
+ mock_entity_type, "ingest_from_gcs"
720
+ ) as mock_import_feature_values:
721
+ yield mock_import_feature_values
722
+
723
+
724
+ @pytest.fixture
725
+ def mock_write_feature_values(mock_entity_type):
726
+ with patch.object(
727
+ mock_entity_type, "write_feature_values"
728
+ ) as mock_write_feature_values:
729
+ yield mock_write_feature_values
730
+
731
+
732
+ @pytest.fixture
733
+ def mock_feature_online_store():
734
+ mock = MagicMock(preview_resources.FeatureOnlineStore)
735
+ yield mock
736
+
737
+
738
+ @pytest.fixture
739
+ def mock_create_feature_online_store(mock_feature_online_store):
740
+ with patch.object(
741
+ preview_resources.FeatureOnlineStore, "create_bigtable_store"
742
+ ) as mock_create_feature_online_store:
743
+ mock_create_feature_online_store.return_value = mock_feature_online_store
744
+ yield mock_create_feature_online_store
745
+
746
+
747
+ @pytest.fixture
748
+ def mock_create_optimized_public_online_store(mock_feature_online_store):
749
+ with patch.object(
750
+ preview_resources.FeatureOnlineStore, "create_optimized_store"
751
+ ) as mock_create_optimized_store:
752
+ mock_create_optimized_store.return_value = mock_feature_online_store
753
+ yield mock_create_optimized_store
754
+
755
+
756
+ @pytest.fixture
757
+ def mock_feature_group():
758
+ mock = MagicMock(preview_resources.FeatureGroup)
759
+ yield mock
760
+
761
+
762
+ @pytest.fixture
763
+ def mock_create_feature_group(mock_feature_group):
764
+ with patch.object(
765
+ preview_resources.FeatureGroup, "create"
766
+ ) as mock_create_feature_group:
767
+ mock_create_feature_group.return_value = mock_feature_group
768
+ yield mock_create_feature_group
769
+
770
+
771
+ @pytest.fixture
772
+ def mock_get_feature_group(mock_feature_group):
773
+ with patch.object(
774
+ preview_resources.FeatureGroup, "__new__"
775
+ ) as mock_get_feature_group:
776
+ mock_get_feature_group.return_value = mock_feature_group
777
+ yield mock_get_feature_group
778
+
779
+
780
+ @pytest.fixture
781
+ def mock_create_optimized_private_online_store(mock_feature_online_store):
782
+ with patch.object(
783
+ preview_resources.FeatureOnlineStore, "create_optimized_store"
784
+ ) as mock_create_optimized_store:
785
+ mock_create_optimized_store.return_value = mock_feature_online_store
786
+ yield mock_create_optimized_store
787
+
788
+
789
+ @pytest.fixture
790
+ def mock_get_feature_online_store(mock_feature_online_store):
791
+ with patch.object(
792
+ preview_resources.FeatureOnlineStore, "__new__"
793
+ ) as mock_get_feature_online_store:
794
+ mock_get_feature_online_store.return_value = mock_feature_online_store
795
+ yield mock_get_feature_online_store
796
+
797
+
798
+ """
799
+ ----------------------------------------------------------------------------
800
+ Experiment Tracking Fixtures
801
+ ----------------------------------------------------------------------------
802
+ """
803
+
804
+
805
+ @pytest.fixture
806
+ def mock_execution():
807
+ mock = MagicMock(aiplatform.Execution)
808
+ mock.assign_input_artifacts.return_value = None
809
+ mock.assign_output_artifacts.return_value = None
810
+ mock.__enter__.return_value = mock
811
+ yield mock
812
+
813
+
814
+ @pytest.fixture
815
+ def mock_artifact():
816
+ mock = MagicMock(aiplatform.Artifact)
817
+ yield mock
818
+
819
+
820
+ @pytest.fixture
821
+ def mock_context():
822
+ mock = MagicMock(aiplatform.Context)
823
+ yield mock
824
+
825
+
826
+ @pytest.fixture
827
+ def mock_experiment():
828
+ mock = MagicMock(aiplatform.Experiment)
829
+ yield mock
830
+
831
+
832
+ @pytest.fixture
833
+ def mock_experiment_run():
834
+ mock = MagicMock(aiplatform.ExperimentRun)
835
+ yield mock
836
+
837
+
838
+ @pytest.fixture
839
+ def mock_pipeline_job():
840
+ mock = MagicMock(aiplatform.PipelineJob)
841
+ yield mock
842
+
843
+
844
+ @pytest.fixture
845
+ def mock_df():
846
+ mock = MagicMock()
847
+ yield mock
848
+
849
+
850
+ @pytest.fixture
851
+ def mock_metrics():
852
+ mock = MagicMock()
853
+ yield mock
854
+
855
+
856
+ @pytest.fixture
857
+ def mock_params():
858
+ mock = MagicMock()
859
+ yield mock
860
+
861
+
862
+ @pytest.fixture
863
+ def mock_time_series_metrics():
864
+ mock = MagicMock()
865
+ yield mock
866
+
867
+
868
+ @pytest.fixture
869
+ def mock_classification_metrics():
870
+ mock = MagicMock()
871
+ yield mock
872
+
873
+
874
+ @pytest.fixture
875
+ def mock_artifacts():
876
+ mock = MagicMock()
877
+ yield mock
878
+
879
+
880
+ @pytest.fixture
881
+ def mock_experiment_models():
882
+ mock = MagicMock()
883
+ yield mock
884
+
885
+
886
+ @pytest.fixture
887
+ def mock_model_info():
888
+ mock = MagicMock()
889
+ yield mock
890
+
891
+
892
+ @pytest.fixture
893
+ def mock_ml_model():
894
+ mock = MagicMock()
895
+ yield mock
896
+
897
+
898
+ @pytest.fixture
899
+ def mock_experiment_model():
900
+ mock = MagicMock(aiplatform.metadata.schema.google.artifact_schema.ExperimentModel)
901
+ yield mock
902
+
903
+
904
+ @pytest.fixture
905
+ def mock_get_execution(mock_execution):
906
+ with patch.object(aiplatform, "Execution") as mock_get_execution:
907
+ mock_get_execution.return_value = mock_execution
908
+ yield mock_get_execution
909
+
910
+
911
+ @pytest.fixture
912
+ def mock_execution_get(mock_execution):
913
+ with patch.object(aiplatform.Execution, "get") as mock_execution_get:
914
+ mock_execution_get.return_value = mock_execution
915
+ yield mock_execution_get
916
+
917
+
918
+ @pytest.fixture
919
+ def mock_create_execution(mock_execution):
920
+ with patch.object(aiplatform.Execution, "create") as mock_create_execution:
921
+ mock_create_execution.return_value = mock_execution
922
+ yield mock_create_execution
923
+
924
+
925
+ @pytest.fixture
926
+ def mock_list_execution(mock_execution):
927
+ with patch.object(aiplatform.Execution, "list") as mock_list_execution:
928
+ # Returning list of 2 executions to avoid confusion with get method
929
+ # which returns one unique execution.
930
+ mock_list_execution.return_value = [mock_execution, mock_execution]
931
+ yield mock_list_execution
932
+
933
+
934
+ @pytest.fixture
935
+ def mock_get_artifact(mock_artifact):
936
+ with patch.object(aiplatform, "Artifact") as mock_get_artifact:
937
+ mock_get_artifact.return_value = mock_artifact
938
+ yield mock_get_artifact
939
+
940
+
941
+ @pytest.fixture
942
+ def mock_context_get(mock_context):
943
+ with patch.object(aiplatform.Context, "get") as mock_context_get:
944
+ mock_context_get.return_value = mock_context
945
+ yield mock_context_get
946
+
947
+
948
+ @pytest.fixture
949
+ def mock_context_list(mock_context):
950
+ with patch.object(aiplatform.Context, "list") as mock_context_list:
951
+ # Returning list of 2 contexts to avoid confusion with get method
952
+ # which returns one unique context.
953
+ mock_context_list.return_value = [mock_context, mock_context]
954
+ yield mock_context_list
955
+
956
+
957
+ @pytest.fixture
958
+ def mock_create_schema_base_context(mock_context):
959
+ with patch.object(
960
+ aiplatform.metadata.schema.base_context.BaseContextSchema, "create"
961
+ ) as mock_create_schema_base_context:
962
+ mock_create_schema_base_context.return_value = mock_context
963
+ yield mock_create_schema_base_context
964
+
965
+
966
+ @pytest.fixture
967
+ def mock_artifact_get(mock_artifact):
968
+ with patch.object(aiplatform.Artifact, "get") as mock_artifact_get:
969
+ mock_artifact_get.return_value = mock_artifact
970
+ yield mock_artifact_get
971
+
972
+
973
+ @pytest.fixture
974
+ def mock_pipeline_job_create(mock_pipeline_job):
975
+ with patch.object(aiplatform, "PipelineJob") as mock_pipeline_job_create:
976
+ mock_pipeline_job_create.return_value = mock_pipeline_job
977
+ yield mock_pipeline_job_create
978
+
979
+
980
+ @pytest.fixture
981
+ def mock_artifact_delete():
982
+ with patch.object(aiplatform.Artifact, "delete") as mock_artifact_delete:
983
+ mock_artifact_delete.return_value = None
984
+ yield mock_artifact_delete
985
+
986
+
987
+ @pytest.fixture
988
+ def mock_execution_delete():
989
+ with patch.object(aiplatform.Execution, "delete") as mock_execution_delete:
990
+ mock_execution_delete.return_value = None
991
+ yield mock_execution_delete
992
+
993
+
994
+ @pytest.fixture
995
+ def mock_context_delete():
996
+ with patch.object(aiplatform.Context, "delete") as mock_context_delete:
997
+ mock_context_delete.return_value = None
998
+ yield mock_context_delete
999
+
1000
+
1001
+ @pytest.fixture
1002
+ def mock_pipeline_job_submit(mock_pipeline_job):
1003
+ with patch.object(mock_pipeline_job, "submit") as mock_pipeline_job_submit:
1004
+ mock_pipeline_job_submit.return_value = None
1005
+ yield mock_pipeline_job_submit
1006
+
1007
+
1008
+ @pytest.fixture
1009
+ def mock_create_artifact(mock_artifact):
1010
+ with patch.object(aiplatform.Artifact, "create") as mock_create_artifact:
1011
+ mock_create_artifact.return_value = mock_artifact
1012
+ yield mock_create_artifact
1013
+
1014
+
1015
+ @pytest.fixture
1016
+ def mock_create_schema_base_artifact(mock_artifact):
1017
+ with patch.object(
1018
+ aiplatform.metadata.schema.base_artifact.BaseArtifactSchema, "create"
1019
+ ) as mock_create_schema_base_artifact:
1020
+ mock_create_schema_base_artifact.return_value = mock_artifact
1021
+ yield mock_create_schema_base_artifact
1022
+
1023
+
1024
+ @pytest.fixture
1025
+ def mock_create_schema_base_execution(mock_execution):
1026
+ with patch.object(
1027
+ aiplatform.metadata.schema.base_execution.BaseExecutionSchema, "create"
1028
+ ) as mock_create_schema_base_execution:
1029
+ mock_create_schema_base_execution.return_value = mock_execution
1030
+ yield mock_create_schema_base_execution
1031
+
1032
+
1033
+ @pytest.fixture
1034
+ def mock_list_artifact(mock_artifact):
1035
+ with patch.object(aiplatform.Artifact, "list") as mock_list_artifact:
1036
+ # Returning list of 2 artifacts to avoid confusion with get method
1037
+ # which returns one unique artifact.
1038
+ mock_list_artifact.return_value = [mock_artifact, mock_artifact]
1039
+ yield mock_list_artifact
1040
+
1041
+
1042
+ @pytest.fixture
1043
+ def mock_start_run(mock_experiment_run):
1044
+ with patch.object(aiplatform, "start_run") as mock_start_run:
1045
+ mock_start_run.return_value = mock_experiment_run
1046
+ yield mock_start_run
1047
+
1048
+
1049
+ @pytest.fixture
1050
+ def mock_start_execution(mock_execution):
1051
+ with patch.object(aiplatform, "start_execution") as mock_start_execution:
1052
+ mock_start_execution.return_value = mock_execution
1053
+ yield mock_start_execution
1054
+
1055
+
1056
+ @pytest.fixture
1057
+ def mock_end_run():
1058
+ with patch.object(aiplatform, "end_run") as mock_end_run:
1059
+ mock_end_run.return_value = None
1060
+ yield mock_end_run
1061
+
1062
+
1063
+ @pytest.fixture
1064
+ def mock_log_metrics():
1065
+ with patch.object(aiplatform, "log_metrics") as mock_log_metrics:
1066
+ mock_log_metrics.return_value = None
1067
+ yield mock_log_metrics
1068
+
1069
+
1070
+ @pytest.fixture
1071
+ def mock_log_time_series_metrics():
1072
+ with patch.object(
1073
+ aiplatform, "log_time_series_metrics"
1074
+ ) as mock_log_time_series_metrics:
1075
+ mock_log_time_series_metrics.return_value = None
1076
+ yield mock_log_time_series_metrics
1077
+
1078
+
1079
+ @pytest.fixture
1080
+ def mock_log_params():
1081
+ with patch.object(aiplatform, "log_params") as mock_log_params:
1082
+ mock_log_params.return_value = None
1083
+ yield mock_log_params
1084
+
1085
+
1086
+ @pytest.fixture
1087
+ def mock_log_classification_metrics():
1088
+ with patch.object(aiplatform, "log_classification_metrics") as mock_log_metrics:
1089
+ mock_log_metrics.return_value = None
1090
+ yield mock_log_metrics
1091
+
1092
+
1093
+ @pytest.fixture
1094
+ def mock_log_model():
1095
+ with patch.object(aiplatform, "log_model") as mock_log_model:
1096
+ mock_log_model.return_value = None
1097
+ yield mock_log_model
1098
+
1099
+
1100
+ @pytest.fixture
1101
+ def mock_save_model():
1102
+ with patch.object(aiplatform, "save_model") as mock_save_model:
1103
+ mock_save_model.return_value = None
1104
+ yield mock_save_model
1105
+
1106
+
1107
+ @pytest.fixture
1108
+ def mock_log_pipeline_job():
1109
+ with patch.object(aiplatform, "log") as mock_log_pipeline_job:
1110
+ mock_log_pipeline_job.return_value = None
1111
+ yield mock_log_pipeline_job
1112
+
1113
+
1114
+ @pytest.fixture
1115
+ def mock_get_run(mock_experiment_run):
1116
+ with patch.object(aiplatform, "ExperimentRun") as mock_get_run:
1117
+ mock_get_run.return_value = mock_experiment_run
1118
+ yield mock_get_run
1119
+
1120
+
1121
+ @pytest.fixture
1122
+ def mock_get_experiment(mock_experiment):
1123
+ with patch.object(aiplatform, "Experiment") as mock_get_experiment:
1124
+ mock_get_experiment.return_value = mock_experiment
1125
+ yield mock_get_experiment
1126
+
1127
+
1128
+ @pytest.fixture
1129
+ def mock_get_backing_tensorboard_resource(mock_experiment, mock_tensorboard):
1130
+ with patch.object(
1131
+ mock_experiment, "get_backing_tensorboard_resource"
1132
+ ) as mock_get_backing_tensorboard_resource:
1133
+ mock_get_backing_tensorboard_resource.return_value = mock_tensorboard
1134
+ yield mock_get_backing_tensorboard_resource
1135
+
1136
+
1137
+ @pytest.fixture
1138
+ def mock_get_with_uri(mock_artifact):
1139
+ with patch.object(aiplatform.Artifact, "get_with_uri") as mock_get_with_uri:
1140
+ mock_get_with_uri.return_value = mock_artifact
1141
+ yield mock_get_with_uri
1142
+
1143
+
1144
+ @pytest.fixture
1145
+ def mock_get_experiment_df(mock_df):
1146
+ with patch.object(aiplatform, "get_experiment_df") as mock_get_experiment_df:
1147
+ mock_get_experiment_df.return_value = mock_df
1148
+ yield mock_get_experiment_df
1149
+
1150
+
1151
+ @pytest.fixture
1152
+ def mock_get_metrics(mock_metrics, mock_experiment_run):
1153
+ with patch.object(mock_experiment_run, "get_metrics") as mock_get_metrics:
1154
+ mock_get_metrics.return_value = mock_metrics
1155
+ yield mock_get_metrics
1156
+
1157
+
1158
+ @pytest.fixture
1159
+ def mock_get_params(mock_params, mock_experiment_run):
1160
+ with patch.object(mock_experiment_run, "get_params") as mock_get_params:
1161
+ mock_get_params.return_value = mock_params
1162
+ yield mock_get_params
1163
+
1164
+
1165
+ @pytest.fixture
1166
+ def mock_get_time_series_metrics(mock_time_series_metrics, mock_experiment_run):
1167
+ with patch.object(
1168
+ mock_experiment_run, "get_time_series_data_frame"
1169
+ ) as mock_get_time_series_metrics:
1170
+ mock_get_time_series_metrics.return_value = mock_time_series_metrics
1171
+ yield mock_get_time_series_metrics
1172
+
1173
+
1174
+ @pytest.fixture
1175
+ def mock_get_classification_metrics(mock_classification_metrics, mock_experiment_run):
1176
+ with patch.object(
1177
+ mock_experiment_run, "get_classification_metrics"
1178
+ ) as mock_get_classification_metrics:
1179
+ mock_get_classification_metrics.return_value = mock_classification_metrics
1180
+ yield mock_get_classification_metrics
1181
+
1182
+
1183
+ @pytest.fixture
1184
+ def mock_get_artifacts(mock_artifacts, mock_experiment_run):
1185
+ with patch.object(mock_experiment_run, "get_artifacts") as mock_get_artifacts:
1186
+ mock_get_artifacts.return_value = mock_artifacts
1187
+ yield mock_get_artifacts
1188
+
1189
+
1190
+ @pytest.fixture
1191
+ def mock_get_experiment_models(mock_experiment_models, mock_experiment_run):
1192
+ with patch.object(
1193
+ mock_experiment_run, "get_experiment_models"
1194
+ ) as mock_get_experiment_models:
1195
+ mock_get_experiment_models.return_value = mock_experiment_models
1196
+ yield mock_get_experiment_models
1197
+
1198
+
1199
+ @pytest.fixture
1200
+ def mock_get_experiment_model(mock_experiment_model):
1201
+ with patch.object(aiplatform, "get_experiment_model") as mock_get_experiment_model:
1202
+ mock_get_experiment_model.return_value = mock_experiment_model
1203
+ yield mock_get_experiment_model
1204
+
1205
+
1206
+ @pytest.fixture
1207
+ def mock_get_model_info(mock_experiment_model, mock_model_info):
1208
+ with patch.object(mock_experiment_model, "get_model_info") as mock_get_model_info:
1209
+ mock_get_model_info.return_value = mock_model_info
1210
+ yield mock_get_model_info
1211
+
1212
+
1213
+ @pytest.fixture
1214
+ def mock_load_model(mock_experiment_model, mock_ml_model):
1215
+ with patch.object(mock_experiment_model, "load_model") as mock_load_model:
1216
+ mock_load_model.return_value = mock_ml_model
1217
+ yield mock_load_model
1218
+
1219
+
1220
+ @pytest.fixture
1221
+ def mock_register_model(mock_experiment_model, mock_model):
1222
+ with patch.object(mock_experiment_model, "register_model") as mock_register_model:
1223
+ mock_register_model.return_value = mock_model
1224
+ yield mock_register_model
1225
+
1226
+
1227
+ @pytest.fixture
1228
+ def mock_update_run_state(mock_experiment_run):
1229
+ with patch.object(mock_experiment_run, "update_state") as mock_update_run_state:
1230
+ mock_update_run_state.return_value = None
1231
+ yield mock_update_run_state
1232
+
1233
+
1234
+ """
1235
+ ----------------------------------------------------------------------------
1236
+ Model Versioning Fixtures
1237
+ ----------------------------------------------------------------------------
1238
+ """
1239
+
1240
+
1241
+ @pytest.fixture
1242
+ def mock_model_registry():
1243
+ mock = MagicMock(aiplatform.models.ModelRegistry)
1244
+ yield mock
1245
+
1246
+
1247
+ @pytest.fixture
1248
+ def mock_version_info():
1249
+ mock = MagicMock(aiplatform.models.VersionInfo)
1250
+ yield mock
1251
+
1252
+
1253
+ @pytest.fixture
1254
+ def mock_init_model_registry(mock_model_registry):
1255
+ with patch.object(aiplatform.models, "ModelRegistry") as mock:
1256
+ mock.return_value = mock_model_registry
1257
+ yield mock
1258
+
1259
+
1260
+ @pytest.fixture
1261
+ def mock_get_model(mock_model_registry):
1262
+ with patch.object(mock_model_registry, "get_model") as mock_get_model:
1263
+ mock_get_model.return_value = mock_model
1264
+ yield mock_get_model
1265
+
1266
+
1267
+ @pytest.fixture
1268
+ def mock_get_model_version_info(mock_model_registry):
1269
+ with patch.object(
1270
+ mock_model_registry, "get_version_info"
1271
+ ) as mock_get_model_version_info:
1272
+ mock_get_model_version_info.return_value = mock_version_info
1273
+ yield mock_get_model_version_info
1274
+
1275
+
1276
+ @pytest.fixture
1277
+ def mock_list_versions(mock_model_registry, mock_version_info):
1278
+ with patch.object(mock_model_registry, "list_versions") as mock_list_versions:
1279
+ mock_list_versions.return_value = [mock_version_info, mock_version_info]
1280
+ yield mock_list_versions
1281
+
1282
+
1283
+ @pytest.fixture
1284
+ def mock_delete_version(mock_model_registry):
1285
+ with patch.object(mock_model_registry, "delete_version") as mock_delete_version:
1286
+ mock_delete_version.return_value = None
1287
+ yield mock_delete_version
1288
+
1289
+
1290
+ @pytest.fixture
1291
+ def mock_add_version_aliases(mock_model_registry):
1292
+ with patch.object(
1293
+ mock_model_registry, "add_version_aliases"
1294
+ ) as mock_add_version_aliases:
1295
+ mock_add_version_aliases.return_value = None
1296
+ yield mock_add_version_aliases
1297
+
1298
+
1299
+ @pytest.fixture
1300
+ def mock_remove_version_aliases(mock_model_registry):
1301
+ with patch.object(
1302
+ mock_model_registry, "remove_version_aliases"
1303
+ ) as mock_remove_version_aliases:
1304
+ mock_remove_version_aliases.return_value = None
1305
+ yield mock_remove_version_aliases
1306
+
1307
+
1308
+ """
1309
+ ----------------------------------------------------------------------------
1310
+ Autologging Fixtures
1311
+ ----------------------------------------------------------------------------
1312
+ """
1313
+
1314
+
1315
+ @pytest.fixture
1316
+ def mock_autolog():
1317
+ with patch.object(aiplatform, "autolog") as mock_autolog_method:
1318
+ mock_autolog_method.return_value = None
1319
+ yield mock_autolog_method
1320
+
1321
+
1322
+ """
1323
+ ----------------------------------------------------------------------------
1324
+ Vector Search Fixtures
1325
+ ----------------------------------------------------------------------------
1326
+ """
1327
+
1328
+
1329
+ @pytest.fixture
1330
+ def mock_index():
1331
+ mock = MagicMock(aiplatform.MatchingEngineIndex)
1332
+ yield mock
1333
+
1334
+
1335
+ @pytest.fixture
1336
+ def mock_index_endpoint():
1337
+ mock = MagicMock(aiplatform.MatchingEngineIndexEndpoint)
1338
+ yield mock
1339
+
1340
+
1341
+ @pytest.fixture
1342
+ def mock_list_indexes(mock_index):
1343
+ with patch.object(aiplatform.MatchingEngineIndex, "list") as mock:
1344
+ mock.return_value = [mock_index, mock_index]
1345
+ yield mock
1346
+
1347
+
1348
+ @pytest.fixture
1349
+ def mock_index_init(mock_index):
1350
+ with patch.object(aiplatform, "MatchingEngineIndex") as mock:
1351
+ mock.return_value = mock_index
1352
+ yield mock
1353
+
1354
+
1355
+ @pytest.fixture
1356
+ def mock_index_update_embeddings(mock_index):
1357
+ with patch.object(mock_index, "update_embeddings") as mock:
1358
+ mock.return_value = None
1359
+ yield mock
1360
+
1361
+
1362
+ @pytest.fixture
1363
+ def mock_index_update_metadata(mock_index):
1364
+ with patch.object(mock_index, "update_metadata") as mock:
1365
+ mock.return_value = None
1366
+ yield mock
1367
+
1368
+
1369
+ @pytest.fixture
1370
+ def mock_index_upsert_datapoints(mock_index):
1371
+ with patch.object(mock_index, "upsert_datapoints") as mock_upsert:
1372
+ mock_upsert.return_value = None
1373
+ yield mock_upsert
1374
+
1375
+
1376
+ @pytest.fixture
1377
+ def mock_index_remove_datapoints(mock_index):
1378
+ with patch.object(mock_index, "remove_datapoints") as mock:
1379
+ mock.return_value = None
1380
+ yield mock
1381
+
1382
+
1383
+ @pytest.fixture
1384
+ def mock_index_delete(mock_index):
1385
+ with patch.object(mock_index, "delete") as mock:
1386
+ mock.return_value = None
1387
+ yield mock
1388
+
1389
+
1390
+ @pytest.fixture
1391
+ def mock_list_index_endpoints(mock_index_endpoint):
1392
+ with patch.object(aiplatform.MatchingEngineIndexEndpoint, "list") as mock:
1393
+ mock.return_value = [
1394
+ mock_index_endpoint,
1395
+ mock_index_endpoint,
1396
+ ]
1397
+ yield mock
1398
+
1399
+
1400
+ @pytest.fixture
1401
+ def mock_index_endpoint_init(mock_index_endpoint):
1402
+ with patch.object(aiplatform, "MatchingEngineIndexEndpoint") as mock:
1403
+ mock.return_value = mock_index_endpoint
1404
+ yield mock
1405
+
1406
+
1407
+ @pytest.fixture
1408
+ def mock_index_endpoint_find_neighbors(mock_index_endpoint):
1409
+ with patch.object(mock_index_endpoint, "find_neighbors") as mock_find_neighbors:
1410
+ mock_find_neighbors.return_value = None
1411
+ yield mock_find_neighbors
1412
+
1413
+
1414
+ @pytest.fixture
1415
+ def mock_index_endpoint_match(mock_index_endpoint):
1416
+ with patch.object(mock_index_endpoint, "match") as mock:
1417
+ mock.return_value = None
1418
+ yield mock
1419
+
1420
+
1421
+ @pytest.fixture
1422
+ def mock_index_endpoint_read_index_datapoints(mock_index_endpoint):
1423
+ with patch.object(mock_index_endpoint, "read_index_datapoints") as mock:
1424
+ mock.return_value = None
1425
+ yield mock
1426
+
1427
+
1428
+ @pytest.fixture
1429
+ def mock_index_create_tree_ah_index(mock_index):
1430
+ with patch.object(
1431
+ aiplatform.MatchingEngineIndex, "create_tree_ah_index"
1432
+ ) as mock_create_tree_ah_index:
1433
+ mock_create_tree_ah_index.return_value = mock_index
1434
+ yield mock_create_tree_ah_index
1435
+
1436
+
1437
+ @pytest.fixture
1438
+ def mock_index_endpoint_create(mock_index_endpoint):
1439
+ with patch.object(
1440
+ aiplatform.MatchingEngineIndexEndpoint, "create"
1441
+ ) as mock_index_endpoint_create:
1442
+ mock_index_endpoint_create.return_value = mock_index_endpoint
1443
+ yield mock_index_endpoint_create
1444
+
1445
+
1446
+ @pytest.fixture
1447
+ def mock_index_endpoint_deploy_index(mock_index_endpoint):
1448
+ with patch.object(mock_index_endpoint, "deploy_index") as mock_deploy_index:
1449
+ mock_deploy_index.return_value = mock_index_endpoint
1450
+ yield mock_deploy_index
1451
+
1452
+
1453
+ @pytest.fixture
1454
+ def mock_index_endpoint_undeploy_index(mock_index_endpoint):
1455
+ with patch.object(mock_index_endpoint, "undeploy_index") as mock:
1456
+ mock.return_value = mock_index_endpoint
1457
+ yield mock
1458
+
1459
+
1460
+ @pytest.fixture
1461
+ def mock_index_endpoint_mutate_deployed_index(mock_index_endpoint):
1462
+ with patch.object(mock_index_endpoint, "mutate_deployed_index") as mock:
1463
+ mock.return_value = mock_index_endpoint
1464
+ yield mock
1465
+
1466
+
1467
+ @pytest.fixture
1468
+ def mock_index_endpoint_delete(mock_index_endpoint):
1469
+ with patch.object(mock_index_endpoint, "delete") as mock:
1470
+ mock.return_value = None
1471
+ yield mock
testbed/googleapis__python-aiplatform/samples/model-builder/create_and_import_dataset_image_sample.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2021 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
+
16
+ # [START aiplatform_sdk_create_and_import_dataset_image_sample]
17
+ from typing import List, Union
18
+
19
+ from google.cloud import aiplatform
20
+
21
+
22
+ def create_and_import_dataset_image_sample(
23
+ project: str,
24
+ location: str,
25
+ display_name: str,
26
+ src_uris: Union[str, List[str]],
27
+ sync: bool = True,
28
+ ):
29
+ """
30
+ src_uris -- a string or list of strings, e.g.
31
+ ["gs://bucket1/source1.jsonl", "gs://bucket7/source4.jsonl"]
32
+ """
33
+
34
+ aiplatform.init(project=project, location=location)
35
+
36
+ ds = aiplatform.ImageDataset.create(
37
+ display_name=display_name,
38
+ gcs_source=src_uris,
39
+ import_schema_uri=aiplatform.schema.dataset.ioformat.image.single_label_classification,
40
+ sync=sync,
41
+ )
42
+
43
+ ds.wait()
44
+
45
+ print(ds.display_name)
46
+ print(ds.resource_name)
47
+ return ds
48
+
49
+
50
+ # [END aiplatform_sdk_create_and_import_dataset_image_sample]
testbed/googleapis__python-aiplatform/samples/model-builder/create_and_import_dataset_image_sample_test.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2021 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
+
16
+ from google.cloud.aiplatform import schema
17
+
18
+ import create_and_import_dataset_image_sample
19
+ import test_constants as constants
20
+
21
+
22
+ def test_create_and_import_dataset_image_sample(
23
+ mock_sdk_init, mock_create_image_dataset
24
+ ):
25
+
26
+ create_and_import_dataset_image_sample.create_and_import_dataset_image_sample(
27
+ project=constants.PROJECT,
28
+ location=constants.LOCATION,
29
+ src_uris=constants.GCS_SOURCES,
30
+ display_name=constants.DISPLAY_NAME,
31
+ )
32
+
33
+ mock_sdk_init.assert_called_once_with(
34
+ project=constants.PROJECT, location=constants.LOCATION
35
+ )
36
+ mock_create_image_dataset.assert_called_once_with(
37
+ display_name=constants.DISPLAY_NAME,
38
+ gcs_source=constants.GCS_SOURCES,
39
+ import_schema_uri=schema.dataset.ioformat.image.single_label_classification,
40
+ sync=True,
41
+ )
testbed/googleapis__python-aiplatform/samples/model-builder/create_and_import_dataset_tabular_bigquery_sample.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2021 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
+
16
+ from google.cloud import aiplatform
17
+
18
+
19
+ # [START aiplatform_sdk_create_and_import_dataset_tabular_bigquery_sample]
20
+ def create_and_import_dataset_tabular_bigquery_sample(
21
+ display_name: str,
22
+ project: str,
23
+ location: str,
24
+ bq_source: str,
25
+ ):
26
+
27
+ aiplatform.init(project=project, location=location)
28
+
29
+ dataset = aiplatform.TabularDataset.create(
30
+ display_name=display_name,
31
+ bq_source=bq_source,
32
+ )
33
+
34
+ dataset.wait()
35
+
36
+ print(f'\tDataset: "{dataset.display_name}"')
37
+ print(f'\tname: "{dataset.resource_name}"')
38
+
39
+
40
+ # [END aiplatform_sdk_create_and_import_dataset_tabular_bigquery_sample]
testbed/googleapis__python-aiplatform/samples/model-builder/create_and_import_dataset_tabular_bigquery_sample_test.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2021 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
+
16
+ import create_and_import_dataset_tabular_bigquery_sample
17
+ import test_constants as constants
18
+
19
+
20
+ def test_create_and_import_dataset_tabular_bigquery_sample(
21
+ mock_sdk_init, mock_create_tabular_dataset
22
+ ):
23
+
24
+ create_and_import_dataset_tabular_bigquery_sample.create_and_import_dataset_tabular_bigquery_sample(
25
+ project=constants.PROJECT,
26
+ location=constants.LOCATION,
27
+ bq_source=constants.BIGQUERY_SOURCE,
28
+ display_name=constants.DISPLAY_NAME,
29
+ )
30
+
31
+ mock_sdk_init.assert_called_once_with(
32
+ project=constants.PROJECT, location=constants.LOCATION
33
+ )
34
+ mock_create_tabular_dataset.assert_called_once_with(
35
+ display_name=constants.DISPLAY_NAME,
36
+ bq_source=constants.BIGQUERY_SOURCE,
37
+ )
testbed/googleapis__python-aiplatform/samples/model-builder/create_and_import_dataset_tabular_gcs_sample.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2021 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 List, Union
16
+
17
+ from google.cloud import aiplatform
18
+
19
+
20
+ # [START aiplatform_sdk_create_and_import_dataset_tabular_gcs_sample]
21
+ def create_and_import_dataset_tabular_gcs_sample(
22
+ display_name: str,
23
+ project: str,
24
+ location: str,
25
+ gcs_source: Union[str, List[str]],
26
+ ):
27
+
28
+ aiplatform.init(project=project, location=location)
29
+
30
+ dataset = aiplatform.TabularDataset.create(
31
+ display_name=display_name,
32
+ gcs_source=gcs_source,
33
+ )
34
+
35
+ dataset.wait()
36
+
37
+ print(f'\tDataset: "{dataset.display_name}"')
38
+ print(f'\tname: "{dataset.resource_name}"')
39
+
40
+
41
+ # [END aiplatform_sdk_create_and_import_dataset_tabular_gcs_sample]
testbed/googleapis__python-aiplatform/samples/model-builder/create_and_import_dataset_tabular_gcs_sample_test.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2021 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
+
16
+ import create_and_import_dataset_tabular_gcs_sample
17
+ import test_constants as constants
18
+
19
+
20
+ def test_create_and_import_dataset_tabular_gcs_sample(
21
+ mock_sdk_init, mock_create_tabular_dataset
22
+ ):
23
+
24
+ create_and_import_dataset_tabular_gcs_sample.create_and_import_dataset_tabular_gcs_sample(
25
+ project=constants.PROJECT,
26
+ location=constants.LOCATION,
27
+ gcs_source=constants.GCS_SOURCES,
28
+ display_name=constants.DISPLAY_NAME,
29
+ )
30
+
31
+ mock_sdk_init.assert_called_once_with(
32
+ project=constants.PROJECT, location=constants.LOCATION
33
+ )
34
+ mock_create_tabular_dataset.assert_called_once_with(
35
+ display_name=constants.DISPLAY_NAME,
36
+ gcs_source=constants.GCS_SOURCES,
37
+ )
testbed/googleapis__python-aiplatform/samples/model-builder/create_and_import_dataset_text_sample.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2021 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 List, Union
16
+
17
+ from google.cloud import aiplatform
18
+
19
+
20
+ # [START aiplatform_sdk_create_and_import_dataset_text_sample]
21
+ def create_and_import_dataset_text_sample(
22
+ project: str,
23
+ location: str,
24
+ display_name: str,
25
+ src_uris: Union[str, List[str]],
26
+ sync: bool = True,
27
+ ):
28
+ aiplatform.init(project=project, location=location)
29
+
30
+ ds = aiplatform.TextDataset.create(
31
+ display_name=display_name,
32
+ gcs_source=src_uris,
33
+ import_schema_uri=aiplatform.schema.dataset.ioformat.text.single_label_classification,
34
+ sync=sync,
35
+ )
36
+
37
+ ds.wait()
38
+
39
+ print(ds.display_name)
40
+ print(ds.resource_name)
41
+ return ds
42
+
43
+
44
+ # [END aiplatform_sdk_create_and_import_dataset_text_sample]
testbed/googleapis__python-aiplatform/samples/model-builder/create_and_import_dataset_text_sample_test.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2021 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
+
16
+ from google.cloud.aiplatform import schema
17
+
18
+ import create_and_import_dataset_text_sample
19
+ import test_constants as constants
20
+
21
+
22
+ def test_create_and_import_dataset_text_sample(mock_sdk_init, mock_create_text_dataset):
23
+
24
+ create_and_import_dataset_text_sample.create_and_import_dataset_text_sample(
25
+ project=constants.PROJECT,
26
+ location=constants.LOCATION,
27
+ src_uris=constants.GCS_SOURCES,
28
+ display_name=constants.DISPLAY_NAME,
29
+ )
30
+
31
+ mock_sdk_init.assert_called_once_with(
32
+ project=constants.PROJECT, location=constants.LOCATION
33
+ )
34
+ mock_create_text_dataset.assert_called_once_with(
35
+ display_name=constants.DISPLAY_NAME,
36
+ gcs_source=constants.GCS_SOURCES,
37
+ import_schema_uri=schema.dataset.ioformat.text.single_label_classification,
38
+ sync=True,
39
+ )
testbed/googleapis__python-aiplatform/samples/model-builder/create_and_import_dataset_time_series_bigquery_sample.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2022 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
+
16
+ from google.cloud import aiplatform
17
+
18
+
19
+ # [START aiplatform_sdk_create_and_import_dataset_time_series_bigquery_sample]
20
+ def create_and_import_dataset_time_series_bigquery_sample(
21
+ display_name: str,
22
+ project: str,
23
+ location: str,
24
+ bigquery_source: str,
25
+ ):
26
+
27
+ aiplatform.init(project=project, location=location)
28
+
29
+ dataset = aiplatform.TimeSeriesDataset.create(
30
+ display_name=display_name,
31
+ bigquery_source=bigquery_source,
32
+ )
33
+
34
+ dataset.wait()
35
+
36
+ print(f'\tDataset: "{dataset.display_name}"')
37
+ print(f'\tname: "{dataset.resource_name}"')
38
+
39
+
40
+ # [END aiplatform_sdk_create_and_import_dataset_time_series_bigquery_sample]
testbed/googleapis__python-aiplatform/samples/model-builder/create_and_import_dataset_time_series_bigquery_sample_test.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2022 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
+
16
+ import create_and_import_dataset_time_series_bigquery_sample
17
+ import test_constants as constants
18
+
19
+
20
+ def test_create_and_import_dataset_time_series_bigquery_sample(
21
+ mock_sdk_init, mock_create_time_series_dataset
22
+ ):
23
+
24
+ create_and_import_dataset_time_series_bigquery_sample.create_and_import_dataset_time_series_bigquery_sample(
25
+ project=constants.PROJECT,
26
+ location=constants.LOCATION,
27
+ bigquery_source=constants.BIGQUERY_SOURCE,
28
+ display_name=constants.DISPLAY_NAME,
29
+ )
30
+
31
+ mock_sdk_init.assert_called_once_with(
32
+ project=constants.PROJECT, location=constants.LOCATION
33
+ )
34
+ mock_create_time_series_dataset.assert_called_once_with(
35
+ display_name=constants.DISPLAY_NAME,
36
+ bigquery_source=constants.BIGQUERY_SOURCE,
37
+ )
testbed/googleapis__python-aiplatform/samples/model-builder/create_and_import_dataset_time_series_gcs_sample.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2022 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 List, Union
16
+
17
+ from google.cloud import aiplatform
18
+
19
+
20
+ # [START aiplatform_sdk_create_and_import_dataset_time_series_gcs_sample]
21
+ def create_and_import_dataset_time_series_gcs_sample(
22
+ display_name: str,
23
+ project: str,
24
+ location: str,
25
+ gcs_source: Union[str, List[str]],
26
+ ):
27
+
28
+ aiplatform.init(project=project, location=location)
29
+
30
+ dataset = aiplatform.TimeSeriesDataset.create(
31
+ display_name=display_name,
32
+ gcs_source=gcs_source,
33
+ )
34
+
35
+ dataset.wait()
36
+
37
+ print(f'\tDataset: "{dataset.display_name}"')
38
+ print(f'\tname: "{dataset.resource_name}"')
39
+
40
+
41
+ # [END aiplatform_sdk_create_and_import_dataset_time_series_gcs_sample]
testbed/googleapis__python-aiplatform/samples/model-builder/create_and_import_dataset_time_series_gcs_sample_test.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2022 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
+
16
+ import create_and_import_dataset_time_series_gcs_sample
17
+ import test_constants as constants
18
+
19
+
20
+ def test_create_and_import_dataset_time_series_gcs_sample(
21
+ mock_sdk_init, mock_create_time_series_dataset
22
+ ):
23
+
24
+ create_and_import_dataset_time_series_gcs_sample.create_and_import_dataset_time_series_gcs_sample(
25
+ project=constants.PROJECT,
26
+ location=constants.LOCATION,
27
+ gcs_source=constants.GCS_SOURCES,
28
+ display_name=constants.DISPLAY_NAME,
29
+ )
30
+
31
+ mock_sdk_init.assert_called_once_with(
32
+ project=constants.PROJECT, location=constants.LOCATION
33
+ )
34
+ mock_create_time_series_dataset.assert_called_once_with(
35
+ display_name=constants.DISPLAY_NAME,
36
+ gcs_source=constants.GCS_SOURCES,
37
+ )
testbed/googleapis__python-aiplatform/samples/model-builder/create_and_import_dataset_video_sample.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2021 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 List, Union
16
+
17
+ from google.cloud import aiplatform
18
+
19
+
20
+ # [START aiplatform_sdk_create_and_import_dataset_video_sample]
21
+ def create_and_import_dataset_video_sample(
22
+ project: str,
23
+ location: str,
24
+ display_name: str,
25
+ src_uris: Union[str, List[str]],
26
+ sync: bool = True,
27
+ ):
28
+ aiplatform.init(project=project, location=location)
29
+
30
+ ds = aiplatform.VideoDataset.create(
31
+ display_name=display_name,
32
+ gcs_source=src_uris,
33
+ import_schema_uri=aiplatform.schema.dataset.ioformat.video.classification,
34
+ sync=sync,
35
+ )
36
+
37
+ ds.wait()
38
+
39
+ print(ds.display_name)
40
+ print(ds.resource_name)
41
+ return ds
42
+
43
+
44
+ # [END aiplatform_sdk_create_and_import_dataset_video_sample]
testbed/googleapis__python-aiplatform/samples/model-builder/create_and_import_dataset_video_sample_test.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2021 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
+
16
+ from google.cloud.aiplatform import schema
17
+
18
+ import create_and_import_dataset_video_sample
19
+ import test_constants as constants
20
+
21
+
22
+ def test_create_and_import_dataset_video_sample(
23
+ mock_sdk_init, mock_create_video_dataset
24
+ ):
25
+
26
+ create_and_import_dataset_video_sample.create_and_import_dataset_video_sample(
27
+ project=constants.PROJECT,
28
+ location=constants.LOCATION,
29
+ src_uris=constants.GCS_SOURCES,
30
+ display_name=constants.DISPLAY_NAME,
31
+ )
32
+
33
+ mock_sdk_init.assert_called_once_with(
34
+ project=constants.PROJECT, location=constants.LOCATION
35
+ )
36
+ mock_create_video_dataset.assert_called_once_with(
37
+ display_name=constants.DISPLAY_NAME,
38
+ gcs_source=constants.GCS_SOURCES,
39
+ import_schema_uri=schema.dataset.ioformat.video.classification,
40
+ sync=True,
41
+ )
testbed/googleapis__python-aiplatform/samples/model-builder/create_batch_prediction_job_bigquery_sample.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2021 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 google.cloud import aiplatform
16
+
17
+
18
+ # [START aiplatform_sdk_create_batch_prediction_job_bigquery_sample]
19
+ def create_batch_prediction_job_bigquery_sample(
20
+ project: str,
21
+ location: str,
22
+ model_resource_name: str,
23
+ job_display_name: str,
24
+ bigquery_source: str,
25
+ bigquery_destination_prefix: str,
26
+ sync: bool = True,
27
+ ):
28
+ aiplatform.init(project=project, location=location)
29
+
30
+ my_model = aiplatform.Model(model_resource_name)
31
+
32
+ batch_prediction_job = my_model.batch_predict(
33
+ job_display_name=job_display_name,
34
+ bigquery_source=bigquery_source,
35
+ bigquery_destination_prefix=bigquery_destination_prefix,
36
+ sync=sync,
37
+ )
38
+
39
+ batch_prediction_job.wait()
40
+
41
+ print(batch_prediction_job.display_name)
42
+ print(batch_prediction_job.resource_name)
43
+ print(batch_prediction_job.state)
44
+ return batch_prediction_job
45
+
46
+
47
+ # [END aiplatform_sdk_create_batch_prediction_job_bigquery_sample]
testbed/googleapis__python-aiplatform/samples/model-builder/create_batch_prediction_job_bigquery_sample_test.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2021 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
+
16
+ import create_batch_prediction_job_bigquery_sample
17
+ import test_constants as constants
18
+
19
+
20
+ def test_create_batch_prediction_job_bigquery_sample(
21
+ mock_sdk_init, mock_model, mock_init_model, mock_batch_predict_model
22
+ ):
23
+
24
+ create_batch_prediction_job_bigquery_sample.create_batch_prediction_job_bigquery_sample(
25
+ project=constants.PROJECT,
26
+ location=constants.LOCATION,
27
+ model_resource_name=constants.MODEL_NAME,
28
+ job_display_name=constants.DISPLAY_NAME,
29
+ bigquery_source=constants.BIGQUERY_SOURCE,
30
+ bigquery_destination_prefix=constants.BIGQUERY_DESTINATION_PREFIX,
31
+ )
32
+
33
+ mock_sdk_init.assert_called_once_with(
34
+ project=constants.PROJECT, location=constants.LOCATION
35
+ )
36
+ mock_init_model.assert_called_once_with(constants.MODEL_NAME)
37
+ mock_batch_predict_model.assert_called_once_with(
38
+ job_display_name=constants.DISPLAY_NAME,
39
+ bigquery_source=constants.BIGQUERY_SOURCE,
40
+ bigquery_destination_prefix=constants.BIGQUERY_DESTINATION_PREFIX,
41
+ sync=True,
42
+ )
testbed/googleapis__python-aiplatform/samples/model-builder/create_batch_prediction_job_dedicated_resources_bigquery_sample.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2021 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, aiplatform_v1
18
+
19
+
20
+ # [START aiplatform_sdk_create_batch_prediction_job_dedicated_resources_bigquery_sample]
21
+ def create_batch_prediction_job_dedicated_resources_bigquery_sample(
22
+ project: str,
23
+ location: str,
24
+ model_resource_name: str,
25
+ job_display_name: str,
26
+ bigquery_source: str,
27
+ bigquery_destination_prefix: str,
28
+ machine_type: str = "n1-standard-2",
29
+ accelerator_count: int = 1,
30
+ accelerator_type: Union[str, aiplatform_v1.AcceleratorType] = "NVIDIA_TESLA_K80",
31
+ starting_replica_count: int = 1,
32
+ max_replica_count: int = 1,
33
+ sync: bool = True,
34
+ ):
35
+ aiplatform.init(project=project, location=location)
36
+
37
+ my_model = aiplatform.Model(model_resource_name)
38
+
39
+ batch_prediction_job = my_model.batch_predict(
40
+ job_display_name=job_display_name,
41
+ bigquery_source=bigquery_source,
42
+ bigquery_destination_prefix=bigquery_destination_prefix,
43
+ machine_type=machine_type,
44
+ accelerator_count=accelerator_count,
45
+ accelerator_type=accelerator_type,
46
+ starting_replica_count=starting_replica_count,
47
+ max_replica_count=max_replica_count,
48
+ sync=sync,
49
+ )
50
+
51
+ batch_prediction_job.wait()
52
+
53
+ print(batch_prediction_job.display_name)
54
+ print(batch_prediction_job.resource_name)
55
+ print(batch_prediction_job.state)
56
+ return batch_prediction_job
57
+
58
+
59
+ # [END aiplatform_sdk_create_batch_prediction_job_dedicated_resources_bigquery_sample]
testbed/googleapis__python-aiplatform/samples/model-builder/create_batch_prediction_job_dedicated_resources_sample.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2021 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 Sequence, Union
16
+
17
+ from google.cloud import aiplatform, aiplatform_v1
18
+
19
+
20
+ # [START aiplatform_sdk_create_batch_prediction_job_dedicated_resources_sample]
21
+ def create_batch_prediction_job_dedicated_resources_sample(
22
+ project: str,
23
+ location: str,
24
+ model_resource_name: str,
25
+ job_display_name: str,
26
+ gcs_source: Union[str, Sequence[str]],
27
+ gcs_destination: str,
28
+ instances_format: str = "jsonl",
29
+ machine_type: str = "n1-standard-2",
30
+ accelerator_count: int = 1,
31
+ accelerator_type: Union[str, aiplatform_v1.AcceleratorType] = "NVIDIA_TESLA_K80",
32
+ starting_replica_count: int = 1,
33
+ max_replica_count: int = 1,
34
+ sync: bool = True,
35
+ ):
36
+ aiplatform.init(project=project, location=location)
37
+
38
+ my_model = aiplatform.Model(model_resource_name)
39
+
40
+ batch_prediction_job = my_model.batch_predict(
41
+ job_display_name=job_display_name,
42
+ gcs_source=gcs_source,
43
+ gcs_destination_prefix=gcs_destination,
44
+ instances_format=instances_format,
45
+ machine_type=machine_type,
46
+ accelerator_count=accelerator_count,
47
+ accelerator_type=accelerator_type,
48
+ starting_replica_count=starting_replica_count,
49
+ max_replica_count=max_replica_count,
50
+ sync=sync,
51
+ )
52
+
53
+ batch_prediction_job.wait()
54
+
55
+ print(batch_prediction_job.display_name)
56
+ print(batch_prediction_job.resource_name)
57
+ print(batch_prediction_job.state)
58
+ return batch_prediction_job
59
+
60
+
61
+ # [END aiplatform_sdk_create_batch_prediction_job_dedicated_resources_sample]
testbed/googleapis__python-aiplatform/samples/model-builder/create_batch_prediction_job_dedicated_resources_sample_bigquery_test.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2021 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
+
16
+ import pytest
17
+
18
+ import create_batch_prediction_job_dedicated_resources_bigquery_sample
19
+ import test_constants as constants
20
+
21
+
22
+ @pytest.mark.usefixtures("mock_model")
23
+ def test_create_batch_prediction_job_bigquery_sample(
24
+ mock_sdk_init, mock_init_model, mock_batch_predict_model
25
+ ):
26
+
27
+ create_batch_prediction_job_dedicated_resources_bigquery_sample.create_batch_prediction_job_dedicated_resources_bigquery_sample(
28
+ project=constants.PROJECT,
29
+ location=constants.LOCATION,
30
+ model_resource_name=constants.MODEL_NAME,
31
+ job_display_name=constants.DISPLAY_NAME,
32
+ bigquery_source=constants.BIGQUERY_SOURCE,
33
+ bigquery_destination_prefix=constants.BIGQUERY_DESTINATION_PREFIX,
34
+ machine_type=constants.ACCELERATOR_TYPE,
35
+ accelerator_count=constants.ACCELERATOR_COUNT,
36
+ accelerator_type=constants.ACCELERATOR_TYPE,
37
+ starting_replica_count=constants.MIN_REPLICA_COUNT,
38
+ max_replica_count=constants.MAX_REPLICA_COUNT,
39
+ )
40
+
41
+ mock_sdk_init.assert_called_once_with(
42
+ project=constants.PROJECT, location=constants.LOCATION
43
+ )
44
+ mock_init_model.assert_called_once_with(constants.MODEL_NAME)
45
+ mock_batch_predict_model.assert_called_once_with(
46
+ job_display_name=constants.DISPLAY_NAME,
47
+ bigquery_source=constants.BIGQUERY_SOURCE,
48
+ bigquery_destination_prefix=constants.BIGQUERY_DESTINATION_PREFIX,
49
+ machine_type=constants.ACCELERATOR_TYPE,
50
+ accelerator_count=constants.ACCELERATOR_COUNT,
51
+ accelerator_type=constants.ACCELERATOR_TYPE,
52
+ starting_replica_count=constants.MIN_REPLICA_COUNT,
53
+ max_replica_count=constants.MAX_REPLICA_COUNT,
54
+ sync=True,
55
+ )
testbed/googleapis__python-aiplatform/samples/model-builder/create_batch_prediction_job_dedicated_resources_sample_test.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2021 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
+
16
+ import pytest
17
+
18
+ import create_batch_prediction_job_dedicated_resources_sample
19
+ import test_constants as constants
20
+
21
+
22
+ @pytest.mark.usefixtures("mock_model")
23
+ def test_create_batch_prediction_job_sample(
24
+ mock_sdk_init, mock_init_model, mock_batch_predict_model
25
+ ):
26
+
27
+ create_batch_prediction_job_dedicated_resources_sample.create_batch_prediction_job_dedicated_resources_sample(
28
+ project=constants.PROJECT,
29
+ location=constants.LOCATION,
30
+ model_resource_name=constants.MODEL_NAME,
31
+ job_display_name=constants.DISPLAY_NAME,
32
+ gcs_source=constants.GCS_SOURCES,
33
+ gcs_destination=constants.GCS_DESTINATION,
34
+ instances_format=constants.INSTANCES_FORMAT,
35
+ machine_type=constants.ACCELERATOR_TYPE,
36
+ accelerator_count=constants.ACCELERATOR_COUNT,
37
+ accelerator_type=constants.ACCELERATOR_TYPE,
38
+ starting_replica_count=constants.MIN_REPLICA_COUNT,
39
+ max_replica_count=constants.MAX_REPLICA_COUNT,
40
+ )
41
+
42
+ mock_sdk_init.assert_called_once_with(
43
+ project=constants.PROJECT, location=constants.LOCATION
44
+ )
45
+ mock_init_model.assert_called_once_with(constants.MODEL_NAME)
46
+ mock_batch_predict_model.assert_called_once_with(
47
+ job_display_name=constants.DISPLAY_NAME,
48
+ gcs_source=constants.GCS_SOURCES,
49
+ gcs_destination_prefix=constants.GCS_DESTINATION,
50
+ instances_format=constants.INSTANCES_FORMAT,
51
+ machine_type=constants.ACCELERATOR_TYPE,
52
+ accelerator_count=constants.ACCELERATOR_COUNT,
53
+ accelerator_type=constants.ACCELERATOR_TYPE,
54
+ starting_replica_count=constants.MIN_REPLICA_COUNT,
55
+ max_replica_count=constants.MAX_REPLICA_COUNT,
56
+ sync=True,
57
+ )
testbed/googleapis__python-aiplatform/samples/model-builder/create_batch_prediction_job_sample.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2021 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 Sequence, Union
16
+
17
+ from google.cloud import aiplatform
18
+
19
+
20
+ # [START aiplatform_sdk_create_batch_prediction_job_text_classification_sample]
21
+ # [START aiplatform_sdk_create_batch_prediction_job_text_entity_extraction_sample]
22
+ # [START aiplatform_sdk_create_batch_prediction_job_text_sentiment_analysis_sample]
23
+ # [START aiplatform_sdk_create_batch_prediction_job_sample]
24
+ def create_batch_prediction_job_sample(
25
+ project: str,
26
+ location: str,
27
+ model_resource_name: str,
28
+ job_display_name: str,
29
+ gcs_source: Union[str, Sequence[str]],
30
+ gcs_destination: str,
31
+ sync: bool = True,
32
+ ):
33
+ aiplatform.init(project=project, location=location)
34
+
35
+ my_model = aiplatform.Model(model_resource_name)
36
+
37
+ batch_prediction_job = my_model.batch_predict(
38
+ job_display_name=job_display_name,
39
+ gcs_source=gcs_source,
40
+ gcs_destination_prefix=gcs_destination,
41
+ sync=sync,
42
+ )
43
+
44
+ batch_prediction_job.wait()
45
+
46
+ print(batch_prediction_job.display_name)
47
+ print(batch_prediction_job.resource_name)
48
+ print(batch_prediction_job.state)
49
+ return batch_prediction_job
50
+
51
+
52
+ # [END aiplatform_sdk_create_batch_prediction_job_text_sentiment_analysis_sample]
53
+ # [END aiplatform_sdk_create_batch_prediction_job_text_entity_extraction_sample]
54
+ # [END aiplatform_sdk_create_batch_prediction_job_text_classification_sample]
55
+ # [END aiplatform_sdk_create_batch_prediction_job_sample]
testbed/googleapis__python-aiplatform/samples/model-builder/create_batch_prediction_job_sample_test.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2021 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
+
16
+ import create_batch_prediction_job_sample
17
+ import test_constants as constants
18
+
19
+
20
+ def test_create_batch_prediction_job_sample(
21
+ mock_sdk_init, mock_model, mock_init_model, mock_batch_predict_model
22
+ ):
23
+
24
+ create_batch_prediction_job_sample.create_batch_prediction_job_sample(
25
+ project=constants.PROJECT,
26
+ location=constants.LOCATION,
27
+ model_resource_name=constants.MODEL_NAME,
28
+ job_display_name=constants.DISPLAY_NAME,
29
+ gcs_source=constants.GCS_SOURCES,
30
+ gcs_destination=constants.GCS_DESTINATION,
31
+ )
32
+
33
+ mock_sdk_init.assert_called_once_with(
34
+ project=constants.PROJECT, location=constants.LOCATION
35
+ )
36
+ mock_init_model.assert_called_once_with(constants.MODEL_NAME)
37
+ mock_batch_predict_model.assert_called_once_with(
38
+ job_display_name=constants.DISPLAY_NAME,
39
+ gcs_source=constants.GCS_SOURCES,
40
+ gcs_destination_prefix=constants.GCS_DESTINATION,
41
+ sync=True,
42
+ )
testbed/googleapis__python-aiplatform/samples/model-builder/create_custom_job_on_persistent_resource_sample.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2024 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 Optional
16
+
17
+ from google.cloud import aiplatform
18
+
19
+
20
+ # [START aiplatform_sdk_create_custom_job_on_persistent_resource_sample]
21
+ def create_custom_job_on_persistent_resource_sample(
22
+ project: str,
23
+ location: str,
24
+ staging_bucket: str,
25
+ display_name: str,
26
+ container_uri: str,
27
+ persistent_resource_id: str,
28
+ service_account: Optional[str] = None,
29
+ ) -> None:
30
+ aiplatform.init(
31
+ project=project, location=location, staging_bucket=staging_bucket
32
+ )
33
+
34
+ worker_pool_specs = [{
35
+ "machine_spec": {
36
+ "machine_type": "n1-standard-4",
37
+ "accelerator_type": "NVIDIA_TESLA_K80",
38
+ "accelerator_count": 1,
39
+ },
40
+ "replica_count": 1,
41
+ "container_spec": {
42
+ "image_uri": container_uri,
43
+ "command": [],
44
+ "args": [],
45
+ },
46
+ }]
47
+
48
+ custom_job = aiplatform.CustomJob(
49
+ display_name=display_name,
50
+ worker_pool_specs=worker_pool_specs,
51
+ persistent_resource_id=persistent_resource_id,
52
+ )
53
+
54
+ custom_job.run(service_account=service_account)
55
+
56
+
57
+ # [END aiplatform_sdk_create_custom_job_on_persistent_resource_sample]
testbed/googleapis__python-aiplatform/samples/model-builder/create_custom_job_on_persistent_resource_sample_test.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2024 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
+
16
+ import create_custom_job_on_persistent_resource_sample
17
+ import test_constants as constants
18
+
19
+
20
+ _PRESISTENT_RESOURCE_ID = "test_persistent_resource_id"
21
+
22
+
23
+ def test_create_custom_job_on_persistent_resource_sample(
24
+ mock_sdk_init,
25
+ mock_get_custom_job,
26
+ mock_run_custom_job,
27
+ ):
28
+ create_custom_job_on_persistent_resource_sample.create_custom_job_on_persistent_resource_sample(
29
+ project=constants.PROJECT,
30
+ location=constants.LOCATION,
31
+ staging_bucket=constants.STAGING_BUCKET,
32
+ display_name=constants.DISPLAY_NAME,
33
+ container_uri=constants.CONTAINER_URI,
34
+ persistent_resource_id=_PRESISTENT_RESOURCE_ID,
35
+ service_account=constants.SERVICE_ACCOUNT,
36
+ )
37
+
38
+ mock_sdk_init.assert_called_once_with(
39
+ project=constants.PROJECT,
40
+ location=constants.LOCATION,
41
+ staging_bucket=constants.STAGING_BUCKET,
42
+ )
43
+
44
+ mock_get_custom_job.assert_called_once_with(
45
+ display_name=constants.DISPLAY_NAME,
46
+ worker_pool_specs=constants.CUSTOM_JOB_WORKER_POOL_SPECS,
47
+ persistent_resource_id=_PRESISTENT_RESOURCE_ID,
48
+ )
49
+
50
+ mock_run_custom_job.assert_called_once_with(
51
+ service_account=constants.SERVICE_ACCOUNT,
52
+ )
testbed/googleapis__python-aiplatform/samples/model-builder/create_custom_job_psci_sample.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2024 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_sdk_create_custom_job_psci_sample]
16
+ from google.cloud import aiplatform
17
+ from google.cloud import aiplatform_v1beta1
18
+
19
+
20
+ def create_custom_job_psci_sample(
21
+ project: str,
22
+ location: str,
23
+ bucket: str,
24
+ display_name: str,
25
+ machine_type: str,
26
+ replica_count: int,
27
+ image_uri: str,
28
+ network_attachment: str,
29
+ ):
30
+ """Custom training job sample with PSC-I through aiplatform_v1beta1."""
31
+ aiplatform.init(project=project, location=location, staging_bucket=bucket)
32
+
33
+ client_options = {"api_endpoint": f"{location}-aiplatform.googleapis.com"}
34
+
35
+ client = aiplatform_v1beta1.JobServiceClient(client_options=client_options)
36
+
37
+ request = aiplatform_v1beta1.CreateCustomJobRequest(
38
+ parent=f"projects/{project}/locations/{location}",
39
+ custom_job=aiplatform_v1beta1.CustomJob(
40
+ display_name=display_name,
41
+ job_spec=aiplatform_v1beta1.CustomJobSpec(
42
+ worker_pool_specs=[
43
+ aiplatform_v1beta1.WorkerPoolSpec(
44
+ machine_spec=aiplatform_v1beta1.MachineSpec(
45
+ machine_type=machine_type,
46
+ ),
47
+ replica_count=replica_count,
48
+ container_spec=aiplatform_v1beta1.ContainerSpec(
49
+ image_uri=image_uri,
50
+ ),
51
+ )
52
+ ],
53
+ psc_interface_config=aiplatform_v1beta1.PscInterfaceConfig(
54
+ network_attachment=network_attachment,
55
+ ),
56
+ ),
57
+ ),
58
+ )
59
+
60
+ response = client.create_custom_job(request=request)
61
+
62
+ return response
63
+
64
+
65
+ # [END aiplatform_sdk_create_custom_job_psci_sample]
testbed/googleapis__python-aiplatform/samples/model-builder/create_custom_job_psci_sample_test.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2024 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 create_custom_job_psci_sample
16
+ from google.cloud import aiplatform_v1beta1
17
+ import test_constants as constants
18
+
19
+
20
+ def test_create_custom_job_psci_sample(
21
+ mock_sdk_init,
22
+ mock_get_job_service_client_v1beta1,
23
+ mock_get_create_custom_job_request_v1beta1,
24
+ mock_create_custom_job_v1beta1,
25
+ ):
26
+ """Custom training job sample with PSC-I through aiplatform_v1beta1."""
27
+ create_custom_job_psci_sample.create_custom_job_psci_sample(
28
+ project=constants.PROJECT,
29
+ location=constants.LOCATION,
30
+ bucket=constants.STAGING_BUCKET,
31
+ display_name=constants.DISPLAY_NAME,
32
+ machine_type=constants.MACHINE_TYPE,
33
+ replica_count=1,
34
+ image_uri=constants.TRAIN_IMAGE,
35
+ network_attachment=constants.NETWORK_ATTACHMENT_NAME,
36
+ )
37
+
38
+ mock_sdk_init.assert_called_once_with(
39
+ project=constants.PROJECT,
40
+ location=constants.LOCATION,
41
+ staging_bucket=constants.STAGING_BUCKET,
42
+ )
43
+
44
+ mock_get_job_service_client_v1beta1.assert_called_once_with(
45
+ client_options={
46
+ "api_endpoint": f"{constants.LOCATION}-aiplatform.googleapis.com"
47
+ }
48
+ )
49
+
50
+ mock_get_create_custom_job_request_v1beta1.assert_called_once_with(
51
+ parent=f"projects/{constants.PROJECT}/locations/{constants.LOCATION}",
52
+ custom_job=aiplatform_v1beta1.CustomJob(
53
+ display_name=constants.DISPLAY_NAME,
54
+ job_spec=aiplatform_v1beta1.CustomJobSpec(
55
+ worker_pool_specs=[
56
+ aiplatform_v1beta1.WorkerPoolSpec(
57
+ machine_spec=aiplatform_v1beta1.MachineSpec(
58
+ machine_type=constants.MACHINE_TYPE,
59
+ ),
60
+ replica_count=constants.REPLICA_COUNT,
61
+ container_spec=aiplatform_v1beta1.ContainerSpec(
62
+ image_uri=constants.TRAIN_IMAGE,
63
+ ),
64
+ )
65
+ ],
66
+ psc_interface_config=aiplatform_v1beta1.PscInterfaceConfig(
67
+ network_attachment=constants.NETWORK_ATTACHMENT_NAME,
68
+ ),
69
+ ),
70
+ ),
71
+ )
72
+
73
+ request = aiplatform_v1beta1.CreateCustomJobRequest(
74
+ mock_get_create_custom_job_request_v1beta1.return_value
75
+ )
76
+
77
+ mock_create_custom_job_v1beta1.assert_called_once_with(request=request)
testbed/googleapis__python-aiplatform/samples/model-builder/create_custom_job_with_experiment_autologging_sample.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 Optional
16
+
17
+ from google.cloud import aiplatform
18
+
19
+
20
+ # [START aiplatform_sdk_create_custom_job_with_experiment_autologging_sample]
21
+ def create_custom_job_with_experiment_autologging_sample(
22
+ project: str,
23
+ location: str,
24
+ staging_bucket: str,
25
+ display_name: str,
26
+ script_path: str,
27
+ container_uri: str,
28
+ service_account: str,
29
+ experiment: str,
30
+ experiment_run: Optional[str] = None,
31
+ ) -> None:
32
+ aiplatform.init(project=project, location=location, staging_bucket=staging_bucket, experiment=experiment)
33
+
34
+ job = aiplatform.CustomJob.from_local_script(
35
+ display_name=display_name,
36
+ script_path=script_path,
37
+ container_uri=container_uri,
38
+ enable_autolog=True,
39
+ )
40
+
41
+ job.run(
42
+ service_account=service_account,
43
+ experiment=experiment,
44
+ experiment_run=experiment_run,
45
+ )
46
+
47
+
48
+ # [END aiplatform_sdk_create_custom_job_with_experiment_autologging_sample]
testbed/googleapis__python-aiplatform/samples/model-builder/create_custom_job_with_experiment_autologging_sample_test.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
16
+ import create_custom_job_with_experiment_autologging_sample
17
+ import test_constants as constants
18
+
19
+
20
+ def test_create_custom_job_with_experiment_autologging_sample(
21
+ mock_sdk_init,
22
+ mock_get_custom_job_from_local_script,
23
+ mock_run_custom_job,
24
+ ):
25
+ create_custom_job_with_experiment_autologging_sample.create_custom_job_with_experiment_autologging_sample(
26
+ project=constants.PROJECT,
27
+ location=constants.LOCATION,
28
+ staging_bucket=constants.STAGING_BUCKET,
29
+ display_name=constants.DISPLAY_NAME,
30
+ script_path=constants.SCRIPT_PATH,
31
+ container_uri=constants.CONTAINER_URI,
32
+ service_account=constants.SERVICE_ACCOUNT,
33
+ experiment=constants.EXPERIMENT_NAME,
34
+ experiment_run=constants.EXPERIMENT_RUN_NAME,
35
+ )
36
+
37
+ mock_sdk_init.assert_any_call(
38
+ project=constants.PROJECT,
39
+ location=constants.LOCATION,
40
+ staging_bucket=constants.STAGING_BUCKET,
41
+ experiment=constants.EXPERIMENT_NAME,
42
+ )
43
+
44
+ mock_get_custom_job_from_local_script.assert_called_once_with(
45
+ display_name=constants.DISPLAY_NAME,
46
+ script_path=constants.SCRIPT_PATH,
47
+ container_uri=constants.CONTAINER_URI,
48
+ enable_autolog=True,
49
+ )
50
+
51
+ mock_run_custom_job.assert_called_once_with(
52
+ service_account=constants.SERVICE_ACCOUNT,
53
+ experiment=constants.EXPERIMENT_NAME,
54
+ experiment_run=constants.EXPERIMENT_RUN_NAME,
55
+ )
testbed/googleapis__python-aiplatform/samples/model-builder/create_custom_job_with_experiment_sample.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 Optional
16
+
17
+ from google.cloud import aiplatform
18
+
19
+
20
+ # [START aiplatform_sdk_create_custom_job_with_experiment_sample]
21
+ def create_custom_job_with_experiment_sample(
22
+ project: str,
23
+ location: str,
24
+ staging_bucket: str,
25
+ display_name: str,
26
+ script_path: str,
27
+ container_uri: str,
28
+ service_account: str,
29
+ experiment: str,
30
+ experiment_run: Optional[str] = None,
31
+ ) -> None:
32
+ aiplatform.init(
33
+ project=project,
34
+ location=location,
35
+ staging_bucket=staging_bucket,
36
+ experiment=experiment
37
+ )
38
+
39
+ job = aiplatform.CustomJob.from_local_script(
40
+ display_name=display_name,
41
+ script_path=script_path,
42
+ container_uri=container_uri,
43
+ )
44
+
45
+ job.run(
46
+ service_account=service_account,
47
+ experiment=experiment,
48
+ experiment_run=experiment_run,
49
+ )
50
+
51
+
52
+ # [END aiplatform_sdk_create_custom_job_with_experiment_sample]
testbed/googleapis__python-aiplatform/samples/model-builder/create_custom_job_with_experiment_sample_test.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
16
+ import create_custom_job_with_experiment_sample
17
+ import test_constants as constants
18
+
19
+
20
+ def test_create_custom_job_with_experiment_sample(
21
+ mock_sdk_init,
22
+ mock_get_custom_job_from_local_script,
23
+ mock_run_custom_job,
24
+ ):
25
+ create_custom_job_with_experiment_sample.create_custom_job_with_experiment_sample(
26
+ project=constants.PROJECT,
27
+ location=constants.LOCATION,
28
+ staging_bucket=constants.STAGING_BUCKET,
29
+ display_name=constants.DISPLAY_NAME,
30
+ script_path=constants.SCRIPT_PATH,
31
+ container_uri=constants.CONTAINER_URI,
32
+ service_account=constants.SERVICE_ACCOUNT,
33
+ experiment=constants.EXPERIMENT_NAME,
34
+ experiment_run=constants.EXPERIMENT_RUN_NAME,
35
+ )
36
+
37
+ mock_sdk_init.assert_called_once_with(
38
+ project=constants.PROJECT,
39
+ location=constants.LOCATION,
40
+ staging_bucket=constants.STAGING_BUCKET,
41
+ experiment=constants.EXPERIMENT_NAME,
42
+ )
43
+
44
+ mock_get_custom_job_from_local_script.assert_called_once_with(
45
+ display_name=constants.DISPLAY_NAME,
46
+ script_path=constants.SCRIPT_PATH,
47
+ container_uri=constants.CONTAINER_URI,
48
+ )
49
+
50
+ mock_run_custom_job.assert_called_once_with(
51
+ service_account=constants.SERVICE_ACCOUNT,
52
+ experiment=constants.EXPERIMENT_NAME,
53
+ experiment_run=constants.EXPERIMENT_RUN_NAME,
54
+ )
testbed/googleapis__python-aiplatform/samples/model-builder/create_endpoint_sample.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2021 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 google.cloud import aiplatform
16
+
17
+
18
+ # [START aiplatform_sdk_create_endpoint_sample]
19
+ def create_endpoint_sample(
20
+ project: str,
21
+ display_name: str,
22
+ location: str,
23
+ ):
24
+ aiplatform.init(project=project, location=location)
25
+
26
+ endpoint = aiplatform.Endpoint.create(
27
+ display_name=display_name,
28
+ project=project,
29
+ location=location,
30
+ )
31
+
32
+ print(endpoint.display_name)
33
+ print(endpoint.resource_name)
34
+ return endpoint
35
+
36
+
37
+ # [END aiplatform_sdk_create_endpoint_sample]
testbed/googleapis__python-aiplatform/samples/model-builder/create_endpoint_sample_test.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2021 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
+
16
+ import create_endpoint_sample
17
+ import test_constants as constants
18
+
19
+
20
+ def test_create_endpoint_sample(mock_sdk_init, mock_create_endpoint):
21
+
22
+ create_endpoint_sample.create_endpoint_sample(
23
+ project=constants.PROJECT,
24
+ display_name=constants.DISPLAY_NAME,
25
+ location=constants.LOCATION,
26
+ )
27
+
28
+ mock_sdk_init.assert_called_once_with(
29
+ project=constants.PROJECT, location=constants.LOCATION
30
+ )
31
+
32
+ mock_create_endpoint.assert_called_once_with(
33
+ display_name=constants.DISPLAY_NAME,
34
+ project=constants.PROJECT,
35
+ location=constants.LOCATION,
36
+ )
testbed/googleapis__python-aiplatform/samples/model-builder/create_entity_type_sample.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2022 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
+
16
+ # [START aiplatform_sdk_create_entity_type_sample]
17
+ from google.cloud import aiplatform
18
+
19
+
20
+ def create_entity_type_sample(
21
+ project: str,
22
+ location: str,
23
+ entity_type_id: str,
24
+ featurestore_name: str,
25
+ ):
26
+
27
+ aiplatform.init(project=project, location=location)
28
+
29
+ my_entity_type = aiplatform.EntityType.create(
30
+ entity_type_id=entity_type_id, featurestore_name=featurestore_name
31
+ )
32
+
33
+ my_entity_type.wait()
34
+
35
+ return my_entity_type
36
+
37
+
38
+ # [END aiplatform_sdk_create_entity_type_sample]
testbed/googleapis__python-aiplatform/samples/model-builder/create_entity_type_sample_test.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2022 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 create_entity_type_sample
16
+ import test_constants as constants
17
+
18
+
19
+ def test_create_entity_type_sample(mock_sdk_init, mock_create_entity_type):
20
+
21
+ create_entity_type_sample.create_entity_type_sample(
22
+ project=constants.PROJECT,
23
+ location=constants.LOCATION,
24
+ entity_type_id=constants.ENTITY_TYPE_ID,
25
+ featurestore_name=constants.FEATURESTORE_NAME,
26
+ )
27
+
28
+ mock_sdk_init.assert_called_once_with(
29
+ project=constants.PROJECT, location=constants.LOCATION
30
+ )
31
+
32
+ mock_create_entity_type.assert_called_once_with(
33
+ entity_type_id=constants.ENTITY_TYPE_ID,
34
+ featurestore_name=constants.FEATURESTORE_NAME,
35
+ )
testbed/googleapis__python-aiplatform/samples/model-builder/create_feature_sample.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2022 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
+
16
+ # [START aiplatform_sdk_create_feature_sample]
17
+ from google.cloud import aiplatform
18
+
19
+
20
+ def create_feature_sample(
21
+ project: str,
22
+ location: str,
23
+ feature_id: str,
24
+ value_type: str,
25
+ entity_type_id: str,
26
+ featurestore_id: str,
27
+ ):
28
+
29
+ aiplatform.init(project=project, location=location)
30
+
31
+ my_feature = aiplatform.Feature.create(
32
+ feature_id=feature_id,
33
+ value_type=value_type,
34
+ entity_type_name=entity_type_id,
35
+ featurestore_id=featurestore_id,
36
+ )
37
+
38
+ my_feature.wait()
39
+
40
+ return my_feature
41
+
42
+
43
+ # [END aiplatform_sdk_create_feature_sample]
testbed/googleapis__python-aiplatform/samples/model-builder/create_feature_sample_test.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2022 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 create_feature_sample
16
+ import test_constants as constants
17
+
18
+
19
+ def test_create_feature_sample(mock_sdk_init, mock_create_feature):
20
+
21
+ create_feature_sample.create_feature_sample(
22
+ project=constants.PROJECT,
23
+ location=constants.LOCATION,
24
+ feature_id=constants.FEATURE_ID,
25
+ value_type=constants.FEATURE_VALUE_TYPE,
26
+ entity_type_id=constants.ENTITY_TYPE_ID,
27
+ featurestore_id=constants.FEATURESTORE_ID,
28
+ )
29
+
30
+ mock_sdk_init.assert_called_once_with(
31
+ project=constants.PROJECT, location=constants.LOCATION
32
+ )
33
+
34
+ mock_create_feature.assert_called_once_with(
35
+ feature_id=constants.FEATURE_ID,
36
+ value_type=constants.FEATURE_VALUE_TYPE,
37
+ entity_type_name=constants.ENTITY_TYPE_ID,
38
+ featurestore_id=constants.FEATURESTORE_ID,
39
+ )
testbed/googleapis__python-aiplatform/samples/model-builder/create_featurestore_sample.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2022 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
+
16
+ # [START aiplatform_sdk_create_featurestore_sample]
17
+ from google.cloud import aiplatform
18
+
19
+
20
+ def create_featurestore_sample(
21
+ project: str,
22
+ location: str,
23
+ featurestore_id: str,
24
+ online_store_fixed_node_count: int = 1,
25
+ sync: bool = True,
26
+ ):
27
+
28
+ aiplatform.init(project=project, location=location)
29
+
30
+ fs = aiplatform.Featurestore.create(
31
+ featurestore_id=featurestore_id,
32
+ online_store_fixed_node_count=online_store_fixed_node_count,
33
+ sync=sync,
34
+ )
35
+
36
+ fs.wait()
37
+
38
+ return fs
39
+
40
+
41
+ # [END aiplatform_sdk_create_featurestore_sample]
testbed/googleapis__python-aiplatform/samples/model-builder/create_featurestore_sample_test.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2022 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 create_featurestore_sample
16
+ import test_constants as constants
17
+
18
+
19
+ def test_create_featurestore_sample(mock_sdk_init, mock_create_featurestore):
20
+
21
+ create_featurestore_sample.create_featurestore_sample(
22
+ project=constants.PROJECT,
23
+ location=constants.LOCATION,
24
+ featurestore_id=constants.FEATURESTORE_ID,
25
+ online_store_fixed_node_count=constants.ONLINE_STORE_FIXED_NODE_COUNT,
26
+ sync=constants.SYNC,
27
+ )
28
+
29
+ mock_sdk_init.assert_called_once_with(
30
+ project=constants.PROJECT, location=constants.LOCATION
31
+ )
32
+
33
+ mock_create_featurestore.assert_called_once_with(
34
+ featurestore_id=constants.FEATURESTORE_ID,
35
+ online_store_fixed_node_count=constants.ONLINE_STORE_FIXED_NODE_COUNT,
36
+ sync=constants.SYNC,
37
+ )
testbed/googleapis__python-aiplatform/samples/model-builder/create_hyperparameter_tuning_job_sample.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2022 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_sdk_create_hyperparameter_tuning_job_sample]
16
+ from google.cloud import aiplatform
17
+
18
+ from google.cloud.aiplatform import hyperparameter_tuning as hpt
19
+
20
+
21
+ def create_hyperparameter_tuning_job_sample(
22
+ project: str,
23
+ location: str,
24
+ staging_bucket: str,
25
+ display_name: str,
26
+ container_uri: str,
27
+ ):
28
+ aiplatform.init(project=project, location=location, staging_bucket=staging_bucket)
29
+
30
+ worker_pool_specs = [
31
+ {
32
+ "machine_spec": {
33
+ "machine_type": "n1-standard-4",
34
+ "accelerator_type": "NVIDIA_TESLA_K80",
35
+ "accelerator_count": 1,
36
+ },
37
+ "replica_count": 1,
38
+ "container_spec": {
39
+ "image_uri": container_uri,
40
+ "command": [],
41
+ "args": [],
42
+ },
43
+ }
44
+ ]
45
+
46
+ custom_job = aiplatform.CustomJob(
47
+ display_name='custom_job',
48
+ worker_pool_specs=worker_pool_specs,
49
+ )
50
+
51
+ hpt_job = aiplatform.HyperparameterTuningJob(
52
+ display_name=display_name,
53
+ custom_job=custom_job,
54
+ metric_spec={
55
+ 'loss': 'minimize',
56
+ },
57
+ parameter_spec={
58
+ 'lr': hpt.DoubleParameterSpec(min=0.001, max=0.1, scale='log'),
59
+ 'units': hpt.IntegerParameterSpec(min=4, max=128, scale='linear'),
60
+ 'activation': hpt.CategoricalParameterSpec(values=['relu', 'selu']),
61
+ 'batch_size': hpt.DiscreteParameterSpec(values=[128, 256], scale='linear')
62
+ },
63
+ max_trial_count=128,
64
+ parallel_trial_count=8,
65
+ labels={'my_key': 'my_value'},
66
+ )
67
+
68
+ hpt_job.run()
69
+
70
+ print(hpt_job.resource_name)
71
+ return hpt_job
72
+
73
+
74
+ # [END aiplatform_sdk_create_hyperparameter_tuning_job_sample]