<s> import adddeps <EOL> import argparse <EOL> import logging <EOL> import opentuner <EOL> from opentuner . measurement import MeasurementInterface <EOL> from opentuner . search . manipulator import ConfigurationManipulator <EOL> from opentuner . search . manipulator import FloatParameter <EOL> log = logging . getLogger ( __name__ ) <EOL> parser = argparse . ArgumentParser ( parents = opentuner . argparsers ( ) ) <EOL> parser . add_argument ( '<STR_LIT>' , type = int , default = <NUM_LIT:2> , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , type = float , default = <NUM_LIT:1000> , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , default = '<STR_LIT>' , <EOL> choices = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> help = '<STR_LIT>' ) <EOL> class Rosenbrock ( MeasurementInterface ) : <EOL> def run ( self , desired_result , input , limit ) : <EOL> cfg = desired_result . configuration . data <EOL> val = <NUM_LIT:0.0> <EOL> if self . args . function == '<STR_LIT>' : <EOL> for d in xrange ( self . args . dimensions - <NUM_LIT:1> ) : <EOL> x0 = cfg [ d ] <EOL> x1 = cfg [ d + <NUM_LIT:1> ] <EOL> val += <NUM_LIT> * ( x1 - x0 ** <NUM_LIT:2> ) ** <NUM_LIT:2> + ( x0 - <NUM_LIT:1> ) ** <NUM_LIT:2> <EOL> elif self . args . function == '<STR_LIT>' : <EOL> for d in xrange ( self . args . dimensions ) : <EOL> xi = cfg [ d ] <EOL> val += xi ** <NUM_LIT:2> <EOL> elif self . args . function == '<STR_LIT>' : <EOL> assert self . args . dimensions == <NUM_LIT:2> <EOL> assert self . args . domain == <NUM_LIT> <EOL> x = cfg [ <NUM_LIT:0> ] <EOL> y = cfg [ <NUM_LIT:1> ] <EOL> val = ( ( <NUM_LIT> - x + x * y ) ** <NUM_LIT:2> + <EOL> ( <NUM_LIT> - x + x * y ** <NUM_LIT:2> ) ** <NUM_LIT:2> + <EOL> ( <NUM_LIT> - x + x * y ** <NUM_LIT:3> ) ** <NUM_LIT:2> ) <EOL> return opentuner . resultsdb . models . Result ( time = val ) <EOL> def manipulator ( self ) : <EOL> manipulator = ConfigurationManipulator ( ) <EOL> for d in xrange ( self . args . dimensions ) : <EOL> manipulator . add_parameter ( FloatParameter ( d , <EOL> - self . args . domain , <EOL> self . args . domain ) ) <EOL> return manipulator <EOL> def program_name ( self ) : <EOL> return self . args . function <EOL> def program_version ( self ) : <EOL> return "<STR_LIT>" % ( self . args . dimensions , self . args . domain ) <EOL> def save_final_config ( self , configuration ) : <EOL> """<STR_LIT>""" <EOL> print "<STR_LIT>" , configuration . data <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> args = parser . parse_args ( ) <EOL> if args . function == '<STR_LIT>' : <EOL> args . domain = <NUM_LIT> <EOL> args . dimensions = <NUM_LIT:2> <EOL> Rosenbrock . main ( args ) </s>
