New fast channel for reproducible random#12
Open
jpn-- wants to merge 21 commits into
Open
Conversation
Introduce a configurable RNG channel type and exercise both implementations in tests. Add Settings.rng_channel_type to choose between the new FastChannel (PCG64 vectorised) and legacy SimpleChannel for reproducibility. Random now accepts a channel_type on init and add_channel accepts fast=None to default to the global channel_type; existing code will pick up settings.rng_channel_type via State initialization and rng access. Implement FastChannel.extend_domain to allow adding new domain rows (initialising per-row PCG64 state when a step is active) and tighten index handling. Update many pipeline tests to parametrize over channel types, isolate per-channel output dirs, and include per-channel expected regression values and checks.
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 introduces a new
activitysim.core.fast_randompackage. It has one public class,FastChannel, which exactly reproduces (I believe) the entire functionality ofactivitysim.core.random.SimpleChannel, except forinit_row_states_for_step, which is only ever used internally bySimpleChannel.We also add plumbing to
activitysim.core.random.Randomandactivitysim.core.configuration.topto use the new fast channel.The
FastChannelimplementation usesnumpy'sPCG64bit generator, and stores the actual 256 bit random state for each index value in the channel. Since we store this state, we do not need to reseed inside a step, nor do we do any state forwarding.We do still need to reseed for each index value once per ActivitySim step to maintain reproducibility, so the runtime benefits for this change will mostly accrue to models that need to make multiple random draws inside a single ActivitySim step.
Also, all existing tests that are contingent on having a stable random result will fail if you change the random generator. Prior code used the (old and slow) Mersenne Twister via the old
numpy.random.RandomState, and the new code uses a different mathematical algorithm, so it cannot be set to give the same stream of random values. Therefore, the default setting is to not use this new feature unless it is explicitly activated.This PR includes unit tests for
FastChannelwhich have been tested and pass on Linux, Mac and Windows.