luinardi / hypermapper

Black-box Optimizer based on Bayesian Optimization
MIT License
154 stars 26 forks source link

Converge problem #78

Closed peterhchen closed 1 year ago

peterhchen commented 2 years ago

Below is the python file hm_placer.py and placer_scenario.json fior benche mark Hypermmaper and OpenTuner. OpenTuner converge very fast. Hypermapper takes 7+ days to run and cannot get the answer. Please improve the hypermapper performance.

""" File Name: hm_placer.py Description: Usage:

python hm_placer.py Created by Peter Hanping Chen (7/16/2022) """

!/usr/bin/python

import math

import os import sys

import warnings

from collections import OrderedDict

ensure backward compatibility

from hypermapper import optimizer # noqa MIN_NUM = sys.float_info.max HM_CNT = 0

def compute_function(x_in): """ Description: Input: 20 features and randomly selected vector values from 64 feature vectors. Values: 20 target values. Calculate the penalty based on the input. :param x_in: dictionary containing the input points. :return: the value of the objective function. """ global MIN_NUM global HM_CNT penalty = 0

Drive all parameters to their 10th value in the categorical space

values = \
    [10, 10, 10, 10, 10,
    10, 10, 10, 10, 10,
    10, 10, 10, 10, 10,
    10, 10, 10, 10, 10]
print("==> x_in:")
print(x_in)            # {'0': '49', '1': '28', ..., '19': '15'} 
parameters = []
for _, value in x_in.items():
    parameters.append(value)
print('==>parameters:')
print(parameters)      # ['49', '28', ..., '15'}
for p_in, t_val in zip(parameters, values): # twenty 10s
    print('p:', p_in)  # 49, 28, 18, 24, ...
    print('t:', t_val) # 10, 10, 10, ..., 10
    penalty += abs(int(p_in)-t_val)
    print('penalty:', penalty)  # 39, 57, 65, 97, 108, 154, ...
#distance = - penalty / len(parameters)
distance = penalty / len(parameters)
print('len(parameters):', len(parameters)) # 20
print('distancey:', distance)  # 21.0, ..., 8.2, 7.1, 7.25
HM_CNT += 1
if distance < MIN_NUM:
    print("HM_CNT:", HM_CNT)
    print("MIN_NUM:", MIN_NUM)
    MIN_NUM = distance

return distance

def main(): """ Description:

  1. Read scenario file
  2. Call Hypermapper optimization function. """ parameters_file = "./placer_scenario.json"

    optimizer.optimize(parameters_file, branin4_function)

    optimizer.optimize(parameters_file, compute_function) print("End of test.")

if name == "main": main()

