mimiqcircuits.decomposition.rules.special_angle

Special angle rewrite rule for Clifford+T decomposition.

Classes

SpecialAngleRewrite([only_cliffords])

Rewrite rule that turns rotations by multiples of pi/4 into Clifford+T gates.

class SpecialAngleRewrite(only_cliffords=False)[source]

Bases: RewriteRule

Rewrite rule that turns rotations by multiples of pi/4 into Clifford+T gates.

A rotation by k*pi/4 equals, up to a global phase, a short product of Clifford gates and at most one T (T†, or T conjugated into the X or Y axis). This rule writes that product out exactly. For example RZ(pi/4) becomes T, RZ(pi/2) becomes S and RX(pi) becomes X. Angles are compared to a multiple of pi/4 with a relative tolerance of 1e-9 (absolute 1e-10 near zero), modulo 2*pi. Other angles are not matched.

Parameters:

only_cliffords (bool) – If True, match only angles k*pi/2, whose rewrite uses Clifford gates only. Defaults to False, which matches every k*pi/4.

Supported Operations

  • GateRX(theta) with theta = k*pi/4

  • GateRY(theta) with theta = k*pi/4

  • GateRZ(lambda) with lambda = k*pi/4

Examples

>>> from mimiqcircuits import *
>>> from symengine import pi
>>> rule = SpecialAngleRewrite()
>>> # 3*pi/4 is a special angle: RZ(3*pi/4) is S followed by T
>>> rule.decompose_step(GateRZ(3*pi/4), [0], [], [])
1-qubit circuit with 2 instructions:
├── S @ q[0]
└── T @ q[0]

>>> # an arbitrary angle is not matched
>>> rule.matches(GateRZ(0.123))
False
>>> # pi/4 needs a T gate, which the Clifford-only mode refuses
>>> SpecialAngleRewrite(only_cliffords=True).matches(GateRZ(pi/4))
False
matches(op)[source]

Check whether an operation is a rotation by a special angle.

Parameters:

op (Operation) – The operation to check.

Returns:

True for a GateRX, GateRY or GateRZ whose angle is a multiple of pi/4, or of pi/2 when only_cliffords is set.

Return type:

bool

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

Rewrite a rotation by a multiple of pi/4 as Clifford+T gates.

The result equals the rotation up to a global phase, and is empty for a multiple of 2*pi.

Parameters:
  • op (Operation) – The GateRX, GateRY or GateRZ to rewrite.

  • qubits (Sequence[int]) – Qubit index the rotation acts on.

  • bits (Sequence[int]) – Classical bit indices (unused).

  • zvars (Sequence[int]) – Z-variable indices (unused).

Returns:

A new Circuit with the rewrite.

Raises:

DecompositionError – If matches() refuses op.

Return type:

Circuit