krzysztofarendt / modestga Goto Github PK
View Code? Open in Web Editor NEWOptimized and benchmarked parallel Genetic Algorithm with inequality constraints, and a scipy-like interface
License: BSD 2-Clause "Simplified" License
Optimized and benchmarked parallel Genetic Algorithm with inequality constraints, and a scipy-like interface
License: BSD 2-Clause "Simplified" License
krza@DESKTOP-3738N1E:~/code/modestga$ python modestga/examples/min_rastrigin_fun.py
Traceback (most recent call last):
File "modestga/examples/min_rastrigin_fun.py", line 37, in <module>
res = minimize(fun, bounds, args=args, callback=callback, options=options)
File "/home/krza/code/modestga/modestga/ga.py", line 171, in minimize
pop = population.Population(opts['pop_size'], bounds, fun, args=args, evaluate=True)
File "/home/krza/code/modestga/modestga/population.py", line 28, in __init__
val=val
File "/home/krza/code/modestga/modestga/individual.py", line 51, in __init__
self.val = self.evaluate()
File "/home/krza/code/modestga/modestga/individual.py", line 68, in evaluate
self.val = self.fun(self.get_estimates(), *self.args)
TypeError: rastrigin() takes 1 positional argument but 3 were given
We cannot guarantee that the cost function will work for the entire range of parameters. In example in ModestPy FMU solvers sometimes fail when unphysical parameters are used (see: sdu-cfei/modest-py#68).
It should be fairly easy to implement some generic exception handling. I think it is sufficient to enclose the following line with a try... except...
block:
modestga/modestga/individual.py
Line 68 in 46a6bde
When exception is caught the function value could be +infinity or some very large number.
end_event
is not set True on Linux (WSL2).
Documentation is missing!
Add nfev to OptRes.
The algorithm doesn't work with negative cost function values. It stops when reaching a value near zero.
The following unit test fails on Windows:
======================================================================
ERROR: test_exotic_pickling (__main__.TestModestga)
----------------------------------------------------------------------
Traceback (most recent call last):
File "modestga\test\test.py", line 233, in test_exotic_pickling
workers=2)
File "d:\code\modestga\modestga\ga.py", line 167, in minimize
p.start()
File "D:\Anaconda3\envs\modestga\lib\multiprocessing\process.py", line 112, in start
self._popen = self._Popen(self)
File "D:\Anaconda3\envs\modestga\lib\multiprocessing\context.py", line 223, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "D:\Anaconda3\envs\modestga\lib\multiprocessing\context.py", line 322, in _Popen
return Popen(process_obj)
File "D:\Anaconda3\envs\modestga\lib\multiprocessing\popen_spawn_win32.py", line 89, in __init__
reduction.dump(process_obj, to_child)
File "D:\Anaconda3\envs\modestga\lib\multiprocessing\reduction.py", line 60, in dump
ForkingPickler(file, protocol).dump(obj)
AttributeError: Can't pickle local object 'TestModestga.test_exotic_pickling.<locals>.FunWrapper'
----------------------------------------------------------------------
On Linux it works fine.
When an exception happens in one of the threads, the main process waits indefinitely for its result. A timeout or exception handling should be implemented.
An example from one of the users of ModestPy:
Traceback (most recent call last):
File "C:\Users\lucjsar\Documents\ModestPy\lucile_GBM_max_flows.py", line 151, in <module>
estimates = session.estimate()
File "C:\Users\lucjsar\Documents\ModestPy\modestpy\estimation.py", line 289, in estimate
m_estimates = m_inst.estimate()
File "C:\Users\lucjsar\Documents\ModestPy\modestpy\estim\ga_parallel\ga_parallel.py", line 315, in estimate
workers=self.workers)
File "C:\Users\lucjsar\AppData\Local\Continuum\anaconda3\lib\site-packages\modestga\ga.py", line 257, in minimize
if pipes[i].poll(0.001):
File "C:\Users\lucjsar\AppData\Local\Continuum\anaconda3\lib\multiprocessing\connection.py", line 257, in poll
return self._poll(timeout)
File "C:\Users\lucjsar\AppData\Local\Continuum\anaconda3\lib\multiprocessing\connection.py", line 330, in _poll
return bool(wait([self], timeout))
File "C:\Users\lucjsar\AppData\Local\Continuum\anaconda3\lib\multiprocessing\connection.py", line 868, in wait
ready_handles = _exhaustive_wait(waithandle_to_obj.keys(), timeout)
File "C:\Users\lucjsar\AppData\Local\Continuum\anaconda3\lib\multiprocessing\connection.py", line 800, in _exhaustive_wait
res = _winapi.WaitForMultipleObjects(L, False, timeout)
When running examples using multiprocessing on Windows, the following errors pops out:
RuntimeError: An attempt has been made to start a new process before the current process has finished its bootstrapping phase. This probably means that you are not using fork to start your child processes and you have forgotten to use the proper idiom in the main module: if __name__ == '__main__': freeze_support() ... The "freeze_support()" line can be omitted if the program is not going to be frozen to produce an executable.
It is because Windows requires the code using multiprocessing to be enclosed with the condition:
if __name__ == '__main__'
.
The examples work fine on Linux.
There should warning about this also in README.
When a user chooses to large tournament size with respect to population size and number of workers, the tournament size should be automatically adjusted and a warning issued.
Currently, the entire population is evaluated once before sending the population to subprocesses.
This can take a lot of time if the cost function is slow.
It would be better to evaluate all subpopulations after sending them to subprocesses.
Compare the performance of the implemented GA with other available methods, especially Monte Carlo (own implementation) and Differential Evolution (from SciPy).
Use Remote Manager and Proxy Objects to share the function to be minimized accross processes.
This will enable to minimize unpickable functions in parallel.
References:
Multiple benchmark cases are likely to be added in the future. They all should be put in some kind of a framework with YAML configuration files.
Consider https://github.com/uqfoundation/dill in favor of cloudpickle.
Pytest is more user friendly and requires less boilerplate code.
Inter-method comparisons should be implemented in pure Python scripts. Remove notebooks from modestga/benchmark
.
Allow constrained optimization via penalty-based soft constraints.
TODO:
if __name__ == "__main__":
v0.6
Failing test:
======================================================================
ERROR: test_args_passing_2workers (__main__.TestModestga)
----------------------------------------------------------------------
Traceback (most recent call last):
File "modestga/test/test.py", line 209, in test_args_passing_2workers
workers=2)
File "/home/krza/code/modestga/modestga/ga.py", line 258, in minimize
data_from.append(pipes[i].recv())
File "/usr/lib/python3.6/multiprocessing/connection.py", line 250, in recv
buf = self._recv_bytes()
File "/usr/lib/python3.6/multiprocessing/connection.py", line 407, in _recv_bytes
buf = self._recv(4)
File "/usr/lib/python3.6/multiprocessing/connection.py", line 383, in _recv
raise EOFError
EOFError
----------------------------------------------------------------------
I'm not sure if args are passed to the cost function.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.