-
Notifications
You must be signed in to change notification settings - Fork 26
Client‐Server Branin
HyperMapper can also be run on Client-Server mode. Client-Server mode is a mode that allows a software to call HyperMapper on demand. The two parties communicate via a client (the third-party software) and server (HyperMapper) protocol defined by HyperMapper. The general idea of the protocol is that the client asks the server the configurations to run. Here, we will show how to do this using the Branin function.
The Branin function can be defined as:
def branin(x1, x2):
a = 1.0
b = 5.1 / (4.0 * math.pi * math.pi)
c = 5.0 / math.pi
r = 6.0
s = 10.0
t = 1.0 / (8.0 * math.pi)
y_value = a * (x2 - b * x1 * x1 + c * x1 - r) ** 2 + s * (1 - t) * math.cos(x1) + s
return y_value
An example of this code can be found in client-server_branin.py.
The json configuration file for this example is:
{
"application_name": "client-server_branin",
"hypermapper_mode": {
"mode": "client-server"
},
"optimization_objectives": ["Value"],
"optimization_iterations": 50,
"input_parameters" : {
"x1": {
"parameter_type" : "real",
"values" : [-5, 10],
"parameter_default" : 0
},
"x2": {
"parameter_type" : "real",
"values" : [0, 15],
"parameter_default" : 0
}
}
}
Note we added an extra field called hypermapper_mode
. This field tells HyperMapper which mode we would like to use. In this example, we set it to client-server
. An example of this json file can be found in interactive_branin_scenario.json.
The key component of the client-server mode is the communication interface between the client function and HyperMapper. We provide a simple template in client-server_branin.py. You can copy paste this template in your code and make some minor modifications to fit.
Briefly the protocol does the following:
**HyperMapper**
Request 1
x1,x2
5,0
**Branin**
x1,x2,Value
5,0,14.3
**HyperMapper**
Request 3
x1,x2
9,0
9,2
5,1
**Branin**
x1,x2,Value
9,0,5.8
9,2,1.2
5,1,12.7
...
The strings **HyperMapper** and **Branin** are present here for the sake of explanation, they are not part of the communication protocol. The number after request specifies the number of evaluations HyperMapper is asking.
x1, x2 are the input parameters defining the search space and Value is the optimization metric.
More information on the communication protocol (client-server mode) can be found here.
Remember to run client-server_branin.py from the $HYPERMAPPER_HOME directory.
cd $HYPERMAPPER_HOME
python3 example_scenarios/synthetic/client-server_branin/client-server_branin.py
An example of stdout output can be found output_branin.txt. In this output example file, you can see 1 random sampling iteration and 50 optimization iterations.
The result of this script is a csv file called client-server_branin_output_dse_samples.csv. You can find all the samples explored by HyperMapper in this file.
See the Client‐Server Chakong‐Haimes example for a more advanced example of the Client-Server mode.