mimiqcircuits.decomposition.rules.toffoli_to_clifford_t

Rewrite rule for decomposing Toffoli into Clifford+T.

Classes

ToffoliToCliffordTRewrite()

Rewrite rule that turns a Toffoli gate into Clifford+T gates.

class ToffoliToCliffordTRewrite[source]

Bases: RewriteRule

Rewrite rule that turns a Toffoli gate into Clifford+T gates.

Replaces GateCCX by the standard exact circuit of 15 gates: 7 T or T†, 2 H and 6 CX. No ancilla is used.

Examples

>>> from mimiqcircuits import *
>>> c = Circuit()
>>> c.push(GateCCX(), 0, 1, 2)
3-qubit circuit with 1 instruction:
└── C₂X @ q[0:1], q[2]

>>> # count the T and T† gates of the rewrite
>>> ct = decompose_step(c, ToffoliToCliffordTRewrite())
>>> sum(isinstance(inst.operation, (GateT, GateTDG)) for inst in ct)
7
matches(op)[source]

Check whether an operation is a Toffoli gate.

Parameters:

op (Operation) – The operation to check.

Returns:

True for GateCCX.

Return type:

bool

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

Rewrite a Toffoli gate as 15 Clifford+T gates.

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

  • qubits (Sequence[int]) – The two control qubits, then the target.

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

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

Returns:

A new Circuit with the rewrite.

Raises:

DecompositionError – If op is not a GateCCX or qubits does not hold exactly 3 indices.

Return type:

Circuit