# How do I pick a random Clifford operation in Stim?

I want to sample random n-qubit Clifford operations. How do I do that in Stim?

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

• can stim generate random errors from depolarizing channel? for example error=stim.DepolarizingChannel(100,0.1) . (100 qubits,p=0.1; I asked this question a few days ago) Commented Oct 7, 2021 at 14:56
• @unknown stim has circuit instructions for single qubit depolarization and two qubit depolarization. But it doesn't return them it just applies them while simulating. Commented Oct 7, 2021 at 17:24
• this might still work. I want to simulate the performance of codes in depolarizing channel. Codes are usually CSS but sometimes more general stabilizer codes. The number of qubits is large (50-1000). Is stim suitable for this sort of simulations? if it is are there examples with performance curves and runtimes? Commented Oct 7, 2021 at 17:34
• @unknown Stim will deal with that easily. It can sample full shots from 10K qubit circuits with 10M operations at 1KHz, after a 15s analysis delay. Watch Part 2 of this talk: youtube.com/watch?v=O3NaTGmY0Rw Commented Oct 7, 2021 at 20:10
• great...you've convinced me to install it. Commented Oct 7, 2021 at 20:35