{ "application_name": "Scenaiofile for rs_5000_ro_5000", "optimization_objectives": ["distance"], "log_file": "hm_placer_min.log", "output_data_file": "hm_placer_min.csv", "design_of_experiment": { "doe_type": "random sampling", "number_of_samples": 5000 }, "optimization_iterations": 5000, "input_parameters" : { "0": { "parameter_type": "categorical", "values": ["0", "1", "2", "3" , "4", "5", "6", "7", "8", "9", "10", "11", "12", "13" , "14", "15", "16", "17", "18", "19", "20", "21", "22", "23" , "24", "25", "26", "27", "28", "29", "30", "31", "32", "33" , "34", "35", "36", "37", "38", "39", "40", "41", "42", "43" , "44", "45", "46", "47", "48", "49", "50", "51", "52", "53" , "54", "55", "56", "57", "58", "59", "60", "61", "62", "63"] }, "1": { "parameter_type": "categorical", "values": ["0", "1", "2", "3" , "4", "5", "6", "7", "8", "9", "10", "11", "12", "13" , "14", "15", "16", "17", "18", "19", "20", "21", "22", "23" , "24", "25", "26", "27", "28", "29", "30", "31", "32", "33" , "34", "35", "36", "37", "38", "39", "40", "41", "42", "43" , "44", "45", "46", "47", "48", "49", "50", "51", "52", "53" , "54", "55", "56", "57", "58", "59", "60", "61", "62", "63"] }, "2": { "parameter_type": "categorical", "values": ["0", "1", "2", "3" , "4", "5", "6", "7", "8", "9", "10", "11", "12", "13" , "14", "15", "16", "17", "18", "19", "20", "21", "22", "23" , "24", "25", "26", "27", "28", "29", "30", "31", "32", "33" , "34", "35", "36", "37", "38", "39", "40", "41", "42", "43" , "44", "45", "46", "47", "48", "49", "50", "51", "52", "53" , "54", "55", "56", "57", "58", "59", "60", "61", "62", "63"] }, "3": { "parameter_type": "categorical", "values": ["0", "1", "2", "3" , "4", "5", "6", "7", "8", "9", "10", "11", "12", "13" , "14", "15", "16", "17", "18", "19", "20", "21", "22", "23" , "24", "25", "26", "27", "28", "29", "30", "31", "32", "33" , "34", "35", "36", "37", "38", "39", "40", "41", "42", "43" , "44", "45", "46", "47", "48", "49", "50", "51", "52", "53" , "54", "55", "56", "57", "58", "59", "60", "61", "62", "63"] }, "4": { "parameter_type": "categorical", "values": ["0", "1", "2", "3" , "4", "5", "6", "7", "8", "9", "10", "11", "12", "13" , "14", "15", "16", "17", "18", "19", "20", "21", "22", "23" , "24", "25", "26", "27", "28", "29", "30", "31", "32", "33" , "34", "35", "36", "37", "38", "39", "40", "41", "42", "43" , "44", "45", "46", "47", "48", "49", "50", "51", "52", "53" , "54", "55", "56", "57", "58", "59", "60", "61", "62", "63"] }, "5": { "parameter_type": "categorical", "values": ["0", "1", "2", "3" , "4", "5", "6", "7", "8", "9", "10", "11", "12", "13" , "14", "15", "16", "17", "18", "19", "20", "21", "22", "23" , "24", "25", "26", "27", "28", "29", "30", "31", "32", "33" , "34", "35", "36", "37", "38", "39", "40", "41", "42", "43" , "44", "45", "46", "47", "48", "49", "50", "51", "52", "53" , "54", "55", "56", "57", "58", "59", "60", "61", "62", "63"] }, "6": { "parameter_type": "categorical", "values": ["0", "1", "2", "3" , "4", "5", "6", "7", "8", "9", "10", "11", "12", "13" , "14", "15", "16", "17", "18", "19", "20", "21", "22", "23" , "24", "25", "26", "27", "28", "29", "30", "31", "32", "33" , "34", "35", "36", "37", "38", "39", "40", "41", "42", "43" , "44", "45", "46", "47", "48", "49", "50", "51", "52", "53" , "54", "55", "56", "57", "58", "59", "60", "61", "62", "63"] }, "7": { "parameter_type": "categorical", "values": ["0", "1", "2", "3" , "4", "5", "6", "7", "8", "9", "10", "11", "12", "13" , "14", "15", "16", "17", "18", "19", "20", "21", "22", "23" , "24", "25", "26", "27", "28", "29", "30", "31", "32", "33" , "34", "35", "36", "37", "38", "39", "40", "41", "42", "43" , "44", "45", "46", "47", "48", "49", "50", "51", "52", "53" , "54", "55", "56", "57", "58", "59", "60", "61", "62", "63"] }, "8": { "parameter_type": "categorical", "values": ["0", "1", "2", "3" , "4", "5", "6", "7", "8", "9", "10", "11", "12", "13" , "14", "15", "16", "17", "18", "19", "20", "21", "22", "23" , "24", "25", "26", "27", "28", "29", "30", "31", "32", "33" , "34", "35", "36", "37", "38", "39", "40", "41", "42", "43" , "44", "45", "46", "47", "48", "49", "50", "51", "52", "53" , "54", "55", "56", "57", "58", "59", "60", "61", "62", "63"] }, "9": { "parameter_type": "categorical", "values": ["0", "1", "2", "3" , "4", "5", "6", "7", "8", "9", "10", "11", "12", "13" , "14", "15", "16", "17", "18", "19", "20", "21", "22", "23" , "24", "25", "26", "27", "28", "29", "30", "31", "32", "33" , "34", "35", "36", "37", "38", "39", "40", "41", "42", "43" , "44", "45", "46", "47", "48", "49", "50", "51", "52", "53" , "54", "55", "56", "57", "58", "59", "60", "61", "62", "63"] }, "10": { "parameter_type": "categorical", "values": ["0", "1", "2", "3" , "4", "5", "6", "7", "8", "9", "10", "11", "12", "13" , "14", "15", "16", "17", "18", "19", "20", "21", "22", "23" , "24", "25", "26", "27", "28", "29", "30", "31", "32", "33" , "34", "35", "36", "37", "38", "39", "40", "41", "42", "43" , "44", "45", "46", "47", "48", "49", "50", "51", "52", "53" , "54", "55", "56", "57", "58", "59", "60", "61", "62", "63"] }, "11": { "parameter_type": "categorical", "values": ["0", "1", "2", "3" , "4", "5", "6", "7", "8", "9", "10", "11", "12", "13" , "14", "15", "16", "17", "18", "19", "20", "21", "22", "23" , "24", "25", "26", "27", "28", "29", "30", "31", "32", "33" , "34", "35", "36", "37", "38", "39", "40", "41", "42", "43" , "44", "45", "46", "47", "48", "49", "50", "51", "52", "53" , "54", "55", "56", "57", "58", "59", "60", "61", "62", "63"] }, "12": { "parameter_type": "categorical", "values": ["0", "1", "2", "3" , "4", "5", "6", "7", "8", "9", "10", "11", "12", "13" , "14", "15", "16", "17", "18", "19", "20", "21", "22", "23" , "24", "25", "26", "27", "28", "29", "30", "31", "32", "33" , "34", "35", "36", "37", "38", "39", "40", "41", "42", "43" , "44", "45", "46", "47", "48", "49", "50", "51", "52", "53" , "54", "55", "56", "57", "58", "59", "60", "61", "62", "63"] }, "13": { "parameter_type": "categorical", "values": ["0", "1", "2", "3" , "4", "5", "6", "7", "8", "9", "10", "11", "12", "13" , "14", "15", "16", "17", "18", "19", "20", "21", "22", "23" , "24", "25", "26", "27", "28", "29", "30", "31", "32", "33" , "34", "35", "36", "37", "38", "39", "40", "41", "42", "43" , "44", "45", "46", "47", "48", "49", "50", "51", "52", "53" , "54", "55", "56", "57", "58", "59", "60", "61", "62", "63"] }, "14": { "parameter_type": "categorical", "values": ["0", "1", "2", "3" , "4", "5", "6", "7", "8", "9", "10", "11", "12", "13" , "14", "15", "16", "17", "18", "19", "20", "21", "22", "23" , "24", "25", "26", "27", "28", "29", "30", "31", "32", "33" , "34", "35", "36", "37", "38", "39", "40", "41", "42", "43" , "44", "45", "46", "47", "48", "49", "50", "51", "52", "53" , "54", "55", "56", "57", "58", "59", "60", "61", "62", "63"] }, "15": { "parameter_type": "categorical", "values": ["0", "1", "2", "3" , "4", "5", "6", "7", "8", "9", "10", "11", "12", "13" , "14", "15", "16", "17", "18", "19", "20", "21", "22", "23" , "24", "25", "26", "27", "28", "29", "30", "31", "32", "33" , "34", "35", "36", "37", "38", "39", "40", "41", "42", "43" , "44", "45", "46", "47", "48", "49", "50", "51", "52", "53" , "54", "55", "56", "57", "58", "59", "60", "61", "62", "63"] }, "16": { "parameter_type": "categorical", "values": ["0", "1", "2", "3" , "4", "5", "6", "7", "8", "9", "10", "11", "12", "13" , "14", "15", "16", "17", "18", "19", "20", "21", "22", "23" , "24", "25", "26", "27", "28", "29", "30", "31", "32", "33" , "34", "35", "36", "37", "38", "39", "40", "41", "42", "43" , "44", "45", "46", "47", "48", "49", "50", "51", "52", "53" , "54", "55", "56", "57", "58", "59", "60", "61", "62", "63"] }, "17": { "parameter_type": "categorical", "values": ["0", "1", "2", "3" , "4", "5", "6", "7", "8", "9", "10", "11", "12", "13" , "14", "15", "16", "17", "18", "19", "20", "21", "22", "23" , "24", "25", "26", "27", "28", "29", "30", "31", "32", "33" , "34", "35", "36", "37", "38", "39", "40", "41", "42", "43" , "44", "45", "46", "47", "48", "49", "50", "51", "52", "53" , "54", "55", "56", "57", "58", "59", "60", "61", "62", "63"] }, "18": { "parameter_type": "categorical", "values": ["0", "1", "2", "3" , "4", "5", "6", "7", "8", "9", "10", "11", "12", "13" , "14", "15", "16", "17", "18", "19", "20", "21", "22", "23" , "24", "25", "26", "27", "28", "29", "30", "31", "32", "33" , "34", "35", "36", "37", "38", "39", "40", "41", "42", "43" , "44", "45", "46", "47", "48", "49", "50", "51", "52", "53" , "54", "55", "56", "57", "58", "59", "60", "61", "62", "63"] }, "19": { "parameter_type": "categorical", "values": ["0", "1", "2", "3" , "4", "5", "6", "7", "8", "9", "10", "11", "12", "13" , "14", "15", "16", "17", "18", "19", "20", "21", "22", "23" , "24", "25", "26", "27", "28", "29", "30", "31", "32", "33" , "34", "35", "36", "37", "38", "39", "40", "41", "42", "43" , "44", "45", "46", "47", "48", "49", "50", "51", "52", "53" , "54", "55", "56", "57", "58", "59", "60", "61", "62", "63"] } } }

arturluis commented 2 years ago

Hi @peterhchen,

Thank you for notifying us and providing your application files to exemplify. It is unfortunate to hear that HyperMapper did not perform as well. We are always looking at ways to improve HyperMapper's performance and new techniques to incorporate, so we will indeed improve it's performance. One such area where we are investigating is performance for applications with many (i.e. more than 15) input parameters such as this. So we expect to improve the performance for this type of problem in the future.

That said, I noticed that in your application you have 20 categorical parameters which all seem to include all integers in [0, 63] and your black-box function computes a distance between the value of the input parameters and the values array. In this scenario where you have integer parameters and a distance-based metric, using a numeric parameter type should work much better. I.e. defining your parameters as integer with "values": [0, 63] would probably yield a considerable boost in performance. I strongly suggest doing that if you want to achieve better results from HyperMapper for this application. This should also make HyperMapper run a bit faster as it allows HM to use some better optimization techniques internally.

In this final note, we are also looking into optimizations in HyperMapper, so that it runs faster for applications with fast black-box functions. So that it does not take that long to run.

Best, Artur Souza