TransWikia.com

Python metaheuristic packages

Data Science Asked by user1403546 on July 7, 2021

I need to use a metaheuristic algorithm to solve an optimization problem on a Python codebase.

Metaheuristics usually need to be written in C++ or Java as they involve a lot of iterations, while Python is weak from this point of view.

Questions:

  1. do any Python metaheuristic packages which wrap faster languages as
    C++/Java exist?
  2. do any Python metaheuristic packages based on maybe
    cython on numba exist?
  3. other solutions?

2 Answers

In Python, people running genetic algorithms normally run Python implementations, specifically the DEAP library is very popular.

There is also the less popular library PGApy, which wraps a fork of PGA Pack, which is written in C.

Another option is to tailor something yourself by means of Cython, a Python extension to write code with native performance. This is what some people did here. Maybe you can reuse their code.

Correct answer by noe on July 7, 2021

As a long shot, if you have a Python version (or implement it yourself), running it with PyPy instead of Python might make things much faster, as it is well suited to code that uses Python built-ins and also many loops. It optimises these cases very well, through tricks such as garbage collection. The latest version also supports Python3.5 and 3.6 as well as NumPy.

From their website the main benefits:

Speed: thanks to its Just-in-Time compiler, Python programs often run faster on PyPy. (What is a JIT compiler?)

“If you want your code to run faster, you should probably just use PyPy.” — Guido van Rossum (creator of Python)

Memory usage: memory-hungry Python programs (several hundreds of MBs or more) might end up taking less space than they do in CPython.

Compatibility: PyPy is highly compatible with existing python code. It supports cffi and can run popular python libraries like twisted and django.

Stackless: PyPy comes by default with support for stackless mode, providing micro-threads for massive concurrency.

Answered by n1k31t4 on July 7, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP