Beispiel #1
0
def main():
    parser = argparse.ArgumentParser(
        description='Executes LeapsAndBounds with a simulated environment.')
    parser.add_argument('--epsilon',
                        help='Epsilon from the paper',
                        type=float,
                        default=0.2)
    parser.add_argument('--delta',
                        help='Delta from the paper',
                        type=float,
                        default=0.2)
    parser.add_argument('--zeta',
                        help='Zeta from the paper',
                        type=float,
                        default=0.1)
    parser.add_argument('--k0',
                        help='Kappa_0 from the paper',
                        type=float,
                        default=1.)
    parser.add_argument('--theta-multiplier',
                        help='Theta multiplier from the paper',
                        type=float,
                        default=1.25)
    parser.add_argument('--measurements-filename',
                        help='Filename to load measurement results from',
                        type=str,
                        default='measurements.dump')
    parser.add_argument('--measurements-timeout',
                        help='Timeout (seconds) used for the measurements',
                        type=float,
                        default=900.)
    args = vars(parser.parse_args())

    epsilon = args['epsilon']
    delta = args['delta']
    zeta = args['zeta']
    k0 = args['k0']
    theta_multiplier = args['theta_multiplier']
    results_file = args['measurements_filename']
    timeout = args['measurements_timeout']

    env = simulated_environment.Environment(results_file, timeout)
    num_configs = env.get_num_configs()
    best_config_index, capped_avg, tau = leaps_and_bounds(
        env, num_configs, epsilon, delta, zeta, k0, theta_multiplier)
    print('best_config_index={}, capped_avg={}, tau={}'.format(
        best_config_index, capped_avg, tau))
    env.print_config_stats(best_config_index, tau=tau)

    def format_runtime(runtime):
        return '{}s = {}m = {}h = {}d'.format(runtime, runtime / 60,
                                              runtime / 3600,
                                              runtime / (3600 * 24))

    print('total runtime: ' + format_runtime(env.get_total_runtime()))
    print('total resumed runtime: ' +
          format_runtime(env.get_total_resumed_runtime()))
Beispiel #2
0
def main(epsilon, delta):
    parser = argparse.ArgumentParser(
        description='Executes LeapsAndBounds with a simulated environment.')
    parser.add_argument('--zeta',
                        help='Zeta from the paper',
                        type=float,
                        default=0.1)
    parser.add_argument('--k0',
                        help='Kappa_0 from the paper',
                        type=float,
                        default=1.)
    parser.add_argument('--theta-multiplier',
                        help='Theta multiplier from the paper',
                        type=float,
                        default=1.25)
    parser.add_argument('--measurements-filename',
                        help='Filename to load measurement results from',
                        type=str,
                        default='measurements.dump')
    parser.add_argument('--measurements-timeout',
                        help='Timeout (seconds) used for the measurements',
                        type=float,
                        default=900.)
    args = vars(parser.parse_args())

    zeta = args['zeta']
    k0 = args['k0']
    theta_multiplier = args['theta_multiplier']
    results_file = args['measurements_filename']
    timeout = args['measurements_timeout']

    try:
        os.mkdir('results')
    except OSError:
        pass

    print("creating simulated environment")
    env = simulated_environment.Environment(results_file, timeout)
    num_configs = env.get_num_configs()

    print("running leaps_and_bounds")
    best_config_index, capped_avg, tau = leaps_and_bounds(
        env, num_configs, epsilon, delta, zeta, k0, theta_multiplier)
    print('best_config_index={}, capped_avg={}, tau={}'.format(
        best_config_index, capped_avg, tau))
    env.print_config_stats(best_config_index, tau=tau)
    print('total runtime: ' + format_runtime(env.get_total_runtime()))
    print('total resumed runtime: ' +
          format_runtime(env.get_total_resumed_runtime()))

    return best_config_index, env.get_total_runtime(
    ), env.get_total_resumed_runtime()
