mimiqcircuits.decomposition.rules.special_angle¶
Special angle rewrite rule for Clifford+T decomposition.
Classes
|
Rewrite rule that turns rotations by multiples of |
- class SpecialAngleRewrite(only_cliffords=False)[source]¶
Bases:
RewriteRuleRewrite rule that turns rotations by multiples of
pi/4into Clifford+T gates.A rotation by
k*pi/4equals, up to a global phase, a short product of Clifford gates and at most oneT(T†, orTconjugated into the X or Y axis). This rule writes that product out exactly. For exampleRZ(pi/4)becomesT,RZ(pi/2)becomesSandRX(pi)becomesX. Angles are compared to a multiple ofpi/4with a relative tolerance of1e-9(absolute1e-10near zero), modulo2*pi. Other angles are not matched.- Parameters:
only_cliffords (bool) – If
True, match only anglesk*pi/2, whose rewrite uses Clifford gates only. Defaults toFalse, which matches everyk*pi/4.
Supported Operations
GateRX(theta)withtheta = k*pi/4GateRY(theta)withtheta = k*pi/4GateRZ(lambda)withlambda = 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
- decompose_step(op, qubits, bits, zvars)[source]¶
Rewrite a rotation by a multiple of
pi/4as Clifford+T gates.The result equals the rotation up to a global phase, and is empty for a multiple of
2*pi.- Parameters:
- Returns:
A new
Circuitwith the rewrite.- Raises:
DecompositionError – If
matches()refusesop.- Return type: