-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
Summary
DefaultUnuranSampler has no way to seed the RNG. All instances share one process-global
numpy.random.default_rng() (see urng.py), making results non-reproducible and tests
order-dependent. initialization.py:241 has a # TODO seed support placeholder.
Problems
- Non-reproducibility — same distribution, different output every run.
- Shared global state — sampling from one instance advances the state seen by all others.
- No per-instance isolation — impossible to have two independent samplers in the same process.
Proposed API
Add seed: int | np.random.Generator | None = None to UnuranMethodConfig. Each sampler
constructs its own Generator via np.random.default_rng(seed) and registers a per-instance
UNUR_URNG (the C API already exposes unur_urng_new). The handle must be freed in
cleanup() alongside the generator.
Thread safety
numpy.random.Generator is not thread-safe. The implementation must ensure:
- Each sampler instance owns an independent
Generator; never share one across threads. - Same seed passed to two samplers in different threads must produce identical sequences in
isolation — achieved by constructing a freshGeneratorper instance, not resetting a shared one.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Status
Backlog