Repository navigation
181 lines (162 loc) · 7.11 KB
/
Copy pathmain.yml
File metadata and controls
181 lines (162 loc) · 7.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# PyGAD GitHub Actions Workflow
# This workflow uses a Matrix Strategy to test PyGAD across multiple Python versions in parallel.
name: PyGAD PyTest Matrix
permissions:
contents: read
on:
push:
# Trigger the workflow on pushes to the 'github-actions' branch.
branches:
- github-actions
# - master
# Only run the workflow if changes are made in these directories.
paths:
- 'pygad/**'
- 'tests/**'
- 'examples/**'
- 'requirements.txt'
- 'pyproject.toml'
- 'setup.py'
- 'MANIFEST.in'
- '.github/workflows/main.yml'
- '.github/workflows/release.yml'
- 'tools/release.py'
# Test relevant pull requests, including fork contributions, against master.
pull_request:
branches:
- master
paths:
- 'pygad/**'
- 'tests/**'
- 'examples/**'
- 'requirements.txt'
- 'pyproject.toml'
- 'setup.py'
- 'MANIFEST.in'
- '.github/workflows/main.yml'
- '.github/workflows/release.yml'
- 'tools/release.py'
# Allows manual triggering of the workflow from the GitHub Actions tab.
workflow_dispatch:
# Release tags run this same matrix before publishing.
workflow_call:
jobs:
numpy-windows:
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
include:
- python-version: "3.9"
numpy-requirement: "numpy==1.24.4"
numpy-label: "NumPy 1.24.4"
- python-version: "3.14"
numpy-requirement: "numpy"
numpy-label: "Latest NumPy"
name: Windows / Python ${{ matrix.python-version }} / ${{ matrix.numpy-label }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install PyGAD and NumPy
run: python -m pip install . pytest "${{ matrix.numpy-requirement }}"
- name: Verify Installed Versions
working-directory: ${{ runner.temp }}
run: python -c "import numpy, pygad; print('NumPy:', numpy.__version__); print('Testing installed package:', pygad.__file__)"
# Windows used 32-bit storage for dtype=int before NumPy 2.0.
# Run the same regression tests on older and current NumPy releases.
- name: Test Gene Storage and Integer Mutation
working-directory: ${{ runner.temp }}
run: >-
python -m pytest
"${{ github.workspace }}/tests/test_python_int_storage.py"
"${{ github.workspace }}/tests/test_gene_type_conversion.py"
"${{ github.workspace }}/tests/test_initial_population.py"
"${{ github.workspace }}/tests/test_mutation_integer_limits.py"
"${{ github.workspace }}/tests/test_nsga3_population_growth.py"
"${{ github.workspace }}/tests/test_sbx_polynomial.py"
"${{ github.workspace }}/tests/test_parent_selection_regressions.py"
"${{ github.workspace }}/tests/test_permutation_mutation.py"
-q -W error::DeprecationWarning
pytest:
# Use the latest Ubuntu runner for all jobs.
runs-on: ubuntu-latest
# The Strategy Matrix defines the environments to test.
# GitHub Actions will spawn a separate, parallel job for each version in the list.
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
# Dynamic name that appears in the GitHub Actions UI for each parallel job.
name: PyTest / Python ${{ matrix.python-version }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
# Setup the specific Python version defined in the current matrix iteration.
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
# Install project dependencies from requirements.txt.
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
# Added timeout and no-cache to prevent SSL/Network decryption errors
pip install --default-timeout=100 --no-cache-dir -r requirements.txt
if [ "${{ matrix.python-version }}" != "3.14" ] && [ "${{ matrix.python-version }}" != "3.8" ]; then
# This block runs if the version IS NOT 3.14 or 3.8
# Using a retry loop for large DL frameworks to handle transient network issues
echo "Installing deep learning libraries."
for i in {1..3}; do
pip install --default-timeout=100 --no-cache-dir tensorflow && break || \
(echo "Retry $i failed, waiting 10s..." && sleep 10)
done
pip install --upgrade keras
pip install torch
else
# This block runs if the version IS 3.14 or 3.8
echo "Skipping heavy deep learning libraries for Python ${{ matrix.python-version }}."
fi
# Verify the core deep learning frameworks
echo "Verifying installations..."
python -c "import tensorflow; print('TensorFlow version:', tensorflow.__version__)" || echo "TensorFlow not installed"
python -c "import keras; print('Keras version:', keras.__version__)" || echo "Keras not installed"
python -c "import torch; print('PyTorch version:', torch.__version__)" || echo "PyTorch not installed"
# Build the PyGAD package distribution (generating .tar.gz and .whl files).
# This ensures the package build process is valid on this Python version.
- name: Build PyGAD
run: |
python3 -m pip install --upgrade build
python3 -m build
# Install the newly built .whl file to verify the package is installable.
# Install with the 'visualize' extra so matplotlib is available for the
# plotting tests (tests/test_visualize.py). This also validates that the
# optional 'visualize' extra resolves correctly.
- name: Install PyGAD from Wheel
run: |
WHEEL=$(ls dist/*.whl)
pip install "${WHEEL}[visualize,report]"
- name: Install PyTest
run: |
pip install pytest responses
if [ "${{ matrix.python-version }}" != "3.8" ]; then
pip install 'vilvik>=0.5.4'
fi
# Run the entire test suite using PyTest.
# PyTest automatically discovers all test files in the 'tests/' directory.
# This includes our new tests for visualization, operators, parallel processing, etc.
- name: Run Tests
run: |
# Run outside the checkout so imports exercise the installed wheel.
cd "$RUNNER_TEMP"
python -c "import pygad; print('Testing installed package:', pygad.__file__)"
if [ "${{ matrix.python-version }}" == "3.14" ] || [ "${{ matrix.python-version }}" == "3.8" ]; then
python -m pytest "$GITHUB_WORKSPACE/tests" \
--ignore="$GITHUB_WORKSPACE/tests/test_kerasga.py" \
--ignore="$GITHUB_WORKSPACE/tests/test_torchga.py"
else
python -m pytest "$GITHUB_WORKSPACE/tests"
fi