Package: open-metaoptim
METAOPTIMmetaoptim is a Python package for metaheuristic optimization algorithms. It also features various benchmark functions that can be used to test the performance of the algorithms.InstallationEnsure that you have Python 3.9 or higher installed. Then, install the package using pip:pip3installopen-metaoptimUsageConfigurationThis package has the ability to accelerate the metaheuristic algorithms usingnumba. To control the use ofnumbayou can control the following flags in themetaoptim.configmodule:importmultiprocessing_numba_cache=True# Set to True/False to enable/disable Numba cache_numba_parallel=False# Set to True/False to enable/disable Numba parallel_numba_nopython=True# Set to True/False to enable/disable Numba nopython_numba_nogil=True# Set to True/False to enable/disable Numba nogil_numba_num_threads=multiprocessing.cpu_count()# Set to the number of threads to use for Numba_disable_jit=True# Set to True/False to enable/disable Numba JITThe aforementioned flags are set to their default values. You can change them to your liking by importing theconfigmodule and setting the flags to the desired values.
e.g.:importmetaoptim.configasconfigconfig._numba_cache=FalseHowever,please ensure that you import any metaheuristic algorithms after you have set the flags. Otherwise, the flags will not take effect.Finally, GPU acceleration is currently not supported, but will be added in the future.RecommendationsNumba is a great tool for accelerating Python code. However, it is not always the best choice. For example, if you are using a metaheuristic algorithm that is already fast, then you may not want to use Numba. In such cases, you can disable Numba by setting the_disable_jitflag toTrue.
You should use Numba acceleration when the metaheuristic algorithm is slow, working in high dimensions, or when you are using a large population size.AlgorithmsThe package currently features the following algorithms:Global Best Particle Swarm OptimizationPlease refer to the class docstrings for more information.Benchmark FunctionsAckley (Dimension: N)Beale (Dimension: 2)Booth (Dimension: 2)Bukin N. 6 (Dimension: 2)Cross-in-Tray (Dimension: 2)Dixon-Price (Dimension: N)Drop-Wave (Dimension: 2)Easom (Dimension: 2)Eggholder (Dimension: 2)Goldstein-Price (Dimension: 2)Griewank (Dimension: N)Himmelblau (Dimension: 2)Holder Table (Dimension: 2)Levy (Dimension: N)Levy N. 13 (Dimension: 2)Matyas (Dimension: 2)McCormick (Dimension: 2)Rastrigin (Dimension: N)Rosenbrock (Dimension: N)Schaffer N. 2 (Dimension: 2)Schaffer N. 4 (Dimension: 2)Sphere (Dimension: N)Styblinski-Tang (Dimension: N)Three-Hump Camel (Dimension: 2)Package StructureThe package is structured as follows:metaoptim: The package directory.config.py: The configuration file.bench_func.py: Contains the benchmark functions.pso: The Particle Swarm Optimization algorithms package.pso.py: ThePSOparent class.gbest_pso.py: The Global Best Particle Swarm Optimization algorithm (GBestPSO). Features an inertia weight, a cognitive and a social component.ContributingGuidelines for ContributingNEW METAHEURISTICS MUST INCLUDE NUMBA ACCELERATIONIn the description of your pull request, please explain clearly what does it implement or fix and your changes. Where possible, you should give examples in the description of the pull request. In cases that the pull request is about a code speedup, report a reproducible example and quantify the speedup.Give your pull request a helpful title that summarises what your contribution does.Write unit tests for your code in thetestdirectory and make sure the existing tests are up-to-date. Usepytestto run the tests:pytestMake sure that there a no stylistic issues in files you have edited usingpycodestyle:pycodestyle<FILE_PATH>where<FILE_PATH>is the path to the file you want to check.To check all files in the package, run:pycodestylesrc/*Make sure your code is properly commented and documented usingreStructuredTextdocstrings and additional comments where necessary. Each public method needs to be documented as the existing ones.Development DependenciesTo install the development dependencies, run the following command:pip3installmetaoptim[dev]