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 PCG Random Number Generator #2912

Merged
merged 17 commits into from
Dec 16, 2015
Merged

Add PCG Random Number Generator #2912

merged 17 commits into from
Dec 16, 2015

Conversation

mppf
Copy link
Member

@mppf mppf commented Nov 13, 2015

  • factors seed generation into RandomSupport
  • takes actual implementation RNG out of Random
  • sketch interface for RandomStream to be implemented by different generators
  • adds NPBRandom and PCGRandom that implement RandomStream
  • adds ldexp function to Math since it is needed to generate a random real from a random int

The default RNG is still the NPB one. In the future I hope we will change
to the PCG generator since it has better integer support. In addition, we need
to be able to name different RNGs intelligently - right now RandomStream
is the name of the NPB generator (to avoid making too many changes
at once).

Reviewed by @daviditen - thanks!
Passed full local testing.

TODO:
I would like for RandomStream to be either a base class or a synonym for the default RNG.
Unfortunately, neither of those work right now:

  • base class -> "Illegal super class" errors, since base class is generic
  • type RandomStream = PCGRandomStream;
    causes errors with a type constructor (seems to be missing generic-ness of type).

* factors seed generation into RandomSupport
* takes actual implementation RNG out of Random
* adds NBPRandom and PCGRandom that implement RandomStream
This is an intermediate state - we hope to move to PCGRandomStream
as the default at some point. This change lets us get started without
changing users of the RNGs.
@mppf mppf reopened this Nov 13, 2015
@mppf mppf closed this Nov 13, 2015
@mppf
Copy link
Member Author

mppf commented Nov 23, 2015

@daviditen can you have an initial look at what I have here?

mppf added 3 commits November 24, 2015 15:58
David suggested it would be nicer to have one file with sub-modules, so
here I rearrange the code to do that.
/*
Generate a seed based on the current time in microseconds as
reported by :proc:`Time.getCurrentTime`, ensuring that it
meets the PRNG's requirements.
Copy link
Member

Choose a reason for hiding this comment

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

This comment is out of date, it leaves it to the caller to ensure the seed meets requirements now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed it to say " Each RNG should adjust a given seed to meet any requirements."

@mppf mppf reopened this Nov 24, 2015
@mppf
Copy link
Member Author

mppf commented Nov 24, 2015

Testing has completed with 6 errors:

  • [Error matching program output for modules/standard/Random/bradc/test-Random-evenseed]
  • [Error matching program output for modules/standard/Random/bradc/writeRandomStream]
  • [Error matching compiler output for release/examples/benchmarks/ssca2/SSCA2_main (compopts: 1)]
  • [Error matching compiler output for studies/ssca2/rachels/SSCA2_test (compopts: 1)]
  • [Error matching compiler output for studies/ssca2/test-rmatalt/nondet]
  • [Error cannot locate compiler output comparison file studies/ssca2/test-rmatalt/reproduc.good]

These look like minor issues to me but I will work through them.

Sorry, something went wrong.

@daviditen
Copy link
Member

I lost the comment about shuffle/permute being on an existing RandomStream. That is OK with me.

Since you're touching all the lines in Random.chpl anyway, could you reindent it please?

Once you get the testing errors fixed I think this is looking good.

@mppf
Copy link
Member Author

mppf commented Nov 24, 2015

  • fixed failing tests
  • re-indent Random.chpl
  • final review from David

Sorry, something went wrong.

@mppf
Copy link
Member Author

mppf commented Dec 14, 2015

Passed full testing. @daviditen, care to give the PR a final look over?

@mppf mppf assigned daviditen and unassigned mppf Dec 14, 2015
@daviditen
Copy link
Member

Minor: The method "PCGRandomStream.getNext(min: eltType, max: eltType)" ignores its arguments and does the same thing as the 0-argument version of getNext.

Otherwise, I think this is looking very good.

@daviditen daviditen assigned mppf and unassigned daviditen Dec 16, 2015
mppf added 2 commits December 16, 2015 15:48
Previous verison didn't produce a number in a range.
Thanks to David for noticing the problem.
Also added a test to check the behavior.
mppf added a commit that referenced this pull request Dec 16, 2015
Add PCG Random Number Generator

* factors seed generation into RandomSupport
* takes actual implementation RNG out of Random
* sketch interface for RandomStream to be implemented by different generators
* adds NPBRandom and PCGRandom that implement RandomStream
* adds ldexp function to Math since it is needed to generate a random real from a random int

The default RNG is still the NPB one. In the future I hope we will change
to the PCG generator since it has better integer support. In addition, we need
to be able to name different RNGs intelligently - right now RandomStream
is the name of the NPB generator (to avoid making too many changes
at once).

Reviewed by @daviditen - thanks!
Passed full local testing.

TODO:
I would like for RandomStream to be either a base class or a synonym for the default RNG.
Unfortunately, neither of those work right now:
 * base class -> "Illegal super class" errors, since base class is generic
 * type RandomStream = PCGRandomStream;
   causes errors with a type constructor (seems to be missing generic-ness of type).
@mppf mppf merged commit 8fb075c into chapel-lang:master Dec 16, 2015
@mppf mppf deleted the rng-work branch December 16, 2015 22:11
@mppf mppf mentioned this pull request Dec 21, 2015
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.

None yet

2 participants