mimiqcircuits.decomposition.basis.clifford_t¶
Clifford+T decomposition basis.
Classes
|
Decomposition basis targeting the Clifford+T gate set. |
- class CliffordTBasis(sk_depth=None, rotations=None, borrow=False, max_ancillas=0, allow_measurement=False)[source]¶
Bases:
DecompositionBasisDecomposition basis targeting the Clifford+T gate set.
Clifford+T is the standard universal gate set of error-corrected quantum computing. The terminal operations of this basis are those of
StimBasisplusGateTandGateTDG, so the two bases always keep the same Clifford and stabilizer operations:single-qubit Cliffords:
GateID,GateX,GateY,GateZ,GateH,GateHXY,GateHYZ,GateS,GateSDG,GateSX,GateSXDG,GateSY,GateSYDG;two-qubit Cliffords:
GateCX,GateCY,GateCZ,GateSWAP,GateISWAP,GateISWAPDG,GateDCX,GateECR;Pauli rotations by
+-pi/2:GateRXX,GateRYY,GateRZZ, andRPauliwith a non-identity Pauli string;the non-Clifford
GateTandGateTDG;measurements, resets and measure-and-resets in the X, Y and Z bases,
MeasureXX,MeasureYY,MeasureZZandMeasurePauli;Pauli noise:
PauliX,PauliY,PauliZ,Depolarizing1,Depolarizing2andPauliNoise;barriers and annotations;
classical operations, which
StimBasisdoes not keep;an
IfStatementwhose body is terminal in this basis, with any condition.StimBasisonly keeps a conditionalGateX,GateYorGateZon a single bit.
Non-terminal operations are rewritten by the first rule that matches, in this order:
SpecialAngleRewrite: rotations by multiples ofpi/4to exact Clifford+T.GateECRtoS,SX,CXandX, as inStimBasis, with no T gate.ToffoliToCliffordTRewrite:GateCCXto Clifford+T with 7 T gates.A
GateUwhose angles are all zero (a pure global phase) is dropped.ZYZRewrite:GateUtoRZ*RY*RZ, andGateRXtoGateRYbetweenSandS†.ToZRotationRewrite:GateRYtoGateRZand Cliffords.The
rotationsrule (defaultGridSynthRewrite): remainingGateRZto an approximate Clifford+T sequence.CanonicalRewrite: any other operation, towardGateUandGateCX. AGateRX,GateRYorGateRZthat reaches this point has a symbolic angle and raisesDecompositionError.
The
rotationsrule only sees angles that step 1 could not decompose exactly. The body of anIfStatementgoes through the same pipeline and stays conditional. No T-count optimization is performed on the result.- Parameters:
sk_depth (int | None) – Use
SolovayKitaevRewritewith this recursion depth as therotationsrule.rotations (RewriteRule) – Rule that synthesizes the remaining Z-rotations. The default
GridSynthRewrite()approximates each rotation to operator-norm error1e-10. The rule must matchGateRZwith a numeric angle and emit only gates of this basis.borrow (bool) – Let decompositions borrow qubits of the circuit that the operation does not act on. A borrowed qubit can be in any state; the decomposition leaves it as it found it.
max_ancillas (int) – Let decompositions add up to this many clean ancillas, numbered after the qubits of the circuit and marked with
AncillaAllocandAncillaFree. Ancillas freed by one operation are reused by the next.allow_measurement (bool) – With
max_ancillas, let decompositions undo steps by measuring an ancilla into one extra bit, numbered after the bits of the circuit. A circuit without bits is refused with aValueError. With a clean ancilla, aGateCCXthen costs 4 T instead of 7.
The three ancilla options are off by default, and only change how multi-controlled X gates are decomposed. Circuits whose width is unknown, such as a lone operation, get no ancillas.
- Raises:
ValueError – If both
sk_depthandrotationsare given, or ifrotationsdoes not matchGateRZ.
Decomposing an operation that no rule handles, such as a noise channel other than the Pauli ones above, raises a
DecompositionError.Examples
>>> from mimiqcircuits import * >>> from symengine import pi >>> c = Circuit() >>> c.push(GateRZ(pi/4), 0) 1-qubit circuit with 1 instruction: └── RZ((1/4)*pi) @ q[0] >>> # a special angle is decomposed exactly >>> decompose(c, CliffordTBasis()) 1-qubit circuit with 1 instruction: └── T @ q[0]
>>> # An arbitrary angle is approximated to 1e-10 by gridsynth >>> c2 = Circuit() >>> c2.push(GateRZ(0.123), 0) 1-qubit circuit with 1 instruction: └── RZ(0.123) @ q[0] >>> decomposed2 = decompose(c2, CliffordTBasis())
>>> # A looser error bound per rotation gives fewer T gates >>> basis = CliffordTBasis(rotations=GridSynthRewrite(epsilon=1e-6)) >>> decomposed3 = decompose(c2, basis) >>> def tcount(c): ... return sum(isinstance(inst.operation, (GateT, GateTDG)) for inst in c) >>> tcount(decomposed3) < tcount(decomposed2) True
>>> # Solovay-Kitaev instead of gridsynth >>> decomposed4 = decompose(c2, CliffordTBasis(sk_depth=0))
- decompose(op, qubits, bits, zvars)[source]¶
Rewrite a non-terminal operation one step toward Clifford+T.
Applies the first matching rule of the list in the class description.
- Parameters:
- Returns:
A new
Circuitwith the rewrite.- Raises:
DecompositionError – If no rule applies to
op.- Return type:
- decompose_ctx(op, qubits, bits, zvars, ctx)[source]¶
Decompose with a context, which only some operations use.
Operations without a rule that uses the context go to
decompose(), so an override of it keeps being called.