#NEWLINE# def run_configuration( config_file , local = False , overwrite = True , queue = 'all.q' , hosts = None , write_summary = True , quiet = False , ablation = 0 , resume = False ) : #NEWLINE# #INDENT# '\n    Takes a configuration file and runs the specified jobs on the grid.\n\n    :param config_path: Path to the configuration file we would like to use.\n    :type config_path: str\n    :param local: Should this be run locally instead of on the cluster?\n    :type local: bool\n    :param overwrite: If the model files already exist, should we overwrite\n                      them instead of re-using them?\n    :type overwrite: bool\n    :param queue: The DRMAA queue to use if we\'re running on the cluster.\n    :type queue: str\n    :param hosts: If running on the cluster, these are the machines we should\n                  use.\n    :type hosts: list of str\n    :param write_summary: Write a tsv file with a summary of the results.\n    :type write_summary: bool\n    :param quiet: Suppress printing of "Loading..." messages.\n    :type quiet: bool\n    :param ablation: Number of features to remove when doing an ablation\n                     experiment. If positive, we will perform repeated ablation\n                     runs for all combinations of features removing the\n                     specified number at a time. If ``None``, we will use all\n                     combinations of all lengths. If 0, the default, no\n                     ablation is performed. If negative, a ``ValueError`` is\n                     raised.\n    :type ablation: int or None\n    :param resume: If result files already exist for an experiment, do not\n                   overwrite them. This is very useful when doing a large\n                   ablation experiment and part of it crashes.\n    :type resume: bool\n\n    :return: A list of paths to .json results files for each variation in the\n             experiment.\n    :rtype: list of str\n\n    ' #NEWLINE# logger = logging . getLogger ( __name__ ) #NEWLINE# ( experiment_name , task , sampler , fixed_sampler_parameters , feature_hasher , hasher_features , id_col , label_col , train_set_name , test_set_name , suffix , featuresets , do_shuffle , model_path , do_grid_search , grid_objectives , probability , results_path , pos_label_str , feature_scaling , min_feature_count , grid_search_jobs , grid_search_folds , cv_folds , save_cv_folds , do_stratified_folds , fixed_parameter_list , param_grid_list , featureset_names , learners , prediction_dir , log_path , train_path , test_path , ids_to_floats , class_map , custom_learner_path ) = _parse_config_file ( config_file ) #NEWLINE# if ( ( not local ) and ( not _HAVE_GRIDMAP ) ) : #NEWLINE# #INDENT# local = True #NEWLINE# logger . warning ( 'gridmap 0.10.1+ not available. Forcing local mode.  To run things on a DRMAA-compatible cluster, install gridmap>=0.10.1 via pip.' ) #NEWLINE# #UNINDENT# if ( ( ablation is None ) or ( ablation > 0 ) ) : #NEWLINE# #INDENT# expanded_fs = [ ] #NEWLINE# expanded_fs_names = [ ] #NEWLINE# for ( features , featureset_name ) in zip ( featuresets , featureset_names ) : #NEWLINE# #INDENT# features = sorted ( features ) #NEWLINE# featureset = set ( features ) #NEWLINE# if ( ablation is None ) : #NEWLINE# #INDENT# for i in range ( 1 , len ( features ) ) : #NEWLINE# #INDENT# for excluded_features in combinations ( features , i ) : #NEWLINE# #INDENT# expanded_fs . append ( sorted ( ( featureset - set ( excluded_features ) ) ) ) #NEWLINE# expanded_fs_names . append ( ( ( featureset_name + '_minus_' ) + _munge_featureset_name ( excluded_features ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# for excluded_features in combinations ( features , ablation ) : #NEWLINE# #INDENT# expanded_fs . append ( sorted ( ( featureset - set ( excluded_features ) ) ) ) #NEWLINE# expanded_fs_names . append ( ( ( featureset_name + '_minus_' ) + _munge_featureset_name ( excluded_features ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# expanded_fs . append ( features ) #NEWLINE# expanded_fs_names . append ( ( featureset_name + '_all' ) ) #NEWLINE# #UNINDENT# featuresets = expanded_fs #NEWLINE# featureset_names = expanded_fs_names #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ablation < 0 ) : #NEWLINE# #INDENT# raise ValueError ( 'Value for "ablation" argument must be either positive integer or None.' ) #NEWLINE# #UNINDENT# #UNINDENT# if ( not local ) : #NEWLINE# #INDENT# jobs = [ ] #NEWLINE# #UNINDENT# result_json_paths = [ ] #NEWLINE# for featureset_name in featureset_names : #NEWLINE# #INDENT# if ( len ( featureset_name ) > 210 ) : #NEWLINE# #INDENT# raise OSError ( 'System generated file length "{}" exceeds the maximum length supported.  Please specify names of your datasets with "featureset_names".  If you are running ablation experiment, please reduce the length of the features in "featuresets" because the auto-generated name would be longer than the file system can handle' . format ( featureset_name ) ) #NEWLINE# #UNINDENT# #UNINDENT# for ( featureset , featureset_name ) in zip ( featuresets , featureset_names ) : #NEWLINE# #INDENT# for ( learner_num , learner_name ) in enumerate ( learners ) : #NEWLINE# #INDENT# for grid_objective in grid_objectives : #NEWLINE# #INDENT# if ( len ( grid_objectives ) == 1 ) : #NEWLINE# #INDENT# job_name_components = [ experiment_name , featureset_name , learner_name ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# job_name_components = [ experiment_name , featureset_name , learner_name , grid_objective ] #NEWLINE# #UNINDENT# job_name = '_' . join ( job_name_components ) #NEWLINE# prediction_prefix = join ( prediction_dir , job_name ) #NEWLINE# temp_logfile = join ( log_path , '{}.log' . format ( job_name ) ) #NEWLINE# result_json_path = join ( results_path , '{}.results.json' . format ( job_name ) ) #NEWLINE# result_json_paths . append ( result_json_path ) #NEWLINE# if ( resume and ( exists ( result_json_path ) and os . path . getsize ( result_json_path ) ) ) : #NEWLINE# #INDENT# logger . info ( 'Running in resume mode and %s exists, so skipping job.' , result_json_path ) #NEWLINE# continue #NEWLINE# #UNINDENT# job_args = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# job_args [ 'experiment_name' ] = experiment_name #NEWLINE# job_args [ 'task' ] = task #NEWLINE# job_args [ 'sampler' ] = sampler #NEWLINE# job_args [ 'feature_hasher' ] = feature_hasher #NEWLINE# job_args [ 'hasher_features' ] = hasher_features #NEWLINE# job_args [ 'job_name' ] = job_name #NEWLINE# job_args [ 'featureset' ] = featureset #NEWLINE# job_args [ 'featureset_name' ] = featureset_name #NEWLINE# job_args [ 'learner_name' ] = grid_search_folds #NEWLINE# job_args [ 'train_path' ] = train_path #NEWLINE# job_args [ 'test_path' ] = test_path #NEWLINE# job_args [ 'train_set_name' ] = train_set_name #NEWLINE# job_args [ 'test_set_name' ] = test_set_name #NEWLINE# job_args [ 'shuffle' ] = do_shuffle #NEWLINE# job_args [ 'model_path' ] = model_path #NEWLINE# job_args [ 'prediction_prefix' ] = prediction_prefix #NEWLINE# job_args [ 'grid_search' ] = do_grid_search #NEWLINE# job_args [ 'grid_objective' ] = grid_objective #NEWLINE# job_args [ 'suffix' ] = suffix #NEWLINE# job_args [ 'log_path' ] = temp_logfile #NEWLINE# job_args [ 'probability' ] = probability #NEWLINE# job_args [ 'results_path' ] = results_path #NEWLINE# job_args [ 'sampler_parameters' ] = ( fixed_sampler_parameters if fixed_sampler_parameters else dict ( ) ) #NEWLINE# job_args [ 'fixed_parameters' ] = ( fixed_parameter_list [ learner_num ] if fixed_parameter_list else dict ( ) ) #NEWLINE# job_args [ 'param_grid' ] = ( param_grid_list [ learner_num ] if param_grid_list else None ) #NEWLINE# job_args [ 'pos_label_str' ] = pos_label_str #NEWLINE# job_args [ 'overwrite' ] = overwrite #NEWLINE# job_args [ 'feature_scaling' ] = feature_scaling #NEWLINE# job_args [ 'min_feature_count' ] = min_feature_count #NEWLINE# job_args [ 'grid_search_jobs' ] = grid_search_jobs #NEWLINE# job_args [ 'grid_search_folds' ] = grid_search_folds #NEWLINE# job_args [ 'cv_folds' ] = cv_folds #NEWLINE# job_args [ 'save_cv_folds' ] = save_cv_folds #NEWLINE# job_args [ 'do_stratified_folds' ] = do_stratified_folds #NEWLINE# job_args [ 'label_col' ] = label_col #NEWLINE# job_args [ 'id_col' ] = id_col #NEWLINE# job_args [ 'ids_to_floats' ] = ids_to_floats #NEWLINE# job_args [ 'quiet' ] = quiet #NEWLINE# job_args [ 'class_map' ] = class_map #NEWLINE# job_args [ 'custom_learner_path' ] = custom_learner_path #NEWLINE# if ( not local ) : #NEWLINE# #INDENT# jobs . append ( Job ( _classify_featureset , [ job_args ] , num_slots = ( MAX_CONCURRENT_PROCESSES if do_grid_search else 1 ) , name = job_name , queue = queue ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# _classify_featureset ( job_args ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# test_set_name = basename ( test_path ) #NEWLINE# if ( ( not local ) and _HAVE_GRIDMAP ) : #NEWLINE# #INDENT# if log_path : #NEWLINE# #INDENT# job_results = process_jobs ( jobs , white_list = hosts , temp_dir = log_path ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# job_results = process_jobs ( jobs , white_list = hosts ) #NEWLINE# #UNINDENT# _check_job_results ( job_results ) #NEWLINE# #UNINDENT# if ( ( ( task == 'cross_validate' ) or ( task == 'evaluate' ) ) and write_summary ) : #NEWLINE# #INDENT# summary_file_name = ( experiment_name + '_summary.tsv' ) #NEWLINE# file_mode = ( 'w' if ( sys . version_info >= ( 3 , 0 ) ) else 'wb' ) #NEWLINE# with open ( join ( results_path , summary_file_name ) , file_mode ) as output_file : #NEWLINE# #INDENT# _write_summary_file ( result_json_paths , output_file , ablation = ablation ) #NEWLINE# #UNINDENT# #UNINDENT# return result_json_paths