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

add freqAnalyzer strategy #1444

Merged
merged 13 commits into from
Jan 10, 2025
Merged

Conversation

miller-ian
Copy link
Contributor

No description provided.

@miller-ian miller-ian marked this pull request as draft July 5, 2024 22:49
@drvinceknight
Copy link
Member

The test failures don't seem to be related to your contribution.

For example:

  Expected:
      Axelrod game: (R,P,S,T) = (3, 1, 0, 5)
  Got:
      Axelrod game: (R,P,S,T) = (np.int64(3), np.int64(1), np.int64(0), np.int64(5))
  

I'd still like to investigate what is happening here though. I wonder if this could be related to numpy's 2.0.0 release.

Here's what tox has installed (indeed numpy==2.0.0).

py311: attrs==23.2.0,Axelrod @ file:///home/runner/work/Axelrod/Axelrod/.tox/.tmp/package/1/axelrod-4.14.0.tar.gz#sha256=4b519abc1589884bdc18d5eaf0f4240bf8d1a3681b080e92b0df52dd62ef4a11,black==24.4.2,click==8.1.7,cloudpickle==3.0.0,contourpy==1.2.1,coverage==7.5.4,cycler==0.12.1,dask==2024.7.0,dask-expr==1.1.7,fonttools==4.53.1,fsspec==2024.6.1,hypothesis==6.105.0,importlib_metadata==8.0.0,iniconfig==2.0.0,isort==5.13.2,kiwisolver==1.4.5,locket==1.0.0,matplotlib==3.9.1,mypy-extensions==1.0.0,numpy==2.0.0,packaging==24.1,pandas==2.2.2,partd==1.4.2,pathspec==0.12.1,pillow==10.4.0,pip==24.1,platformdirs==4.2.2,pluggy==1.5.0,pyarrow==16.1.0,pyparsing==3.1.2,pytest==8.2.2,pytest-cov==5.0.0,pytest-randomly==3.15.0,pytest-sugar==1.0.0,python-dateutil==2.9.0.post0,pytz==2024.1,PyYAML==6.0.1,scipy==1.14.0,setuptools==70.1.0,six==1.16.0,sortedcontainers==2.4.0,termcolor==2.4.0,toolz==0.12.1,tqdm==4.66.4,tzdata==2024.1,wheel==0.43.0,zipp==3.19.2

@miller-ian
Copy link
Contributor Author

The test failures don't seem to be related to your contribution.

For example:

  Expected:
      Axelrod game: (R,P,S,T) = (3, 1, 0, 5)
  Got:
      Axelrod game: (R,P,S,T) = (np.int64(3), np.int64(1), np.int64(0), np.int64(5))
  

I'd still like to investigate what is happening here though. I wonder if this could be related to numpy's 2.0.0 release.

Here's what tox has installed (indeed numpy==2.0.0).

py311: attrs==23.2.0,Axelrod @ file:///home/runner/work/Axelrod/Axelrod/.tox/.tmp/package/1/axelrod-4.14.0.tar.gz#sha256=4b519abc1589884bdc18d5eaf0f4240bf8d1a3681b080e92b0df52dd62ef4a11,black==24.4.2,click==8.1.7,cloudpickle==3.0.0,contourpy==1.2.1,coverage==7.5.4,cycler==0.12.1,dask==2024.7.0,dask-expr==1.1.7,fonttools==4.53.1,fsspec==2024.6.1,hypothesis==6.105.0,importlib_metadata==8.0.0,iniconfig==2.0.0,isort==5.13.2,kiwisolver==1.4.5,locket==1.0.0,matplotlib==3.9.1,mypy-extensions==1.0.0,numpy==2.0.0,packaging==24.1,pandas==2.2.2,partd==1.4.2,pathspec==0.12.1,pillow==10.4.0,pip==24.1,platformdirs==4.2.2,pluggy==1.5.0,pyarrow==16.1.0,pyparsing==3.1.2,pytest==8.2.2,pytest-cov==5.0.0,pytest-randomly==3.15.0,pytest-sugar==1.0.0,python-dateutil==2.9.0.post0,pytz==2024.1,PyYAML==6.0.1,scipy==1.14.0,setuptools==70.1.0,six==1.16.0,sortedcontainers==2.4.0,termcolor==2.4.0,toolz==0.12.1,tqdm==4.66.4,tzdata==2024.1,wheel==0.43.0,zipp==3.19.2

Yep, looks like numpy installation is the issue. I'm seeing this error in my local jupyter notebook I'm using for testing:

