Using one seed to generate one batch of sample and then compute the logical error rate is obviously statistically safe. But in case I want to sample one small batch at a time, how can I configure the measurement sampler(s) to make different batches independent at the stim Python API level? Should I use different seeds, or is there a way to configure the seeds to make it safe?

Or, can I just call Circuit.sampler() without providing a seed, since sinter also creates detector_sampler without a seed and sample in small batches?


1 Answer 1


If you want unique samples, just don't specify a seed at all. If you don't specify a seed, stim's samplers all default to getting entropy from the system using std::random_device when they are constructed. Only use a seed if you want the ability to re-run with the same randomness (on the same machine with the same version of stim).

AFAIK the main danger is if you construct a sampler and then fork the process. That will duplicate the internal prng state between the two forks. In python, if you're using multiprocessing, this can happen without you realizing because the multiprocessing module defaults to forking on unix systems. If using multiprocessing I strongly recommend forcing "spawn" instead of "fork", and also creating sampler objects as late as possible so that if things get forked it's less likely that the sampler already exists.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.