Skip to content

Improve extend method in LimitedHistory to enforce memory depth - #1458

Merged
drvinceknight merged 2 commits into
Axelrod-Python:devfrom
LindyZh:memory-depth-fix
Dec 9, 2024
Merged

drvinceknight merged 2 commits into
Axelrod-Python:devfrom
LindyZh:memory-depth-fix

Conversation

@LindyZh

@LindyZh LindyZh commented Nov 30, 2024

Copy link
Copy Markdown
Contributor

This pull request fixes #1451 , specifically to the history.py and test_history.py files. The most important changes include the addition of the extend method, and the corresponding unit tests for the new method.

Changes to axelrod/history.py:

  • Reordered the superclass initialization in the __init__ method of the LimitedHistory class to occur after setting the memory_depth attribute.
  • Added a new extend method to the LimitedHistory class, which extends the plays and coplays lists while respecting the memory_depth limit.

Changes to axelrod/tests/unit/test_history.py:

  • Added a new unit test test_extend to verify the functionality of the extend method in the LimitedHistory class.
  • Added a corresponding unit test in axelrod/tests/unit/test_history.py to validate changing memory-depth behavior.
  • Formatted all committed files using black for consistent code style.

- Updated the extend method in the LimitedHistory class to properly truncate oldest entries when the combined history exceeds the defined memory depth.

- Added a corresponding unit test in axelrod/tests/unit/test_history.py to validate this behavior.

- Formatted all committed files using black for consistent code style.
@drvinceknight

Copy link
Copy Markdown
Member

Thanks for this, it looks like the failure is due to a health check done by hypothesis:

  =================================== FAILURES ===================================
  _______________________ TestAsymmetricGame.test_equality _______________________
  
  self = <axelrod.tests.unit.test_game.TestAsymmetricGame testMethod=test_equality>
  
      @given(asymgame1=asymmetric_games(), asymgame2=asymmetric_games())
  >   @settings(max_examples=5)
  E   hypothesis.errors.FailedHealthCheck: Data generation is extremely slow: Only produced 2 valid examples in 1.04 seconds (0 invalid ones and 2 exceeded maximum size). Try decreasing size of the data you're generating (with e.g. max_size or max_leaves parameters).
  E                 count | fraction |    slowest draws (seconds)
  E     asymgame1 |    4  |     63%  |      --   0.096,  0.169,  0.178,  0.208
  E     asymgame2 |    4  |     37%  |      --   0.044,  0.057,  0.091,  0.199
  E   See https://hypothesis.readthedocs.io/en/latest/healthchecks.html for more information about this. If you want to disable just this health check, add HealthCheck.too_slow to the suppress_health_check settings for this test.

Could you try disabling the healthcheck (as it suggests in the traceback). If not we can take a look at that.

- add suppress_health_check to test_equality function in test_game.py to prevent workflow failure in Github remote.
- Update HealthCheck module import order in test_game.py
@LindyZh

LindyZh commented Dec 4, 2024 •

Copy link
Copy Markdown
Contributor Author

@drvinceknight @gaffney2010 The mentioned healthcheck was disabled and all checks have passed. Let me know if there's anything I could address/add before merging😃

@gaffney2010

Copy link
Copy Markdown
Member

lgtm, thanks!

@drvinceknight

Copy link
Copy Markdown
Member

Looks good to me! Thanks :)

@drvinceknight
drvinceknight merged commit a7bab91 into Axelrod-Python:dev Dec 9, 2024
barlowa124 pushed a commit to barlowa124/Axelrod that referenced this pull request Dec 4, 2026
…rod-Python#1458)

* Improve extend method in LimitedHistory to enforce memory depth

- Updated the extend method in the LimitedHistory class to properly truncate oldest entries when the combined history exceeds the defined memory depth.

- Added a corresponding unit test in axelrod/tests/unit/test_history.py to validate this behavior.

- Formatted all committed files using black for consistent code style.

* Ignore workflow failures by adding suppress_health_check
- add suppress_health_check to test_equality function in test_game.py to prevent workflow failure in Github remote.
- Update HealthCheck module import order in test_game.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LimitedHistory should override extend.

3 participants