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

Clean up fox-in-a-hole #198

Merged
merged 2 commits into from
Jul 25, 2024
Merged

Conversation

dstrain115
Copy link
Collaborator

  • Add lots of comments and clean up some code paths
  • Hopefully should make it easier to understand.

- Add lots of comments and clean up some code paths
- Hopefully should make it easier to understand.
@dstrain115 dstrain115 requested review from cantwellc and cognigami July 4, 2024 17:18
@dstrain115 dstrain115 requested a review from solodov July 16, 2024 16:37
"""

def __init__(self, hole_nr=5, seed=None):
def __init__(self, number_of_holes: int = 5, seed: int = None):
Copy link
Collaborator

Choose a reason for hiding this comment

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

seed: Optional[int] = None since default value is not an int

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

self.state = self.hole_nr * [0.0]
index = self.rng.integers(low=0, high=self.hole_nr)
# All holes start as empty
self.state = self.number_of_holes * [0.0]
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe that's just me, but [0.0] * self.number_of_holes reads better, intention of making a list of numbers of a certain size is clearer

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

@@ -162,18 +247,25 @@ class QuantumGame(Game):
(QuantumWorld, [QuantumObject]) -> quantum world, list of holes
"""

def __init__(self, hole_nr=5, iswap=False, qprob=0.5, seed=None):
def __init__(self, number_of_holes=5, iswap=False, qprob=0.5, seed=None):
Copy link
Collaborator

Choose a reason for hiding this comment

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

type annotations?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added.

for i, prob in enumerate(probs):
if prob > 0:
non_empty_holes.append(i)
non_empty_holes = [i for i in range(len(probs)) if probs[i] > 0]
Copy link
Collaborator

Choose a reason for hiding this comment

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

list comprehension can be made nicer with [i for i, p in enumerate(probs) if p > 0]

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

@dstrain115 dstrain115 requested a review from solodov July 25, 2024 00:37
@dstrain115 dstrain115 merged commit 8748255 into quantumlib:main Jul 25, 2024
6 checks passed
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