I want to sample random n-qubit Clifford operations. How do I do that in Stim?
(Self-answering because this was requested when the feature already existed)
Quantum Computing Stack Exchange is a question and answer site for engineers, scientists, programmers, and computing professionals interested in quantum computing. It only takes a minute to sign up.
Sign up to join this communityI want to sample random n-qubit Clifford operations. How do I do that in Stim?
(Self-answering because this was requested when the feature already existed)
The method stim.Tableau.random(n)
generates a uniformly random n-qubit Clifford operation, using the algorithm from "Hadamard-free circuits expose the structure of the Clifford group", and returns its stabilizer tableau.
example
import stim
t = stim.Tableau.random(10)
print(repr(t))
sample output
stim.Tableau.from_conjugated_generators(
xs=[
stim.PauliString("-ZZXZZY__YX"),
stim.PauliString("-___XXXZZZ_"),
stim.PauliString("+YXZY_Y_Z__"),
stim.PauliString("-YZYXXXY_YY"),
stim.PauliString("+YZXZYXZ__Y"),
stim.PauliString("+ZZZXZYYY__"),
stim.PauliString("-_YZ___ZYXY"),
stim.PauliString("+_YXYZXYY_Y"),
stim.PauliString("-Y__YZ_____"),
stim.PauliString("+ZZXZ_Z_XYY"),
],
zs=[
stim.PauliString("+_YZXXZZYZZ"),
stim.PauliString("-YXZXYXY_XY"),
stim.PauliString("-_YXXXZYYYX"),
stim.PauliString("+_YYZYZ_ZYX"),
stim.PauliString("-_XY___YYZY"),
stim.PauliString("-ZX_ZZYZ_YY"),
stim.PauliString("-_Y_XXXZYXZ"),
stim.PauliString("-Y__ZYXY_XX"),
stim.PauliString("-Y_X_YZXZYY"),
stim.PauliString("+Y__ZXZY_XX"),
],
)
performance
This method has asymptotic cubic scaling (eg. it performs a schoolbook matrix multiplication).
>>> %time t = stim.Tableau.random(10)
Wall time: 253 µs
>>> %time t = stim.Tableau.random(100)
Wall time: 11.3 ms
>>> %time t = stim.Tableau.random(1000)
Wall time: 289 ms
>>> %time t = stim.Tableau.random(10000)
Wall time: 2min 20s