Skip to main content

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

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
Samples a uniformly random Clifford operation as a tableau.
@staticmethod
def random(num_qubits: int) -> stim.Tableau
import stim

t = stim.Tableau.random(4)
t_inv = t.inverse()
identity = stim.Tableau(4)
assert t * t_inv == identity
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")
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
NameTypeDescription
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
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")],
)
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

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
NameTypeDescription
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])
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")
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))
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

Returns the inverse tableau T^-1 such that T * T^-1 = identity.
def inverse(self, *, unsigned: bool = False) -> stim.Tableau
Parameters
NameTypeDescription
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)
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")

Querying Pauli transformations

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)
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)
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
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)
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

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

@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.

Output representations

Returns the stabilizer generators (Z outputs) of the tableau, optionally in canonical form.
def to_stabilizers(self, *, canonicalize: bool = False) -> List[stim.PauliString]
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
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[...]
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

Build docs developers (and LLMs) love