quantumlib / Stim

A fast stabilizer circuit library.
Apache License 2.0
305 stars 88 forks source link

`stim.CompiledDemSampler.sample(return_errors=True)` too slow when the error matrix is sparse #746

Open fangzh-umich opened 3 months ago

fangzh-umich commented 3 months ago

I think in many cases it can be useful to get a "ground truth" when sampling errors. From my understanding the intended way to do so with Stim is stim.CompiledDemSampler.sample(return_errors=True). However this can be much slower than return_errors=False when the error matrix is sparse:

image

Would it be possible to return a sparse representation of the errors without so much time overhead?

Strilanc commented 3 months ago

I was expecting adding bit_packed=True to the sample call to save 8x on the overhead here, but it doesn't. This suggests there's something wrong other than the size of the output. I'll look into it. My best guess is that it has to do with transposing the data when moving from the internal representation to the external result.