Skip to content

Commit 931777d

Browse files
authored
Merge pull request #354 from ahmedfgad/github-actions
GitHub actions
2 parents 0246a80 + 3b98796 commit 931777d

109 files changed

Lines changed: 9060 additions & 21989 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/main.yml

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
# The Strategy Matrix defines the environments to test.
2828
# GitHub Actions will spawn a separate, parallel job for each version in the list.
2929
strategy:
30+
fail-fast: false
3031
matrix:
3132
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
3233

@@ -35,19 +36,41 @@ jobs:
3536

3637
steps:
3738
- name: Checkout Repository
38-
uses: actions/checkout@v3
39+
uses: actions/checkout@v4
3940

4041
# Setup the specific Python version defined in the current matrix iteration.
4142
- name: Setup Python ${{ matrix.python-version }}
42-
uses: actions/setup-python@v4
43+
uses: actions/setup-python@v5
4344
with:
4445
python-version: ${{ matrix.python-version }}
4546

4647
# Install project dependencies from requirements.txt.
4748
- name: Install Dependencies
4849
run: |
4950
python -m pip install --upgrade pip
50-
pip install -r requirements.txt
51+
# Added timeout and no-cache to prevent SSL/Network decryption errors
52+
pip install --default-timeout=100 --no-cache-dir -r requirements.txt
53+
54+
if [ "${{ matrix.python-version }}" != "3.14" ] && [ "${{ matrix.python-version }}" != "3.8" ]; then
55+
# This block runs if the version IS NOT 3.14 or 3.8
56+
# Using a retry loop for large DL frameworks to handle transient network issues
57+
echo "Installing deep learning libraries."
58+
for i in {1..3}; do
59+
pip install --default-timeout=100 --no-cache-dir tensorflow && break || \
60+
(echo "Retry $i failed, waiting 10s..." && sleep 10)
61+
done
62+
pip install --upgrade keras
63+
pip install torch
64+
else
65+
# This block runs if the version IS 3.14 or 3.8
66+
echo "Skipping heavy deep learning libraries for Python ${{ matrix.python-version }}."
67+
fi
68+
69+
# Verify the core deep learning frameworks
70+
echo "Verifying installations..."
71+
python -c "import tensorflow; print('TensorFlow version:', tensorflow.__version__)" || echo "TensorFlow not installed"
72+
python -c "import keras; print('Keras version:', keras.__version__)" || echo "Keras not installed"
73+
python -c "import torch; print('PyTorch version:', torch.__version__)" || echo "PyTorch not installed"
5174
5275
# Build the PyGAD package distribution (generating .tar.gz and .whl files).
5376
# This ensures the package build process is valid on this Python version.
@@ -59,7 +82,7 @@ jobs:
5982
# Install the newly built .whl file to verify the package is installable.
6083
- name: Install PyGAD from Wheel
6184
run: |
62-
find ./dist/*.whl | xargs pip install
85+
pip install dist/*.whl
6386
6487
- name: Install PyTest
6588
run: pip install pytest
@@ -69,4 +92,8 @@ jobs:
6992
# This includes our new tests for visualization, operators, parallel processing, etc.
7093
- name: Run Tests
7194
run: |
72-
pytest
95+
if [ "${{ matrix.python-version }}" == "3.14" ] || [ "${{ matrix.python-version }}" == "3.8" ]; then
96+
pytest --ignore=tests/test_kerasga.py --ignore=tests/test_torchga.py
97+
else
98+
pytest
99+
fi

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,10 @@
88
__pycache__/
99
*.py[cod]
1010
*$py.class
11+
12+
# =============================================================================
13+
# Documentation build output and local doc-build virtual environments.
14+
# These are generated by Sphinx and should not be committed.
15+
# =============================================================================
16+
docs/build/
17+
.venv-docs/

.readthedocs.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ formats:
2727
- pdf
2828
- epub
2929

30-
# Optional but recommended, declare the Python requirements required
31-
# to build your documentation
30+
# Declare the Python requirements needed to build the documentation.
3231
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
33-
# python:
34-
# install:
35-
# - requirements: docs/requirements.txt
32+
python:
33+
install:
34+
- requirements: docs/requirements.txt

README.md

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
# PyGAD: Genetic Algorithm in Python
1+
# PyGAD: Genetic Algorithm in Python
22

33
[PyGAD](https://pypi.org/project/pygad) is an open-source easy-to-use Python 3 library for building the genetic algorithm and optimizing machine learning algorithms. It supports Keras and PyTorch. PyGAD supports optimizing both single-objective and multi-objective problems.
44

5-
> Try the [Optimization Gadget](https://optimgadget.com), a free cloud-based tool powered by PyGAD. It simplifies optimization by reducing or eliminating the need for coding while providing insightful visualizations.
5+
> Try the [Optimization Gadget](https://optimgadget.com), a free cloud-based tool powered by PyGAD. It makes optimization easier by reducing or removing the need for coding, and it shows helpful visualizations.
66
7-
Check documentation of the [PyGAD](https://pygad.readthedocs.io/en/latest).
7+
Read the [PyGAD documentation](https://pygad.readthedocs.io/en/latest).
88

99
[![PyPI Downloads](https://pepy.tech/badge/pygad)](https://pepy.tech/project/pygad) [![Conda Downloads](https://img.shields.io/conda/dn/conda-forge/pygad.svg?label=Conda%20Downloads)](
1010
https://anaconda.org/conda-forge/PyGAD) [![PyPI version](https://badge.fury.io/py/pygad.svg)](https://badge.fury.io/py/pygad)![Docs](https://readthedocs.org/projects/pygad/badge)[![PyGAD PyTest / Python 3.13](https://github.com/ahmedfgad/GeneticAlgorithmPython/actions/workflows/main_py313.yml/badge.svg)](https://github.com/ahmedfgad/GeneticAlgorithmPython/actions/workflows/main_py313.yml) [![PyGAD PyTest / Python 3.12](https://github.com/ahmedfgad/GeneticAlgorithmPython/actions/workflows/main_py312.yml/badge.svg)](https://github.com/ahmedfgad/GeneticAlgorithmPython/actions/workflows/main_py312.yml) [![PyGAD PyTest / Python 3.11](https://github.com/ahmedfgad/GeneticAlgorithmPython/actions/workflows/main_py311.yml/badge.svg)](https://github.com/ahmedfgad/GeneticAlgorithmPython/actions/workflows/main_py311.yml) [![PyGAD PyTest / Python 3.10](https://github.com/ahmedfgad/GeneticAlgorithmPython/actions/workflows/main_py310.yml/badge.svg)](https://github.com/ahmedfgad/GeneticAlgorithmPython/actions/workflows/main_py310.yml) [![PyGAD PyTest / Python 3.9](https://github.com/ahmedfgad/GeneticAlgorithmPython/actions/workflows/main_py39.yml/badge.svg)](https://github.com/ahmedfgad/GeneticAlgorithmPython/actions/workflows/main_py39.yml) [![PyGAD PyTest / Python 3.8](https://github.com/ahmedfgad/GeneticAlgorithmPython/actions/workflows/main_py38.yml/badge.svg)](https://github.com/ahmedfgad/GeneticAlgorithmPython/actions/workflows/main_py38.yml) [![License](https://img.shields.io/badge/License-BSD_3--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause) [![Translation](https://hosted.weblate.org/widgets/weblate/-/svg-badge.svg)](https://hosted.weblate.org/engage/weblate/) [![REUSE](https://api.reuse.software/badge/github.com/WeblateOrg/weblate)](https://api.reuse.software/info/github.com/WeblateOrg/weblate) [![Stack Overflow](https://img.shields.io/badge/stackoverflow-Ask%20questions-blue.svg)](
1111
https://stackoverflow.com/questions/tagged/pygad) [![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/ahmedfgad/GeneticAlgorithmPython/badge)](https://securityscorecards.dev/viewer/?uri=github.com/ahmedfgad/GeneticAlgorithmPython) [![DOI](https://zenodo.org/badge/DOI/10.1007/s11042-023-17167-y.svg)](https://doi.org/10.1007/s11042-023-17167-y)
1212

1313
![PYGAD-LOGO](https://user-images.githubusercontent.com/16560492/101267295-c74c0180-375f-11eb-9ad0-f8e37bd796ce.png)
1414

15-
[PyGAD](https://pypi.org/project/pygad) supports different types of crossover, mutation, and parent selection. [PyGAD](https://pypi.org/project/pygad) allows different types of problems to be optimized using the genetic algorithm by customizing the fitness function.
15+
[PyGAD](https://pypi.org/project/pygad) supports different types of crossover, mutation, and parent selection. It lets you optimize many types of problems with the genetic algorithm by writing your own fitness function.
1616

1717
The library is under active development and more features are added regularly. If you want a feature to be supported, please check the **Contact Us** section to send a request.
1818

@@ -25,19 +25,19 @@ The library is under active development and more features are added regularly. I
2525

2626
# Installation
2727

28-
To install [PyGAD](https://pypi.org/project/pygad), simply use pip to download and install the library from [PyPI](https://pypi.org/project/pygad) (Python Package Index). The library is at PyPI at this page https://pypi.org/project/pygad.
28+
To install [PyGAD](https://pypi.org/project/pygad), use pip to download and install the library from [PyPI](https://pypi.org/project/pygad) (Python Package Index). The library is available on PyPI at this page: https://pypi.org/project/pygad.
2929

3030
Install PyGAD with the following command:
3131

32-
```python
32+
```
3333
pip install pygad
3434
```
3535

36-
To get started with PyGAD, please read the documentation at [Read The Docs](https://pygad.readthedocs.io/) https://pygad.readthedocs.io.
36+
To get started with PyGAD, read the documentation at [Read the Docs](https://pygad.readthedocs.io).
3737

3838
# PyGAD Source Code
3939

40-
The source code of the PyGAD' modules is found in the following GitHub projects:
40+
The source code of the PyGAD modules is in the following GitHub projects:
4141

4242
- [pygad](https://github.com/ahmedfgad/GeneticAlgorithmPython): (https://github.com/ahmedfgad/GeneticAlgorithmPython)
4343
- [pygad.nn](https://github.com/ahmedfgad/NumPyANN): https://github.com/ahmedfgad/NumPyANN
@@ -47,13 +47,11 @@ The source code of the PyGAD' modules is found in the following GitHub projects:
4747
- [pygad.kerasga](https://github.com/ahmedfgad/KerasGA): https://github.com/ahmedfgad/KerasGA
4848
- [pygad.torchga](https://github.com/ahmedfgad/TorchGA): https://github.com/ahmedfgad/TorchGA
4949

50-
The documentation of PyGAD is available at [Read The Docs](https://pygad.readthedocs.io/) https://pygad.readthedocs.io.
51-
5250
# PyGAD Documentation
5351

54-
The documentation of the PyGAD library is available at [Read The Docs](https://pygad.readthedocs.io) at this link: https://pygad.readthedocs.io. It discusses the modules supported by PyGAD, all its classes, methods, attribute, and functions. For each module, a number of examples are given.
52+
The PyGAD documentation is available at [Read the Docs](https://pygad.readthedocs.io) at this link: https://pygad.readthedocs.io. It explains the modules supported by PyGAD and all its classes, methods, attributes, and functions. For each module, several examples are given.
5553

56-
If there is an issue using PyGAD, feel free to post at issue in this [GitHub repository](https://github.com/ahmedfgad/GeneticAlgorithmPython) https://github.com/ahmedfgad/GeneticAlgorithmPython or by sending an e-mail to ahmed.f.gad@gmail.com.
54+
If you have an issue using PyGAD, feel free to post an issue in this [GitHub repository](https://github.com/ahmedfgad/GeneticAlgorithmPython) or send an e-mail to ahmed.f.gad@gmail.com.
5755

5856
If you built a project that uses PyGAD, then please drop an e-mail to ahmed.f.gad@gmail.com with the following information so that your project is included in the documentation.
5957

@@ -65,7 +63,7 @@ Please check the **Contact Us** section for more contact details.
6563

6664
# Life Cycle of PyGAD
6765

68-
The next figure lists the different stages in the lifecycle of an instance of the `pygad.GA` class. Note that PyGAD stops when either all generations are completed or when the function passed to the `on_generation` parameter returns the string `stop`.
66+
The next figure shows the main stages in the life cycle of a `pygad.GA` instance. PyGAD stops when all generations are completed or when the function passed to the `on_generation` parameter returns the string `stop`.
6967

7068
![PyGAD Lifecycle](https://user-images.githubusercontent.com/16560492/220486073-c5b6089d-81e4-44d9-a53c-385f479a7273.jpg)
7169

@@ -122,7 +120,7 @@ ga_instance = pygad.GA(num_generations=3,
122120
ga_instance.run()
123121
```
124122

125-
Based on the used 3 generations as assigned to the `num_generations` argument, here is the output.
123+
Because `num_generations` is set to 3, here is the output.
126124

127125
```
128126
on_start()
@@ -158,7 +156,7 @@ import numpy
158156

159157
"""
160158
Given the following function:
161-
y = f(w1:w6) = w1x1 + w2x2 + w3x3 + w4x4 + w5x5 + 6wx6
159+
y = f(w1:w6) = w1x1 + w2x2 + w3x3 + w4x4 + w5x5 + w6x6
162160
where (x1,x2,x3,x4,x5,x6)=(4,-2,3.5,5,-11,-4.7) and y=44
163161
What are the best values for the 6 weights (w1 to w6)? We are going to use the genetic algorithm to optimize this function.
164162
"""
@@ -168,7 +166,7 @@ desired_output = 44 # Function output.
168166

169167
def fitness_func(ga_instance, solution, solution_idx):
170168
# Calculating the fitness value of each solution in the current population.
171-
# The fitness function calulates the sum of products between each input and its corresponding weight.
169+
# The fitness function calculates the sum of products between each input and its corresponding weight.
172170
output = numpy.sum(solution*function_inputs)
173171
fitness = 1.0 / numpy.abs(output - desired_output)
174172
return fitness
@@ -203,7 +201,7 @@ ga_instance = pygad.GA(num_generations=num_generations,
203201
# Running the GA to optimize the parameters of the function.
204202
ga_instance.run()
205203

206-
# After the generations complete, some plots are showed that summarize the how the outputs/fitenss values evolve over generations.
204+
# After the generations complete, a plot is shown that summarizes how the fitness values evolve over the generations.
207205
ga_instance.plot_fitness()
208206

209207
# Returning the details of the best solution.
@@ -229,7 +227,7 @@ loaded_ga_instance.plot_fitness()
229227

230228
# For More Information
231229

232-
There are different resources that can be used to get started with the genetic algorithm and building it in Python.
230+
Here are some resources to help you get started with the genetic algorithm and build it in Python.
233231

234232
## Tutorial: Implementing Genetic Algorithm in Python
235233

@@ -239,7 +237,7 @@ To start with coding the genetic algorithm, you can check the tutorial titled [*
239237
- [Towards Data Science](https://towardsdatascience.com/genetic-algorithm-implementation-in-python-5ab67bb124a6)
240238
- [KDnuggets](https://www.kdnuggets.com/2018/07/genetic-algorithm-implementation-python.html)
241239

242-
[This tutorial](https://www.linkedin.com/pulse/genetic-algorithm-implementation-python-ahmed-gad) is prepared based on a previous version of the project but it still a good resource to start with coding the genetic algorithm.
240+
[This tutorial](https://www.linkedin.com/pulse/genetic-algorithm-implementation-python-ahmed-gad) is based on an earlier version of the project, but it is still a good resource to start coding the genetic algorithm.
243241

244242
[![Genetic Algorithm Implementation in Python](https://user-images.githubusercontent.com/16560492/78830052-a3c19300-79e7-11ea-8b9b-4b343ea4049c.png)](https://www.linkedin.com/pulse/genetic-algorithm-implementation-python-ahmed-gad)
245243

0 commit comments

Comments
 (0)