Make live point generation deterministic #105
Merged
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.
Currently, live point generation (and therefore the entire algorithm) is non-deterministic, even if the seed is fixed.
Old approach:
Root process waits as
nprocs-1
other processes generate live points at random positions, calculate logL and pass to the root, and keep going until told to stop when the root has nprior samples.The issue here is that the processes will run at different speeds, leading to the random number generations getting all mixed up.
New approach:Root process generatesnprocs
random live points, and scatters these to all processes (including itself). Each process calculates logL and the results are gathered. The root then adds the points >log0, and repeats the above until it hasnprior
(and sends arrays full of -1 to tell the other workers to stop).This way, only the root is generating random numbers, so they will appear in the same order for a given seed.
Possible issues:Since the root waits for all workers to complete their calculation, if one of them gets stuck, the whole algorithm will get stuck.Second pass:
A simpler approach is to just offload all the random number generation to the root node, and pass this along when requesting points from the workers. The key is that PolyChord waits for all active workers to finish generating prior samples before it moves on.
This avoids the issue from the first pass where all workers have to wait for a slow evaluation.