Skip to content

Conversation

@oscarxblanco
Copy link
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
Contributor Author

Dear all, who could review this PR ?

@swhite2401
Copy link
Contributor

@oscarxblanco , I believe @lfarv should review it.

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

@lfarv lfarv left a comment

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
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.

4 participants