Delete experiments
This page describes how to delete or batch delete experiments using the H2O MLOps Python client.
Constants
The following constants are used in the provided sample script:
- MLOPS_API_URL: The URL endpoint for the MLOps Gateway component. You can verify the correct URL by navigating to the API URL in your browser. It should provide a page with a list of available routes.
- TOKEN_ENDPOINT_URL: Defines the token endpoint URL of the Identity Provider. This uses Keycloak as the Identity Provider. Keycloak Realm should be provided.
- REFRESH_TOKEN: The user's refresh token for authentication.
- CLIENT_ID: The client ID for authentication.
- PROJECT_NAME: The name of the project where the target experiment is located.
- EXPERIMENT_NAME: The name of the experiment that you want to delete.
Batch deletion-specific constants
- PROJECT_NAMES: List containing the names of projects where the experiments are present. For example,- ["project01", "project02"]
- EXPERIMENT_NAMES: List of experiment names that you want to delete. For example,- ["Wine_SKLearn", "Wine_Torch"]
Functions
- _get_project_id(projects): Returns the ID of the specified project.
- _get_experiment_id(experiments): Returns the ID of the specified experiment.
Workflow: Single experiment deletion
- Initialize the token provider using the provided refresh token.
- Set up the H2O MLOps client with the gateway URL and token provider.
- List all projects for the user.
- Fetch the ID of the target project using the _get_project_idfunction.
- List all experiments for the obtained project ID.
- Fetch the ID of the target experiment using the _get_experiment_idfunction.
- Delete the experiment using its ID and the project's ID.
Sample script: Delete experiment
# Delete single Experiment
EXPERIMENT_ID = "cb9096c0-cfdf-400b-85eb-cdfc0005a09b"
PROJECT_ID = "d31df5a6-8eb0-4a65-86c0-a970da4ac182"
# Delete the Experiment from a specific Project by providing the Experiment and Project IDs
mlops_client.storage.experiment.delete_experiment(
        mlops.StorageDeleteExperimentRequest(id=EXPERIMENT_ID, project_id=PROJECT_ID)
    )
Workflow: Batch experiment deletion
- Initialize the token provider using the provided refresh token.
- Set up the H2O MLOps client with the gateway URL and token provider.
- List all projects for the user.
- Fetch the IDs of the target projects using the _get_project_idfunction.
- List all experiments for the obtained project IDs.
- Fetch the IDs of the target experiments using the _get_experiment_idfunction. This can be across multiple projects.
- Form batch experiment deletion payload.
- Delete the experiments in a batch.
note
For batch deletion, you can delete across a combination of projects and experiments with a single invocation.
Sample script: Batch delete experiments
    # List MLOps Projects for the user.
    prj: mlops.StorageProject
    projects: mlops.StorageListProjectsResponse = mlops_client.storage.project.list_projects(
        mlops.StorageListProjectsRequest()
    )
    prj_ids = _get_project_id(projects.project)
    to_be_deleted_project_experiment_ids = {}
    experiment: mlops.StorageExperiments
    # Get all ids for the experiments to be deleted. This can be across multiple projects.
    for id in prj_ids:
        experiments_list: mlops.StorageListExperimentsResponse = mlops_client.storage.experiment.list_experiments(
        mlops.StorageListExperimentsRequest(project_id=id)
        )
        experiment_ids = _get_experiment_id(experiments_list.experiment)
        to_be_deleted_project_experiment_ids[id] = experiment_ids
    # Form batch experiment payload
    delete_experiment_requests: List[mlops.StorageDeleteExperimentRequest] = []
    for k,v in to_be_deleted_project_experiment_ids.items():
        for exp_id in v:
            delete_experiment_requests.append(mlops.StorageDeleteExperimentRequest(project_id=k, id=exp_id))
    # Delete the experiments.
    batch_delete_experiment_request = mlops.StorageBatchDeleteExperimentRequest(experiment_request=delete_experiment_requests)
    batch_delete_experiment_response = mlops_client.storage.experiment.batch_delete_experiment(batch_delete_experiment_request)
Feedback
- Submit and view feedback for this page
- Send feedback about H2O MLOps to cloud-feedback@h2o.ai