Skip to content

New fast channel for reproducible random#12

Open
jpn-- wants to merge 21 commits into
RSGInc:mainfrom
driftlesslabs:reroll
Open

New fast channel for reproducible random#12
jpn-- wants to merge 21 commits into
RSGInc:mainfrom
driftlesslabs:reroll

Conversation

@jpn--
Copy link
Copy Markdown
Collaborator

@jpn-- jpn-- commented May 2, 2026

This pull request introduces a new activitysim.core.fast_random package. It has one public class, FastChannel, which exactly reproduces (I believe) the entire functionality of activitysim.core.random.SimpleChannel, except for init_row_states_for_step, which is only ever used internally by SimpleChannel.

We also add plumbing to activitysim.core.random.Random and activitysim.core.configuration.top to use the new fast channel.

The FastChannel implementation uses numpy's PCG64 bit 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 FastChannel which have been tested and pass on Linux, Mac and Windows.

jpn-- added 21 commits April 30, 2026 11:43
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant