# SolovayKitaev

`qiskit.transpiler.passes.SolovayKitaev(*args, **kwargs)`

Bases: `TransformationPass`

Approximately decompose 1q gates to a discrete basis using the Solovay-Kitaev algorithm.

The Solovay-Kitaev theorem [1] states that any single qubit gate can be approximated to arbitrary precision by a set of fixed single-qubit gates, if the set generates a dense subset in $SU(2)$. This is an important result, since it means that any single-qubit gate can be expressed in terms of a discrete, universal gate set that we know how to implement fault-tolerantly. Therefore, the Solovay-Kitaev algorithm allows us to take any non-fault tolerant circuit and rephrase it in a fault-tolerant manner.

This implementation of the Solovay-Kitaev algorithm is based on [2].

For example, the following circuit

```
┌─────────┐
q_0: ┤ RX(0.8) ├
└─────────┘
```

can be decomposed into

```
global phase: 7π/8
┌───┐┌───┐┌───┐
q_0: ┤ H ├┤ T ├┤ H ├
└───┘└───┘└───┘
```

with an L2-error of approximately 0.01.

## Examples

Per default, the basis gate set is `["t", "tdg", "h"]`

:

```
import numpy as np
from qiskit.circuit import QuantumCircuit
from qiskit.transpiler.passes.synthesis import SolovayKitaev
from qiskit.quantum_info import Operator
circuit = QuantumCircuit(1)
circuit.rx(0.8, 0)
print("Original circuit:")
print(circuit.draw())
skd = SolovayKitaev(recursion_degree=2)
discretized = skd(circuit)
print("Discretized circuit:")
print(discretized.draw())
print("Error:", np.linalg.norm(Operator(circuit).data - Operator(discretized).data))
```

```
Original circuit:
┌─────────┐
q: ┤ Rx(0.8) ├
└─────────┘
Discretized circuit:
global phase: 7π/8
┌───┐┌───┐┌───┐
q: ┤ H ├┤ T ├┤ H ├
└───┘└───┘└───┘
Error: 2.828408279166474
```

For individual basis gate sets, the `generate_basic_approximations`

function can be used:

```
from qiskit.synthesis import generate_basic_approximations
from qiskit.transpiler.passes import SolovayKitaev
basis = ["s", "sdg", "t", "tdg", "z", "h"]
approx = generate_basic_approximations(basis, depth=3)
skd = SolovayKitaev(recursion_degree=2, basic_approximations=approx)
```

## References

**[1]: Kitaev, A Yu (1997). Quantum computations: algorithms and error correction.**

Russian Mathematical Surveys. 52 (6): 1191–1249. Online (opens in a new tab).

**[2]: Dawson, Christopher M.; Nielsen, Michael A. (2005) The Solovay-Kitaev Algorithm.**

arXiv:quant-ph/0505030 (opens in a new tab).

**Parameters**

**recursion_degree**– The recursion depth for the Solovay-Kitaev algorithm. A larger recursion depth increases the accuracy and length of the decomposition.**basic_approximations**– The basic approximations for the finding the best discrete decomposition at the root of the recursion. If a string, it specifies the`.npy`

file to load the approximations from. If a dictionary, it contains`{label: SO(3)-matrix}`

pairs. If None, a default based on the H, T and Tdg gates up to combinations of depth 10 is generated.

## Attributes

### is_analysis_pass

Check if the pass is an analysis pass.

If the pass is an AnalysisPass, that means that the pass can analyze the DAG and write the results of that analysis in the property set. Modifications on the DAG are not allowed by this kind of pass.

### is_transformation_pass

Check if the pass is a transformation pass.

If the pass is a TransformationPass, that means that the pass can manipulate the DAG, but cannot modify the property set (but it can be read).

## Methods

### execute

`execute(passmanager_ir, state, callback=None)`

Execute optimization task for input Qiskit IR.

**Parameters**

**passmanager_ir**(*Any*(opens in a new tab)) – Qiskit IR to optimize.**state**(*PassManagerState*) – State associated with workflow execution by the pass manager itself.**callback**(*Callable*(opens in a new tab)*| None*) – A callback function which is caller per execution of optimization task.

**Returns**

Optimized Qiskit IR and state of the workflow.

**Return type**

tuple (opens in a new tab)[*Any* (opens in a new tab), qiskit.passmanager.compilation_status.PassManagerState]

### name

`name()`

Name of the pass.

**Return type**

### run

`run(dag)`

Run the `SolovayKitaev`

pass on dag.

**Parameters**

**dag** (*DAGCircuit*) – The input dag.

**Returns**

Output dag with 1q gates synthesized in the discrete target basis.

**Raises**

**TranspilerError** – if a gates does not have to_matrix

**Return type**

### update_status

`update_status(state, run_state)`

Update workflow status.

**Parameters**

**state**(*PassManagerState*) – Pass manager state to update.**run_state**(*RunState*) – Completion status of current task.

**Returns**

Updated pass manager state.

**Return type**