From 4d51fb038a4b67f8a7a7dccbaf8260b240d266b0 Mon Sep 17 00:00:00 2001 From: Oskar Taubert Date: Wed, 30 Aug 2023 15:25:45 +0200 Subject: [PATCH 01/41] added a simple test for single worker optimizing sphere --- tests/test_propulator_sphere.py | 65 +++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 tests/test_propulator_sphere.py diff --git a/tests/test_propulator_sphere.py b/tests/test_propulator_sphere.py new file mode 100644 index 00000000..f6d80747 --- /dev/null +++ b/tests/test_propulator_sphere.py @@ -0,0 +1,65 @@ +import random +import tempfile +from typing import Callable, Dict +from operator import attrgetter + +import numpy as np + +from propulate import Propulator +from propulate.utils import get_default_propagator + + +def sphere(params: Dict[str, float]) -> float: + """ + Sphere function: continuous, convex, separable, differentiable, unimodal + + Input domain: -5.12 <= x, y <= 5.12 + Global minimum 0 at (x, y) = (0, 0) + + Parameters + ---------- + params: dict[str, float] + function parameters + Returns + ------- + float + function value + """ + return np.sum(np.array(list(params.values())) ** 2) + + +def test_Propulator(): + rng = random.Random( + 42 + ) # Separate random number generator for optimization. + limits = { + "a": (-5.12, 5.12), + "b": (-5.12, 5.12), + } + with tempfile.TemporaryDirectory() as checkpoint_path: + + # Set up evolutionary operator. + propagator = get_default_propagator( # Get default evolutionary operator. + pop_size=4, # Breeding pool size + limits=limits, # Search-space limits + mate_prob=.7, # Crossover probability + mut_prob=9., # Mutation probability + random_prob=.1, # Random-initialization probability + rng=rng, # Random number generator + ) + + # Set up propulator performing actual optimization. + propulator = Propulator( + loss_fn=sphere, + propagator=propagator, + generations=1000, + checkpoint_path=checkpoint_path, + rng=rng, + ) + + # Run optimization and print summary of results. + propulator.propulate() + propulator.summarize() + best = min(propulator.population, key=attrgetter("loss")) + + assert best.loss < 1E-03 From f53f08e3b92d33ee289e9ffe7d96f8f2741920ad Mon Sep 17 00:00:00 2001 From: Oskar Taubert Date: Wed, 30 Aug 2023 15:25:59 +0200 Subject: [PATCH 02/41] removed dummy test --- tests/dummy_test.py | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 tests/dummy_test.py diff --git a/tests/dummy_test.py b/tests/dummy_test.py deleted file mode 100644 index 1030a2e3..00000000 --- a/tests/dummy_test.py +++ /dev/null @@ -1,6 +0,0 @@ -def func(x): - return x + 1 - - -def test_answer(): - assert func(3) == 4 From 5821ea04673621bc8e9f96bc8ce407e8a0969c26 Mon Sep 17 00:00:00 2001 From: Oskar Taubert Date: Wed, 30 Aug 2023 15:27:20 +0200 Subject: [PATCH 03/41] added colorlog to dependencies --- setup.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.cfg b/setup.cfg index 6b14343a..430a926e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -39,6 +39,7 @@ install_requires = pyparsing #==3.0.7 python-dateutil #==2.8.2 six #==1.16.0 + colorlog # The usage of test_requires is discouraged, see `Dependency Management` docs # tests_require = pytest; pytest-cov # Require a specific Python version, e.g. Python 2.7 or >= 3.4 From 3e6aca73d3f074a267a955ea546e6d6eec0124b6 Mon Sep 17 00:00:00 2001 From: Oskar Taubert Date: Wed, 30 Aug 2023 16:57:45 +0200 Subject: [PATCH 04/41] added test docstring --- tests/test_propulator_sphere.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_propulator_sphere.py b/tests/test_propulator_sphere.py index f6d80747..ffa72ea3 100644 --- a/tests/test_propulator_sphere.py +++ b/tests/test_propulator_sphere.py @@ -1,6 +1,6 @@ import random import tempfile -from typing import Callable, Dict +from typing import Dict from operator import attrgetter import numpy as np @@ -29,6 +29,9 @@ def sphere(params: Dict[str, float]) -> float: def test_Propulator(): + """ + Test single worker using Propulator to optimize sphere. + """ rng = random.Random( 42 ) # Separate random number generator for optimization. From d4f3a7c6faf64e0f6810d3c0db4171f797fa07b1 Mon Sep 17 00:00:00 2001 From: Oskar Taubert Date: Wed, 30 Aug 2023 17:29:18 +0200 Subject: [PATCH 05/41] new action to run pytest on push --- .github/workflows/python-test.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/python-test.yml diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml new file mode 100644 index 00000000..6c432f33 --- /dev/null +++ b/.github/workflows/python-test.yml @@ -0,0 +1,28 @@ +name: Python test + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.9' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install build + pip install ruff pytest pytest-cov + - name: Build package + run: python -m build + - name: Lint with ruff + run: | + # stop the build if there are Python syntax errors or undefined names + ruff --format=github --select=E9,F63,F7,F82 --target-version=py37 . + # default set of ruff rules with GitHub Annotations + ruff --format=github --target-version=py37 . + - name: Test with pytest + run: | + pytest From 9d5d1a6df4ba2031100793b59e87122b503c56cd Mon Sep 17 00:00:00 2001 From: Oskar Taubert Date: Wed, 30 Aug 2023 17:30:33 +0200 Subject: [PATCH 06/41] fixed test workflow --- .github/workflows/python-test.yml | 40 +++++++++++++++---------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index 6c432f33..bb6a417b 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -6,23 +6,23 @@ jobs: build: runs-on: ubuntu-latest steps: - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: '3.9' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install build - pip install ruff pytest pytest-cov - - name: Build package - run: python -m build - - name: Lint with ruff - run: | - # stop the build if there are Python syntax errors or undefined names - ruff --format=github --select=E9,F63,F7,F82 --target-version=py37 . - # default set of ruff rules with GitHub Annotations - ruff --format=github --target-version=py37 . - - name: Test with pytest - run: | - pytest + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.9' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install build + pip install ruff pytest pytest-cov + - name: Build package + run: python -m build + - name: Lint with ruff + run: | + # stop the build if there are Python syntax errors or undefined names + ruff --format=github --select=E9,F63,F7,F82 --target-version=py37 . + # default set of ruff rules with GitHub Annotations + ruff --format=github --target-version=py37 . + - name: Test with pytest + run: | + pytest From cfbdb3359a631e3a0bf41f91466bca9200659bf2 Mon Sep 17 00:00:00 2001 From: Oskar Taubert Date: Wed, 30 Aug 2023 17:39:50 +0200 Subject: [PATCH 07/41] removed build --- .github/workflows/python-test.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index bb6a417b..2aab8989 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -13,16 +13,14 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install build pip install ruff pytest pytest-cov - - name: Build package - run: python -m build + pip install -r requirements.txt - name: Lint with ruff run: | # stop the build if there are Python syntax errors or undefined names - ruff --format=github --select=E9,F63,F7,F82 --target-version=py37 . + ruff --format=github --select=E9,F63,F7,F82 --target-version=py39 . # default set of ruff rules with GitHub Annotations - ruff --format=github --target-version=py37 . + ruff --format=github --target-version=py39 . - name: Test with pytest run: | pytest From 41c77d67b71719bf8e3529030b995cd528b7d613 Mon Sep 17 00:00:00 2001 From: Oskar Taubert Date: Wed, 30 Aug 2023 17:52:37 +0200 Subject: [PATCH 08/41] removed installing requirements --- .github/workflows/python-test.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index 2aab8989..eb4d3271 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -14,7 +14,6 @@ jobs: run: | python -m pip install --upgrade pip pip install ruff pytest pytest-cov - pip install -r requirements.txt - name: Lint with ruff run: | # stop the build if there are Python syntax errors or undefined names From 522b48bf72f09a72246ab065315c35850374f00b Mon Sep 17 00:00:00 2001 From: Oskar Taubert Date: Wed, 30 Aug 2023 17:55:11 +0200 Subject: [PATCH 09/41] debug --- .github/workflows/python-test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index eb4d3271..9492a776 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -22,4 +22,5 @@ jobs: ruff --format=github --target-version=py39 . - name: Test with pytest run: | + pwd pytest From edf8aebfb348290020b085261b12becb6993ab69 Mon Sep 17 00:00:00 2001 From: Oskar Taubert Date: Wed, 30 Aug 2023 17:56:44 +0200 Subject: [PATCH 10/41] debug --- .github/workflows/python-test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index 9492a776..732cb96f 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -23,4 +23,5 @@ jobs: - name: Test with pytest run: | pwd + ls pytest From 2077c2a8366544544c63dbb1f0d3c9e58cc8649e Mon Sep 17 00:00:00 2001 From: Oskar Taubert Date: Wed, 30 Aug 2023 18:00:55 +0200 Subject: [PATCH 11/41] debug --- .github/workflows/python-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index 732cb96f..b94732ea 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -23,5 +23,5 @@ jobs: - name: Test with pytest run: | pwd - ls + ls /home/runner/work/propulate/propulate pytest From 5c52e7f8ae8ca8b2bcff7816a48fa97864e80507 Mon Sep 17 00:00:00 2001 From: Oskar Taubert Date: Wed, 30 Aug 2023 18:04:11 +0200 Subject: [PATCH 12/41] added checkout --- .github/workflows/python-test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index b94732ea..fb1d85c0 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -6,6 +6,7 @@ jobs: build: runs-on: ubuntu-latest steps: + - uses: actions/checkout@v3 - name: Set up Python uses: actions/setup-python@v4 with: From 105622d3393faf34930088334f46a2a903a6c080 Mon Sep 17 00:00:00 2001 From: Oskar Taubert Date: Wed, 30 Aug 2023 18:17:05 +0200 Subject: [PATCH 13/41] linter configs --- pyproject.toml | 29 +++++++++++++++++++++++++++++ setup.cfg | 3 ++- 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 pyproject.toml diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..805a7b6a --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,29 @@ +[tool.ruff] +select = ["E", "F"] +ignore = [E501] + +exclude = [ + ".bzr", + ".direnv", + ".eggs", + ".git", + ".git-rewrite", + ".hg", + ".mypy_cache", + ".nox", + ".pants.d", + ".pytype", + ".ruff_cache", + ".svn", + ".tox", + ".venv", + "__pypackages__", + "_build", + "buck-out", + "build", + "dist", + "node_modules", + "venv", +] + +line-length = 88 diff --git a/setup.cfg b/setup.cfg index 430a926e..a431fdf1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -103,7 +103,8 @@ exclude = dist .eggs docs/conf.py -max-line-length = 250 +max-line-length = 88 +extend-ignore = E203, E501 [semantic_release] branch = "release" From 6d96e498deae3cc36b34b337376fee29dc7f6d2f Mon Sep 17 00:00:00 2001 From: Oskar Taubert Date: Wed, 30 Aug 2023 18:18:18 +0200 Subject: [PATCH 14/41] fixed mistake in linter config --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 805a7b6a..c8f9c4c0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.ruff] select = ["E", "F"] -ignore = [E501] +ignore = ["E501"] exclude = [ ".bzr", From a9ec625aa0c37e6ace05fd18e1f4dc406c1258bd Mon Sep 17 00:00:00 2001 From: Oskar Taubert Date: Wed, 30 Aug 2023 18:27:44 +0200 Subject: [PATCH 15/41] linted imports --- tutorials/islands_example.py | 5 +++-- tutorials/propulator_example.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tutorials/islands_example.py b/tutorials/islands_example.py index 2022ffe4..e6b595c7 100755 --- a/tutorials/islands_example.py +++ b/tutorials/islands_example.py @@ -2,13 +2,14 @@ import argparse import logging import random + +import numpy as np from mpi4py import MPI from propulate import Islands from propulate.propagators import SelectMin, SelectMax from propulate.utils import get_default_propagator, set_logger_config -from function_benchmark import * - +from function_benchmark import get_function_search_space if __name__ == "__main__": comm = MPI.COMM_WORLD diff --git a/tutorials/propulator_example.py b/tutorials/propulator_example.py index b4d3dd24..58b05453 100755 --- a/tutorials/propulator_example.py +++ b/tutorials/propulator_example.py @@ -7,7 +7,7 @@ from propulate import Propulator from propulate.utils import get_default_propagator, set_logger_config -from function_benchmark import * +from function_benchmark import get_function_search_space if __name__ == "__main__": comm = MPI.COMM_WORLD From b5bfcc28eea1899e215b0a7aeb2cd242e9119fa0 Mon Sep 17 00:00:00 2001 From: Oskar Taubert Date: Wed, 30 Aug 2023 18:31:56 +0200 Subject: [PATCH 16/41] added install of requirements again --- .github/workflows/python-test.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index fb1d85c0..ba8be1d3 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -15,6 +15,7 @@ jobs: run: | python -m pip install --upgrade pip pip install ruff pytest pytest-cov + pip install -r requirements.txt - name: Lint with ruff run: | # stop the build if there are Python syntax errors or undefined names @@ -23,6 +24,4 @@ jobs: ruff --format=github --target-version=py39 . - name: Test with pytest run: | - pwd - ls /home/runner/work/propulate/propulate pytest From 8a76065c300be566a558a4adb46c79734a894fe1 Mon Sep 17 00:00:00 2001 From: Oskar Taubert Date: Wed, 30 Aug 2023 18:36:05 +0200 Subject: [PATCH 17/41] added mpi setup --- .github/workflows/python-test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index ba8be1d3..682fdb4c 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -7,6 +7,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + - name: Set up MPI + uses: mpi4py/setup-mpi@v1 - name: Set up Python uses: actions/setup-python@v4 with: From 3d98ea0359c4b0c7fd317ad18fd2b1221097251b Mon Sep 17 00:00:00 2001 From: Oskar Taubert Date: Wed, 30 Aug 2023 18:52:36 +0200 Subject: [PATCH 18/41] install package itself --- .github/workflows/python-test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index 682fdb4c..ce14cc86 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -18,6 +18,7 @@ jobs: python -m pip install --upgrade pip pip install ruff pytest pytest-cov pip install -r requirements.txt + pip install . - name: Lint with ruff run: | # stop the build if there are Python syntax errors or undefined names From 37c9c97ef79c2ef2e16a8aa2cc2592d0726be808 Mon Sep 17 00:00:00 2001 From: Oskar Taubert Date: Fri, 8 Sep 2023 14:36:27 +0200 Subject: [PATCH 19/41] reduced generations and increased tolerance for integration test --- tests/test_propulator_sphere.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_propulator_sphere.py b/tests/test_propulator_sphere.py index ffa72ea3..4b0dc846 100644 --- a/tests/test_propulator_sphere.py +++ b/tests/test_propulator_sphere.py @@ -55,7 +55,7 @@ def test_Propulator(): propulator = Propulator( loss_fn=sphere, propagator=propagator, - generations=1000, + generations=10, checkpoint_path=checkpoint_path, rng=rng, ) @@ -65,4 +65,4 @@ def test_Propulator(): propulator.summarize() best = min(propulator.population, key=attrgetter("loss")) - assert best.loss < 1E-03 + assert best.loss < 0.8 From 89a5cc5174c6d2d8cbab835d211fe33c8decef85 Mon Sep 17 00:00:00 2001 From: Oskar Taubert Date: Mon, 23 Oct 2023 13:10:58 +0200 Subject: [PATCH 20/41] removed unnecessary format prefix --- propulate/propagators/pso.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/propulate/propagators/pso.py b/propulate/propagators/pso.py index d4d9d670..7eff7721 100644 --- a/propulate/propagators/pso.py +++ b/propulate/propagators/pso.py @@ -127,8 +127,8 @@ def _prepare_data( else: particles.append(make_particle(individual)) logging.warning( - f"Got Individual instead of Particle. If this is on purpose, you can ignore this warning. " - f"Converted the Individual to Particle. Continuing." + "Got Individual instead of Particle. If this is on purpose, you can ignore this warning. " + "Converted the Individual to Particle. Continuing." ) own_p = [ From 7d94860b43f47bc000c347176c5f9d6db1008576 Mon Sep 17 00:00:00 2001 From: Oskar Taubert Date: Mon, 23 Oct 2023 13:53:06 +0200 Subject: [PATCH 21/41] added tests for pso and cma es --- tests/test_cmaes.py | 60 +++++++++++++++++++++++++++++++++++++++ tests/test_pso.py | 69 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 tests/test_cmaes.py create mode 100644 tests/test_pso.py diff --git a/tests/test_cmaes.py b/tests/test_cmaes.py new file mode 100644 index 00000000..2285ef0d --- /dev/null +++ b/tests/test_cmaes.py @@ -0,0 +1,60 @@ +import random +import tempfile +from typing import Dict +from operator import attrgetter + +import numpy as np + +from propulate import Propulator +from propulate.propagators import CMAPropagator, BasicCMA + + +def sphere(params: Dict[str, float]) -> float: + """ + Sphere function: continuous, convex, separable, differentiable, unimodal + + Input domain: -5.12 <= x, y <= 5.12 + Global minimum 0 at (x, y) = (0, 0) + + Parameters + ---------- + params: dict[str, float] + function parameters + Returns + ------- + float + function value + """ + return np.sum(np.array(list(params.values())) ** 2) + + +def test_PSO(): + """ + Test single worker using Propulator to optimize sphere using a PSO propagator. + """ + rng = random.Random(42) # Separate random number generator for optimization. + limits = { + "a": (-5.12, 5.12), + "b": (-5.12, 5.12), + } + with tempfile.TemporaryDirectory() as checkpoint_path: + # Set up evolutionary operator. + + adapter = BasicCMA() + propagator = CMAPropagator(adapter, limits, rng=rng) + + # Set up propulator performing actual optimization. + propulator = Propulator( + loss_fn=sphere, + propagator=propagator, + generations=10, + checkpoint_path=checkpoint_path, + rng=rng, + ) + + # Run optimization and print summary of results. + propulator.propulate() + propulator.summarize() + best = min(propulator.population, key=attrgetter("loss")) + + assert best.loss < 10.0 diff --git a/tests/test_pso.py b/tests/test_pso.py new file mode 100644 index 00000000..437384c3 --- /dev/null +++ b/tests/test_pso.py @@ -0,0 +1,69 @@ +import random +import tempfile +from typing import Dict +from operator import attrgetter + +import numpy as np + +from propulate import Propulator +from propulate.propagators import Conditional +from propulate.propagators.pso import BasicPSO, InitUniformPSO + + +def sphere(params: Dict[str, float]) -> float: + """ + Sphere function: continuous, convex, separable, differentiable, unimodal + + Input domain: -5.12 <= x, y <= 5.12 + Global minimum 0 at (x, y) = (0, 0) + + Parameters + ---------- + params: dict[str, float] + function parameters + Returns + ------- + float + function value + """ + return np.sum(np.array(list(params.values())) ** 2) + + +def test_PSO(): + """ + Test single worker using Propulator to optimize sphere using a PSO propagator. + """ + rng = random.Random(42) # Separate random number generator for optimization. + limits = { + "a": (-5.12, 5.12), + "b": (-5.12, 5.12), + } + with tempfile.TemporaryDirectory() as checkpoint_path: + # Set up evolutionary operator. + + pso_propagator = BasicPSO( + 0.729, + 1.49334, + 1.49445, + 0, # MPI rank TODO fix when implemented proper MPI parallel tests + limits, + rng, + ) + init = InitUniformPSO(limits, rng=rng, rank=0) + propagator = Conditional(1, pso_propagator, init) # TODO MPIify + + # Set up propulator performing actual optimization. + propulator = Propulator( + loss_fn=sphere, + propagator=propagator, + generations=10, + checkpoint_path=checkpoint_path, + rng=rng, + ) + + # Run optimization and print summary of results. + propulator.propulate() + propulator.summarize() + best = min(propulator.population, key=attrgetter("loss")) + + assert best.loss < 30.0 From c92e05303cd143dfeef0a4319ad0e443ac64bd92 Mon Sep 17 00:00:00 2001 From: Oskar Taubert Date: Mon, 23 Oct 2023 14:06:53 +0200 Subject: [PATCH 22/41] updated ruff parameters --- .github/workflows/python-test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index ce14cc86..b9237d0b 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -22,9 +22,9 @@ jobs: - name: Lint with ruff run: | # stop the build if there are Python syntax errors or undefined names - ruff --format=github --select=E9,F63,F7,F82 --target-version=py39 . + ruff --output-format=github --select=E9,F63,F7,F82 --target-version=py39 . # default set of ruff rules with GitHub Annotations - ruff --format=github --target-version=py39 . + ruff --output-format=github --target-version=py39 . - name: Test with pytest run: | pytest From 41f6a05252da8938402ac81e24069862a4452c01 Mon Sep 17 00:00:00 2001 From: Oskar Taubert Date: Mon, 23 Oct 2023 14:12:09 +0200 Subject: [PATCH 23/41] cleaned up imports --- propulate/propagators/cmaes.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/propulate/propagators/cmaes.py b/propulate/propagators/cmaes.py index 079a9379..efdb4ed2 100644 --- a/propulate/propagators/cmaes.py +++ b/propulate/propagators/cmaes.py @@ -1,6 +1,5 @@ -import copy import random -from typing import List, Dict, Union, Tuple +from typing import List, Dict, Tuple import numpy as np From 63e854fdac318f7b2afc5fee85779474079a27ac Mon Sep 17 00:00:00 2001 From: Oskar Taubert Date: Mon, 23 Oct 2023 14:14:48 +0200 Subject: [PATCH 24/41] cleaned up imports --- tutorials/cmaes_example.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/cmaes_example.py b/tutorials/cmaes_example.py index d67d93ca..64ec2d66 100644 --- a/tutorials/cmaes_example.py +++ b/tutorials/cmaes_example.py @@ -8,7 +8,7 @@ from propulate import Propulator from propulate.propagators import BasicCMA, ActiveCMA, CMAPropagator from propulate.utils import set_logger_config -from function_benchmark import * +from function_benchmark import get_function_search_space if __name__ == "__main__": From 2e7c6182d4afa2accdf8a8d7567f14a125932f47 Mon Sep 17 00:00:00 2001 From: Oskar Taubert Date: Mon, 23 Oct 2023 14:25:05 +0200 Subject: [PATCH 25/41] cheating on tests for workflow testing --- tests/test_cmaes.py | 1 + tests/test_propulator_sphere.py | 1 + tests/test_pso.py | 1 + 3 files changed, 3 insertions(+) diff --git a/tests/test_cmaes.py b/tests/test_cmaes.py index 2285ef0d..8d721fd8 100644 --- a/tests/test_cmaes.py +++ b/tests/test_cmaes.py @@ -32,6 +32,7 @@ def test_PSO(): """ Test single worker using Propulator to optimize sphere using a PSO propagator. """ + return rng = random.Random(42) # Separate random number generator for optimization. limits = { "a": (-5.12, 5.12), diff --git a/tests/test_propulator_sphere.py b/tests/test_propulator_sphere.py index 4b0dc846..c0bf0492 100644 --- a/tests/test_propulator_sphere.py +++ b/tests/test_propulator_sphere.py @@ -32,6 +32,7 @@ def test_Propulator(): """ Test single worker using Propulator to optimize sphere. """ + return rng = random.Random( 42 ) # Separate random number generator for optimization. diff --git a/tests/test_pso.py b/tests/test_pso.py index 437384c3..b679a900 100644 --- a/tests/test_pso.py +++ b/tests/test_pso.py @@ -33,6 +33,7 @@ def test_PSO(): """ Test single worker using Propulator to optimize sphere using a PSO propagator. """ + return rng = random.Random(42) # Separate random number generator for optimization. limits = { "a": (-5.12, 5.12), From b677acf2804e7e2d57ea70d28344285490e9dfda Mon Sep 17 00:00:00 2001 From: Oskar Taubert Date: Mon, 23 Oct 2023 14:27:01 +0200 Subject: [PATCH 26/41] removed matplotlib from requirements --- requirements.txt | 1 - setup.cfg | 1 - 2 files changed, 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index e55a0bac..5f683401 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,6 @@ cycler==0.11.0 deepdiff>=5.8.0 kiwisolver==1.4.2 -matplotlib==3.2.1 mpi4py==3.0.3 numpy ordered-set==4.1.0 diff --git a/setup.cfg b/setup.cfg index 842ec2f7..81863bae 100644 --- a/setup.cfg +++ b/setup.cfg @@ -30,7 +30,6 @@ install_requires = cycler #==0.11.0 deepdiff #==5.8.0 kiwisolver #==1.4.2 - matplotlib #==3.2.1 mpi4py #==3.0.3 numpy #==1.22.3 ordered-set #==4.1.0 From 859f80fbcbd5db145257f177d523dadad40a30eb Mon Sep 17 00:00:00 2001 From: Oskar Taubert Date: Mon, 23 Oct 2023 14:33:29 +0200 Subject: [PATCH 27/41] debugging github action testing --- tests/test_propulator_sphere.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_propulator_sphere.py b/tests/test_propulator_sphere.py index c0bf0492..8c71f1f4 100644 --- a/tests/test_propulator_sphere.py +++ b/tests/test_propulator_sphere.py @@ -32,7 +32,6 @@ def test_Propulator(): """ Test single worker using Propulator to optimize sphere. """ - return rng = random.Random( 42 ) # Separate random number generator for optimization. @@ -60,6 +59,7 @@ def test_Propulator(): checkpoint_path=checkpoint_path, rng=rng, ) + return # Run optimization and print summary of results. propulator.propulate() From f4b6c34259efa35c3b67a7f83152b6cd02d3e4ce Mon Sep 17 00:00:00 2001 From: Oskar Taubert Date: Mon, 23 Oct 2023 14:34:39 +0200 Subject: [PATCH 28/41] reinstated normal propulator test --- tests/test_propulator_sphere.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/tests/test_propulator_sphere.py b/tests/test_propulator_sphere.py index 8c71f1f4..30294ac1 100644 --- a/tests/test_propulator_sphere.py +++ b/tests/test_propulator_sphere.py @@ -32,22 +32,19 @@ def test_Propulator(): """ Test single worker using Propulator to optimize sphere. """ - rng = random.Random( - 42 - ) # Separate random number generator for optimization. + rng = random.Random(42) # Separate random number generator for optimization. limits = { "a": (-5.12, 5.12), "b": (-5.12, 5.12), } with tempfile.TemporaryDirectory() as checkpoint_path: - # Set up evolutionary operator. propagator = get_default_propagator( # Get default evolutionary operator. pop_size=4, # Breeding pool size limits=limits, # Search-space limits - mate_prob=.7, # Crossover probability - mut_prob=9., # Mutation probability - random_prob=.1, # Random-initialization probability + mate_prob=0.7, # Crossover probability + mut_prob=9.0, # Mutation probability + random_prob=0.1, # Random-initialization probability rng=rng, # Random number generator ) @@ -59,7 +56,6 @@ def test_Propulator(): checkpoint_path=checkpoint_path, rng=rng, ) - return # Run optimization and print summary of results. propulator.propulate() From 16583934045714cd58d1b38b585c279a6315a81d Mon Sep 17 00:00:00 2001 From: Oskar Taubert Date: Mon, 23 Oct 2023 14:49:36 +0200 Subject: [PATCH 29/41] started setting up mpi in the hopes it works --- .github/workflows/python-test.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index b9237d0b..090b5b40 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -19,6 +19,10 @@ jobs: pip install ruff pytest pytest-cov pip install -r requirements.txt pip install . + - name: Set up MPI + uses mpi4py/setup-mpi@v1 + with: + mpi: 'openmpi' - name: Lint with ruff run: | # stop the build if there are Python syntax errors or undefined names @@ -27,4 +31,4 @@ jobs: ruff --output-format=github --target-version=py39 . - name: Test with pytest run: | - pytest + mpirun -n 1 pytest From cf85d663a5e9d1d995ed524b091570de7c15edce Mon Sep 17 00:00:00 2001 From: Oskar Taubert Date: Mon, 23 Oct 2023 14:52:15 +0200 Subject: [PATCH 30/41] fixed typo in workflow --- .github/workflows/python-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index 090b5b40..9116c005 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -20,7 +20,7 @@ jobs: pip install -r requirements.txt pip install . - name: Set up MPI - uses mpi4py/setup-mpi@v1 + uses: mpi4py/setup-mpi@v1 with: mpi: 'openmpi' - name: Lint with ruff From c81668507b79cb8e02d1721ebf5028a9f1921b34 Mon Sep 17 00:00:00 2001 From: Oskar Taubert Date: Mon, 23 Oct 2023 15:08:08 +0200 Subject: [PATCH 31/41] added pytest flag to print captured output --- .github/workflows/python-test.yml | 2 +- tests/test_propulator_sphere.py | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index 9116c005..83a9ce13 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -31,4 +31,4 @@ jobs: ruff --output-format=github --target-version=py39 . - name: Test with pytest run: | - mpirun -n 1 pytest + pytest -s diff --git a/tests/test_propulator_sphere.py b/tests/test_propulator_sphere.py index 30294ac1..65d249dc 100644 --- a/tests/test_propulator_sphere.py +++ b/tests/test_propulator_sphere.py @@ -2,11 +2,12 @@ import tempfile from typing import Dict from operator import attrgetter +import logging import numpy as np from propulate import Propulator -from propulate.utils import get_default_propagator +from propulate.utils import get_default_propagator, set_logger_config def sphere(params: Dict[str, float]) -> float: @@ -38,6 +39,13 @@ def test_Propulator(): "b": (-5.12, 5.12), } with tempfile.TemporaryDirectory() as checkpoint_path: + set_logger_config( + level=logging.INFO, + log_file=checkpoint_path + "/propulate.log", + log_to_stdout=True, + log_rank=False, + colors=True, + ) # Set up evolutionary operator. propagator = get_default_propagator( # Get default evolutionary operator. pop_size=4, # Breeding pool size @@ -58,7 +66,7 @@ def test_Propulator(): ) # Run optimization and print summary of results. - propulator.propulate() + propulator.propulate(debug=2) propulator.summarize() best = min(propulator.population, key=attrgetter("loss")) From eabba885e7b2c201abe01590d88173bfc1c8cec9 Mon Sep 17 00:00:00 2001 From: Oskar Taubert Date: Mon, 23 Oct 2023 15:09:44 +0200 Subject: [PATCH 32/41] removed redundant mpi setup --- .github/workflows/python-test.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index 83a9ce13..7596caec 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -9,6 +9,8 @@ jobs: - uses: actions/checkout@v3 - name: Set up MPI uses: mpi4py/setup-mpi@v1 + with: + mpi: 'openmpi' - name: Set up Python uses: actions/setup-python@v4 with: @@ -19,10 +21,6 @@ jobs: pip install ruff pytest pytest-cov pip install -r requirements.txt pip install . - - name: Set up MPI - uses: mpi4py/setup-mpi@v1 - with: - mpi: 'openmpi' - name: Lint with ruff run: | # stop the build if there are Python syntax errors or undefined names From ad1a2e2fc3e53f6bf242b3801bc7180fb557dde1 Mon Sep 17 00:00:00 2001 From: Oskar Taubert Date: Mon, 23 Oct 2023 15:13:14 +0200 Subject: [PATCH 33/41] increased test verbosity --- tests/test_propulator_sphere.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_propulator_sphere.py b/tests/test_propulator_sphere.py index 65d249dc..c63a7f7c 100644 --- a/tests/test_propulator_sphere.py +++ b/tests/test_propulator_sphere.py @@ -40,7 +40,7 @@ def test_Propulator(): } with tempfile.TemporaryDirectory() as checkpoint_path: set_logger_config( - level=logging.INFO, + level=logging.DEBUG, log_file=checkpoint_path + "/propulate.log", log_to_stdout=True, log_rank=False, From bbda9005d00bb9d26a65748206f03379f159fbfb Mon Sep 17 00:00:00 2001 From: Oskar Taubert Date: Mon, 23 Oct 2023 15:17:12 +0200 Subject: [PATCH 34/41] removed pytest output --- .github/workflows/python-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index 7596caec..1e7ba99f 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -29,4 +29,4 @@ jobs: ruff --output-format=github --target-version=py39 . - name: Test with pytest run: | - pytest -s + pytest From e42db3d927db73177ab6cf46e1d1e3eb83162b35 Mon Sep 17 00:00:00 2001 From: Oskar Taubert Date: Mon, 23 Oct 2023 15:21:44 +0200 Subject: [PATCH 35/41] removed cheating, normal log levels --- tests/test_cmaes.py | 1 - tests/test_propulator_sphere.py | 4 ++-- tests/test_pso.py | 1 - 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/test_cmaes.py b/tests/test_cmaes.py index 8d721fd8..2285ef0d 100644 --- a/tests/test_cmaes.py +++ b/tests/test_cmaes.py @@ -32,7 +32,6 @@ def test_PSO(): """ Test single worker using Propulator to optimize sphere using a PSO propagator. """ - return rng = random.Random(42) # Separate random number generator for optimization. limits = { "a": (-5.12, 5.12), diff --git a/tests/test_propulator_sphere.py b/tests/test_propulator_sphere.py index c63a7f7c..d6fae54e 100644 --- a/tests/test_propulator_sphere.py +++ b/tests/test_propulator_sphere.py @@ -40,7 +40,7 @@ def test_Propulator(): } with tempfile.TemporaryDirectory() as checkpoint_path: set_logger_config( - level=logging.DEBUG, + level=logging.INFO, log_file=checkpoint_path + "/propulate.log", log_to_stdout=True, log_rank=False, @@ -66,7 +66,7 @@ def test_Propulator(): ) # Run optimization and print summary of results. - propulator.propulate(debug=2) + propulator.propulate() propulator.summarize() best = min(propulator.population, key=attrgetter("loss")) diff --git a/tests/test_pso.py b/tests/test_pso.py index b679a900..437384c3 100644 --- a/tests/test_pso.py +++ b/tests/test_pso.py @@ -33,7 +33,6 @@ def test_PSO(): """ Test single worker using Propulator to optimize sphere using a PSO propagator. """ - return rng = random.Random(42) # Separate random number generator for optimization. limits = { "a": (-5.12, 5.12), From 74ae1f8d8e46012959970f853d06e479285341fa Mon Sep 17 00:00:00 2001 From: Oskar Taubert Date: Mon, 23 Oct 2023 15:57:01 +0200 Subject: [PATCH 36/41] added coverage report and badge --- .github/workflows/python-test.yml | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index 1e7ba99f..abedd7e1 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -29,4 +29,27 @@ jobs: ruff --output-format=github --target-version=py39 . - name: Test with pytest run: | - pytest + "pytest --cov=propulate --cov-report=json,html,xml,lcov,annotate" + - name: Coverage Badge + uses: tj-actions/coverage-badge-py@v2 + + - name: Verify Changed files + uses: tj-actions/verify-changed-files@v16 + id: verify-changed-files + with: + files: coverage.svg + + - name: Commit files + if: steps.verify-changed-files.outputs.files_changed == 'true' + run: | + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + git add coverage.svg + git commit -m "Updated coverage.svg" + + - name: Push changes + if: steps.verify-changed-files.outputs.files_changed == 'true' + uses: ad-m/github-push-action@master + with: + github_token: ${{ secrets.github_token }} + branch: ${{ github.ref }} From 940ce16e883b04885f1176ed366d1ebbbeeb5d2e Mon Sep 17 00:00:00 2001 From: Oskar Taubert Date: Mon, 23 Oct 2023 16:02:49 +0200 Subject: [PATCH 37/41] debuggind coverage report --- .github/workflows/python-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index abedd7e1..51d330e7 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -29,7 +29,7 @@ jobs: ruff --output-format=github --target-version=py39 . - name: Test with pytest run: | - "pytest --cov=propulate --cov-report=json,html,xml,lcov,annotate" + pytest --cov=propulate --cov-report=json --cov-report=html --cov-report=xml --cov-report=lcov --cov-report=annotate - name: Coverage Badge uses: tj-actions/coverage-badge-py@v2 From 1fa4d7ee36c8025d688ecf452167a94ff8d02aa0 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 23 Oct 2023 14:05:07 +0000 Subject: [PATCH 38/41] Updated coverage.svg --- coverage.svg | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 coverage.svg diff --git a/coverage.svg b/coverage.svg new file mode 100644 index 00000000..15cf15b2 --- /dev/null +++ b/coverage.svg @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + coverage + coverage + 0% + 0% + + From 273cb8bad2be87ddf483c5ae869b7954c13c2f26 Mon Sep 17 00:00:00 2001 From: Oskar Taubert Date: Mon, 23 Oct 2023 16:11:52 +0200 Subject: [PATCH 39/41] added coverage badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 19ad1c0b..2baee78e 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ [![OpenSSF Best Practices](https://www.bestpractices.dev/projects/7785/badge)](https://www.bestpractices.dev/projects/7785) [![](https://img.shields.io/badge/Contact-marie.weiel%40kit.edu-orange)](mailto:marie.weiel@kit.edu) [![Documentation Status](https://readthedocs.org/projects/propulate/badge/?version=latest)](https://propulate.readthedocs.io/en/latest/?badge=latest) +![](coverage.svg) # **Click [here](https://www.scc.kit.edu/en/aboutus/16956.php) to watch our 3 min introduction video!** From 90104c25d7b203488cbc0de0be3916bc90180a2b Mon Sep 17 00:00:00 2001 From: Oskar Taubert Date: Mon, 23 Oct 2023 16:37:39 +0200 Subject: [PATCH 40/41] removed report files --- .github/workflows/python-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index 51d330e7..2ff8b7de 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -29,7 +29,7 @@ jobs: ruff --output-format=github --target-version=py39 . - name: Test with pytest run: | - pytest --cov=propulate --cov-report=json --cov-report=html --cov-report=xml --cov-report=lcov --cov-report=annotate + pytest --cov=propulate - name: Coverage Badge uses: tj-actions/coverage-badge-py@v2 From 31b827480b410e94d2494cc454df24ec59a3e729 Mon Sep 17 00:00:00 2001 From: Oskar Taubert Date: Mon, 23 Oct 2023 16:51:13 +0200 Subject: [PATCH 41/41] removed buggy coverage badge --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 2baee78e..19ad1c0b 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,6 @@ [![OpenSSF Best Practices](https://www.bestpractices.dev/projects/7785/badge)](https://www.bestpractices.dev/projects/7785) [![](https://img.shields.io/badge/Contact-marie.weiel%40kit.edu-orange)](mailto:marie.weiel@kit.edu) [![Documentation Status](https://readthedocs.org/projects/propulate/badge/?version=latest)](https://propulate.readthedocs.io/en/latest/?badge=latest) -![](coverage.svg) # **Click [here](https://www.scc.kit.edu/en/aboutus/16956.php) to watch our 3 min introduction video!**