Skip to content

GitHub Actions Workflows and new additions #187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 35 commits into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
38e27cb
Upload all package files
ahmedfgad Apr 16, 2023
05ace78
Delete pygad.py
ahmedfgad Apr 16, 2023
bf87baa
Delete __init__.py
ahmedfgad Apr 16, 2023
8ee348f
Rename __init__.py to pygad/__init__.py
ahmedfgad Apr 16, 2023
78daf35
Rename pygad.py to pygad/pygad.py
ahmedfgad Apr 16, 2023
7aedc6d
Rename example.py to examples/example.py
ahmedfgad Apr 16, 2023
34d3879
Rename lifecycle.py to examples/lifecycle.py
ahmedfgad Apr 16, 2023
8f2c6d4
Rename example_logger.py to examples/example_logger.py
ahmedfgad Apr 16, 2023
e356f3d
Rename example_custom_operators.py to examples/example_custom_operato…
ahmedfgad Apr 16, 2023
ffc3bf9
Rename example_clustering_3.py to examples/example_clustering_3.py
ahmedfgad Apr 16, 2023
28c64cd
Rename example_clustering_2.py to examples/example_clustering_2.py
ahmedfgad Apr 16, 2023
c63706a
Create a workflow YAML file.
ahmedfgad Apr 16, 2023
de14ddc
Merge pull request #176 from ahmedfgad/master
ahmedfgad Apr 16, 2023
88013f7
Rename example_travelling_salesman.ipynb to examples/example_travelli…
ahmedfgad Apr 16, 2023
ef9e366
Merge pull request #177 from ahmedfgad/master
ahmedfgad Apr 16, 2023
b42bcd0
Metadata pyproject.toml File
ahmedfgad Apr 16, 2023
97f3c16
Add more classifiers
ahmedfgad Apr 16, 2023
2b79ddb
Edit links
ahmedfgad Apr 16, 2023
ab97247
Add [build-system] table
ahmedfgad Apr 16, 2023
a1ab6aa
Add tests
ahmedfgad Apr 20, 2023
aca9f54
Merge remote-tracking branch 'origin/master' into github-actions
ahmedfgad Apr 20, 2023
c964118
PyTest metadata
ahmedfgad Apr 25, 2023
44cf9fb
Running tests using GitHub Actions
ahmedfgad Apr 25, 2023
36b7bc3
Running tests on github-actions branch
ahmedfgad Apr 25, 2023
b3d55d2
Build and install PyGAD in Actions Workflow
ahmedfgad Apr 25, 2023
6e19c04
Update the version
ahmedfgad Apr 27, 2023
262463e
Test number of callbacks calls
ahmedfgad Apr 27, 2023
d774769
Change test file name
ahmedfgad Apr 27, 2023
66ec895
Solve duplicates deeply
ahmedfgad May 1, 2023
160a836
Refactor unique.py
ahmedfgad May 1, 2023
19be8b0
Refactoring the code
ahmedfgad May 2, 2023
1c44692
More tests
ahmedfgad May 2, 2023
6b94152
Fixes and more tests
ahmedfgad May 3, 2023
2f139d3
Fixes and more tests
ahmedfgad May 3, 2023
d8b6372
Test lifecycle without crossover & mutation
ahmedfgad May 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Testing PyGAD using PyTest

on:
push:
branches:
- github-actions
# - master

jobs:
job_id_1:
runs-on: ubuntu-latest
name: PyTest Workflow Job

steps:
- name: Checkout Pre-Built Action
uses: actions/checkout@v3

- name: Setup Python 3.10
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Build PyGAD from the Repository
run: |
python3 -m pip install --upgrade build
python3 -m build

- name: Install PyGAD after Building the .whl File
run: |
find ./dist/*.whl | xargs pip install

- name: Install PyTest
run: pip install pytest

- name: Run the Tests by Calling PyTest
run: |
pytest
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,4 @@ def fitness_func(ga_instance, solution, solution_idx):
matplotlib.pyplot.scatter(cluster_x, cluster_y)
matplotlib.pyplot.scatter(cluster_centers[cluster_idx, 0], cluster_centers[cluster_idx, 1], linewidths=5)
matplotlib.pyplot.title("Clustering using PyGAD")
matplotlib.pyplot.show()
matplotlib.pyplot.show()
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ def mutation_func(offspring, ga_instance):
mutation_type=mutation_func)

ga_instance.run()
ga_instance.plot_fitness()
ga_instance.plot_fitness()
41 changes: 41 additions & 0 deletions examples/example_fitness_wrapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import pygad
import numpy

"""
All the callback functions/methods in PyGAD have limits in the number of arguments passed.
For example, the fitness function accepts only 3 arguments:
1. The pygad.GA instance.
2. The solution(s).
3. The index (indices) of the passed solution(s).
If it is necessary to pass extra arguments to the fitness function, for example, then follow these steps:
1. Create a wrapper function that accepts only the number of arguments meeded by PyGAD.
2. Define the extra arguments in the body of the wrapper function.
3. Create an inner fitness function inside the wrapper function with whatever extra arguments needed.
4. Call the inner fitness function from the wrapper function while passing the extra arguments.

This is an example that passes a list ([10, 20, 30]) to the inner fitness function. The list has 3 numbers.
A number is randomly selected from the list and added to the calculated fitness.
"""

function_inputs = [4,-2,3.5,5,-11,-4.7]
desired_output = 44

def fitness_func_wrapper(ga_instanse, solution, solution_idx):
def fitness_func(ga_instanse, solution, solution_idx, *args):
output = numpy.sum(solution*function_inputs)
output += numpy.random.choice(args)
fitness = 1.0 / (numpy.abs(output - desired_output) + 0.000001)
return fitness
args = [10, 20, 30]
fitness = fitness_func(ga_instanse, solution, solution_idx, *args)
return fitness

ga_instance = pygad.GA(num_generations=3,
num_parents_mating=5,
fitness_func=fitness_func_wrapper,
sol_per_pop=10,
num_genes=len(function_inputs),
suppress_warnings=True)

ga_instance.run()
ga_instance.plot_fitness()
File renamed without changes.
53,070 changes: 26,535 additions & 26,535 deletions example_travelling_salesman.ipynb → examples/example_travelling_salesman.ipynb

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions pygad/cnn/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .cnn import *

__version__ = "1.0.0"

Loading