-
Notifications
You must be signed in to change notification settings - Fork 263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
History class #1241
History class #1241
Conversation
The pickle issue has something to do with the MetaPlayer having a sequence player in the team (ThueMorse or ThueMorseInverse). When unpickled the subplayer isn't equal to itself, but its own test passes... |
ab90fdb
to
247dca7
Compare
Sounds interesting @marcharper, I'll try and get to this next week. 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor comments after an initial read through, it all looks good to me though 👍
I haven't had a go at debugging the failing test, I'll try and get to that when I get a bit more time :)
return self._plays == other._plays and self._coplays == other._coplays | ||
raise TypeError("Cannot compare types.") | ||
|
||
def __getitem__(self, key): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a comment: This could be useful if we want to incorporate misperception (as opposed to noise). 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice idea!
@@ -172,101 +167,3 @@ def test_alt_strategy_stops_after_round_180(self): | |||
expected_actions=expected_actions, | |||
match_attributes={"length": 200}, | |||
) | |||
|
|||
|
|||
class TestModuleMethods(unittest.TestCase): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can we remove all of these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. Some are just testing Player class properties that already have their own tests. But it looks like I was a bit overzealous.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I think all of these tests are redundant. If we want to keep any I'd prefer we re-write them to use an actual match rather than simply overwriting the history, which is a practice that we shouldn't encourage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I agree about not encouraging using history overwriting, could we either rewrite as part of this PR or leave them in and open an issue to remove them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll check but I think these tests are just directly targeting the subfuctions of the strategy and are all covered by the "standard" tests above in the file, so rewriting them would produce near identical tests
Updates:
I suspect the pickle errors have something to do with the decorated meta classes and how they are rebuilt. I changed the meta classes so that each player on the meta team tracks its own history. Previously they were not updated with the history and so may not have properly set their internal variables properly as play proceeds. This PR has caused or exposed the issue. |
I'm still not sure why the meta players with sequence players on their teams don't pass the pickle test. (It's sufficient to use just ThueMorse as the team.) When you examine the players on team you see this:
Note that the sequence_generator attribute seem to correlate the instances when passed through the Oddly enough when I add similar tests to the |
Also note that I made a significant change to the metaplayers in that they now pass along the team member's individual play choices rather than all sharing a single history. I think this makes more sense but it will impact how they play. |
Yeah I'm fine with this change, they'll still always be looking at the correct history for the opponent. 👍 |
I've started to have a look (really sorry it's taking me so long to try and be helpful). The I'm not entirely sure why this would fall over when checking pickling equality but perhaps that's something worth considering? (If you haven't already). |
I believe I have fixed the remaining issues:
Tournaments take about 25% longer overall. In addition to the tasks in the first comment, we can get some or all of that back by optimizing in a subsequent PR or on the 5.0.0 branch:
|
Nice work!
Is there any merit in me running a full tournament to see if the 25% increase scales well? |
Yes, and we should take a look at the impact on the Meta strategies |
Ok cool, I'll aim to get some things running for that. |
I've got some code running. Will report back once it's done 👍 |
Increased runtime for the full standard tournament is 15% (30 hours versus 26 on my desktop). I think we'll easily get that back since removing function call overhead in #1239 yielded an improvement of ~25%. |
@drvinceknight @meatballs I think this is good to go in, PTAL when you get a chance. |
I agree it's pretty much there (sorry for being so slow to get back to you, I've got a tonne of marking at the moment), I've got some long (probably too long) tournaments running for timing experiments but we can merge and if they come back atrocious (which I doubt they will) we can always figure that out later. I've already looked through and everything looks good to me, but a close look from @meatballs would be great 👍 |
@meatballs PTAL |
Adds a History class, refactors Player a bit, and simplifies a number of tests and constructions. Note there were some subtle errors in the Meta players.
Increased runtime for a noisy tournament is ~25% but there are some optimizations possible:
Also, I believe we could further refactor the dual transformer to be more efficient now but I didn't try that yet.
Updates:
LimitedHistory
class that only retainsN
rounds of history, which improves the memory_depth testPlayer
class, which should always be discouraged IMOI have fixed the remaining issues:
update_history
method to thePlayer
andMetaPlayer
classes to fix, this method allows "post processing" of the moves by the players to fully end the round.SequencePlayer
s could not be pickled (there was no test). They can now and there are various new tests. I ended up adding a__getstate__
method toPlayer
(overridden inSequencePlayer
and needed an abstract version inPlayer
).Tournaments take about 25% longer overall. In addition to the tasks in the first comment, we can get some or all of that back by optimizing in a subsequent PR or on the 5.0.0 branch:
Increased runtime for the full standard tournament is 15% (30 hours versus 26 on my desktop). I think we'll easily get that back since removing function call overhead in #1239 yielded an improvement of ~25%.