Beispiel #3
0
def main(epsilon, deltas):
    parser = argparse.ArgumentParser(description='Executes Structured Procrastination with a simulated environment.')
    parser.add_argument('--epsilon', help='Epsilon from the paper', type=float, default=0.1)
    # parser.add_argument('--delta', help='Delta from the paper', type=float, default=0.2)
    parser.add_argument('--zeta', help='Zeta from the paper', type=float, default=0.1)
    parser.add_argument('--k0', help='Kappa_0 from the paper', type=float, default=1.)
    parser.add_argument('--k-bar', help='bar{Kappa} from the paper', type=float, default=1000000.)
    parser.add_argument('--theta-multiplier', help='Theta multiplier from the paper', type=float, default=2.0)
    parser.add_argument('--measurements-filename', help='Filename to load measurement results from', type=str, default='measurements.dump')
    parser.add_argument('--measurements-timeout', help='Timeout (seconds) used for the measurements', type=float, default=900.)
    parser.add_argument('--total-time-budget', help='Total time (seconds) allowed', type=float, default=2160000000.)  # 86400 seconds = 1 CPU day; 103680000 == 1200 CPU days
    args = vars(parser.parse_args())

    # epsilon = args['epsilon']
    # delta = args['delta']
    zeta = args['zeta']
    k0 = args['k0']
    k_bar = args['k_bar']
    theta_multiplier = args['theta_multiplier']
    results_file = args['measurements_filename']
    timeout = args['measurements_timeout']
    total_time_budget = args['total_time_budget']

    try: os.mkdir('results')
    except OSError: pass

    print("creating simulated environment")
    env = simulated_environment.Environment(results_file, timeout)
    num_configs = env.get_num_configs()

    print("running structured_procrastination")

    step_size = int(day_in_seconds)  # CPU day, in second
    stop_times = list(range(step_size, 10 * int(day_in_seconds), step_size)) + list(range(10 * int(day_in_seconds), int(total_time_budget) + 1, 10 * step_size))  # check results at 1,2,3,..,9,10,20,30,... CPU days

    best_config_index, delta = structured_procrastination(env, num_configs, epsilon, zeta, k0, k_bar, theta_multiplier, stop_times, deltas)

    print('best_config_index={}, delta={}'.format(best_config_index, delta))
    env.print_config_stats(best_config_index)

    print('total runtime: ' + format_runtime(env.get_total_runtime()))
    print('total resumed runtime: ' + format_runtime(env.get_total_resumed_runtime()))
def main():
    parser = argparse.ArgumentParser(
        description=
        'Executes Structured Procrastination with Confidence with a simulated environment.'
    )
    parser.add_argument('--k0',
                        help='Kappa_0 from the paper',
                        type=float,
                        default=1.)
    parser.add_argument('--theta-multiplier',
                        help='Theta multiplier from the paper',
                        type=float,
                        default=2.)
    parser.add_argument('--measurements-filename',
                        help='Filename to load measurement results from',
                        type=str,
                        default='measurements.dump')
    parser.add_argument('--measurements-timeout',
                        help='Timeout (seconds) used for the measurements',
                        type=float,
                        default=900.)
    parser.add_argument('--total_time_budget',
                        help='Total time (seconds) allowed',
                        type=float,
                        default=24. * 60. * 60. * 2700.)  # 2700 CPU days;
    args = vars(parser.parse_args())

    k0 = args['k0']
    theta_multiplier = args['theta_multiplier']
    results_file = args['measurements_filename']
    timeout = args['measurements_timeout']
    total_time_budget = args['total_time_budget']

    try:
        os.mkdir('results')
    except OSError:
        pass

    print("creating simulated environment")
    env = simulated_environment.Environment(results_file, timeout)
    num_configs = env.get_num_configs()

    print("running structured_procrastination_confidence")

    step_size = int(day_in_seconds)  # CPU day, in second
    # stop_times = list(range(step_size, 10 * int(day_in_seconds), step_size)) + list(range(10 * int(day_in_seconds), int(total_time_budget) + 1, 10 * step_size))  # check results at 1,2,3,..,9,10,20,30,... CPU days
    stop_times = list(range(
        step_size, 10 * int(day_in_seconds) + 1, step_size)) + list(
            range(50 * int(day_in_seconds),
                  int(total_time_budget) + 1, 50 * step_size)
        )  # check results at 1,2,3,..,9,10,50,100,150,... CPU days

    t0 = time.time()
    best_config_index, configs = structured_procrastination_confidence(
        env, num_configs, k0, theta_multiplier, total_time_budget, stop_times)
    t1 = time.time()

    print("")
    print("for total_time_budget={}".format(total_time_budget))
    print('best_config_index={}'.format(best_config_index))

    print("")
    print('total runtime: ' + format_runtime(env.get_total_runtime()))
    print('total resumed runtime: ' +
          format_runtime(env.get_total_resumed_runtime()))

    print("")
    print("Total real time to run: {}".format(t1 - t0))
