From 4ede21cccdd8d5278988bf627fe84d83c23822da Mon Sep 17 00:00:00 2001 From: Aiden010200 <150222139+Aiden010200@users.noreply.github.com> Date: Mon, 29 Jan 2024 23:36:10 +0800 Subject: [PATCH] Upload run experiment example (#2653) * Upload examples of kfp v2 * Upload run experiment example. --- .../vertex_pipeline_kfpv2/run-experiment.py | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 community-content/vertex_pipeline_kfpv2/run-experiment.py diff --git a/community-content/vertex_pipeline_kfpv2/run-experiment.py b/community-content/vertex_pipeline_kfpv2/run-experiment.py new file mode 100644 index 000000000..8cb9fcdf0 --- /dev/null +++ b/community-content/vertex_pipeline_kfpv2/run-experiment.py @@ -0,0 +1,33 @@ +from kfp.v2 import dsl + +@dsl.component(base_image='python:3.8',packages_to_install=['google-cloud-aiplatform==1.36.0']) +def run_experiment( + project_id: str, + location: str, + experiment_name: str, + run_name: str, +): + import json + from google.cloud import aiplatform + + aiplatform.init( + project=project_id, + location=location, + ) + test_expt = aiplatform.Experiment.create(experiment_name) + test_run = aiplatform.ExperimentRun.create(run_name, experiment=test_expt) + metric = test_run.get_classification_metrics()[0] + print(metric) + + + +@dsl.pipeline(name='run_experiment') +def pipeline_run_experiment(): + run_experiment('990000000009', 'us-west1', 'test-experiment', 'test-run') + + +if __name__ == "__main__": + from kfp.v2 import compiler + compiler.Compiler().compile( + pipeline_func=pipeline_run_experiment, + package_path='run_experiment.json') \ No newline at end of file