Skip to content

set hasSpare to false at initialization of random number generator - #979

Merged
oscarxblanco merged 1 commit into
masterfrom
fix_pcg32_cycle
Sep 8, 2025
Merged

set hasSpare to false at initialization of random number generator #979
oscarxblanco merged 1 commit into
masterfrom
fix_pcg32_cycle

Conversation

@oscarxblanco

Copy link
Copy Markdown
Contributor

This PR is a possible solution to issue #978 where the Buffer implementation for the WHITENOISE mode of the VariableThinMultipole (see #839 ) shows a cycle of 2 after repeated calls to track functions.

The bool variable hasSpare in the pcg_state_setseq_64 struct was unset at initialization, leaving the next state in an alternate True/False value from subsequent calls.

This fix proposes to set hasSpare to False at initialization. I have done a test in pyat and the sequence behaves as expected, i.e. it repeats when a seed is given.

>>> zout,*_ = thering.track(zin[:,0], nturns=5,seed=20)
>>> elewhitenoise.BufferA
array([-0.50023502, -0.71931482, -0.59066089,  0.29808669, -0.5266456 ])
>>> zout,*_ = thering.track(zin[:,0], nturns=5,seed=20)
>>> elewhitenoise.BufferA
array([-0.50023502, -0.71931482, -0.59066089,  0.29808669, -0.5266456 ])
>>> zout,*_ = thering.track(zin[:,0], nturns=5,seed=20)
>>> elewhitenoise.BufferA
array([-0.50023502, -0.71931482, -0.59066089,  0.29808669, -0.5266456 ])
>>> zout,*_ = thering.track(zin[:,0], nturns=5,seed=20)
>>> elewhitenoise.BufferA
array([-0.50023502, -0.71931482, -0.59066089,  0.29808669, -0.5266456 ])

@oscarxblanco oscarxblanco added bug fix C For C code / pass methods labels Aug 22, 2025
@oscarxblanco oscarxblanco changed the title set hasSpare to false at initialization set hasSpare to false at initialization of random number generator Aug 22, 2025
@oscarxblanco

Copy link
Copy Markdown
Contributor Author

Dear all, who could review this PR ?

@swhite2401

Copy link
Copy Markdown
Contributor

@oscarxblanco , I believe @lfarv should review it.

@swhite2401
swhite2401 requested a review from lfarv September 2, 2025 13:45

@lfarv lfarv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Well done, thanks. I hope that this will solve the problem of random generators with OpneMP. I'll check that…

@oscarxblanco
oscarxblanco merged commit 05c4e34 into master Sep 8, 2025
28 checks passed
@oscarxblanco
oscarxblanco deleted the fix_pcg32_cycle branch July 31, 2026 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug fix C For C code / pass methods

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants