quantumlib/Stim

Feature Request: Enhanced ramdom seed api

Closed this issue · 1 comments

problem description

In the current version, the samplers only takes in the ramdom seed at initialization, so if I want to reproduce a result at the third sample of the sampler, I could not skip the first 2 samples. It doesn't matter when I just want the 3rd sample, while it would be problematic if want a very late sample.

expected improvement

allow user to pass a rng state when sampling, e.g.

import random

rng_state = random.getstate()[1]
sampler = dem.compile_sampler()
syndromes,logical_flips,_ = sampler.sample(shots=num_shots, rng_key = rng_state)

So that the user can manage and trace the rng state by themselves if necessary.

Unfortunately, stim internally doesn't use the python random number generator. In fact, the simulation code is pure C++ with no knowledge of python at all. So this would be an absolutely enormous refactor to implement.

Also, entropy generation is one of the most performance sensitive parts of the code; incurring the overhead of a python call for each random number is likely to seriously hurt performance.

Because of these two reasons, I am not going to implement this change. I like the suggestion. It's not an unreasonable idea. It's just too much work for too little benefit.