Fix windows error where random seeds could be too large for C long#274
Open
AlexanderFengler wants to merge 3 commits into
Open
Fix windows error where random seeds could be too large for C long#274AlexanderFengler wants to merge 3 commits into
AlexanderFengler wants to merge 3 commits into
Conversation
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
Codecov Report❌ Patch coverage is
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request focuses on improving the robustness and clarity of random seed handling for the C-level random number generator (RNG) used in the simulator. The main changes ensure that integer seeds passed to the simulator are always within the valid range for a 32-bit signed C
long, preventing platform-dependent errors, especially on Windows. Additionally, the documentation has been updated for clarity, and new tests and notebooks have been added for validation and demonstration purposes.Random seed validation and handling improvements:
_validate_random_state_for_c_rnginsimulator.pyto check that integer seeds provided to the simulator are within the valid 32-bit signed Clongrange ([-231, 231 - 1]). This prevents overflow errors in the Cython layer, particularly on Windows, and provides a clear Python error if the value is out of range._get_unique_seedfunction to generate seeds within the safe range for all platforms, matching the requirements of the C-level RNG.simulatorfunction and thesimulatemethod ofSimulatorclass, ensuring all entry points enforce the seed range. [1] [2]simulator_class.pyto include the new validation function.Documentation updates:
random_stateparameter in bothsimulatorandsimulateto specify the valid integer range and the reason for the restriction (compatibility with Clong). [1] [2]Testing and demonstration:
notebooks/int_bug_test.ipynbto test simulator behavior with various models and seeds, and to check the package version.notebooks/test_ziggurat.ipynbthat implements and visualizes the Ziggurat algorithm for Gaussian random number generation, likely for further RNG testing or demonstration.Other changes:
0.12.4inpyproject.tomlto reflect these improvements and fixes.numberstosimulator.pyfor type checking in the new validation function.These changes make the simulator more robust across platforms, prevent subtle bugs related to random seed overflow, and improve clarity for users and developers.