Skip to main content

class GraphRepresentation

ZX graph built from a stim circuit. Contains the graph and all auxiliary data needed for sampling.

add_dummy

Add a dummy boundary vertex for a qubit.

add_lane

Initialize a qubit lane if it doesn’t exist.

c_nxyz

Period 3 axis cycling gate, sending -X -> Y -> Z -> -X.

c_nzyx

Period 3 axis cycling gate, sending -Z -> Y -> X -> -Z.

c_xnyz

Period 3 axis cycling gate, sending X -> -Y -> Z -> X.

c_xynz

Period 3 axis cycling gate, sending X -> Y -> -Z -> X.

c_xyz

Right handed period 3 axis cycling gate, sending X -> Y -> Z -> X.

c_znyx

Period 3 axis cycling gate, sending Z -> -Y -> X -> Z.

c_zynx

Period 3 axis cycling gate, sending Z -> Y -> -X -> Z.

c_zyx

Left handed period 3 axis cycling gate, sending Z -> Y -> X -> Z.

cnot

Apply CNOT (controlled-X) gate.

correlated_error

Add a correlated error term affecting multiple qubits with given Pauli types.

correlated_error_probs

Build probability distribution for correlated error chain. Given conditional probabilities [p1, p2, …, pk] from a chain of CORRELATED_ERROR(p1) ELSE_CORRELATED_ERROR(p2) … ELSE_CORRELATED_ERROR(pk), computes the joint probability distribution over 2^k outcomes. Since errors are mutually exclusive, only outcomes with at most one bit set have non-zero probability.
  • probs[0] is the probability that no branch fires.
  • probs[1 \<\< i] is the probability that branch i fires after all previous branches did not fire.
Parameters:
  • probabilities (list[float]) — List of conditional probabilities [p1, p2, …, pk]
Returns:
  • np.ndarray — Array of shape (2^k,) with probabilities for each outcome.

cxswap

Apply CX then SWAP.

cy

Apply controlled-Y gate.

cz

Apply controlled-Z gate.

czswap

Apply CZ then SWAP.

depolarize1

Apply single-qubit depolarizing channel with total error probability p.

depolarize2

Apply two-qubit depolarizing channel with total error probability p.

detector

Add detector annotation that XORs the given measurement record bits.

ensure_lane

Ensure qubit lane exists.

error_probs

Single-bit error channel. Returns [P(bit0=0), P(bit0=1)].

finalize_correlated_error

Finalize the current correlated error channel.
  1. Rename all “c{i}” phases to “e{num_error_bits + i}” in the graph
  2. Compute and append the 2^k probability array to channel_probs
  3. Increment num_error_bits by k
  4. Reset num_correlated_error_bits to 0 and correlated_error_probs to []

h

Apply Hadamard gate.

h_nxy

Apply Hadamard-like gate that sends -X <-> Y, Z -> -Z.

h_nxz

Apply Hadamard-like gate that sends -X <-> Z.

h_nyz

Apply Hadamard-like gate that sends -Y <-> Z, X -> -X.

h_xy

Apply variant of Hadamard gate that swaps the X and Y axes (instead of X and Z).

h_yz

Apply variant of Hadamard gate that swaps the Y and Z axes (instead of X and Z).

heralded_erase

Apply heralded erasure channel. Special case of heralded_pauli_channel_1 with equal probabilities p/4 for each of I, X, Y, Z when the channel fires.

heralded_pauli_channel_1

Apply heralded single-qubit Pauli channel. Records a herald bit into the measurement record. When the channel fires (with total probability pi+px+py+pz), the herald is 1 and one of I/X/Y/Z is applied. When it doesn’t fire, the herald is 0 and nothing happens.

heralded_pauli_channel_1_probs

Heralded single-qubit Pauli channel. Returns shape (8,). Bit layout:
  • bit 0: herald bit, written to the measurement record
  • bit 1: Z error component
  • bit 2: X error component
The non-zero outcomes are:
  • index 0 (0b000): no herald, no Pauli error
  • index 1 (0b001): herald + I
  • index 3 (0b011): herald + Z
  • index 5 (0b101): herald + X
  • index 7 (0b111): herald + Y, represented as X+Z

i

Apply identity (advances the row).

ii

Apply two-qubit identity (advances the row on both qubits).

iswap

Swap two qubits and phase the -1 eigenspace of the ZZ observable by i.

iswap_dag

Swap two qubits and phase the -1 eigenspace of the ZZ observable by -i.

last_edge

Get the last edge for a qubit.

last_row

Get the row of the last vertex for a qubit.

m

Measure qubit in Z basis with optional bit-flip error probability p.

mpad

Pad measurement record with a fixed bit value. Parameters:
  • b (GraphRepresentation) — The graph representation to modify.
  • value (int) — The bit value to record (0 or 1).
  • p (float) — Error probability for the recorded bit.

mpp

Measure a single Pauli product. Parameters:
  • b (GraphRepresentation) — The graph representation to modify.
  • paulis (list[tuple[Literal['X', 'Y', 'Z'], int]]) — List of (pauli_type, qubit) pairs defining the Pauli product.
  • invert (bool) — Whether to invert the measurement result.
  • p (float) — Measurement flip error probability.

mr

Z-basis demolition measurement (optionally noisy). Projects each target qubit into |0> or |1>, reports its value (false=|0>, true=|1>), then resets to |0>.

mrx

X-basis demolition measurement (optionally noisy). Projects each target qubit into |+> or |->, reports its value (false=|+>, true=|->), then resets to |+>.

mry

Y-basis demolition measurement (optionally noisy). Projects each target qubit into |i> or |-i>, reports its value (false=|i>, true=|-i>), then resets to |i>.

