q2_mlab/doctor.py
def doctor_hyperparameter_search(
    dataset,
    preparation,
    target,
    algorithm,
    base_dir,
    max_results=1000,
    delete_duplicates=False,
):
    """Identify jobs to relaunch to generate missing result artifacts

    Searches for the job description file for the experiment described by
    this function's parameters, searches through the files produced for
    missing results, and relaunches jobs necessary for completing those results.

    Parameters
    ----------
    dataset : str
        Name of dataset.
    preparation : str
        Name of data type/preparation (e.g. 16S).
    target : str
        Name of the target variable in the metadata.
    algorithm : str
        Valid algorithm included in q2_mlab.
    base_dir : str
        The directory in which create the file structure.
    max_results : str, optional
        The maximum number of result artifacts to expect. Defaults to 1000.
    delete_duplicates : bool, optional
        If ``True``, deletes the older of duplicate results on the same
        parameter id. Defaults to ``False`` where duplicate results are
        ignored.

    Returns
    -------
    cmd : str
        Command to regenerate missing artifacts.

    Raises
    ------
    FileNotFoundError
        If ``base_dir`` does not exist.
    FileNotFoundError
        If directory with results for this experiement does not exist.
    FileNotFoundError
        If the job script for this experiment does not exist.
    FileNotFoundError
        If the info file for this experiment does not exist.

    See Also
    --------
    q2_mlab.orchestrator.orchestrate_hyperparameter_search

    """
    results_dir = os.path.join(
        base_dir, dataset, preparation, target, algorithm
    )
    output_script = os.path.join(
        base_dir, dataset, "_".join([preparation, target, algorithm]) + ".sh"
    )
    info_doc = os.path.join(
        base_dir,
        dataset,
        "_".join([preparation, target, algorithm]) + "_info.txt",
    )

    if not os.path.isdir(base_dir):
        msg = "Cannot find directory with result file structure. This is typically generated with 'mlab-orchestrator'.\n"
        raise FileNotFoundError(msg + base_dir + " does not exist.")

    if not os.path.isdir(results_dir):
        msg = "Cannot find directory with results. This is typically generated with 'mlab-orchestrator' or 'qiime mlab unit_benchmark'\n"
        raise FileNotFoundError(msg + results_dir + " does not exist.")

    if not os.path.exists(output_script):
        msg = "Cannot find the job script for this experiment. This is typically generated with 'mlab-orchestrator'\n"
        raise FileNotFoundError(msg + output_script + " does not exist.")

    if not os.path.exists(info_doc):
        msg = "Cannot find info file for this experiment. This is typically generated with 'mlab-orchestrator'\n"
        raise FileNotFoundError(msg + info_doc + " does not exist.")

    # Parse info doc for expected result info
    info_dict = parse_info(info_doc)

    # Get all filenames in the results directory
    uninserted_filenames = get_results(results_dir)
    inserted_dir = os.path.join(results_dir, "inserted")
    inserted_filenames = get_results(inserted_dir)

    # Remove duplicate parameter indices
    if len(inserted_filenames) > 0:
        inserted_filenames = filter_duplicate_parameter_results(
            inserted_filenames, inserted_dir, delete=delete_duplicates
        )
    if len(uninserted_filenames) > 0:
        uninserted_filenames = filter_duplicate_parameter_results(
            uninserted_filenames, results_dir, delete=delete_duplicates
        )

    # Compute missing parameter indices:
    expected_num_results = min(max_results, info_dict["parameter_space_size"])
    expected_param_indices = set(range(1, expected_num_results + 1))

    all_filenames = inserted_filenames + uninserted_filenames
    all_param_indices = {int(f.split("_")[0]) for f in all_filenames}

    missing_param_indices = expected_param_indices - all_param_indices

    if len(missing_param_indices) == 0:
        return None

    chunks_to_rerun = set()
    for missing_idx in missing_param_indices:
        # Identify which chunk to run:
        chunk_size = info_dict["chunk_size"]
        missing_chunk = ((missing_idx - 1) // chunk_size) + 1
        chunks_to_rerun.add(missing_chunk)

    # Return command to re-run missing chunks
    cmd = f"qsub -t {','.join(map(str, chunks_to_rerun))} {output_script}"
    print(cmd)
    return cmd
Identify jobs to relaunch to generate missing result artifacts

    Searches for the job description file for the experiment described by
    this function's parameters, searches through the files produced for
    missing results, and relaunches jobs necessary for completing those results.

    Parameters
    ----------
    dataset : str
        Name of dataset.
    preparation : str
        Name of data type/preparation (e.g. 16S).
    target : str
        Name of the target variable in the metadata.
    algorithm : str
        Valid algorithm included in q2_mlab.
    base_dir : str
        The directory in which create the file structure.
    max_results : str, optional
        The maximum number of result artifacts to expect. Defaults to 1000.
    delete_duplicates : bool, optional
        If ``True``, deletes the older of duplicate results on the same
        parameter id. Defaults to ``False`` where duplicate results are
        ignored.

    Returns
    -------
    cmd : str
        Command to regenerate missing artifacts.

    Raises
    ------
    FileNotFoundError
        If ``base_dir`` does not exist.
    FileNotFoundError
        If directory with results for this experiement does not exist.
    FileNotFoundError
        If the job script for this experiment does not exist.
    FileNotFoundError
        If the info file for this experiment does not exist.

    See Also
    --------
    q2_mlab.orchestrator.orchestrate_hyperparameter_search

    
Identify jobs to relaunch to generate missing result artifacts
Searches for the job description file for the experiment described by
this function's parameters, searches through the files produced for
missing results, and relaunches jobs necessary for completing those results.

Parameters

dataset : str
Name of dataset.
preparation : str
Name of data type/preparation .
target : str
Name of the target variable in the metadata.
algorithm : str
Valid algorithm included in q2_mlab.
base_dir : str
The directory in which create the file structure.
max_results : str, optional
The maximum number of result artifacts to expect. Defaults to 1000.
delete_duplicates : bool, optional
If ``True``, deletes the older of duplicate results on the same
parameter id. Defaults to ``False`` where duplicate results are
ignored.

Returns

cmd : str
Command to regenerate missing artifacts.

Raises



See Also


Identify jobs to relaunch to generate missing result artifacts Searches for the job description file for the experiment described by this function ' s parameters searches through the files produced for missing results and relaunches jobs necessary for completing those results . Parameters dataset : str Name of dataset . preparation : str Name of data type / preparation . target : str Name of the target variable in the metadata . algorithm : str Valid algorithm included in q2_mlab . base_dir : str The directory in which create the file structure . max_results : str optional The maximum number of result artifacts to expect . Defaults to 1000 . delete_duplicates : bool optional If ` ` True ` ` deletes the older of duplicate results on the same parameter id . Defaults to ` ` False ` ` where duplicate results are ignored . Returns cmd : str Command to regenerate missing artifacts . Raises See Also
def doctor_hyperparameter_search(
    dataset,
    preparation,
    target,
    algorithm,
    base_dir,
    max_results=1000,
    delete_duplicates=False,
):
    results_dir = os.path.join(
        base_dir, dataset, preparation, target, algorithm
    )
    output_script = os.path.join(
        base_dir, dataset, "_".join([preparation, target, algorithm]) + ".sh"
    )
    info_doc = os.path.join(
        base_dir,
        dataset,
        "_".join([preparation, target, algorithm]) + "_info.txt",
    )
    if not os.path.isdir(base_dir):
        msg = "Cannot find directory with result file structure. This is typically generated with 'mlab-orchestrator'.\n"
        raise FileNotFoundError(msg + base_dir + " does not exist.")
    if not os.path.isdir(results_dir):
        msg = "Cannot find directory with results. This is typically generated with 'mlab-orchestrator' or 'qiime mlab unit_benchmark'\n"
        raise FileNotFoundError(msg + results_dir + " does not exist.")
    if not os.path.exists(output_script):
        msg = "Cannot find the job script for this experiment. This is typically generated with 'mlab-orchestrator'\n"
        raise FileNotFoundError(msg + output_script + " does not exist.")
    if not os.path.exists(info_doc):
        msg = "Cannot find info file for this experiment. This is typically generated with 'mlab-orchestrator'\n"
        raise FileNotFoundError(msg + info_doc + " does not exist.")
    info_dict = parse_info(info_doc)
    uninserted_filenames = get_results(results_dir)
    inserted_dir = os.path.join(results_dir, "inserted")
    inserted_filenames = get_results(inserted_dir)
    if len(inserted_filenames) > 0:
        inserted_filenames = filter_duplicate_parameter_results(
            inserted_filenames, inserted_dir, delete=delete_duplicates
        )
    if len(uninserted_filenames) > 0:
        uninserted_filenames = filter_duplicate_parameter_results(
            uninserted_filenames, results_dir, delete=delete_duplicates
        )
    expected_num_results = min(max_results, info_dict["parameter_space_size"])
    expected_param_indices = set(range(1, expected_num_results + 1))
    all_filenames = inserted_filenames + uninserted_filenames
    all_param_indices = {int(f.split("_")[0]) for f in all_filenames}
    missing_param_indices = expected_param_indices - all_param_indices
    if len(missing_param_indices) == 0:
        return None
    chunks_to_rerun = set()
    for missing_idx in missing_param_indices:
        chunk_size = info_dict["chunk_size"]
        missing_chunk = ((missing_idx - 1) // chunk_size) + 1
        chunks_to_rerun.add(missing_chunk)
    cmd = f"qsub -t {','.join(map(str, chunks_to_rerun))} {output_script}"
    print(cmd)
    return cmd
def doctor_hyperparameter_search ( dataset , preparation , target , algorithm , base_dir , max_results = 1000 , delete_duplicates = False , ) : results_dir = os . path . join ( base_dir , dataset , preparation , target , algorithm ) output_script = os . path . join ( base_dir , dataset , "_" . join ( [ preparation , target , algorithm ] ) + ".sh" ) info_doc = os . path . join ( base_dir , dataset , "_" . join ( [ preparation , target , algorithm ] ) + "_info.txt" , ) if not os . path . isdir ( base_dir ) : msg = "Cannot find directory with result file structure. This is typically generated with 'mlab-orchestrator'.\n" raise FileNotFoundError ( msg + base_dir + " does not exist." ) if not os . path . isdir ( results_dir ) : msg = "Cannot find directory with results. This is typically generated with 'mlab-orchestrator' or 'qiime mlab unit_benchmark'\n" raise FileNotFoundError ( msg + results_dir + " does not exist." ) if not os . path . exists ( output_script ) : msg = "Cannot find the job script for this experiment. This is typically generated with 'mlab-orchestrator'\n" raise FileNotFoundError ( msg + output_script + " does not exist." ) if not os . path . exists ( info_doc ) : msg = "Cannot find info file for this experiment. This is typically generated with 'mlab-orchestrator'\n" raise FileNotFoundError ( msg + info_doc + " does not exist." ) info_dict = parse_info ( info_doc ) uninserted_filenames = get_results ( results_dir ) inserted_dir = os . path . join ( results_dir , "inserted" ) inserted_filenames = get_results ( inserted_dir ) if len ( inserted_filenames ) > 0 : inserted_filenames = filter_duplicate_parameter_results ( inserted_filenames , inserted_dir , delete = delete_duplicates ) if len ( uninserted_filenames ) > 0 : uninserted_filenames = filter_duplicate_parameter_results ( uninserted_filenames , results_dir , delete = delete_duplicates ) expected_num_results = min ( max_results , info_dict [ "parameter_space_size" ] ) expected_param_indices = set ( range ( 1 , expected_num_results + 1 ) ) all_filenames = inserted_filenames + uninserted_filenames all_param_indices = { int ( f . split ( "_" ) [ 0 ] ) for f in all_filenames } missing_param_indices = expected_param_indices - all_param_indices if len ( missing_param_indices ) == 0 : return None chunks_to_rerun = set ( ) for missing_idx in missing_param_indices : chunk_size = info_dict [ "chunk_size" ] missing_chunk = ( ( missing_idx - 1 ) // chunk_size ) + 1 chunks_to_rerun . add ( missing_chunk ) cmd = f"qsub -t {','.join(map(str, chunks_to_rerun))} {output_script}" print ( cmd ) return cmd
Identify jobs to relaunch to generate missing result artifacts
Searches for the job description file for the experiment described by
this function's parameters, searches through the files produced for
missing results, and relaunches jobs necessary for completing those results.
Identify jobs to relaunch to generate missing result artifacts Searches for the job description file for the experiment described by this function ' s parameters searches through the files produced for missing results and relaunches jobs necessary for completing those results .
"""Identify jobs to relaunch to generate missing result artifacts

    Searches for the job description file for the experiment described by
    this function's parameters, searches through the files produced for
    missing results, and relaunches jobs necessary for completing those results.

    Parameters
    ----------
    dataset : str
        Name of dataset.
    preparation : str
        Name of data type/preparation (e.g. 16S).
    target : str
        Name of the target variable in the metadata.
    algorithm : str
        Valid algorithm included in q2_mlab.
    base_dir : str
        The directory in which create the file structure.
    max_results : str, optional
        The maximum number of result artifacts to expect. Defaults to 1000.
    delete_duplicates : bool, optional
        If ``True``, deletes the older of duplicate results on the same
        parameter id. Defaults to ``False`` where duplicate results are
        ignored.

    Returns
    -------
    cmd : str
        Command to regenerate missing artifacts.

    Raises
    ------
    FileNotFoundError
        If ``base_dir`` does not exist.
    FileNotFoundError
        If directory with results for this experiement does not exist.
    FileNotFoundError
        If the job script for this experiment does not exist.
    FileNotFoundError
        If the info file for this experiment does not exist.

    See Also
    --------
    q2_mlab.orchestrator.orchestrate_hyperparameter_search

    """ # Parse info doc for expected result info # Get all filenames in the results directory # Remove duplicate parameter indices # Compute missing parameter indices: # Identify which chunk to run: # Return command to re-run missing chunks
dataset
preparation
target
algorithm
base_dir
max_results
delete_duplicates