Skip to content

Commit 88405a4

Browse files
committed
Merge branch 'dev' into main
2 parents 1025b3c + 7361bee commit 88405a4

File tree

9 files changed

+29
-28
lines changed

9 files changed

+29
-28
lines changed

.github/workflows/python-test.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ name: test
55

66
on:
77
push:
8-
branches: [ main, dev ]
8+
branches: [ 'main', 'dev', 'dev-*' ]
99
tags: [ '*' ]
1010
pull_request:
11-
branches: [ main, dev ]
11+
branches: [ 'main', 'dev', 'dev-*' ]
1212

1313
jobs:
1414
build:
1515
runs-on: ${{ matrix.os }}
1616
strategy:
1717
matrix:
1818
os: [ubuntu-latest] # [ubuntu-latest, windows-latest, macos-latest]
19-
python-version: [3.8]
19+
python-version: ['3.6', '3.7', '3.8', '3.9']
2020

2121
steps:
2222
- uses: actions/checkout@v2

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ be made to members, instead new members should be created with the modified valu
6565
easily implement efficient multi-threading, see below!
6666

6767
The trainer automatically constructs `HallOfFame` and `LogBook` objects which keep track of your
68-
population and offspring. `EaModule` provides defaults for `get_stats_groups` that can be overridden
69-
if you wish to customize the tracked statistics.
68+
population and offspring. `EaModule` provides defaults for `get_stats_groups` and `get_progress_stats`
69+
that can be overridden if you wish to customize the tracked statistics and statistics displayed by tqdm.
7070

7171

7272
### Minimal OneMax Example

requirements.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pip>=21.0
2-
numpy>=1.21.0
3-
tqdm>=4.60.0
2+
numpy>=1.19
3+
tqdm>=4
4+
# ray should be an optional requirement
45
ray>=1.6.0

ruck/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,9 @@
3232
from ruck._train import Trainer
3333
from ruck._train import yield_population_steps
3434

35+
from ruck._history import HallOfFame
36+
from ruck._history import Logbook
37+
from ruck._history import StatsGroup
38+
3539
# functional utils
3640
from ruck import functional as R

ruck/_history.py

-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ def __iter__(self):
239239
yield self[i]
240240

241241

242-
243242
# ========================================================================= #
244243
# END #
245244
# ========================================================================= #

ruck/_module.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
from typing import Sequence
3030
from typing import TypeVar
3131

32+
import numpy as np
33+
3234
from ruck._history import StatsGroup
3335
from ruck._member import Population
3436
from ruck.util._args import HParamsMixin
@@ -47,12 +49,15 @@ class EaModule(Generic[T], HParamsMixin):
4749
# OVERRIDABLE DEFAULTS
4850

4951
def get_stats_groups(self) -> Dict[str, StatsGroup[T, Any]]:
50-
# additional stats to be recorded
51-
return {}
52+
# default stats groups
53+
return {
54+
'fit': StatsGroup(lambda pop: [m.fitness for m in pop], min=np.min, max=np.max, mean=np.mean)
55+
}
5256

5357
def get_progress_stats(self) -> Sequence[str]:
5458
# which stats are included in the progress bar
55-
return ('evals', 'fit:max',)
59+
# - values added by trainer
60+
return ('evals', 'fit:max')
5661

5762
# REQUIRED
5863

@@ -62,10 +67,10 @@ def gen_starting_values(self) -> List[T]:
6267
def generate_offspring(self, population: Population[T]) -> Population[T]:
6368
raise NotImplementedError
6469

65-
def select_population(self, population: Population[T], offspring: Population[T]) -> Population[T]:
70+
def evaluate_values(self, values: List[T]) -> List[float]:
6671
raise NotImplementedError
6772

68-
def evaluate_values(self, values: List[T]) -> List[float]:
73+
def select_population(self, population: Population[T], offspring: Population[T]) -> Population[T]:
6974
raise NotImplementedError
7075

7176

ruck/_train.py

+2-13
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ def __init__(
130130
def fit(self, module: EaModule[T]) -> Tuple[Population[T], Logbook[T], HallOfFame[T]]:
131131
assert isinstance(module, EaModule)
132132
# history trackers
133-
logbook, halloffame = self._create_default_trackers(module)
133+
logbook = Logbook('gen', 'evals', **module.get_stats_groups())
134+
halloffame = HallOfFame(n_best=self._history_n_best, maximize=True)
134135
# progress bar and training loop
135136
with tqdm(total=self._generations, desc='generation', disable=not self._progress, ncols=120) as p:
136137
for gen, population, offspring, evals in itertools.islice(self._offspring_generator(module), self._generations):
@@ -143,18 +144,6 @@ def fit(self, module: EaModule[T]) -> Tuple[Population[T], Logbook[T], HallOfFam
143144
# done
144145
return population, logbook, halloffame.freeze()
145146

146-
def _create_default_trackers(self, module: EaModule[T]) -> Tuple[Logbook[T], HallOfFame[T]]:
147-
halloffame = HallOfFame(
148-
n_best=self._history_n_best,
149-
maximize=True,
150-
)
151-
logbook = Logbook(
152-
'gen', 'evals',
153-
fit=StatsGroup(lambda pop: [m.fitness for m in pop], min=np.min, max=np.max, mean=np.mean),
154-
**module.get_stats_groups()
155-
)
156-
return logbook, halloffame
157-
158147

159148
# ========================================================================= #
160149
# END #

setup.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@
4848
author="Nathan Juraj Michlo",
4949
author_email="[email protected]",
5050

51-
version="0.0.1.dev1",
52-
python_requires=">=3.8",
51+
version="0.1.0",
52+
python_requires=">=3.6",
5353
packages=setuptools.find_packages(),
5454

5555
install_requires=install_requires,
@@ -62,7 +62,10 @@
6262
classifiers=[
6363
"License :: OSI Approved :: MIT License",
6464
"Operating System :: OS Independent",
65+
"Programming Language :: Python :: 3.6",
66+
"Programming Language :: Python :: 3.7",
6567
"Programming Language :: Python :: 3.8",
68+
"Programming Language :: Python :: 3.9",
6669
"Intended Audience :: Science/Research",
6770
],
6871
)

tests/test.py tests/test_ruck.py

File renamed without changes.

0 commit comments

Comments
 (0)