Skip to content

Create wa-tor algorithm #8899

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

Merged
merged 24 commits into from
Aug 14, 2023

Conversation

CaedenPH
Copy link
Contributor

Describe your change:

Implements the wa-tor algorithm (https://en.wikipedia.org/wiki/Wa-Tor)

The wa-tor algorithm is a cellular automata featuring predators and prey. All code is doctested and documented, linking to multiple sources.

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the description above includes the issue number(s) with a closing keyword: "Fixes #ISSUE-NUMBER".

@algorithms-keeper algorithms-keeper bot added require descriptive names This PR needs descriptive function and/or variable names require type hints https://docs.python.org/3/library/typing.html labels Jul 28, 2023
Copy link

@algorithms-keeper algorithms-keeper bot left a comment

Choose a reason for hiding this comment

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

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

@algorithms-keeper algorithms-keeper bot added awaiting reviews This PR is ready to be reviewed tests are failing Do not merge until tests pass labels Jul 28, 2023
@algorithms-keeper algorithms-keeper bot removed require descriptive names This PR needs descriptive function and/or variable names require type hints https://docs.python.org/3/library/typing.html labels Jul 28, 2023
@CaedenPH
Copy link
Contributor Author

CaedenPH commented Jul 28, 2023

@cclauss Large file to review, apologies for that. All functions are doctested and documented, with comments explaining all the code.
Build is failing because of another file, see #8900

@algorithms-keeper algorithms-keeper bot removed the tests are failing Do not merge until tests pass label Jul 28, 2023
@CaedenPH CaedenPH requested a review from cclauss July 28, 2023 18:50
@algorithms-keeper algorithms-keeper bot added the tests are failing Do not merge until tests pass label Jul 28, 2023
@CaedenPH
Copy link
Contributor Author

CaedenPH commented Jul 28, 2023

Again, not sure why build is failing. All tests pass locally for my algorithm
Interesting pytest error.

@tianyizheng02
Copy link
Contributor

tianyizheng02 commented Jul 28, 2023

Fatal Python error: Illegal instruction

Thread 0x00007fae8081e640 (most recent call first):
  File "/opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/concurrent/futures/thread.py", line 81 in _worker
  File "/opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/threading.py", line 975 in run
  File "/opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/threading.py", line 1038 in _bootstrap_inner
  File "/opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/threading.py", line 995 in _bootstrap

Current thread 0x00007faf07b3cb80 (most recent call first):
  File "/opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/projectq/backends/_sim/_simulator.py", line 83 in __init__
  File "/opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/projectq/cengines/_main.py", line 135 in __init__
  File "<doctest quantum.quantum_random.get_random_number[0]>", line 1 in <module>
  ...

Extension modules: numpy.core._multiarray_umath, numpy.core._multiarray_tests, numpy.linalg._umath_linalg,
...
/home/runner/work/_temp/96683403-d4c6-40d5-997a-4fb01d92a187.sh: line 1:  1824 Illegal instruction     (core dumped) pytest --ignore=quantum/q_fourier_transform.py --ignore=project_euler/ --ignore=scripts/validate_solutions.py --cov-report=term-missing:skip-covered --cov=. .
quantum/quantum_random.py 
Error: Process completed with exit code 132.

It looks to be something in one of quantum/quantum_random.py's doctests causing an illegal instruction error. The automatic builds on my fork have been failing because of this too.

@cclauss
Copy link
Member

cclauss commented Jul 28, 2023

Please rename quantum/quantum_random.py —> quantum/quantum_random.py.DISABLED

@tianyizheng02
Copy link
Contributor

@CaedenPH Let's see if the build succeeds now

@algorithms-keeper algorithms-keeper bot removed the tests are failing Do not merge until tests pass label Jul 29, 2023
@CaedenPH
Copy link
Contributor Author

Works 👍

Copy link
Contributor

@tianyizheng02 tianyizheng02 left a comment

Choose a reason for hiding this comment

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

General feedback:

  1. Per PEP8, x is True -> x
  2. Rather than iterating over the 4 possible directions and having multiple nested if-statements handling each direction, it's a lot simpler to just iterate over a list of the 4 neighboring squares and handle them in a more generic manner. For example, instead of checking if row - 1 >= 0 when the direction is North and if row + 1 < self.height when the direction is South, just check whether the row to move to is in bounds: 0 <= r < self.height. An extra comparison or two is worth the increased readability, IMO.

@github-actions github-actions bot force-pushed the create-wa-tor-algorithm branch from ea3869f to 9f23c25 Compare July 30, 2023 18:30
@github-actions github-actions bot force-pushed the create-wa-tor-algorithm branch from 6f61366 to e659bd1 Compare July 30, 2023 18:33
@github-actions github-actions bot force-pushed the create-wa-tor-algorithm branch from c025f8a to d277dba Compare July 30, 2023 18:34
@github-actions github-actions bot force-pushed the create-wa-tor-algorithm branch from faafb49 to 7dc6788 Compare July 30, 2023 18:38
@algorithms-keeper algorithms-keeper bot added tests are failing Do not merge until tests pass and removed tests are failing Do not merge until tests pass labels Jul 30, 2023
@cclauss cclauss requested a review from tianyizheng02 August 3, 2023 07:03
@CaedenPH
Copy link
Contributor Author

@tianyizheng02 Apologies for not responding earlier, I've been very busy with work. The suggestions regarding simplifying the logic for neighbouring cells you made are logical, however they don't account for the weighting order. Might be better to leave it as is

Copy link
Contributor

@tianyizheng02 tianyizheng02 left a comment

Choose a reason for hiding this comment

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

LGTM

@tianyizheng02 tianyizheng02 merged commit 9d86d4e into TheAlgorithms:master Aug 14, 2023
@algorithms-keeper algorithms-keeper bot removed the awaiting reviews This PR is ready to be reviewed label Aug 14, 2023
@CaedenPH CaedenPH deleted the create-wa-tor-algorithm branch August 14, 2023 08:12
sedatguzelsemme pushed a commit to sedatguzelsemme/Python that referenced this pull request Sep 15, 2024
* feat(cellular_automata): Create wa-tor algorithm

* updating DIRECTORY.md

* chore(quality): Implement algo-keeper bot changes

* Update cellular_automata/wa_tor.py

Co-authored-by: Christian Clauss <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* refactor(repr): Return repr as python object

* Update cellular_automata/wa_tor.py

Co-authored-by: Tianyi Zheng <[email protected]>

* Update cellular_automata/wa_tor.py

Co-authored-by: Tianyi Zheng <[email protected]>

* Update cellular_automata/wa_tor.py

Co-authored-by: Tianyi Zheng <[email protected]>

* Update cellular_automata/wa_tor.py

Co-authored-by: Tianyi Zheng <[email protected]>

* Update cellular_automata/wa_tor.py

Co-authored-by: Tianyi Zheng <[email protected]>

* Update cellular_automata/wa_tor.py

Co-authored-by: Tianyi Zheng <[email protected]>

* Update cellular_automata/wa_tor.py

Co-authored-by: Tianyi Zheng <[email protected]>

* Update cellular_automata/wa_tor.py

Co-authored-by: Tianyi Zheng <[email protected]>

* Update cellular_automata/wa_tor.py

Co-authored-by: Tianyi Zheng <[email protected]>

* Update cellular_automata/wa_tor.py

Co-authored-by: Tianyi Zheng <[email protected]>

* Update cellular_automata/wa_tor.py

Co-authored-by: Tianyi Zheng <[email protected]>

* refactor(display): Rename to display_visually to visualise

* refactor(wa-tor): Use double for loop

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* chore(wa-tor): Implement suggestions from code review

---------

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Co-authored-by: Christian Clauss <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Tianyi Zheng <[email protected]>
@isidroas isidroas mentioned this pull request Jan 25, 2025
14 tasks
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.

3 participants