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

Closes #3086: Add choice to random number generators #3114

Merged
merged 3 commits into from
Apr 25, 2024

Conversation

stress-tess
Copy link
Member

This PR (closes #3086) adds choice to random number generators.

I had to make a very slight modification to sampleDomWeighted (just moving the increment to be after indexing) to avoid an out of bounds error.

@stress-tess stress-tess marked this pull request as draft April 23, 2024 02:15
@stress-tess
Copy link
Member Author

The tests are passing for me with chpl 2.0. sample wasn't introduced until 2.0, so I'm calling choice in the compat modules. It looks like the earlier versions are compiling correctly but failing on test_choice_flags. I wonder if this is due to an issue in choice or an issue with the way I'm calling it.

@jeremiah-corrado
Copy link
Contributor

@stress-tess, looking at your code nothing is standing out as incorrect. I'm guessing there is an issue with choice itself. I'll checkout your branch and see if I can figure it out.

@jeremiah-corrado
Copy link
Contributor

jeremiah-corrado commented Apr 23, 2024

Yep, unfortunately it looks like there is a subtle bug in choice where it can call the module-level shuffle proc (which generates a new random seed), rather than the random stream's shuffle method. This only comes up in the unweighted case when replace=false and the number of samples is greater than log2(pop_size).

patch for Chapel 1.33...
diff --git a/modules/standard/Random.chpl b/modules/standard/Random.chpl
index 51e8d8723f..b5c50ed4c2 100644
--- a/modules/standard/Random.chpl
+++ b/modules/standard/Random.chpl
@@ -948,7 +948,7 @@ module Random {
           }
         } else {
           var indices: [X] int = X;
-          shuffle(indices);
+          stream.shuffle(indices);
           for i in samples.domain {
             samples[i] = (indices[X.dim(0).orderToIndex(i)]);
           }

I'm not sure whether this is worth fixing, but I suppose the solution would be to add a correct implementation of choice to Arkouda instead of calling the implementation in the Random module.

@stress-tess
Copy link
Member Author

stress-tess commented Apr 23, 2024

Yep, unfortunately it looks like there is a subtle bug in choice where it can call the module-level shuffle proc (which generates a new random seed), rather than the random stream's shuffle method. This only comes up in the unweighted case when replace=false and the number of samples is greater than log2(pop_size).

patch for Chapel 1.33...
I'm not sure whether this is worth fixing, but I suppose the solution would be to add a correct implementation of choice to Arkouda.

thanks so much for running this down for me @jeremiah-corrado!! Unfortunately I think most of our users haven't made the jump to 2.0 yet, so I do think adding a correct implementation of choice is prob the way to go even tho that does not seem like the most fun task lol

I was thinking I might skip that test for now and then add the correct choice impl in a separate issue and re-enable the test then. @Bears-R-Us/arkouda-core-dev , what are y'all's thoughts on that?

Captured in #3118

@stress-tess stress-tess marked this pull request as ready for review April 24, 2024 02:18
Copy link
Contributor

@ajpotts ajpotts left a comment

Choose a reason for hiding this comment

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

Looks good to me! I like how you used the chi-squared test :)

PROTO_tests/tests/random_test.py Outdated Show resolved Hide resolved
PROTO_tests/tests/random_test.py Outdated Show resolved Hide resolved
This PR (closes Bears-R-Us#3086) adds `choice` to random number generators.

I had to make a very slight modification to `sampleDomWeighted` (just moving the increment to be after indexing) to avoid an out of bounds error.
@stress-tess stress-tess merged commit 35539e5 into Bears-R-Us:master Apr 25, 2024
13 checks passed
@stress-tess stress-tess deleted the 3086_rng_choice branch April 25, 2024 19:11
stress-tess added a commit to stress-tess/arkouda that referenced this pull request Apr 25, 2024
This PR closes Bears-R-Us#3118 by moving the implemention of `choice` into arkouda for chpl versions prior to 2.0. This allows us to no longer skip `test_choice_flags`.

We could have done this as part of Bears-R-Us#3114, since it was much less involved than I thought it would be. I was expecting to need to copy several internal procs and records from chpl's random modules, but it more or less just worked to copy it over and change `sample` to `stream.sample`
github-merge-queue bot pushed a commit that referenced this pull request Apr 26, 2024
This PR closes #3118 by moving the implemention of `choice` into arkouda for chpl versions prior to 2.0. This allows us to no longer skip `test_choice_flags`.

We could have done this as part of #3114, since it was much less involved than I thought it would be. I was expecting to need to copy several internal procs and records from chpl's random modules, but it more or less just worked to copy it over and change `sample` to `stream.sample`

Co-authored-by: Tess Hayes <[email protected]>
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.

Add choice to random number generators
4 participants