1
$\begingroup$

I am trying to run some Monte-Carlo simulations whereby I have to call the TableauSimulator N times and use the measurement results to get an average. Is there any way to parallelise this loop? I am getting this sort of error:

TypeError: cannot pickle 'stim._stim_sse2.TableauSimulator' object

Much appreciated.

$\endgroup$

1 Answer 1

1
$\begingroup$

It's actually kind of intentional that this doesn't work. You were just saved from potentially making an enormous mistake where you duplicated the entire state of the simulator. To make seeding work the simulator's state includes the state of its random number generator! If you had actually managed to pickle it then you would have silently sampled the same thing in all child processes, breaking any statistical analysis you then did.

You can work around this issue by extracting and sending the simulator's quantum state to the child process. Use stim.TableauSimulator.current_inverse_tableau to get the simulator's quantum state (it's a stim.Tableau). Later, with a new stim.TableauSimulator() (made by the child process so you know its random number generator is for sure independent of other children!) use set_inverse_tableau to overwrite its state.

$\endgroup$
1
  • $\begingroup$ Thanks for the help! $\endgroup$
    – Q W
    Commented Feb 3, 2023 at 11:26

Your Answer

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

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