Skip to content

Commit

Permalink
Add a test using pytest-freethreaded
Browse files Browse the repository at this point in the history
  • Loading branch information
porink0424 committed Oct 30, 2024
1 parent fd026f6 commit ee54926
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ jobs:
nogil: true
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools numpy hypothesis
python -m pip install --upgrade pip setuptools numpy hypothesis pytest pytest-freethreaded
pip install --progress-bar off .
- run: python -m unittest
- run: python -m pytest --threads 1 --iterations 1 --require-gil-disabled tests/test_free_threaded.py
test-numpy2:
runs-on: ubuntu-latest
steps:
Expand Down
22 changes: 22 additions & 0 deletions tests/test_free_threaded.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import numpy as np
import pytest
from cmaes import CMA


@pytest.mark.freethreaded(threads=10, iterations=200)
def test_simple_optimization():
optimizer = CMA(mean=np.zeros(2), sigma=1.3)

def quadratic(x1: float, x2: float) -> float:
return (x1 - 3) ** 2 + (10 * (x2 + 2)) ** 2

while True:
solutions = []
for _ in range(optimizer.population_size):
x = optimizer.ask()
value = quadratic(x[0], x[1])
solutions.append((x, value))
optimizer.tell(solutions)

if optimizer.should_stop():
break

0 comments on commit ee54926

Please sign in to comment.