-
Notifications
You must be signed in to change notification settings - Fork 100
A Generic Process to Use Distributed ZOOpt
In ZOOclient, an optimization problem is abstracted in several components: Objective
, Dimension
, Parameter
, and Solution
, each is a Julia type.
An Objective
object is initialized with a Dimension
object as the input, where the Dimension
object defines the dimension size and boundaries of the search space. A Parameter
object specifies algorithm parameters. The zoo_min
function makes the optimization happen, and returns a Solution
object which contains the final solution and the function value. Moreover, after the optimization, the Objective
object contains the history of the optimization for observation.
The Generic process to use Distributed ZOOpt contains five steps:
- Start the control server (ZOOsrv)
- Start the evaluation servers ( ZOOsrv)
- Define the objective function
- Run Julia client code ( ZOOclient)
- Define a
Dimension
objectdim
, then usesdim
to construct anObjective
object - Define a
Parameter
objectpar
- Use
zoo_min
to optimize - Run client code
- Define a
- Shut down evaluation servers and the control server (ZOOsrv)
The step 1 and the step 2 can be omitted if the servers have been started. Commonly the step 4 is executed several times for different tasks. The step 5 could be executed only when users do not want to run client code any more.
Users carry out step 1, 2 and 5 on general servers and step 3 and 4 for specific tasks.
Users should provide a port to start the control server.
from zoosrv import control_server
# users should provide the port occupied by the control server
control_server.start(20000)
Users should provide a configuration file to start the evaluation servers.
from zoosrv import evaluation_server
evaluation_server.start("evaluation_server.cfg")
configuration file is listed as follows:
[evaluation server]
shared fold = /path/to/project/ZOOsrv/example/objective_function/
control server ip_port = 192.168.0.103:20000
evaluation processes = 10
starting port = 60003
ending port = 60020
shared fold
indicates the root directory your julia client and evaluation servers work under. The objective function should be defined under this directory. constrol server's ip_port
means the address of the control server. The last three lines state we want to start 10 evaluation processes by choosing 10 available ports from 60003 to 60020.
An objective function should satisfy the interface def func(solution):
, where solution
is a Solution
object that encapsulates x and f(x). In general, users can custom their objective function by
def func(solution):
x = solution.get_x() # fixed pattern
value = f(x) # function f takes a vector x as input
return value
In the Sphere function example, the objective function looks like
def sphere(solution):
x = solution.get_x()
value = sum([(i-0.2)*(i-0.2) for i in x]) # sphere center is (0.2, 0.2)
return value
-
Define a
Dimension
objectdim
, then usesdim
to construct anObjective
object.Dimension
type looks liketype Dimension size::Int64 regions types end
size
is an integer indicating the dimension size.regions
is a list that contains the search space of each dimension (search space is a two-element list showing the range of each dimension, e.g., [-1, 1] for the range from -1 to 1).tys
is a list of boolean value,True
means continuous in this dimension andFalse
means discrete.In the Sphere function example,
dim
looks likedim_size = 100 dim_regs = [[-1, 1] for i = 1:dim_size] dim_tys = [true for i = 1:dim_size] mydim = Dimension(dim_size, dim_regs, dim_tys)
Then use
dim
to construct anObjective
object.obj = Objective(mydim)
-
Define a
Parameter
objectpar
The type
Parameter
defines all parameters used in the optimization algorithms. Commonly, five parameters are needed to be manually determined by users. Respectively arebudget
,evaluation_server_num
,control_server_ip_port
,objective_file
andfunc
.# budget: the number of calls to the objective function # evalueation_server_num: the number of evaluation servers # control_server_ip_port: the ip:port of the control server # objective_file: the objective funtion is defined in this file # func: the name of the objective function par = Parameter(budget=10000, evaluation_server_num=10, control_server_ip_port="192.168.1.105:20000", objective_file="fx.py", func="sphere")
-
Use
zoo_min
to optimizesol = zoo_min(obj, par) # print the Solution object sol_print(sol)
-
Run client code
$ ./julia -p 10 /path/to/your/clent/code/client.jl
Starting with
julia -p n
providesn
worker processes on the local machine. Generally it makes sense forn
to equal the number of CPU cores on the machine. -
Shut down evaluation servers and the control server
The control server process can interact with users. The evaluation processes should be shut down by the control server. Otherwise, later tasks will receive the ip:ports of invalid evaluation processes. A simple example to shut down servers is listed here.