Repository navigation
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.
(cherry picked from commit 4f48b1f)
(cherry picked from commit 7157d6f)
Add EET scaling coverage, workload profiles, reproducibility checks, result artifacts, and CI integration.
Generate stable-universe shocks in chooser batches rather than allocating the full chooser-by-sample-by-alternative array. This prevents large EET models from exhausting memory while retaining only active uniforms or winning positions. Preserve per-row draw order and validate the entire chooser index before batching. Regression tests enforce allocation bounds and exact results and subsequent streams for both accelerated channels.
Use explicit row counts when reshaping vectorized draws so zero-length dimensions return correctly shaped empty arrays. Return immediately for zero-size choice instead of consuming a full population permutation, and support zero samples in batched Gumbel-max draws. Add cross-channel empty-draw regressions and low-level tests covering both bit generators, multidimensional empty shapes, and empty row selections. Verify that subsequent draws and generator states remain unchanged.
Reject negative or fractional sample dimensions, non-vector populations, empty populations with nonzero samples, and oversized samples without replacement. Use integer-index validation and a Python dimension product to avoid silent truncation or overflow. Validate before lazy seeding or draw consumption so rejected calls leave reproducible streams untouched. Add NumPy parity and state-preservation regressions, plus coverage for valid tuple sizes and empty populations with zero samples.
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.