File ~/Library/Python/3.9/lib/python/site-packages/matplotlib/transforms.py:49
     [46](https://file+.vscode-resource.vscode-cdn.net/Users/ianmiller/sources/projects/Axelrod/~/Library/Python/3.9/lib/python/site-packages/matplotlib/transforms.py:46) from numpy.linalg import inv
     [48](https://file+.vscode-resource.vscode-cdn.net/Users/ianmiller/sources/projects/Axelrod/~/Library/Python/3.9/lib/python/site-packages/matplotlib/transforms.py:48) from matplotlib import _api
---> [49](https://file+.vscode-resource.vscode-cdn.net/Users/ianmiller/sources/projects/Axelrod/~/Library/Python/3.9/lib/python/site-packages/matplotlib/transforms.py:49) from matplotlib._path import (
     [50](https://file+.vscode-resource.vscode-cdn.net/Users/ianmiller/sources/projects/Axelrod/~/Library/Python/3.9/lib/python/site-packages/matplotlib/transforms.py:50)     affine_transform, count_bboxes_overlapping_bbox, update_path_extents)
     [51](https://file+.vscode-resource.vscode-cdn.net/Users/ianmiller/sources/projects/Axelrod/~/Library/Python/3.9/lib/python/site-packages/matplotlib/transforms.py:51) from .path import Path
     [53](https://file+.vscode-resource.vscode-cdn.net/Users/ianmiller/sources/projects/Axelrod/~/Library/Python/3.9/lib/python/site-packages/matplotlib/transforms.py:53) DEBUG = False

ImportError: numpy.core.multiarray failed to import

New numpy release is incompatible with older version of matplotlib and for some reason, pip's dependency resolver wasn't working properly. I was able to resolve locally by upgrading pip, numpy, and matplotlib.

@miller-ian miller-ian mentioned this pull request Jul 11, 2024
@marcharper
Copy link
Member

A few tests are failing:

  • one in the docs that counts total strategies of various types
  • one involving the name / repr of your strategy
  • lines 89 and 93 are uncovered

@Nikoleta-v3
Copy link
Member

Hello @miller-ian 👋🏻

The tests are failing at your test_strategy_random function. This is because you are expecting your strategy to defect on the 31st round, but it cooperates.

The opponent hasn't defected yet, so in your player's mind, there has only been cooperation. Therefore, it will keep cooperating. Actually your opponent based on the opponent_actions is set to defect on the 32 round 😄

  E   AssertionError: Tuples differ: (30, C) != (30, D)
  E   
  E   First differing element 1:
  E   C
  E   D
  E   
  E   - (30, C)
  E   ?      ^
  E   
  E   + (30, D)
  E   ?      ^

@miller-ian
Copy link
Contributor Author

Hello @miller-ian 👋🏻

The tests are failing at your test_strategy_random function. This is because you are expecting your strategy to defect on the 31st round, but it cooperates.

The opponent hasn't defected yet, so in your player's mind, there has only been cooperation. Therefore, it will keep cooperating. Actually your opponent based on the opponent_actions is set to defect on the 32 round 😄

  E   AssertionError: Tuples differ: (30, C) != (30, D)
  E   
  E   First differing element 1:
  E   C
  E   D
  E   
  E   - (30, C)
  E   ?      ^
  E   
  E   + (30, D)
  E   ?      ^

yep was a bit confused about the format of the test inputs but should be working now

@miller-ian miller-ian marked this pull request as ready for review January 8, 2025 18:10
Copy link
Member

@marcharper marcharper left a comment

Choose a reason for hiding this comment

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

Thanks for coming back to this! Just a few minor comments on potential style / comment improvements.

axelrod/strategies/frequency_analyzer.py Outdated Show resolved Hide resolved
axelrod/strategies/frequency_analyzer.py Outdated Show resolved Hide resolved
axelrod/strategies/frequency_analyzer.py Outdated Show resolved Hide resolved
axelrod/strategies/frequency_analyzer.py Outdated Show resolved Hide resolved
@miller-ian miller-ian requested a review from marcharper January 9, 2025 15:32
@marcharper
Copy link
Member

@drvinceknight @Nikoleta-v3 PTAL

@drvinceknight drvinceknight merged commit 684b354 into Axelrod-Python:dev Jan 10, 2025
7 checks passed
@miller-ian miller-ian deleted the ian/new-strat branch January 10, 2025 18:08
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.

4 participants