Skip to content

Client‐Server Chakong‐Haimes

arturluis edited this page Oct 9, 2020 · 3 revisions

Here, we will show how to use HyperMapper's client-server mode to optimize the constrained Chakong-Haimes multi-objective function. We look for minimizing the values of this function given two parameters x1 and x2, where some combinations of x1 and x2 are unfeasible.

The Objective Function

The Chakong-Haimes function is defined as:

def chakong_haimes(x1, x2):
  f1_value = 2 + (x1 - 2)*(x1 - 2) + (x2 - 1)*(x2 - 1)
  f2_value = 9*x1 - (x2 - 1)*(x2 - 1)

  g1 = x1*x1 + x2*x2 <= 225
  g2 = x1 - 3*x2 + 10 <= 0
  valid = g1 and g2
  return g1, g2, valid

Note that we compute both values of the function and a feasibility indicator for x1 and x2. These three values must be returned to HyperMapper. An example of this code can be found in client-server_chakong_haimes.py.

The JSON Configuration File

The following is what needs to be specified as a json syntax to run Chakong-Haimes:

{
    "application_name": "client-server_chakong_haimes",
    "optimization_objectives": ["f1_value", "f2_value"],
    "hypermapper_mode": {
        "mode": "client-server"
    },
    "feasible_output": {
        "enable_feasible_predictor": true,
        "name": "Valid",
        "true_value": "True",
        "false_value": "False"
    },
    "optimization_iterations": 50,
    "input_parameters" : {
        "x1": {
            "parameter_type" : "real",
            "values" : [-20, 20],
            "parameter_default" : 0
        },
        "x2": {
            "parameter_type" : "real",
            "values" : [-20, 20],
            "parameter_default" : 0
        }
    }
}

Recall that we add the hypermapper_mode field to tell HyperMapper to run on client-server mode. You can find this json in client-server_chakong_haimes_scenario.json.

The Communication Protocol

The missing part is now the communication interface between the Chakong-Haimes function and HyperMapper. This is implemented in client-server_chakong_haimes.py. Briefly the protocol does the following:

**HyperMapper**
Request 3
x1,x2
-10,12
1,6
-8,20
**Chakong-Haimes**
x1,x2,f1_value,f2_value,Valid
-10,12,267,-211,False
1,6,28,-16,True
-8,20,463,-433,False
**HyperMapper** 
Request 1
x1,x2
3,7
**Chakong-Haimes**
x1,x2,f1_value,f2_value,Valid
3,7,39,-9,True
...
**HyperMapper**
End of HyperMapper

Note that the black-box function must return the value of all of the optimization metrics and the feasible flag to HyperMapper. HyperMapper sends an "End of HyperMapper" message once optimization is done.

Run HyperMapper

Remember to run client-server_chakong_haimes.py from the $HYPERMAPPER_HOME directory. In order to run this example, we use:

cd $HYPERMAPPER_HOME
python3 example_scenarios/clients/python/client-server_chakong_haimes.py

An example of stdout output can be found here.

The result of this script is a csv file called client-server_chakong_haimes_output_samples.csv.

Compute Pareto

After running HyperMapper, we can compute the Pareto front of the DSE using the compute_pareto.py script:

python3 scripts/compute_pareto.py example_scenarios/clients/python/client-server_chakong_haimes_scenario.json

The result of this script is a csv file called client-server_chakong_haimes_output_pareto.csv. Note that the pareto front contains only feasible points.

Visualize Pareto

We can also visualize the Pareto front using the plot_dse.py script:

python3 scripts/plot_dse.py example_scenarios/clients/python/client-server_chakong_haimes_scenario.json

The result of this script is a pdf image client-server_chakong_haimes_output_pareto.pdf.

Clone this wiki locally