Skip to main content
IBM Quantum Platform

SolovayKitaevDecomposition

class qiskit.synthesis.SolovayKitaevDecomposition(basic_approximations=None, *, basis_gates=None, depth=12, check_input=False)

GitHub

Bases: object

The Solovay Kitaev discrete decomposition algorithm.

This class is called recursively by the transpiler pass, which is why it is separated. See SolovayKitaev for more information.

Parameters

  • basic_approximations (str |dict[str, np.ndarray] | list[GateSequence] | None) –

    A specification of the basic SO(3) approximations in terms of discrete gates. At each iteration this algorithm, the remaining error is approximated with the closest sequence of gates in this set. If a str, this specifies a filename from which to load the approximation. If a dict, then this contains {gates: effective_SO3_matrix} pairs, e.g. {"h t": np.array([[0, 0.7071, -0.7071], [0, -0.7071, -0.7071], [-1, 0, 0]]}. If a list, this contains the same information as the dict, but already converted to GateSequence objects, which contain the SO(3) matrix and gates.

    Either this parameter, or basis_gates and depth can be specified.

  • basis_gates (list[str |Gate] | None) – A list of discrete (i.e., non-parameterized) standard gates. Defaults to ["h", "t", "tdg"].

  • depth (int) – The number of basis gate combinations to consider in the basis set. This determines how fast (and if) the algorithm converges and should be chosen sufficiently high.

  • check_input (bool) – If True, perform intermediate steps checking whether the matrices are of expected form.


Attributes

basis_gates

The basis gate set of the basic approximations.

If None, defaults to ["h", "t", "tdg"].

check_input

Whether to perform runtime checks on the internal data.

depth

The maximum gate depth of the basic approximations.


Methods

find_basic_approximation

find_basic_approximation(sequence)

GitHub

Find GateSequence in self._basic_approximations that approximates sequence.

Deprecated since version 2.1_pending

The method qiskit.synthesis.discrete_basis.solovay_kitaev.SolovayKitaevDecomposition.find_basic_approximation() is pending deprecation as of Qiskit 2.1. It will be marked deprecated in a future release, and then removed no earlier than 3 months after the release date. Use query_basic_approximation instead, which takes a Gate or matrix as input and returns a QuantumCircuit object.

Parameters

sequence (GateSequence) – GateSequence to find the approximation to.

Returns

GateSequence in that approximates sequence.

Return type

GateSequence

load_basic_approximations

static load_basic_approximations(data)

GitHub

Load basic approximations.

Parameters

data (list |str |dict) – If a string, specifies the path to the file from where to load the data. If a dictionary, directly specifies the decompositions as {gates: matrix} or {gates: (matrix, global_phase)}. There, gates are the names of the gates producing the SO(3) matrix matrix, e.g. {"h t": np.array([[0, 0.7071, -0.7071], [0, -0.7071, -0.7071], [-1, 0, 0]]} and the global_phase can be given to account for a global phase difference between the U(2) matrix of the quantum gates and the stored SO(3) matrix. If not given, the global_phase will be assumed to be 0.

Returns

A list of basic approximations as type GateSequence.

Raises

ValueError – If the number of gate combinations and associated matrices does not match.

Return type

list[GateSequence]

query_basic_approximation

query_basic_approximation(gate)

GitHub

Query a basic approximation of a matrix.

Parameters

gate (np.ndarray | Gate) –

Return type

QuantumCircuit

run

run(gate_matrix, recursion_degree, return_dag=False, check_input=True)

GitHub

Run the algorithm.

Parameters

  • gate_matrix (np.ndarray | Gate) – The single-qubit gate to approximate. Can either be a Gate, where Gate.to_matrix() returns the matrix, or a 2×22\times 2 unitary matrix representing the gate.
  • recursion_degree (int) – The recursion degree, called nn in the paper.
  • return_dag (bool) – If True return a DAGCircuit, else a QuantumCircuit.
  • check_input (bool) – If True check that the input matrix is valid for the decomposition. Overrides the class attribute with the same name, but only for this function call.

Returns

A one-qubit circuit approximating the gate_matrix in the specified discrete basis.

Return type

QuantumCircuit | DAGCircuit

save_basic_approximations

save_basic_approximations(filename)

GitHub

Save the basic approximations into a file.

This can then be loaded again via the class initializer (preferred) or via load_basic_approximations():

filename = "approximations.bin"
sk.save_basic_approximations(filename)
 
new_sk = SolovayKitaevDecomposition(filename)

Parameters

filename (str) – The filename to store the approximations in.

Raises

ValueError – If the filename has a .npy extension. The format is not .npy, and storing as such can cause errors when loading the file again.

Was this page helpful?
Report a bug or request content on GitHub.