mimiqcircuits.decomposition.basis.stim

Stim stabilizer simulator decomposition basis.

Classes

StimBasis()

Decomposition basis targeting the gate set of the Stim stabilizer simulator.

class StimBasis[source]

Bases: DecompositionBasis

Decomposition basis targeting the gate set of the Stim stabilizer simulator.

Stim simulates stabilizer circuits: Clifford gates, Pauli measurements and resets, Pauli noise and quantum error correction annotations. Gates are rewritten toward that set by the first rule that matches, in this order:

  1. A GateU whose angles are all zero (a pure global phase) is dropped.

  2. ZYZRewrite: GateU to RZ*RY*RZ, and GateRX to GateRY between S and S†.

  3. SpecialAngleRewrite with only_cliffords=True: rotations by multiples of pi/2 to Clifford gates.

  4. GateECR to S, SX, CX and X, equal up to a global phase. Stim has no ECR instruction, and the canonical decomposition goes through non-Clifford RZX(+-pi/4).

  5. CanonicalRewrite: any other operation.

A GateRX, GateRY or GateRZ by any other angle is not a Clifford gate and raises DecompositionError; so does any non-Clifford gate that reduces to one, such as GateT. Use CliffordTBasis for such circuits.

The terminal operations are:

  • single-qubit Cliffords: GateID, GateX, GateY, GateZ, GateH, GateHXY, GateHYZ, GateS, GateSDG, GateSX, GateSXDG, GateSY and GateSYDG;

  • two-qubit Cliffords: GateCX, GateCY, GateCZ, GateSWAP, GateISWAP, GateISWAPDG and GateDCX;

  • Pauli rotations by +-pi/2: GateRXX, GateRYY, GateRZZ, and RPauli with a non-identity Pauli string. Angles are compared modulo 2*pi, since a rotation by 3*pi/2 equals one by -pi/2 up to a global phase. Other angles are decomposed;

  • measurements in any Pauli basis: Measure, MeasureX, MeasureY, MeasureXX, MeasureYY, MeasureZZ and MeasurePauli;

  • resets and measure-and-resets in the Z, X and Y bases: Reset, ResetX, ResetY, MeasureReset, MeasureResetX and MeasureResetY;

  • Pauli noise: PauliX, PauliY, PauliZ, Depolarizing1, Depolarizing2 and PauliNoise;

  • Barrier and annotations, including Detector, ObservableInclude and QubitCoordinates;

  • feedback: an IfStatement of GateX, GateY or GateZ conditioned on a single bit being 1.

The same Pauli conditioned on a bit being 0 becomes the Pauli followed by the Pauli conditioned on 1. Any other conditional operation has its body decomposed while staying conditional, and raises DecompositionError if that does not lead to conditional Paulis.

The terminal operations correspond to Stim instructions as follows.

MIMIQ Operation

Stim Operation

GateID

I

GateX

X

GateY

Y

GateZ

Z

GateH

H

GateHXY

H_XY

GateHYZ

H_YZ

GateS

S

GateSDG

S_DAG

GateSX

SQRT_X

GateSXDG

SQRT_X_DAG

GateSY

SQRT_Y

GateSYDG

SQRT_Y_DAG

GateCX

CNOT / CX

GateCY

CY

GateCZ

CZ

GateSWAP

SWAP

GateISWAP

ISWAP

GateISWAPDG

ISWAP_DAG

GateDCX

SWAPCX

GateRXX(+-pi/2)

SQRT_XX / SQRT_XX_DAG

GateRYY(+-pi/2)

SQRT_YY / SQRT_YY_DAG

GateRZZ(+-pi/2)

SQRT_ZZ / SQRT_ZZ_DAG

RPauli(P, +-pi/2)

SPP / SPP_DAG

IfStatement(GateX(), 1)

CX rec[-k] q

IfStatement(GateY(), 1)

CY rec[-k] q

IfStatement(GateZ(), 1)

CZ rec[-k] q

Measure

M

MeasureX

MX

MeasureY

MY

MeasureXX

MXX

MeasureYY

MYY

MeasureZZ

MZZ

MeasurePauli

MPP

Reset

R

ResetX

RX

ResetY

RY

MeasureReset

MR

MeasureResetX

MRX

MeasureResetY

MRY

PauliX

X_ERROR

PauliY

Y_ERROR

PauliZ

Z_ERROR

Depolarizing1

DEPOLARIZE1

Depolarizing2

DEPOLARIZE2

PauliNoise

PAULI_CHANNEL_1, PAULI_CHANNEL_2 or E / ELSE_CORRELATED_ERROR

Detector

DETECTOR

ObservableInclude

OBSERVABLE_INCLUDE

QubitCoordinates

QUBIT_COORDS

GateECR is terminal as a Clifford gate but has no Stim instruction of its own.

Examples

>>> from mimiqcircuits import *
>>> from symengine import pi
>>> c = Circuit()
>>> c.push(GateRY(pi/2), 0)
1-qubit circuit with 1 instruction:
└── RY((1/2)*pi) @ q[0]

>>> c.push(GateCX(), 0, 1)
2-qubit circuit with 2 instructions:
├── RY((1/2)*pi) @ q[0]
└── CX @ q[0], q[1]

>>> # RY(pi/2) is the Clifford SY; CX is already a Stim gate
>>> decompose(c, StimBasis())
2-qubit circuit with 2 instructions:
├── SY @ q[0]
└── CX @ q[0], q[1]
>>> # a T gate is not a Clifford gate and is refused
>>> c = Circuit()
>>> c.push(GateT(), 0)
1-qubit circuit with 1 instruction:
└── T @ q[0]

>>> decompose(c, StimBasis())
Traceback (most recent call last):
    ...
mimiqcircuits.decomposition.abstract.DecompositionError: Rotation RZ cannot be decomposed into the Stim basis. Only rotations with angles that are multiples of pi/2 are Clifford gates.

See also

CliffordTBasis, QASMBasis, CanonicalBasis

isterminal(op)[source]

Check whether an operation is terminal in the Stim basis.

Parameters:

op (Operation) – The operation to check.

Returns:

True if op is one of the terminal operations listed in the class description.

Return type:

bool

decompose(op, qubits, bits, zvars)[source]

Rewrite a non-terminal operation one step toward the Stim gate set.

Applies the first matching rule of the list in the class description. A conditional operation is handled as described there.

Parameters:
  • op (Operation) – The operation to rewrite.

  • qubits (Sequence[int]) – Qubit indices the operation acts on.

  • bits (Sequence[int]) – Classical bit indices the operation acts on.

  • zvars (Sequence[int]) – Z-variable indices the operation acts on.

Returns:

A new Circuit with the rewrite.

Raises:

DecompositionError – If op is a rotation by an angle that is not a multiple of pi/2, a conditional operation Stim cannot express, or has no built-in decomposition.

Return type:

Circuit