Beispiel #5
0
def plot_results():

    parser = argparse.ArgumentParser(description='Plots the saved results from the configuration procedures.')
    parser.add_argument('--measurements-timeout', help='Timeout (seconds) used for the measurements', type=float, default=900.)
    args = vars(parser.parse_args())

    timeout = args['measurements_timeout']

    try:
        with open(os.path.join('results', 'results_lb_grid.p'), 'rb') as f:
            results_lb = pickle.load(f)
    except IOError as err:
        print(err, "no lb results saved")
        return

    try:
        with open(os.path.join('results', 'results_sp_grid.p'), 'rb') as f:
            results_sp = pickle.load(f)
    except IOError as err:
        print(err, "no sp results saved")
        return

    try:
        with open(os.path.join('results', 'results_spc.p'), 'rb') as f:
            results_spc = pickle.load(f)
    except IOError as err:
        print(err, "no spc results saved")
        return

    try:
        with open(os.path.join('results', 'means_uncap.p'), 'rb') as f:
            means_uncap = pickle.load(f)
    except IOError:
        env = simulated_environment.Environment('measurements.dump', timeout)
        results = env.get_results()
        results_uncap = [[timeout if x > timeout else x for x in res] for res in results]
        means_uncap = [np.mean(res) for res in results_uncap]
        with open(os.path.join('results', 'means_uncap.p'), 'wb') as f:
            pickle.dump(means_uncap, f)

    best_config_means_lb = [means_uncap[res['best_config']] for res in results_lb]
    times_lb = [res['total_runtime'] / day_in_seconds for res in results_lb]

    best_config_means_sp = [means_uncap[res['best_config']] for res in results_sp]
    times_sp = [res['total_runtime'] / day_in_seconds for res in results_sp]

    best_config_means_spc = [means_uncap[res['best_config']] for res in results_spc]
    times_spc = [res['total_runtime'] / day_in_seconds for res in results_spc]

    colours_lb = [5. * config['delta'] ** 4 for config in results_lb]
    sizes_lb = [150. * config['epsilon'] for config in results_lb]

    colours_sp = [5. * config['best_config_delta'] ** 4 for config in results_sp]
    sizes_sp = [150. * config['epsilon'] for config in results_sp]

    fig, (ax1) = plt.subplots(1, 1, figsize=(10, 6))
    plt.rcParams.update({'font.size': 23})

    ax1.plot(times_spc, best_config_means_spc, '.-', color='mediumblue', alpha=.5, label="SPC", linewidth=2, markersize=5)
    ax1.scatter(times_lb, best_config_means_lb, color='maroon', alpha=.5, c=colours_lb, cmap=plt.cm.get_cmap('Reds'), s=sizes_lb, label="LB")
    ax1.scatter(times_sp, best_config_means_sp, color='green', alpha=.7, c=colours_sp, cmap=plt.cm.get_cmap('Greens'), s=sizes_sp, label="SP")

    opt = min(means_uncap)
    del_max = ax1.scatter(-1000, opt, color='lightcoral', alpha=.8)  # dummy points off plot to force legend style
    del_min = ax1.scatter(-1000, opt, color='maroon', alpha=.1)
    eps_min = ax1.scatter(-1000, opt, color='maroon', alpha=.4, s=np.min([2. * (1. / config['epsilon'])**2 for config in results_lb]))
    eps_max = ax1.scatter(-1000, opt, color='maroon', alpha=.4, s=np.max([1.5 * (1. / config['epsilon'])**2 for config in results_lb]))
    ax1.axhline(opt, linestyle='--', color='dodgerblue', label="OPT", linewidth=1)
    # ax1.set_title("Mean runtime of sol'n returned \n(capped at max cap)")
    ax1.set_xlabel("CPU days")
    ax1.set_ylabel("Mean runtime")
    plt.xscale('log')
    # plt.xticks([1] + [300 * i for i in range(1, 9)])
    ax1.set_xlim(0, 3500)
    ax1.set_ylim(19, 21.7)
    ax1.locator_params(axis='y', nbins=8)

    handles, labels = ax1.get_legend_handles_labels()
    handles[1], handles[2], handles[3] = handles[2], handles[3], handles[1]
    labels[1], labels[2], labels[3] = labels[2], labels[3], labels[1]
    legend1 = plt.legend(handles, labels, loc=(.724, .751), prop={'size':11.6})
    plt.gca().add_artist(legend1)
    legend2 = plt.legend([eps_min, eps_max, del_min, del_max], [r"$\epsilon={}$".format(0.1), r"$\epsilon={}$".format(0.9), r"$\delta={}$".format(0.1), r"$\delta={}$".format(0.5),], loc=(.846,.7515), prop={'size': 11.5})

    rect = patches.Rectangle((346, 21), 2750, 0.63, linewidth=1 ,facecolor='none')
    ax1.add_patch(rect)

    plt.savefig('img/mean_plot.pdf', bbox_inches='tight')
    plt.clf()