alan-turing-institute / p2lab-pokemon

A Python library for running genetic algorithms to optimize Pokemon teams!
BSD 3-Clause "New" or "Revised" License
8 stars 1 forks source link

Better tests, better `__main__.py`, no duplicates on teams #53

Closed phinate closed 1 year ago

phinate commented 1 year ago

turns out the use of deepcopy in the Team class in #36 #40 #41 didn't actually fix our issue -- the cause is probably right since it always happens with duplicate pokemon, but this didn't make the pokemon separate from the point of view of the bot.

this fixes the issue indirectly in fitness_mutate and mutate by forcing a resampling whenever duplicate pokemon are generated for the same team. additionally, there's a hard guard to this in Team now which checks the pokemon upon initialisation.

what's not protected against is modifying the .pokemon attribute directly, so I've made this a tuple for now -- needs some ironing out for use in the crossover methods, since they've been designed for numpy arrays. (i cast once or twice atm to get partially around this).

phinate commented 1 year ago

I've also ensured that pokemon cannot be modified in-place by storing them in a tuple, and making the Team module an immutable dataclass. With this and a bunch of duplicate checking, I have yet to encounter #36!

phinate commented 1 year ago

oh aaaaaaand there's support again to write-out teams in the main function -- see p2lab --help :)

phinate commented 1 year ago

i've requested a couple reviews:

AoifeHughes commented 1 year ago

All tests are passing on latest commit for me.

phinate commented 1 year ago

I'm gonna merge this since I think it's a good base to build on -- we can work out any creases in the genetic algorithm with separate PRs :)

AoifeHughes commented 1 year ago

I've also ensured that pokemon cannot be modified in-place by storing them in a tuple, and making the Team module an immutable dataclass. With this and a bunch of duplicate checking, I have yet to encounter #36!

This is scary in terms of performance, no?

phinate commented 1 year ago

This is scary in terms of performance, no?

from what? i haven't noticed a slowdown, don't think that the object types here are an issue -- feel free to benchmark something and show me!

AoifeHughes commented 1 year ago

Also, @phinate https://github.com/alan-turing-institute/p2lab-pokemon/actions/runs/5399005143/jobs/9805574268 any thoughts on this does this need to be raised as an issue?

phinate commented 1 year ago

Also, @phinate https://github.com/alan-turing-institute/p2lab-pokemon/actions/runs/5399005143/jobs/9805574268 any thoughts on this does this need to be raised as an issue?

Ty, just made #57