-
Notifications
You must be signed in to change notification settings - Fork 4
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
Use random number generators, not global seeds #94
Conversation
Actually the tutorial experiment no longer converges after these changes. Need to look further into it |
False alarm, the new generator was just giving a particularly bad sampling with that seed so config recovery couldn't bootstrap. Changing the seed brought things back to normal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The notebooks need to be updated too, to use a single random generator rather than repeatedly passing the same integer seed.
So this means all of the functions need to be updated to accept a |
Any function that accepts a
|
@kevinsung , thanks, I think I have it right now |
"from qiskit_addon_sqd.counts import generate_counts_uniform\n", | ||
"\n", | ||
"# Create a seed to control randomness throughout this workflow\n", | ||
"rand_seed = 42\n", | ||
"rand_seed = np.random.default_rng(2**24)\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an oddly specific seed, might as well keep using 42
or any other number. Also, the variable should be called rng
for consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docs say to use a very large number. I figure this is better than 42 or writing out a bunch of digits
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"
Seeds should be large positive integers. default_rng can take positive integers of any size. We recommend using very large, unique numbers to ensure that your seed is different from anyone else’s.
"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the varnames in notebooks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The motivation for using a large number is to ensure that you don't accidentally choose the same seed as somebody else in the world. But this is not a concern here, where we only need our results to be statistically valid by themselves. Usually for these situations (testing, or just to make a notebook deterministic), you can use any integer, even 0.
But if you insist on using a very large number, then certainly 2**24
is not big enough. The doc you link suggests this:
secrets.randbits(128)
But again, this is really unnecessary here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It truly doesn't matter at all to me. I would think 42 (a number used by everyone in every context for everything) would be worse. I'll change it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. In this situation, 42 is fine. If we were going to publish scientific results, then we should indeed use a large number, such as 266529787016279213832423171828752297713.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK I updated them all to 24
🤝
Fixes #52
This PR removes the use of global seeds to control numpy randomness throughout the source