def objective(space): #This function will be unpickled by hyperopt and we need to reimport everythinng for it to work import time from hyperopt import STATUS_OK, STATUS_FAIL import random import sys import launch import evaluate_forget import math import os from hyperopt_tests.support.launch_cartpole import launch_cartpole import hyperopt_tests os.path.dirname(hyperopt_tests.__file__) #we cheat to get the directory of the parameters file. we find the directory of the hyperopt_tests import cwd = os.path.dirname(hyperopt_tests.__file__) paramsfile_relative = '../params/cartpole_nn_hyperopt_params.py' paramsfile = os.path.abspath(os.path.join(cwd, paramsfile_relative)) params = space #since hyperopt is ran from somewhere else, set the results directory correctly for saving results params['results_dir'] = os.path.abspath(os.path.join(cwd, '../results/')) + '/' #set any parameteers here to override the parameters in the params file params['simname'] = 'cartpole_hyperopt_nn_initialtest1' #Give each run a random unique identifier for the version. This allows us to locate any saved results via a signature in the filename rnd_str = '_' for i in range(12): rnd_str += random.choice('ABCDEFGHIJKLMNOPQRSTUVWXYZ') params['version'] = rnd_str t = time.time() #TODO? Maybe catch exceptions and set status to failed if the occur? #try: (obj, argmin) = launch_cartpole(paramsfile, params) print('obj: ' + str(obj) + ' argmin: ' + str(argmin)) return { 'loss': obj, 'argmin': str(argmin), 'status': STATUS_OK, 'eval_time': str(time.time() - t), 'rnd_str': rnd_str #any additional logging goes here # 'attachments': # {'stdout' : str(stdout), # 'stderr' : str(stderr), # 'params' : str(params)} }
def objective(space): #This function will be unpickled by hyperopt and we need to reimport everythinng for it to work import time from hyperopt import STATUS_OK, STATUS_FAIL import random import sys import launch import evaluate_forget import math import os from hyperopt_tests.support.launch_cartpole import launch_cartpole import hyperopt_tests os.path.dirname(hyperopt_tests.__file__) #we cheat to get the directory of the parameters file. we find the directory of the hyperopt_tests import cwd = os.path.dirname(hyperopt_tests.__file__) paramsfile_relative = '../params/cartpole_nn_hyperopt_params.py' paramsfile = os.path.abspath(os.path.join(cwd,paramsfile_relative)) params = space #since hyperopt is ran from somewhere else, set the results directory correctly for saving results params['results_dir'] = os.path.abspath(os.path.join(cwd,'../results/')) + '/' #set any parameteers here to override the parameters in the params file params['simname'] = 'cartpole_hyperopt_nn_initialtest3' #Give each run a random unique identifier for the version. This allows us to locate any saved results via a signature in the filename rnd_str = '_' for i in range(12): rnd_str += random.choice('ABCDEFGHIJKLMNOPQRSTUVWXYZ') params['version'] = rnd_str t = time.time() #TODO? Maybe catch exceptions and set status to failed if the occur? #try: (obj,argmin) = launch_cartpole(paramsfile,params) print('obj: ' + str(obj) + ' argmin: ' + str(argmin)) return { 'loss' : obj, 'argmin' : str(argmin), 'status' : STATUS_OK, 'eval_time': str(time.time() - t), 'rnd_str' : rnd_str #any additional logging goes here # 'attachments': # {'stdout' : str(stdout), # 'stderr' : str(stderr), # 'params' : str(params)} }
def objective(space): # This function will be unpickled by hyperopt and we need to reimport everythinng for it to work import time from hyperopt import STATUS_OK, STATUS_FAIL import random import sys import math import os from hyperopt_tests.support.launch_cartpole import launch_cartpole import hyperopt_tests os.path.dirname(hyperopt_tests.__file__) # we cheat to get the directory of the parameters file. we find the directory of the hyperopt_tests import cwd = os.path.dirname(hyperopt_tests.__file__) paramsfile_relative = "../params/cartpole_nn_clusterfunc_hyperopt_params.py" paramsfile = os.path.abspath(os.path.join(cwd, paramsfile_relative)) params = space # since hyperopt is ran from somewhere else, set the results directory correctly for saving results params["results_dir"] = os.path.abspath(os.path.join(cwd, "../newton_results/")) + "/" # set any parameteers here to override the parameters in the params file params["simname"] = "cartpole_hyperopt_nn_clustertest_again" # Give each run a random unique identifier for the version. This allows us to locate any saved results via a signature in the filename rnd_str = "_" for i in range(12): rnd_str += random.choice("ABCDEFGHIJKLMNOPQRSTUVWXYZ") params["version"] = rnd_str t = time.time() # TODO? Maybe catch exceptions and set status to failed if the occur? # try: (obj, argmin) = launch_cartpole(paramsfile, params) print("obj: " + str(obj) + " argmin: " + str(argmin)) return { "loss": obj, "argmin": str(argmin), "status": STATUS_OK, "eval_time": str(time.time() - t), "rnd_str": rnd_str # any additional logging goes here # 'attachments': # {'stdout' : str(stdout), # 'stderr' : str(stderr), # 'params' : str(params)} }