mx

Measure qubit in X basis.

mxx

Measure two qubits in XX basis.

my

Measure qubit in Y basis.

myy

Measure two qubits in YY basis.

mzz

Measure two qubits in ZZ basis.

observable_include

Add observable annotation that XORs the given measurement record bits.

pauli_channel_1

Apply single-qubit Pauli channel with given X, Y, Z error probabilities.

pauli_channel_1_probs

Single-qubit Pauli channel. Returns shape (4,). Bit layout:
  • bit 0: Z error component
  • bit 1: X error component
The outcomes are:
  • index 0 (0b00): I
  • index 1 (0b01): Z
  • index 2 (0b10): X
  • index 3 (0b11): Y

pauli_channel_2

Apply two-qubit Pauli channel with given error probabilities for all 15 Pauli pairs.

pauli_channel_2_probs

Two-qubit Pauli channel. Returns shape (16,). Bit layout:
  • bit 0: Z error component on qubit_i
  • bit 1: X error component on qubit_i
  • bit 2: Z error component on qubit_j
  • bit 3: X error component on qubit_j
With that layout, index z_i + 2*x_i + 4*z_j + 8*x_j stores the probability for the corresponding two-qubit Pauli outcome. The arguments follow Stim’s naming convention: pix is I on qubit_i and X on qubit_j, pzi is Z on qubit_i and I on qubit_j, etc.

r

Z-basis reset. Forces each target qubit into the |0> state by silently measuring it in the Z basis and applying an X gate if it ended up in the |1> state.

r_x

Apply R_X rotation gate with given phase (in units of π).

r_y

Apply R_Y rotation gate with given phase (in units of π).

r_z

Apply R_Z rotation gate with given phase (in units of π).

rx

X-basis reset. Forces each target qubit into the |+> state by silently measuring it in the X basis and applying a Z gate if it ended up in the |-> state.

ry

Y-basis reset. Forces each target qubit into the |i> state by silently measuring it in the Y basis and applying an X gate if it ended up in the |-i> state.

s

Apply S gate (π/2 Z rotation).

s_dag

Apply S† gate (-π/2 Z rotation).

spp

Apply exp(-i pi/4 P) (up to global phase) for a Pauli product P. Phases the -1 eigenspace of P by i (or -i if dagger). For a single qubit, SPP Z0 is the S gate and SPP_DAG Z0 is S_DAG. Parameters:
  • b (GraphRepresentation) — The graph representation to modify.
  • paulis (list[tuple[Literal['X', 'Y', 'Z'], int]]) — List of (pauli_type, qubit) pairs defining the Pauli product P.
  • dagger (bool) — If True, apply exp(+i pi/4 P) (phase by -i) instead.

sqrt_x

Apply √X gate (π/2 X rotation).

sqrt_x_dag

Apply √X† gate (-π/2 X rotation).

sqrt_xx

Phases the -1 eigenspace of the XX observable by i.

sqrt_xx_dag

Phases the -1 eigenspace of the XX observable by -i.

sqrt_y

Apply √Y gate (π/2 Y rotation).

sqrt_y_dag

Apply √Y† gate (-π/2 Y rotation).

sqrt_yy

Phases the -1 eigenspace of the YY observable by i.

sqrt_yy_dag

Phases the -1 eigenspace of the YY observable by -i.

sqrt_z

Apply √Z gate (alias for S gate).

sqrt_z_dag

Apply √Z† gate (alias for S† gate).

sqrt_zz

Phases the -1 eigenspace of the ZZ observable by i.

sqrt_zz_dag

Phases the -1 eigenspace of the ZZ observable by -i.

swap

Apply SWAP gate.

swapcx

Apply SWAP then CX.

swapcz

Apply SWAP then CZ.

t

Apply T gate (π/4 Z rotation).

t_dag

Apply T† gate (-π/4 Z rotation).

tick

Add a tick to the circuit (align all qubits to same row).

tpp

Apply exp(-i pi/8 P) (up to global phase) for a Pauli product P. Phases the -1 eigenspace of P by exp(i pi/4) (or exp(-i pi/4) if dagger). For a single qubit, TPP Z0 is the T gate and TPP_DAG Z0 is T_DAG. Parameters:
  • b (GraphRepresentation) — The graph representation to modify.
  • paulis (list[tuple[Literal['X', 'Y', 'Z'], int]]) — List of (pauli_type, qubit) pairs defining the Pauli product P.
  • dagger (bool) — If True, apply exp(+i pi/8 P) (phase by exp(-i pi/4)) instead.

u3

Apply U3 gate: U3(θ,φ,λ) = R_Z(φ)·R_Y(θ)·R_Z(λ).

x

Apply Pauli X gate.

x_error

Apply X error with probability p.

x_phase

Apply X-axis rotation to qubit. This is equivalent to r_x up to a phase.

xcx

X-controlled X gate. Applies X to target if control is in |-> state.

xcy

X-controlled Y gate. Applies Y to target if control is in |-> state.

xcz

X-controlled Z gate. Applies Z to target if control is in |-> state.

y

Apply Pauli Y gate.

y_error

Apply Y error with probability p.

ycx

Y-controlled X gate. Applies X to target if control is in |-i> state.

ycy

Y-controlled Y gate. Applies Y to target if control is in |-i> state.

ycz

Y-controlled Z gate. Applies Z to target if control is in |-i> state.

z

Apply Pauli Z gate.

z_error

Apply Z error with probability p.

z_phase

Apply Z-axis phase rotation to qubit. This is equivalent to r_z up to a phase.