#NEWLINE# def search_plan( sym , ntrial = 6 , **kwargs ) : #NEWLINE# #INDENT# 'Quickly heurestic search over possible plans to find good memory plan.\n\n    Parameters\n    ----------\n    sym : symbolic\n       Symbolic configurations\n\n    ntrial: integer\n       Additional grid search steps\n    ' #NEWLINE# history = [ ] #NEWLINE# threshold = 0 #NEWLINE# min_threshold = None #NEWLINE# min_cost = None #NEWLINE# nbegin = 3 #NEWLINE# for k in range ( nbegin ) : #NEWLINE# #INDENT# info = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# sym = make_mirror_plan ( sym , threshold = threshold , plan_info = info , ** kwargs ) #NEWLINE# cost = get_cost ( sym , ** kwargs ) #NEWLINE# save_size = ( info [ 'save_size' ] >> 20 ) #NEWLINE# local_size = ( info [ 'max_size' ] >> 20 ) #NEWLINE# guess = int ( math . sqrt ( ( ( save_size * local_size ) / 2 ) ) ) #NEWLINE# if ( ( min_cost is None ) or ( min_cost > cost ) ) : #NEWLINE# #INDENT# min_cost = cost #NEWLINE# #UNINDENT# if ( ( min_threshold is None ) or ( local_size < min_threshold ) ) : #NEWLINE# #INDENT# min_threshold = local_size #NEWLINE# #UNINDENT# print ( ( 'Search threshold=%d MB, cost=%d MB' % ( threshold , cost ) ) ) #NEWLINE# history . append ( ( cost , threshold , sym ) ) #NEWLINE# threshold = guess #NEWLINE# #UNINDENT# max_threshold = ( threshold * math . sqrt ( 2 ) ) #NEWLINE# step = int ( ( ( max_threshold - min_threshold ) / ntrial ) ) #NEWLINE# threshold = ( min_threshold + step ) #NEWLINE# if ( step > 0 ) : #NEWLINE# #INDENT# for k in range ( ntrial ) : #NEWLINE# #INDENT# sym = make_mirror_plan ( sym , threshold = threshold , plan_info = info , ** kwargs ) #NEWLINE# cost = get_cost ( sym , ** kwargs ) #NEWLINE# print ( ( 'Search threshold=%d MB, cost=%d MB' % ( threshold , cost ) ) ) #NEWLINE# history . append ( ( cost , threshold , sym ) ) #NEWLINE# threshold += step #NEWLINE# #UNINDENT# #UNINDENT# history . sort ( key = ( lambda x : x [ 0 ] ) ) #NEWLINE# ( cost , threshold , sym ) = threshold [ 0 ] #NEWLINE# print ( ( 'Find best plan with threshold=%d, cost=%d MB' % ( threshold , cost ) ) ) #NEWLINE# return sym