Skip to content
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

Pet Priority #91

Merged
merged 7 commits into from
Sep 29, 2022
Merged

Pet Priority #91

merged 7 commits into from
Sep 29, 2022

Conversation

jolpica
Copy link

@jolpica jolpica commented Sep 27, 2022

Refactor update_pet_priority into calculate_pet_priority and rewrite to no longer prioritise health (#89)

  • Added tests for calculate_pet_priority
  • Added seed to calculate_pet_priority
  • calculate_pet_priority is no longer a static method
  • Added various type annotations

The calculate_pet_priority seed uses the new numpy random generators which should improve performance.
Might be worth checking if the performance increase gets it anywhere close to MockRandomState's performance.

Copy link
Owner

@manny405 manny405 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good to me. I will checkout the new numpy random generators when I have more time later this week.

The performance issue I noticed with previous RandomState was team creation. This is obviously an issue because if one wants to run millions of battles or games. An issue can be created to update to the newer Numpy implementation. Then performance can be re-checked against the notes in MockRandomState.

sapai/sapai/rand.py

Lines 4 to 14 in ec22d83

class MockRandomState:
"""
Numpy RandomState is actually extremely slow, requiring about 300 microseconds
for any operation involving state. Therefore, when reproducibility is not
necessary, this class should be used to immensly improve efficiency.
Tests were run for Player:
%timeit _ = Player.from_state(pstate)
# ORIGINAL: 26.8 ms ± 788 µs per loop
# MockRandomState: 1.15 ms ± 107 µs per loop
Use of MockRandomState improved the performance by 10x. This is very important.

sapai/battle.py Outdated Show resolved Hide resolved
@jolpica jolpica requested a review from manny405 September 28, 2022 20:53
@manny405 manny405 merged commit 0dac3d2 into manny405:loop_effect_queue Sep 29, 2022
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.

2 participants