def test_create_pipeline( self, host='', ): import kfp if host: client = kfp.Client(host) else: client = kfp.Client() #create pipeline pipeline_ids = [] for idx in range(self.create_pipeline_num): body = { 'name': 'test_' + str(self.test_num) + '_pipeline_' + str(idx), 'url': { "pipeline_url": self.pipeline_url } } try: response = client.pipelines.create_pipeline(body) print('pipeline #' + str(idx) + ' created!') pipeline_ids.append(response.id) except: print('Pipeline creation failed at ' + str(idx) + ' pipeline') return pipeline_ids print('Successfully created {} pipelines!'.format( self.create_pipeline_num)) self.test_num += 1 return pipeline_ids
def test_create_pipeline_versions( self, pipeline_ids, host='', ): import kfp if host: client = kfp.Client(host) else: client = kfp.Client() #create pipeline for pipeline_idx, pipeline_id in enumerate(pipeline_ids): for version_idx in range(self.create_pipeline_version_num): version_name = 'test_' + str( self.test_num ) + '_pipeline_' + pipeline_id + '_version_' + str(version_idx) version_body = { "name": version_name, \ "package_url": {"pipeline_url": self.pipeline_url}, \ "resource_references": [{"key": {"id": pipeline_id, "type":3}, "relationship":1}] } try: response = client.pipelines.create_pipeline_version( version_body) print('version #' + str(version_idx) + ' for pipeline ' + pipeline_id + ' created!') except: print('Pipeline creation failed at pipeline #' + pipeline_id + ' version #' + str(version_idx)) return print('Successfully created {} versions each for {} pipelines!'.format( self.create_pipeline_version_num, len(pipeline_ids))) return pipeline_ids
def main(host: str, create_pipeline: str, create_run_in: str, force: bool): if create_pipeline != "" and create_run_in != "": logging.error( 'only one of --create-run-in and --create-pipeline may be set') return 1 if host != "": client = kfp.Client(host=host) else: client = kfp.Client() run_id = "" if create_run_in != "": logging.info('creating run in pipeline "{}"'.format(create_run_in)) pid = pipeline_id(client, create_run_in) if pid == "": logging.error('could not find pipeline "{}" to create job'.format( create_run_in)) sys.exit(1) # Create a run in the target pipeline using the new pipeline ID run_info = client.run_pipeline( job_name="pach-job-{}".format(os.environ["PACH_JOB_ID"]), pipeline_id=pid, experiment_id=experiment_id(client, "Default"), params={ "s3_endpoint": os.environ["S3_ENDPOINT"], "input_bucket": "input", }) run_id = run_info.id elif create_pipeline != "": # Local machine is just creating the pipeline with tempfile.NamedTemporaryFile(suffix='.zip') as pipeline_file: compiler.Compiler().compile(kubeflow_pipeline, pipeline_file.name) pid = pipeline_id(client, create_pipeline) if pid != "": client.delete_pipeline(pid) logging.info("creating pipeline: {}".format(create_pipeline)) try: client.upload_pipeline(pipeline_file.name, create_pipeline) except TypeError: pass # https://github.com/kubeflow/pipelines/issues/2764 # This can be removed once KF proper uses the latest KFP else: # Pachyderm job is creating both the pipeline and the run run_id = client.create_run_from_pipeline_func( kubeflow_pipeline, run_name="pach-job-{}".format(os.environ["PACH_JOB_ID"]), arguments={ "s3_endpoint": os.environ["S3_ENDPOINT"], "input_bucket": "input", }).run_id if run_id != "": logging.info("waiting on kubeflow run id: {}".format(run_id)) j = client.wait_for_run_completion(run_id, 60) assert j.run.status == 'Succeeded' return 0
def _assert_successful_run_completion(self, host: Text, run_id: Text, timeout: int): """Waits and asserts a successful KFP pipeline execution. Args: host: the endpoint of the KFP deployment. run_id: the run ID of the execution, can be obtained from the respoonse when submitting the pipeline. timeout: maximal waiting time for this execution, in seconds. Raises: RuntimeError: when timeout exceeds after waiting for specified duration. """ status = None start_time = datetime.datetime.now() while True: client = kfp.Client(host=host) get_run_response = client._run_api.get_run(run_id=run_id) if (get_run_response and get_run_response.run and get_run_response.run.status and get_run_response.run.status.lower() in _KFP_FINAL_STATUS): # Break because final status is reached. status = get_run_response.run.status break elif (datetime.datetime.now() - start_time).seconds > timeout: # Timeout. raise RuntimeError( 'Waiting for run timeout at %s' % datetime.datetime.now().strftime('%H:%M:%S')) else: logging.info('Waiting for the job to complete...') time.sleep(10) self.assertEqual(status.lower(), _KFP_SUCCESS_STATUS)
def main(context: str, host: str, gcr_root: str, gcs_root: str, experiment: str = 'v2_sample_test'): client = kfp.Client(host=host) client.create_experiment( name=experiment, description='An experiment with Kubeflow Pipelines v2 sample test runs.' ) run_result = client.create_run_from_pipeline_func( v2_sample_test, { 'context': context, 'launcher_destination': f'{gcr_root}/kfp-launcher', 'gcs_root': gcs_root, 'samples_destination': f'{gcr_root}/v2-sample-test', 'kfp_host': host, }, experiment_name=experiment, ) print("Run details page URL:") print(f"{host}/#/runs/details/{run_result.run_id}") run_response = run_result.wait_for_run_completion(20 * MINUTE) run = run_response.run from pprint import pprint # Hide verbose content run_response.run.pipeline_spec.workflow_manifest = None pprint(run_response.run) print("Run details page URL:") print(f"{host}/#/runs/details/{run_result.run_id}") assert run.status == 'Succeeded'
def __init__(self, host=None): """Creates a new instance of KFPClient. Args: host: the host to talk to Kubeflow Pipelines. """ self._client = kfp.Client(host)
def main(compile=False): """Compile the pipeline and also create a run.""" if compile: kfp.compiler.Compiler().compile(train_pipeline, "train_pipeline.tar.gz") client = kfp.Client(host="{{ host }}") client.create_run_from_pipeline_func(train_pipeline, arguments={})
def setUp(self): super(CliKubeflowEndToEndTest, self).setUp() # List of packages installed. self._pip_list = pip_utils.get_package_names() # Check if Kubeflow is installed before running E2E tests. if labels.KUBEFLOW_PACKAGE_NAME not in self._pip_list: sys.exit('Kubeflow not installed.') # Change the encoding for Click since Python 3 is configured to use ASCII as # encoding for the environment. if codecs.lookup(locale.getpreferredencoding()).name == 'ascii': os.environ['LANG'] = 'en_US.utf-8' # Initialize CLI runner. self.runner = click_testing.CliRunner() # Testdata path. self._testdata_dir = os.path.join( os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'testdata') self._testdata_dir_updated = self.tmp_dir fileio.makedirs(self._testdata_dir_updated) self._pipeline_name = ('cli-kubeflow-e2e-test-' + test_utils.generate_random_id()) absl.logging.info('Pipeline name is %s' % self._pipeline_name) self._pipeline_name_v2 = self._pipeline_name + '_v2' orig_pipeline_path = os.path.join(self._testdata_dir, 'test_pipeline_kubeflow_1.py') self._pipeline_path = os.path.join(self._testdata_dir_updated, 'test_pipeline_kubeflow_1.py') self._pipeline_path_v2 = os.path.join(self._testdata_dir_updated, 'test_pipeline_kubeflow_2.py') test_utils.copy_and_change_pipeline_name( orig_pipeline_path, self._pipeline_path, 'chicago_taxi_pipeline_kubeflow', self._pipeline_name) self.assertTrue(fileio.exists(self._pipeline_path)) test_utils.copy_and_change_pipeline_name( orig_pipeline_path, self._pipeline_path_v2, 'chicago_taxi_pipeline_kubeflow', self._pipeline_name_v2) self.assertTrue(fileio.exists(self._pipeline_path_v2)) # Endpoint URL self._endpoint = self._get_endpoint( subprocess.check_output( 'kubectl describe configmap inverse-proxy-config -n kubeflow'. split())) absl.logging.info('ENDPOINT: ' + self._endpoint) self._pipeline_package_path = '{}.tar.gz'.format(self._pipeline_name) try: # Create a kfp client for cleanup after running commands. self._client = kfp.Client(host=self._endpoint) except kfp_server_api.rest.ApiException as err: absl.logging.info(err)
def get_pipeline_info(input_name, client_key): page_size = 200 page_token = '' pipeline_runs = [] client = kfp.Client(host=client_key) res = client.list_runs(page_size=page_size, page_token=page_token) for runs in res.runs: if runs.resource_references[1].name == input_name: pipeline_runs.append(runs) if len(pipeline_runs) !=0: for prun in pipeline_runs: if prun.status == 'Running': return None # if prun.status == 'Succeeded': tmp = { 'pipelineID': prun.resource_references[1].key.id, 'experimentID': prun.resource_references[0].key.id, 'status': prun.status, 'new_run_name': 'triggered_'+str(datetime.datetime.now())} return tmp # pid = get_pipeline_id(input_name,client) # print("pid: ", name) return None
def main(): # A sample demonstrating how to access KFP API (list of pipeines) # With an authentication token provided by Azure AD # # Usage: # python sample_api.py --kfp_host <kfp_host> --tenant <tenant> --service_principal <Service Principal> --sp_secret <Service Principal Secret> # noqa: E501 parser = argparse.ArgumentParser("run pipeline") parser.add_argument("--kfp_host", type=str, required=False, default="http://localhost:8080/pipeline", help="KFP endpoint") parser.add_argument("--tenant", type=str, required=True, help="Tenant") parser.add_argument("--service_principal", type=str, required=True, help="Service Principal") parser.add_argument("--sp_secret", type=str, required=True, help="Service Principal Secret") args = parser.parse_args() token = get_access_token(args.tenant, args.service_principal, args.sp_secret) # noqa: E501 client = kfp.Client(host=args.kfp_host, existing_token=token) pipelines = client.list_pipelines() print(pipelines)
def print_failure_log_for_run(host: Text, run_id: Text, namespace: Text): """Prints logs of failed components of a run. Prints execution logs for failed componentsusing `logging.info`. This resembles the behavior of `argo logs` but uses K8s API directly. Don't print anything if the run was successful. Args: host: address of the KFP deployment. run_id: id of the execution of the pipeline. namespace: namespace of K8s cluster. """ client = kfp.Client(host=host) run = client.get_run(run_id=run_id) workflow_manifest = json.loads(run.pipeline_runtime.workflow_manifest) if kube_utils.PodPhase(workflow_manifest['status'] ['phase']) != kube_utils.PodPhase.FAILED: return k8s_client = kube_utils.make_core_v1_api() pods = [ i for i in workflow_manifest['status']['nodes'] if i['type'] == 'Pod' ] for pod in pods: if kube_utils.PodPhase(pod['phase']) != kube_utils.PodPhase.FAILED: continue display_name = pod['displayName'] pod_id = pod['id'] log = k8s_client.read_namespaced_pod_log(pod_id, namespace=namespace, container='main') for line in log.splitlines(): logging.info('%s:%s', display_name, line)
def main( output_directory: Optional[str] = None, # example host: Optional[str] = None, external_host: Optional[str] = None, launcher_image: Optional['URI'] = None, experiment: str = 'v2_sample_test_samples', ): """Test file CLI entrypoint used by Fire. :param host: Hostname pipelines can access, defaults to 'http://ml-pipeline:8888'. :type host: str, optional :param external_host: External hostname users can access from their browsers. :type external_host: str, optional :param output_directory: pipeline output directory that holds intermediate artifacts, example gs://your-bucket/path/to/workdir. :type output_directory: str, optional :param launcher_image: override launcher image, only used in V2_COMPATIBLE mode :type launcher_image: URI, optional :param experiment: experiment the run is added to, defaults to 'v2_sample_test_samples' :type experiment: str, optional """ # Default to env values, so people can set up their env and run these # tests without specifying any commands. if host is None: host = os.getenv('KFP_HOST', 'http://ml-pipeline:8888') if external_host is None: external_host = host if output_directory is None: output_directory = os.getenv('KFP_OUTPUT_DIRECTORY') client = kfp.Client(host=host) def run_pipeline( pipeline_func: Callable, mode: kfp.dsl.PipelineExecutionMode = kfp.dsl.PipelineExecutionMode. V2_COMPATIBLE, arguments: dict = {}, ): run_result = client.create_run_from_pipeline_func( pipeline_func, mode=mode, arguments={ kfp.dsl.ROOT_PARAMETER_NAME: output_directory, **arguments }, launcher_image=launcher_image, experiment_name=experiment, ) print("Run details page URL:") print(f"{external_host}/#/runs/details/{run_result.run_id}") run_response = run_result.wait_for_run_completion(10 * MINUTE) run = run_response.run from pprint import pprint # Hide detailed information run.pipeline_spec.workflow_manifest = None pprint(run) return run callback(run_pipeline=run_pipeline)
def _compile_and_run_pipeline(self, pipeline: tfx_pipeline.Pipeline, **kwargs): """Compiles and runs a KFP pipeline. In this method, provided TFX pipeline will be submitted via kfp.Client() instead of from Argo. Args: pipeline: The logical pipeline to run. **kwargs: Key-value pairs of runtime paramters passed to the pipeline execution. """ client = kfp.Client(host=self._KFP_ENDPOINT) pipeline_name = pipeline.pipeline_info.pipeline_name config = kubeflow_dag_runner.KubeflowDagRunnerConfig( kubeflow_metadata_config=self._get_kubeflow_metadata_config(), tfx_image=self._CONTAINER_IMAGE) kubeflow_dag_runner.KubeflowDagRunner(config=config).run(pipeline) file_path = os.path.join(self._test_dir, '{}.tar.gz'.format(pipeline_name)) self.assertTrue(tf.io.gfile.exists(file_path)) run_result = client.create_run_from_pipeline_package( pipeline_file=file_path, arguments=kwargs) run_id = run_result.run_id self._assert_successful_run_completion(host=self._KFP_ENDPOINT, run_id=run_id, pipeline_name=pipeline_name, timeout=self._TIME_OUT)
def _get_client(host=None): global _client if _client is None: _client = kfp.Client() return _client
def deploy_pipeline_to_kfp(self, pipeline_source): """ Import the generated kfp pipeline definition and deploy it to a running KFP instance """ import kfp.compiler as compiler import kfp import importlib.util # create a tmp folder tmp_dir = tempfile.mkdtemp() # copy generated script to temp dir copyfile(pipeline_source, tmp_dir + '/' + "pipeline_code.py") spec = importlib.util.spec_from_file_location( tmp_dir.split('/')[-1], tmp_dir + '/' + 'pipeline_code.py') foo = importlib.util.module_from_spec(spec) spec.loader.exec_module(foo) pipeline_filename = self.pipeline_name + '.pipeline.tar.gz' compiler.Compiler().compile(foo.auto_generated_pipeline, pipeline_filename) try: # Get or create an experiment and submit a pipeline run client = kfp.Client(host=self.kfp_url) experiment = client.create_experiment(self.pipeline_name) # Submit a pipeline run run_name = self.pipeline_name + '_run' client.run_pipeline(experiment.id, run_name, pipeline_filename, {}) except Exception as e: # remove auto-generated tar package (used for deploy) os.remove(self.pipeline_name + '.pipeline.tar.gz') print(f"Kale deployment failed with exception: {e}")
def get_pipeline( self, db_session: sqlalchemy.orm.Session, run_id: str, project: typing.Optional[str] = None, namespace: str = mlrun.mlconf.namespace, format_: mlrun.api.schemas.PipelinesFormat = mlrun.api.schemas.PipelinesFormat.summary, ): kfp_client = kfp.Client(namespace=namespace) run = None try: api_run_detail = kfp_client.get_run(run_id) if api_run_detail.run: run = api_run_detail.to_dict()["run"] if project and project != "*": run_project = self.resolve_project_from_pipeline(run) if run_project != project: raise mlrun.errors.MLRunInvalidArgumentError( f"Pipeline run with id {run_id} is not of project {project}" ) run = self._format_run( db_session, run, format_, api_run_detail.to_dict() ) except Exception as exc: raise mlrun.errors.MLRunRuntimeError( f"Failed getting kfp run: {exc}" ) from exc return run
def run_exp(pipeline_name, pipeline_archive, experiment_name=None, run_name=None, pipeline_args=None, kfp_namespace="kubeflow"): client = kfp.Client(namespace=kfp_namespace) # client.upload_pipeline( # pipeline_package_path=pipeline_archive, # pipeline_name=pipeline_name); run = client.create_run_from_pipeline_package( arguments=pipeline_args, run_name=run_name, experiment_name=experiment_name, pipeline_file=pipeline_archive) response = client.wait_for_run_completion(run_id=run.run_id, timeout=560) if response.run.error != None: print(response.run.error) raise RuntimeError( "Execution of run {} failed. Please check kubeflow pipelines for details" .format(run.run_id))
def main(): parser = argparse.ArgumentParser("publish pipeline") parser.add_argument("--run_id", type=str, required=True, help="unique CI run id") parser.add_argument("--kfp_host", type=str, required=False, default="http://localhost:8080/pipeline", help="KFP endpoint") parser.add_argument("--pipeline_file_path", type=str, required=False, default="pipeline.py.tar.gz", help="KFP pipeline file path") parser.add_argument("--pipeline_name", type=str, required=True, help="KFP pipeline name ") parser.add_argument("--tenant", type=str, required=True, help="Tenant") parser.add_argument("--service_principal", type=str, required=True, help="Service Principal") parser.add_argument("--sp_secret", type=str, required=True, help="Service Principal Secret") args = parser.parse_args() pipeline_file_path = args.pipeline_file_path pipeline_name = "{0}-{1}".format(args.pipeline_name, args.run_id) token = get_access_token(args.tenant, args.service_principal, args.sp_secret) # noqa: E501 client = kfp.Client(host=args.kfp_host, existing_token=token) pipeline_file = os.path.join(pipeline_file_path) try: # We upload a new pipline every time with a run_id in the pipeline name # until the issue with uploading a pipeline version is resolved # see https://github.com/kubeflow/pipelines/issues/3442 pipeline = client.pipeline_uploads.upload_pipeline( pipeline_file, name=pipeline_name) # noqa: E501 return pipeline.id except TypeError as err: print( "An error related to this issue https://github.com/kubeflow/pipelines/issues/3441 {0}" .format(err)) # noqa: E501
def process(self, pipeline): timestamp = datetime.now().strftime("%m%d%H%M%S") pipeline_name = f'{pipeline.name}-{timestamp}' runtime_configuration = self._get_runtime_configuration( pipeline.runtime_config) api_endpoint = runtime_configuration.metadata['api_endpoint'] cos_endpoint = runtime_configuration.metadata['cos_endpoint'] cos_bucket = runtime_configuration.metadata['cos_bucket'] with tempfile.TemporaryDirectory() as temp_dir: pipeline_path = os.path.join(temp_dir, f'{pipeline_name}.tar.gz') self.log.info("Pipeline : %s", pipeline_name) self.log.debug("Creating temp directory %s", temp_dir) # Compile the new pipeline try: pipeline_function = lambda: self._cc_pipeline( pipeline, pipeline_name) # nopep8 E731 kfp.compiler.Compiler().compile(pipeline_function, pipeline_path) except Exception as ex: raise RuntimeError( 'Error compiling pipeline {} at {}'.format( pipeline_name, pipeline_path), str(ex)) self.log.info("Kubeflow Pipeline successfully compiled.") self.log.debug("Kubeflow Pipeline was created in %s", pipeline_path) # Upload the compiled pipeline and create an experiment and run client = kfp.Client(host=api_endpoint) try: kfp_pipeline = client.upload_pipeline(pipeline_path, pipeline_name) except MaxRetryError: raise RuntimeError( 'Error connecting to pipeline server {}'.format( api_endpoint)) self.log.info("Kubeflow Pipeline successfully uploaded to : %s", api_endpoint) run = client.run_pipeline( experiment_id=client.create_experiment(pipeline_name).id, job_name=timestamp, pipeline_id=kfp_pipeline.id) self.log.info("Starting Kubeflow Pipeline Run...") return PipelineProcessorResponse( run_url="{}/#/runs/details/{}".format(api_endpoint, run.id), object_storage_url="{}".format(cos_endpoint), object_storage_path="/{}/{}".format(cos_bucket, pipeline_name), ) return None
def setUp(self): super().setUp() self._namespace = 'kubeflow' self._endpoint = self._get_endpoint(self._namespace) self._kfp_client = kfp.Client(host=self._endpoint) logging.info('ENDPOINT: %s', self._endpoint) self.enter_context( test_case_utils.override_env_var( 'KUBEFLOW_HOME', os.path.join(self._temp_dir, 'kubeflow')))
def deploy_pipeline(host, version): client = kfp.Client(host=host) name = f'pysearchml_{version}' # Supposed page_token is not necessary for this application pipeline = get_pipe_by_name(client, name) if not pipeline: pipeline = client.upload_pipeline( pipeline_package_path='pipeline.tar.gz', pipeline_name=name)
def execute_pipeline(name: str, params: Dict[str, Any]): compile_pipeline(name=name) client = kfp.Client(host=os.getenv("KF_HOST")) experiment = client.create_experiment(name=name) client.run_pipeline( experiment_id=experiment.id, job_name=name, pipeline_package_path=f"../data/11_kubeflow_files/{name}.yaml", params=params, )
def main(compile=False): """Compile the pipeline and also create a run.""" if compile: kfp.compiler.Compiler().compile(train_pipeline, "train_pipeline.tar.gz") try: client = kfp.Client(host="{{ host }}") client.create_run_from_pipeline_func(train_pipeline, arguments={}) except ApiException as e: print("{0}: KFP Dashboard unreachable. Please update the config.yaml with latest hostname.".format(e.reason))
def __init__(self, flags_dict): self.flags_dict = flags_dict self._handler_home_dir = self._get_handler_home('kubeflow_pipelines') # TODO(b/132286477): Change to setup config instead of flags if needed. # Create client. self._client = kfp.Client( host=self.flags_dict[labels.ENDPOINT], client_id=self.flags_dict[labels.IAP_CLIENT_ID], namespace=self.flags_dict[labels.NAMESPACE])
def handle_newfile(data, context): PIPELINES_HOST = os.environ.get( 'PIPELINES_HOST', "Environment variable PIPELINES_HOST not set") PROJECT = os.environ.get('PROJECT', "Environment variable PROJECT not set") BUCKET = os.environ.get('BUCKET', "Environment variable BUCKET not set") client = kfp.Client(host=PIPELINES_HOST) client.create_run_from_pipeline_func(preprocess_train_deploy, { 'project': PROJECT, 'bucket': BUCKET })
def list_pipelines( self, db_session: sqlalchemy.orm.Session, project: str, namespace: str = mlrun.mlconf.namespace, sort_by: str = "", page_token: str = "", filter_: str = "", format_: mlrun.api.schemas.PipelinesFormat = mlrun.api.schemas.PipelinesFormat.metadata_only, page_size: typing.Optional[int] = None, ) -> typing.Tuple[int, typing.Optional[int], typing.List[dict]]: if project != "*" and (page_token or page_size or sort_by or filter_): raise mlrun.errors.MLRunInvalidArgumentError( "Filtering by project can not be used together with pagination, sorting, or custom filter" ) if format_ == mlrun.api.schemas.PipelinesFormat.summary: # we don't support summary format in list pipelines since the returned runs doesn't include the workflow # manifest status that includes the nodes section we use to generate the DAG. # (There is a workflow manifest under the run's pipeline_spec field, but it doesn't include the status) raise mlrun.errors.MLRunInvalidArgumentError( "Summary format is not supported for list pipelines, use get instead" ) kfp_client = kfp.Client(namespace=namespace) if project != "*": run_dicts = [] while page_token is not None: response = kfp_client._run_api.list_runs( page_token=page_token, page_size=mlrun.api.schemas.PipelinesPagination.max_page_size, ) run_dicts.extend([run.to_dict() for run in response.runs or []]) page_token = response.next_page_token project_runs = [] for run_dict in run_dicts: run_project = self.resolve_project_from_pipeline(run_dict) if run_project == project: project_runs.append(run_dict) runs = project_runs total_size = len(project_runs) next_page_token = None else: response = kfp_client._run_api.list_runs( page_token=page_token, page_size=page_size or mlrun.api.schemas.PipelinesPagination.default_page_size, sort_by=sort_by, filter=filter_, ) runs = [run.to_dict() for run in response.runs or []] total_size = response.total_size next_page_token = response.next_page_token runs = self._format_runs(db_session, runs, format_) return total_size, next_page_token, runs
def get_run_info(run_id: str): """Example of getting run info for current pipeline run.""" import kfp print(f'Current run ID is {run_id}.') # KFP API server is usually available as ml-pipeline service in the same # namespace, but for full Kubeflow deployment, you need to edit this to # http://ml-pipeline.kubeflow:8888, because your pipelines are running in # user namespaces, but the API is at kubeflow namespace. client = kfp.Client(host='http://ml-pipeline:8888') run_info = client.get_run(run_id=run_id) # Hide verbose info print(run_info.run)
def main(): #Specify pipeline argument values arguments = {'a': '7', 'b': '8'} result = kfp.Client().create_run_from_pipeline_func(pipeline, arguments=arguments) print(result) # client = kfp.Client() # print( client.list_pipelines() ) return
def main( context: str, gcr_root: str, gcs_root: str, experiment: str = 'v2_sample_test', timeout_mins: float = 40, kfp_package_path: str = 'git+https://github.com/kubeflow/pipelines#egg=kfp&subdirectory=sdk/python', samples_config: str = os.path.join('samples', 'test', 'config.yaml'), ): REPO_ROOT = os.path.join('..', '..', '..', '..') samples_config_path = os.path.join(REPO_ROOT, samples_config) samples_config_content = None with open(samples_config_path, 'r') as stream: samples_config_content = yaml.safe_load(stream) client = kfp.Client() # TODO(Bobgy): avoid using private fields when getting loaded config host = client._existing_config.host client.create_experiment( name=experiment, description='An experiment with Kubeflow Pipelines v2 sample test runs.' ) conf = kfp.dsl.PipelineConf() conf.set_timeout( timeout_mins * _MINUTE ) # add timeout to avoid pipelines stuck in running leak indefinetely print('Using KFP package path: {}'.format(kfp_package_path)) run_result = client.create_run_from_pipeline_func( v2_sample_test, { 'samples_config': samples_config_content, 'context': context, 'image_registry': f'{gcr_root}/test', 'gcs_root': gcs_root, 'kfp_host': host, 'kfp_package_path': kfp_package_path, }, experiment_name=experiment, pipeline_conf=conf, ) print("Run details page URL:") print(f"{host}/#/runs/details/{run_result.run_id}") run_response = run_result.wait_for_run_completion(timeout_mins * _MINUTE) run = run_response.run from pprint import pprint # Hide verbose content run_response.run.pipeline_spec.workflow_manifest = None pprint(run_response.run) print("Run details page URL:") print(f"{host}/#/runs/details/{run_result.run_id}") assert run.status == 'Succeeded'
def create_kf_pipeline(self) -> t.Any: compiler.Compiler().compile(self.mlcube_pipeline, self.mlcube.name + '.tar.gz') client = kfp.Client(host=self.mlcube.runner.pipeline_host) mlcube_experiment = client.create_experiment(name=self.mlcube.name) timestamp = datetime.now().strftime("%d-%m-%y-%H-%M-%S") run = client.run_pipeline(mlcube_experiment.id, 'mlcube-pipeline-' + timestamp, pipeline_package_path=self.mlcube.name + '.tar.gz', params={}) return run