Documentation Index Fetch the complete documentation index at: https://mintlify.com/quantumlib/Stim/llms.txt
Use this file to discover all available pages before exploring further.
stim.Tableau represents a Clifford operation by explicitly recording how the operation conjugates each single-qubit Pauli generator (X and Z for each qubit) into a product of Paulis. This is the standard stabilizer tableau representation from Aaronson and Gottesman (2004). Tableaux support composition, inversion, and conversion to and from circuits. They are the internal state tracked by stim.TableauSimulator.
Constructor
stim.Tableau(num_qubits) — identity tableau
Creates the identity tableau acting on num_qubits qubits. def __init__ ( self , num_qubits : int ) -> None
import stim
t = stim.Tableau( 3 )
print (t)
# +-xz-xz-xz-
# | ++ ++ ++
# | XZ __ __
# | __ XZ __
# | __ __ XZ
stim.Tableau.random() — uniformly random Clifford
stim.Tableau.from_named_gate() — standard gates
Returns the tableau of a named Clifford gate such as "H", "S", "CNOT", "CZ", "SWAP", etc. @ staticmethod
def from_named_gate ( name : str ) -> stim.Tableau
import stim
h = stim.Tableau.from_named_gate( "H" )
cnot = stim.Tableau.from_named_gate( "CNOT" )
s = stim.Tableau.from_named_gate( "S" )
s_dag = stim.Tableau.from_named_gate( "S_DAG" )
stim.Tableau.from_circuit() — compile circuit to tableau
Converts a Clifford circuit into its equivalent tableau. @ staticmethod
def from_circuit (
circuit : stim.Circuit,
* ,
ignore_noise : bool = False ,
ignore_measurement : bool = False ,
ignore_reset : bool = False ,
) -> stim.Tableau
Parameters Name Type Description circuitstim.CircuitThe circuit to compile. ignore_noiseboolSkip noise instructions instead of raising. ignore_measurementboolSkip measurements instead of raising. ignore_resetboolSkip resets instead of raising.
import stim
t = stim.Tableau.from_circuit(stim.Circuit( '''
H 0
CNOT 0 1
''' ))
print (t.x_output( 0 )) # +Z_
print (t.z_output( 0 )) # +XX
stim.Tableau.from_conjugated_generators() — explicit specification
Creates a tableau from explicit lists of X and Z outputs. @ staticmethod
def from_conjugated_generators (
* ,
xs : List[stim.PauliString],
zs : List[stim.PauliString],
) -> stim.Tableau
import stim
# Build CNOT manually
cnot = stim.Tableau.from_conjugated_generators(
xs = [stim.PauliString( "+XX" ), stim.PauliString( "+_X" )],
zs = [stim.PauliString( "+Z_" ), stim.PauliString( "+ZZ" )],
)
stim.Tableau.from_stabilizers() — from stabilizer state
Creates the tableau of a stabilizer state specified by its stabilizer generators. @ staticmethod
def from_stabilizers (
stabilizers : Iterable[stim.PauliString],
* ,
allow_redundant : bool = False ,
allow_underconstrained : bool = False ,
) -> stim.Tableau
import stim
# Bell state |Φ+⟩ has stabilizers XX and ZZ
t = stim.Tableau.from_stabilizers([
stim.PauliString( "XX" ),
stim.PauliString( "ZZ" ),
])
Composition
prepend() — apply gate before existing content
Prepends an operation’s effect into this tableau, mutating it in place. The prepended gate is applied before the current tableau. def prepend ( self , gate : stim.Tableau, targets : Sequence[ int ]) -> None
Parameters Name Type Description gatestim.TableauThe tableau of the operation to prepend. targetsSequence[int]The qubit indices the gate acts on within this tableau.
import stim
t = stim.Tableau( 2 )
h = stim.Tableau.from_named_gate( "H" )
cnot = stim.Tableau.from_named_gate( "CNOT" )
t.prepend(h, [ 0 ])
t.prepend(cnot, [ 0 , 1 ])
append() — apply gate after existing content
Appends an operation’s effect into this tableau, mutating it in place. The appended gate is applied after the current tableau. def append ( self , gate : stim.Tableau, targets : Sequence[ int ]) -> None
import stim
# Build SWAP = CNOT(0,1) * CNOT(1,0) * CNOT(0,1)
cnot = stim.Tableau.from_named_gate( "CNOT" )
t = stim.Tableau( 2 )
t.append(cnot, [ 0 , 1 ])
t.append(cnot, [ 1 , 0 ])
t.append(cnot, [ 0 , 1 ])
assert t == stim.Tableau.from_named_gate( "SWAP" )
__mul__ — tableau product
Returns T1 * T2, the composition where T2 is applied first, then T1. def __mul__ ( self , rhs : stim.Tableau) -> stim.Tableau
import stim
t1 = stim.Tableau.random( 4 )
t2 = stim.Tableau.random( 4 )
t3 = t1 * t2 # apply t2 first, then t1
p = stim.PauliString.random( 4 )
assert t3(p) == t1(t2(p))
then() — sequential composition
Returns a tableau that applies self first, then the given second tableau. def then ( self , second : stim.Tableau) -> stim.Tableau
import stim
h = stim.Tableau.from_named_gate( "H" )
s = stim.Tableau.from_named_gate( "S" )
hs = h.then(s) # first H, then S
Returns the direct sum (block-diagonal concatenation) of two tableaus. def __add__ ( self , rhs : stim.Tableau) -> stim.Tableau
import stim
h = stim.Tableau.from_named_gate( "H" )
s = stim.Tableau.from_named_gate( "S" )
hs_tensor = h + s # H on qubit 0, S on qubit 1
Inversion
inverse() — compute the inverse tableau
Returns the inverse tableau T^-1 such that T * T^-1 = identity. def inverse ( self , * , unsigned : bool = False ) -> stim.Tableau
Parameters Name Type Description unsignedboolWhen True, skips sign computation (O(n²) → O(n)). Use when only Pauli terms are needed.
import stim
s = stim.Tableau.from_named_gate( "S" )
s_dag = stim.Tableau.from_named_gate( "S_DAG" )
assert s.inverse() == s_dag
t = stim.Tableau.random( 10 )
assert t * t.inverse() == stim.Tableau( 10 )
__pow__ — integer exponentiation
Raises the tableau to an integer power. Supports negative exponents (equivalent to repeated inversion). def __pow__ ( self , exponent : int ) -> stim.Tableau
import stim
s = stim.Tableau.from_named_gate( "S" )
assert s ** 4 == stim.Tableau( 1 )
assert s **- 1 == stim.Tableau.from_named_gate( "S_DAG" )
x_output(), y_output(), z_output() — conjugated generators
Returns the Pauli string that a given qubit’s X, Y, or Z generator maps to under conjugation by this tableau. def x_output ( self , target : int ) -> stim.PauliString
def y_output( self , target: int ) -> stim.PauliString
def z_output( self , target: int ) -> stim.PauliString
import stim
h = stim.Tableau.from_named_gate( "H" )
print (h.x_output( 0 )) # +Z (H maps X → Z)
print (h.z_output( 0 )) # +X (H maps Z → X)
cnot = stim.Tableau.from_named_gate( "CNOT" )
print (cnot.x_output( 0 )) # +XX (CNOT maps X⊗I → X⊗X)
print (cnot.z_output( 1 )) # +ZZ (CNOT maps I⊗Z → Z⊗Z)
x_output_pauli(), z_output_pauli() — single Pauli lookup
Returns an integer identifying the Pauli (0=I, 1=X, 2=Y, 3=Z) at a specific output position. Runs in O(1) time. def x_output_pauli ( self , input_index : int , output_index : int ) -> int
def y_output_pauli( self , input_index: int , output_index: int ) -> int
def z_output_pauli( self , input_index: int , output_index: int ) -> int
import stim
cnot = stim.Tableau.from_named_gate( "CNOT" )
# cnot.x_output(0) == "+XX"
print (cnot.x_output_pauli( 0 , 0 )) # 1 (X)
print (cnot.x_output_pauli( 0 , 1 )) # 1 (X)
inverse_x_output(), inverse_z_output() — inverse tableau query
Conjugates a generator by the inverse tableau, without computing the full inverse. def inverse_x_output ( self , input_index : int , * , unsigned : bool = False ) -> stim.PauliString
def inverse_z_output( self , input_index: int , * , unsigned: bool = False ) -> stim.PauliString
x_sign(), y_sign(), z_sign() — output sign only
Returns only the sign (+1 or -1) of the conjugated generator. x_sign and z_sign run in O(1) time; y_sign runs in O(n) time. def x_sign ( self , target : int ) -> int
def y_sign( self , target: int ) -> int
def z_sign( self , target: int ) -> int
import stim
s_dag = stim.Tableau.from_named_gate( "S_DAG" )
s_dag.x_sign( 0 ) # -1 (S_DAG maps X → -Y)
__call__ — conjugate a PauliString
Conjugates a stim.PauliString by this tableau’s Clifford operation, returning C * P * C^-1. def __call__ ( self , pauli_string : stim.PauliString) -> stim.PauliString
import stim
cnot = stim.Tableau.from_named_gate( "CNOT" )
p = stim.PauliString( "XX" )
print (cnot(p)) # +X_
Circuit conversion
to_circuit() — decompose into gates
Converts the tableau into an equivalent Clifford circuit. def to_circuit (
self ,
method : Literal[ "elimination" , "graph_state" ] = 'elimination' ,
) -> stim.Circuit
import stim
t = stim.Tableau.random( 5 )
circuit = t.to_circuit()
assert stim.Tableau.from_circuit(circuit) == t
Other constructors
from_unitary_matrix
from_state_vector
from_numpy
iter_all
@ staticmethod
def from_unitary_matrix (
matrix : Iterable[Iterable[ float ]],
* ,
endian : Literal[ "little" , "big" ] = 'little' ,
) -> stim.Tableau
Creates a tableau from the unitary matrix of a Clifford operation. Raises ValueError if the matrix is not Clifford. @ staticmethod
def from_state_vector (
state_vector : Iterable[ float ],
* ,
endian : Literal[ "little" , "big" ],
) -> stim.Tableau
Creates the stabilizer tableau of the stabilizer state with the given amplitude vector. @ staticmethod
def from_numpy (
* ,
x2x : np.ndarray,
x2z : np.ndarray,
z2x : np.ndarray,
z2z : np.ndarray,
x_signs : Optional[np.ndarray] = None ,
z_signs : Optional[np.ndarray] = None ,
) -> stim.Tableau
Creates a tableau from the four binary coupling matrices in the Aaronson–Gottesman representation. @ staticmethod
def iter_all ( num_qubits : int ) -> stim.TableauIterator
Returns an iterator over all distinct n-qubit Clifford operations. For n=1 this yields 24 tableaus.
Output representations
to_stabilizers() — Z output generators
Returns the stabilizer generators (Z outputs) of the tableau, optionally in canonical form. def to_stabilizers ( self , * , canonicalize : bool = False ) -> List[stim.PauliString]
to_state_vector() — amplitude vector
Returns the state vector produced by applying this tableau to |0...0⟩. Requires O(n·2ⁿ) time. def to_state_vector (
self ,
* ,
endian : Literal[ "little" , "big" ] = 'little' ,
) -> np.ndarray
to_numpy() — binary matrix representation
Returns the six binary matrices (x2x, x2z, z2x, z2z, x_signs, z_signs) describing the tableau. def to_numpy ( self , * , bit_packed : bool = False ) -> Tuple[ ... ]
to_pauli_string() — as a Pauli product
If the tableau is equivalent to a Pauli product (e.g. a product of single-qubit X, Y, Z gates), returns the corresponding stim.PauliString. Raises ValueError otherwise. def to_pauli_string ( self ) -> stim.PauliString