qml.ops.sk_decomposition¶
- sk_decomposition(op, epsilon, *, max_depth=5, basis_set=('T', 'T*', 'H'), basis_length=10)[source]¶
Approximate an arbitrary single-qubit gate in the Clifford+T basis using the Solovay-Kitaev algorithm.
This method implements the Solovay-Kitaev decomposition algorithm that approximates any single-qubit operation with \(\epsilon > 0\) error. The procedure exits when the approximation error becomes less than \(\epsilon\), or when
max_depth
approximation passes have been made. In the latter case, the approximation error could be \(\geq \epsilon\).This algorithm produces a decomposition with \(O(\text{log}^{3.97}(1/\epsilon))\) operations.
- Parameters
op (Operation) – A single-qubit gate operation.
epsilon (float) – The maximum permissible error.
- Keyword Arguments
max_depth (int) – The maximum number of approximation passes. A smaller \(\epsilon\) would generally require a greater number of passes. Default is
5
.basis_set (list[str]) – Basis set to be used for the decomposition and building an approximate set internally. It accepts the following gate terms:
['X', 'Y', 'Z', 'H', 'T', 'T*', 'S', 'S*']
, where*
refers to the gate adjoint. Default value is['T', 'T*', 'H']
.basis_length (int) – Maximum expansion length of Clifford+T sequences in the internally-built approximate set. Default is
10
.
- Returns
A list of gates in the Clifford+T basis set that approximates the given operation along with a final global phase operation. The operations are in the circuit-order.
- Return type
list[Operation]
- Raises
ValueError – If the given operator acts on more than one wires.
Example
Suppose one would like to decompose
RZ
with rotation angle \(\phi = \pi/3\):import numpy as np import pennylane as qml op = qml.RZ(np.pi/3, wires=0) # Get the gate decomposition in ['T', 'T*', 'H'] ops = qml.ops.sk_decomposition(op, epsilon=1e-3) # Get the approximate matrix from the ops matrix_sk = qml.prod(*reversed(ops)).matrix()
When the function is run for a sufficient
depth
with a good enough approximate set, the output gate sequence should implement the same operation approximately.>>> qml.math.allclose(op.matrix(), matrix_sk, atol=1e-3) True