Genetic Engine
==============
[](https://geneticengine.readthedocs.io/en/latest/)
[](https://codecov.io/gh/alcides/GeneticEngine)
GeneticEngine is a search-based Python library that allows you to describe the structure of your solutions as Python dataclasses and abstract classes, and explores the solution space using different algorithms, such as enumerative search, hill climbing, and several flavors of Genetic Programming.
Documentation
-------------
* [Documentation](https://geneticengine.readthedocs.io/)
* [Examples](examples/)
```python
class MyExpr(ABC):
"MyExpr is a non-terminal/abstract class."
def eval(self):
...
@dataclass
class Plus(MyExpr):
"E -> E + E"
left: MyExpr
right: MyExpr
def eval(self):
return self.left.eval() + self.right.eval()
@dataclass
class Literal(MyExpr):
"E -> <int>"
value: int
def eval(self):
return self.value
```
In this small example, we are defining the language that supports the plus operator and integer literals. GeneticEngine will be able to automatically generate all possible expressions, such as `Plus(left=Plus(left=Literal(12), right=Literal(12)), right=Literal(15))`, and guide the search towards your goal (e.g., `lambda x: abs(x-2022)`). For this very simple toy problem, it will find an expression that computes 2022, ideally as small as possible. And this is a very uninteresting example. But if you introduce variables into the mix, you have a very powerful symbolic regression toolkit for arbitrarily complex expressions.
Contributing
-------------
After cloning the repo, please run `source setup_dev.sh` to install virtualenv, all dependencies and setup all pre-commit hooks.
Pull Requests are more than welcome!
Authors
----------
GeneticEngine has been developed at [LASIGE](https://www.lasige.pt), [University of Lisbon](https://ciencias.ulisboa.pt) by:
* [Alcides Fonseca](http://alcidesfonseca.com)
* [Leon Ingelse](https://leoningel.github.io)
* [Guilherme Espada](https://www.lasige.di.fc.ul.pt/user/732)
* [Paulo Santos](https://pcanelas.com/)
* [Pedro Barbosa](https://www.lasige.di.fc.ul.pt/user/661)
* [Eduardo Madeira](https://www.lasige.pt/member/jose-eduardo-madeira)
* [Lishun Su](https://lasige.pt/member/su-lishun/)
* [Paulo Silva](https://github.com/PauloHS-Silva)
* [Abhisek Limbu](https://github.com/AbhisekLimbu/AbhisekLimbu)
Acknowledgements
----------------
This work was supported by Fundação para a Ciência e Tecnologia (FCT) through:
* [the LASIGE Research Unit](https://www.lasige.pt) (ref. UID/00408/2025)
* Pedro Barbosa PhD fellowship (SFRH/BD/137062/2018)
* Guilherme Espada PhD fellowship (UI/BD/151179/2021)
* Paulo Santos CMU|Portugal PhD fellowship (SFRH/BD/151469/2021)
* [the FCT Exploratory project RAP](http://wiki.alcidesfonseca.com/research/projects/rap/) (EXPL/CCI-COM/1306/2021)
* the FCT Advanced Computing projects (2022.15800.CPCA.A1, CPCA/A1/395424/2021, CPCA/A1/5613/2020, CPCA/A2/6009/2020)
And by Lisboa2020, Compete2020 and FEDER through:
* [the CMU|Portugal CAMELOT project](http://wiki.alcidesfonseca.com/research/projects/camelot/) (LISBOA-01-0247-FEDER-045915)
Publications
-----------------
* [Comparing the expressive power of Strongly-Typed and Grammar-Guided Genetic Programming](https://www.researchgate.net/publication/370277603_Comparing_the_expressive_power_of_Strongly-Typed_and_Grammar-Guided_Genetic_Programming) at GECCO'23
* [Data types as a more ergonomic frontend for Grammar-Guided Genetic Programming](https://arxiv.org/pdf/2210.04826) at GPCE'22
* [Grammatical Evolution Mapping for Semantically-Constrained Genetic Programming](https://www.researchgate.net/profile/Alcides-Fonseca/publication/358528379_Grammatical_Evolution_Mapping_for_Semantically-Constrained_Genetic_Programming/links/620a1ecf634ff774f4cc2cee/Grammatical-Evolution-Mapping-for-Semantically-Constrained-Genetic-Programming.pdf) at GPTP'21
* [The Usability Argument for Refinement Typed Genetic Programming](https://link.springer.com/chapter/10.1007/978-3-030-58115-2_2) at PPSN'20
Applications of GeneticEngine
-----------------------------
* [Semantically Rich Local Dataset Generation for Explainable AI in Genomics](https://www.researchgate.net/publication/381960322_Semantically_Rich_Local_Dataset_Generation_for_Explainable_AI_in_Genomics) at GECCO'24
* [Comparing Individual Representations in Grammar-Guided Genetic Programming for Glucose Prediction in People with Diabetes](https://www.researchgate.net/publication/371324298_Comparing_Individual_Representations_in_Gram-mar-Guided_Genetic_Programming_for_Glucose_Prediction_in_People_with_Diabetes) at Grammatical Workshop at GECCO'23
* [Domain-Aware Feature Learning with Grammar-Guided Genetic Programming](https://link.springer.com/chapter/10.1007/978-3-031-29573-7_15) at EuroGP'23
* [Benchmarking Individual Representation in Grammar-Guided Genetic Programming](https://wwwww.easychair.org/publications/preprint_download/wqrb) at Evo*'22
Let us know if your paper uses Genetic Engine, to list it here.
Please cite as:
```
Espada, Guilherme, et al. "Data types as a more ergonomic frontend for Grammar-Guided Genetic Programming.", GPCE '22: Concepts and Experiences, 2022
```
Bibtex:
```
@inproceedings{espada2022data,
author={Guilherme Espada and Leon Ingelse and Paulo Canelas and Pedro Barbosa and Alcides Fonseca},
editor = {Bernhard Scholz and Yukiyoshi Kameyama},
title={Datatypes as a More Ergonomic Frontend for Grammar-Guided Genetic Programming},
booktitle = {{GPCE} '22: Concepts and Experiences, Auckland, NZ, December 6 - 7, 2022},
pages = {1},
publisher = {{ACM}},
year = {2022},
}
```
Raw data
{
"_id": null,
"home_page": null,
"name": "GeneticEngine",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "program synthesis, machine learning, genetic programming",
"author": null,
"author_email": "\"Alcides Fonseca et al.\" <me@alcidesfonseca.com>",
"download_url": "https://files.pythonhosted.org/packages/19/a8/d0f5009b5112ea295d1e7f62033297188b77505e67e21f65b675f6bb632a/geneticengine-0.8.7.tar.gz",
"platform": null,
"description": "Genetic Engine\n==============\n\n[](https://geneticengine.readthedocs.io/en/latest/)\n[](https://codecov.io/gh/alcides/GeneticEngine)\n\nGeneticEngine is a search-based Python library that allows you to describe the structure of your solutions as Python dataclasses and abstract classes, and explores the solution space using different algorithms, such as enumerative search, hill climbing, and several flavors of Genetic Programming.\n\n\nDocumentation\n-------------\n\n* [Documentation](https://geneticengine.readthedocs.io/)\n* [Examples](examples/)\n\n```python\nclass MyExpr(ABC):\n\t\"MyExpr is a non-terminal/abstract class.\"\n\tdef eval(self):\n\t\t...\n\n@dataclass\nclass Plus(MyExpr):\n\t\"E -> E + E\"\n\tleft: MyExpr\n\tright: MyExpr\n\n\tdef eval(self):\n\t\treturn self.left.eval() + self.right.eval()\n\n@dataclass\nclass Literal(MyExpr):\n\t\"E -> <int>\"\n\tvalue: int\n\n\tdef eval(self):\n\t\treturn self.value\n```\n\nIn this small example, we are defining the language that supports the plus operator and integer literals. GeneticEngine will be able to automatically generate all possible expressions, such as `Plus(left=Plus(left=Literal(12), right=Literal(12)), right=Literal(15))`, and guide the search towards your goal (e.g., `lambda x: abs(x-2022)`). For this very simple toy problem, it will find an expression that computes 2022, ideally as small as possible. And this is a very uninteresting example. But if you introduce variables into the mix, you have a very powerful symbolic regression toolkit for arbitrarily complex expressions.\n\n\nContributing\n-------------\n\nAfter cloning the repo, please run `source setup_dev.sh` to install virtualenv, all dependencies and setup all pre-commit hooks.\n\nPull Requests are more than welcome!\n\n\nAuthors\n----------\nGeneticEngine has been developed at [LASIGE](https://www.lasige.pt), [University of Lisbon](https://ciencias.ulisboa.pt) by:\n\n* [Alcides Fonseca](http://alcidesfonseca.com)\n* [Leon Ingelse](https://leoningel.github.io)\n* [Guilherme Espada](https://www.lasige.di.fc.ul.pt/user/732)\n* [Paulo Santos](https://pcanelas.com/)\n* [Pedro Barbosa](https://www.lasige.di.fc.ul.pt/user/661)\n* [Eduardo Madeira](https://www.lasige.pt/member/jose-eduardo-madeira)\n* [Lishun Su](https://lasige.pt/member/su-lishun/)\n* [Paulo Silva](https://github.com/PauloHS-Silva)\n* [Abhisek Limbu](https://github.com/AbhisekLimbu/AbhisekLimbu)\n\nAcknowledgements\n----------------\n\nThis work was supported by Funda\u00e7\u00e3o para a Ci\u00eancia e Tecnologia (FCT) through:\n\n* [the LASIGE Research Unit](https://www.lasige.pt) (ref. UID/00408/2025)\n* Pedro Barbosa PhD fellowship (SFRH/BD/137062/2018)\n* Guilherme Espada PhD fellowship (UI/BD/151179/2021)\n* Paulo Santos CMU|Portugal PhD fellowship (SFRH/BD/151469/2021)\n* [the FCT Exploratory project RAP](http://wiki.alcidesfonseca.com/research/projects/rap/) (EXPL/CCI-COM/1306/2021)\n* the FCT Advanced Computing projects (2022.15800.CPCA.A1, CPCA/A1/395424/2021, CPCA/A1/5613/2020, CPCA/A2/6009/2020)\n\nAnd by Lisboa2020, Compete2020 and FEDER through:\n\n* [the CMU|Portugal CAMELOT project](http://wiki.alcidesfonseca.com/research/projects/camelot/) (LISBOA-01-0247-FEDER-045915)\n\n\nPublications\n-----------------\n\n* [Comparing the expressive power of Strongly-Typed and Grammar-Guided Genetic Programming](https://www.researchgate.net/publication/370277603_Comparing_the_expressive_power_of_Strongly-Typed_and_Grammar-Guided_Genetic_Programming) at GECCO'23\n* [Data types as a more ergonomic frontend for Grammar-Guided Genetic Programming](https://arxiv.org/pdf/2210.04826) at GPCE'22\n* [Grammatical Evolution Mapping for Semantically-Constrained Genetic Programming](https://www.researchgate.net/profile/Alcides-Fonseca/publication/358528379_Grammatical_Evolution_Mapping_for_Semantically-Constrained_Genetic_Programming/links/620a1ecf634ff774f4cc2cee/Grammatical-Evolution-Mapping-for-Semantically-Constrained-Genetic-Programming.pdf) at GPTP'21\n* [The Usability Argument for Refinement Typed Genetic Programming](https://link.springer.com/chapter/10.1007/978-3-030-58115-2_2) at PPSN'20\n\nApplications of GeneticEngine\n-----------------------------\n* [Semantically Rich Local Dataset Generation for Explainable AI in Genomics](https://www.researchgate.net/publication/381960322_Semantically_Rich_Local_Dataset_Generation_for_Explainable_AI_in_Genomics) at GECCO'24\n* [Comparing Individual Representations in Grammar-Guided Genetic Programming for Glucose Prediction in People with Diabetes](https://www.researchgate.net/publication/371324298_Comparing_Individual_Representations_in_Gram-mar-Guided_Genetic_Programming_for_Glucose_Prediction_in_People_with_Diabetes) at Grammatical Workshop at GECCO'23\n* [Domain-Aware Feature Learning with Grammar-Guided Genetic Programming](https://link.springer.com/chapter/10.1007/978-3-031-29573-7_15) at EuroGP'23\n* [Benchmarking Individual Representation in Grammar-Guided Genetic Programming](https://wwwww.easychair.org/publications/preprint_download/wqrb) at Evo*'22\n\n\nLet us know if your paper uses Genetic Engine, to list it here.\n\nPlease cite as:\n\n```\nEspada, Guilherme, et al. \"Data types as a more ergonomic frontend for Grammar-Guided Genetic Programming.\", GPCE '22: Concepts and Experiences, 2022\n```\n\nBibtex:\n\n```\n@inproceedings{espada2022data,\n author={Guilherme Espada and Leon Ingelse and Paulo Canelas and Pedro Barbosa and Alcides Fonseca},\n editor = {Bernhard Scholz and Yukiyoshi Kameyama},\n title={Datatypes as a More Ergonomic Frontend for Grammar-Guided Genetic Programming},\n booktitle = {{GPCE} '22: Concepts and Experiences, Auckland, NZ, December 6 - 7, 2022},\n pages = {1},\n publisher = {{ACM}},\n year = {2022},\n}\n```\n",
"bugtrack_url": null,
"license": "https://opensource.org/licenses/MIT",
"summary": "Genetic Programming with Types and Grammars",
"version": "0.8.7",
"project_urls": {
"documentation": "https://github.com/alcides/GeneticEngine/",
"homepage": "https://github.com/alcides/GeneticEngine/",
"repository": "https://github.com/alcides/GeneticEngine/"
},
"split_keywords": [
"program synthesis",
" machine learning",
" genetic programming"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "952c6ef5e2f8f80096323040682d93d74cdbb32a88b43e8f7df671549f9b638b",
"md5": "d9fd04fdc9d6b0ab24f8bd8b8594e6ef",
"sha256": "0759db13cba6a5867348d6950bd6d889a44c30409398cda7edd4f671fd2f294d"
},
"downloads": -1,
"filename": "geneticengine-0.8.7-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d9fd04fdc9d6b0ab24f8bd8b8594e6ef",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 207472,
"upload_time": "2025-07-24T09:47:52",
"upload_time_iso_8601": "2025-07-24T09:47:52.735339Z",
"url": "https://files.pythonhosted.org/packages/95/2c/6ef5e2f8f80096323040682d93d74cdbb32a88b43e8f7df671549f9b638b/geneticengine-0.8.7-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "19a8d0f5009b5112ea295d1e7f62033297188b77505e67e21f65b675f6bb632a",
"md5": "9921bc4f6bb3059018dc365fa071d376",
"sha256": "e6ac1e64cd140c9c7e1018b82a837e0e8c6c4b328a47785228902fc922447b2f"
},
"downloads": -1,
"filename": "geneticengine-0.8.7.tar.gz",
"has_sig": false,
"md5_digest": "9921bc4f6bb3059018dc365fa071d376",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 131006,
"upload_time": "2025-07-24T09:47:54",
"upload_time_iso_8601": "2025-07-24T09:47:54.242581Z",
"url": "https://files.pythonhosted.org/packages/19/a8/d0f5009b5112ea295d1e7f62033297188b77505e67e21f65b675f6bb632a/geneticengine-0.8.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-24 09:47:54",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "alcides",
"github_project": "GeneticEngine",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "dill",
"specs": [
[
"==",
"0.4.0"
]
]
},
{
"name": "lark",
"specs": [
[
"==",
"1.2.2"
]
]
},
{
"name": "loguru",
"specs": [
[
"==",
"0.7.3"
]
]
},
{
"name": "numpy",
"specs": [
[
"==",
"2.2.6"
]
]
},
{
"name": "palettable",
"specs": [
[
"==",
"3.3.3"
]
]
},
{
"name": "pandas",
"specs": [
[
"==",
"2.3.1"
]
]
},
{
"name": "pathos",
"specs": [
[
"==",
"0.3.4"
]
]
},
{
"name": "polyleven",
"specs": [
[
"==",
"0.9.0"
]
]
},
{
"name": "pytest",
"specs": [
[
"==",
"8.4.1"
]
]
},
{
"name": "pytest-benchmark",
"specs": [
[
"==",
"5.1.0"
]
]
},
{
"name": "scikit-learn",
"specs": [
[
"==",
"1.6.1"
]
]
},
{
"name": "seaborn",
"specs": [
[
"==",
"0.13.2"
]
]
},
{
"name": "sympy",
"specs": [
[
"==",
"1.14.0"
]
]
},
{
"name": "threadpoolctl",
"specs": [
[
"==",
"3.6.0"
]
]
},
{
"name": "z3-solver",
"specs": [
[
"==",
"4.15.1.0"
]
]
}
],
"lcname": "geneticengine"
}