#NEWLINE# @ borg . annotations ( out_path = 'results CSV output path' , runs = ( 'path to JSON runs specification' , 'positional' , None , borg . util . load_json ) , repeats = ( 'number of times to repeat each run' , 'option' , None , int ) , workers = ( 'submit jobs?' , 'option' , 'w' , int ) , local = ( 'workers are local?' , 'flag' ) ) #NEWLINE# def main( out_path , runs , repeats = 5 , workers = 0 , local = False ) : #NEWLINE# #INDENT# 'Simulate portfolio and solver behavior.' #NEWLINE# logger . info ( 'simulating %i runs' , ( len ( runs ) * repeats ) ) #NEWLINE# get_run_data = borg . util . memoize ( borg . storage . RunData . from_bundle ) #NEWLINE# def yield_jobs( ) : #NEWLINE# #INDENT# for run in runs : #NEWLINE# #INDENT# train_data = get_run_data ( run [ 'train_bundle' ] ) #NEWLINE# if run . get ( 'only_nontrivial' , False ) : #NEWLINE# #INDENT# train_data = train_data . only_nontrivial ( ) #NEWLINE# #UNINDENT# if ( run [ 'test_bundle' ] == '-' ) : #NEWLINE# #INDENT# validation = sklearn . cross_validation . KFold ( len ( train_data ) , repeats , indices = False ) #NEWLINE# data_sets = [ ( train_data . masked ( v ) , train_data . masked ( e ) ) for ( v , e ) in validation ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# test_data = get_run_data ( run [ 'test_bundle' ] ) #NEWLINE# if run . get ( 'only_nontrivial' , False ) : #NEWLINE# #INDENT# test_data = test_data . only_nontrivial ( ) #NEWLINE# #UNINDENT# data_sets = ( [ ( train_data , test_data ) ] * repeats ) #NEWLINE# #UNINDENT# if ( run [ 'portfolio_name' ] == '-' ) : #NEWLINE# #INDENT# makers = map ( SolverMaker , train_data . solver_names ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# makers = [ PortfolioMaker ( run [ 'portfolio_name' ] ) ] #NEWLINE# #UNINDENT# for maker in makers : #NEWLINE# #INDENT# for ( train_fold_data , test_fold_data ) in data_sets : #NEWLINE# #INDENT# ( yield ( simulate_run , [ run , maker , train_fold_data , test_fold_data ] ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# with borg . util . openz ( out_path , 'wb' ) as out_file : #NEWLINE# #INDENT# writer = csv . writer ( out_file ) #NEWLINE# writer . writerow ( [ 'category' , 'solver' , 'budget' , 'cost' , 'success' , 'split' ] ) #NEWLINE# for ( _ , rows ) in condor . do ( yield_jobs ( ) , workers , yield_jobs ) : #NEWLINE# #INDENT# writer . writerows ( rows ) #NEWLINE# out_file . flush ( )