def get_all_experiment_run_directories()

in notebooks/utils.py [0:0]


def get_all_experiment_run_directories(experiment_name):
    """ Fetch run ids and run directories for a given experiment
    """
    try:
        # Get list of all experiment runs for a given experiment
        runs = vertex_ai.ExperimentRun.list(experiment=experiment_name)
        # Get run id and run directory for each run
        run_details = []
        for run in runs:
            # Create run instance
            run = vertex_ai.ExperimentRun(experiment=experiment_name, run_name=run.name)
            # Fetch artifacts for the run
            run_artifacts = run.get_artifacts()
            run_dir = None
            if len(run_artifacts) > 0:
                # fetch run directory
                run_dir = [artifact.uri for artifact in run.get_artifacts() 
                           if artifact.display_name=='trained_model'][0]
            run_details.append({'RUN_ID':run.name, 'RUN_DIR':run_dir})

        sorted_items = sorted(run_details, key=lambda r: r['RUN_ID'])

        # Return results
        df = pd.DataFrame(run_details)
        return df
    except Exception as e:
        print(e)
        print(f"Cannot fetch runs and run directory for experiment={experiment_name}")
        print("Please check the experiment name.")