Skip to content

Commit

Permalink
Merge pull request #385 from Happy-Algorithms-League/maint/update-numpy
Browse files Browse the repository at this point in the history
Support more recent version of numpy
  • Loading branch information
jakobj authored Feb 13, 2024
2 parents 790b783 + 5acd8cf commit 2d708e6
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 deletions.
4 changes: 3 additions & 1 deletion cgp/ea/mu_plus_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@ def _create_new_offspring_generation(self, pop: Population) -> List[IndividualBa

offsprings: List[IndividualBase] = []
while len(offsprings) < self.n_offsprings:
tournament_pool = pop.rng.permutation(pop.parents)[: self.tournament_size]
tournament_pool = pop.rng.permutation(pop.parents)[ # type: ignore
: self.tournament_size
]
best_in_tournament = sorted(tournament_pool, reverse=True)[0]
offsprings.append(best_in_tournament.clone())

Expand Down
2 changes: 1 addition & 1 deletion cgp/hl_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def evolve(
callback(pop)

# perform evolution
max_fitness = np.finfo(float).min
max_fitness = float(np.finfo(float).min)
# Main loop: -1 offset since the last loop iteration will still increase generation by one
while pop.generation < max_generations - 1 and ea.n_objective_calls < max_objective_calls:

Expand Down
26 changes: 13 additions & 13 deletions extra-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# extra requirements
matplotlib ~= 3.4.1
scipy ~= 1.6.2
sympy ~= 1.8
torch ~= 1.8.0
gym ~= 0.18.3
matplotlib >= 3.4.1
scipy >= 1.6.2
sympy >= 1.8
torch >= 1.8.0
gym ~= 0.25.0
# dev requirements
pytest ~= 5.4.1
mypy ~= 0.800
mypy >= 0.800
click ~= 8.0.1
black ~= 19.10b0
flake8 ~= 3.7.9
isort ~=5.2.2
# doc requirements
jinja2 ~= 3.0.1
sphinx ~=3.1.2
recommonmark~=0.6.0
msmb_theme~=1.2.0
sphinx-rtd-theme~=0.5.0
sphinx-gallery~=0.8.0
pillow~=8.1.1
jinja2 >= 3.0.1
sphinx >=3.1.2
recommonmark >= 0.6.0
msmb_theme >= 1.2.0
sphinx-rtd-theme >= 0.5.0
sphinx-gallery >= 0.8.0
pillow ~= 8.1.1
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
numpy ~= 1.19.0
numpy >= 1.19.0
docopt-ng~=0.7.2
6 changes: 4 additions & 2 deletions test/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ def _test_to_numpy(genome, x, y_target):
def _test_to_torch(genome, x, y_target):
torch = pytest.importorskip("torch")
graph = cgp.CartesianGraph(genome)
assert graph.to_torch()(torch.Tensor(x).reshape(1, -1)) == pytest.approx(y_target)
assert graph.to_torch()(torch.Tensor(x).reshape(1, -1)).detach().numpy() == pytest.approx(
y_target
)


def _test_to_sympy(genome, x, y_target):
Expand Down Expand Up @@ -461,7 +463,7 @@ class CustomAdd(cgp.OperatorNode):


def test_raise_broken_def_numpy_output():
with pytest.raises(ValueError):
with pytest.raises(TypeError):

class CustomAdd(cgp.OperatorNode):
_arity = 2
Expand Down

0 comments on commit 2d708e6

Please sign in to comment.