qiskit-documentation/docs/api/qiskit/0.46/synthesis.mdx

688 lines
39 KiB
Plaintext
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: synthesis
description: API reference for qiskit.synthesis
in_page_toc_min_heading_level: 2
python_api_type: module
python_api_name: qiskit.synthesis
---
<span id="module-qiskit.synthesis" />
<span id="qiskit-synthesis" />
<span id="circuit-synthesis-qiskit-synthesis" />
# Circuit Synthesis
<span id="module-qiskit.synthesis" />
`qiskit.synthesis`
<span id="id1" />
## Evolution Synthesis
| | |
| ---------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| [`EvolutionSynthesis`](qiskit.synthesis.EvolutionSynthesis "qiskit.synthesis.EvolutionSynthesis")() | Interface for evolution synthesis algorithms. |
| [`ProductFormula`](qiskit.synthesis.ProductFormula "qiskit.synthesis.ProductFormula")(order\[, reps, ...]) | Product formula base class for the decomposition of non-commuting operator exponentials. |
| [`LieTrotter`](qiskit.synthesis.LieTrotter "qiskit.synthesis.LieTrotter")(\[reps, insert\_barriers, ...]) | The Lie-Trotter product formula. |
| [`SuzukiTrotter`](qiskit.synthesis.SuzukiTrotter "qiskit.synthesis.SuzukiTrotter")(\[order, reps, ...]) | The (higher order) Suzuki-Trotter product formula. |
| [`MatrixExponential`](qiskit.synthesis.MatrixExponential "qiskit.synthesis.MatrixExponential")() | Exact operator evolution via matrix exponentiation and unitary synthesis. |
| [`QDrift`](qiskit.synthesis.QDrift "qiskit.synthesis.QDrift")(\[reps, insert\_barriers, ...]) | The QDrift Trotterization method, which selects each each term in the Trotterization randomly, with a probability proportional to its weight. |
## Linear Function Synthesis
### synth\_cnot\_count\_full\_pmh
<Function id="qiskit.synthesis.synth_cnot_count_full_pmh" github="https://github.com/qiskit/qiskit/tree/stable/0.46/qiskit/synthesis/linear/cnot_synth.py" signature="qiskit.synthesis.synth_cnot_count_full_pmh(state, section_size=2)">
Synthesize linear reversible circuits for all-to-all architecture using Patel, Markov and Hayes method.
This function is an implementation of the Patel, Markov and Hayes algorithm from \[1] for optimal synthesis of linear reversible circuits for all-to-all architecture, as specified by an n x n matrix.
**Parameters**
* **state** ([*list*](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.12)")*\[*[*list*](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.12)")*] or ndarray*) n x n boolean invertible matrix, describing the state of the input circuit
* **section\_size** ([*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.12)")) the size of each section, used in the PatelMarkovHayes algorithm \[1]. section\_size must be a factor of num\_qubits.
**Returns**
a CX-only circuit implementing the linear transformation.
**Return type**
[QuantumCircuit](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")
**Raises**
[**QiskitError**](exceptions#qiskit.exceptions.QiskitError "qiskit.exceptions.QiskitError") when variable “state” isnt of type numpy.ndarray
**References**
1. Patel, Ketan N., Igor L. Markov, and John P. Hayes, *Optimal synthesis of linear reversible circuits*, Quantum Information & Computation 8.3 (2008): 282-294. [arXiv:quant-ph/0302002 \[quant-ph\]](https://arxiv.org/abs/quant-ph/0302002)
</Function>
### synth\_cnot\_depth\_line\_kms
<Function id="qiskit.synthesis.synth_cnot_depth_line_kms" github="https://github.com/qiskit/qiskit/tree/stable/0.46/qiskit/synthesis/linear/linear_depth_lnn.py" signature="qiskit.synthesis.synth_cnot_depth_line_kms(mat)">
Synthesize linear reversible circuit for linear nearest-neighbor architectures using Kutin, Moulton, Smithline method.
Synthesis algorithm for linear reversible circuits from \[1], Chapter 7. Synthesizes any linear reversible circuit of n qubits over linear nearest-neighbor architecture using CX gates with depth at most 5\*n.
**Parameters**
**mat** (*np.ndarray]*) A boolean invertible matrix.
**Returns**
the synthesized quantum circuit.
**Return type**
[QuantumCircuit](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")
**Raises**
[**QiskitError**](exceptions#qiskit.exceptions.QiskitError "qiskit.exceptions.QiskitError") if mat is not invertible.
**References**
1. Kutin, S., Moulton, D. P., Smithline, L., *Computation at a distance*, Chicago J. Theor. Comput. Sci., vol. 2007, (2007), [arXiv:quant-ph/0701194](https://arxiv.org/abs/quant-ph/0701194)
</Function>
## Linear-Phase Synthesis
### synth\_cz\_depth\_line\_mr
<Function id="qiskit.synthesis.synth_cz_depth_line_mr" github="https://github.com/qiskit/qiskit/tree/stable/0.46/qiskit/synthesis/linear_phase/cz_depth_lnn.py" signature="qiskit.synthesis.synth_cz_depth_line_mr(mat)">
Synthesis of a CZ circuit for linear nearest neighbour (LNN) connectivity, based on Maslov and Roetteler.
Note that this method *reverts* the order of qubits in the circuit, and returns a circuit containing CX and phase (S, Sdg or Z) gates.
**Parameters**
**mat** ([*ndarray*](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.0)")) an upper-diagonal matrix representing the CZ circuit. mat\[i]\[j]=1 for i\<j represents a CZ(i,j) gate
**Returns**
a circuit implementation of the CZ circuit of depth 2\*n+2 for LNN connectivity.
**Return type**
[QuantumCircuit](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")
**Reference:**
1. Dmitri Maslov, Martin Roetteler, *Shorter stabilizer circuits via Bruhat decomposition and quantum circuit transformations*, [arXiv:1705.09176](https://arxiv.org/abs/1705.09176).
</Function>
### synth\_cx\_cz\_depth\_line\_my
<Function id="qiskit.synthesis.synth_cx_cz_depth_line_my" github="https://github.com/qiskit/qiskit/tree/stable/0.46/qiskit/synthesis/linear_phase/cx_cz_depth_lnn.py" signature="qiskit.synthesis.synth_cx_cz_depth_line_my(mat_x, mat_z)">
Joint synthesis of a -CZ-CX- circuit for linear nearest neighbour (LNN) connectivity, with 2-qubit depth at most 5n, based on Maslov and Yang. This method computes the CZ circuit inside the CX circuit via phase gate insertions.
**Parameters**
* **mat\_z** ([*ndarray*](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.0)")) a boolean symmetric matrix representing a CZ circuit. Mz\[i]\[j]=1 represents a CZ(i,j) gate
* **mat\_x** ([*ndarray*](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.0)")) a boolean invertible matrix representing a CX circuit.
**Returns**
a circuit implementation of a CX circuit following a CZ circuit, denoted as a -CZ-CX- circuit,in two-qubit depth at most 5n, for LNN connectivity.
**Return type**
[QuantumCircuit](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")
**Reference:**
1. Kutin, S., Moulton, D. P., Smithline, L., *Computation at a distance*, Chicago J. Theor. Comput. Sci., vol. 2007, (2007), [arXiv:quant-ph/0701194](https://arxiv.org/abs/quant-ph/0701194)
2. Dmitri Maslov, Willers Yang, *CNOT circuits need little help to implement arbitrary Hadamard-free Clifford transformations they generate*, [arXiv:2210.16195](https://arxiv.org/abs/2210.16195).
</Function>
### synth\_cnot\_phase\_aam
<Function id="qiskit.synthesis.synth_cnot_phase_aam" github="https://github.com/qiskit/qiskit/tree/stable/0.46/qiskit/synthesis/linear_phase/cnot_phase_synth.py" signature="qiskit.synthesis.synth_cnot_phase_aam(cnots, angles, section_size=2)">
This function is an implementation of the GraySynth algorithm of Amy, Azimadeh and Mosca.
GraySynth is a heuristic algorithm from \[1] for synthesizing small parity networks. It is inspired by Gray codes. Given a set of binary strings S (called “cnots” bellow), the algorithm synthesizes a parity network for S by repeatedly choosing an index i to expand and then effectively recursing on the co-factors S\_0 and S\_1, consisting of the strings y in S, with y\_i = 0 or 1 respectively. As a subset S is recursively expanded, CNOT gates are applied so that a designated target bit contains the (partial) parity ksi\_y(x) where y\_i = 1 if and only if y\_i = 1 for all y in S. If S is a singleton \{y}, then y = y, hence the target bit contains the value ksi\_y(x) as desired.
Notably, rather than uncomputing this sequence of CNOT gates when a subset S is finished being synthesized, the algorithm maintains the invariant that the remaining parities to be computed are expressed over the current state of bits. This allows the algorithm to avoid the backtracking inherent in uncomputing-based methods.
The algorithm is described in detail in section 4 of \[1].
**Parameters**
* **cnots** ([*list*](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.12)")*\[*[*list*](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.12)")*]*)
a matrix whose columns are the parities to be synthesized e.g.:
```python
[[0, 1, 1, 1, 1, 1],
[1, 0, 0, 1, 1, 1],
[1, 0, 0, 1, 0, 0],
[0, 0, 1, 0, 1, 0]]
```
corresponds to:
```python
x1^x2 + x0 + x0^x3 + x0^x1^x2 + x0^x1^x3 + x0^x1
```
* **angles** ([*list*](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.12)")) a list containing all the phase-shift gates which are to be applied, in the same order as in “cnots”. A number is interpreted as the angle of p(angle), otherwise the elements have to be t, tdg, s, sdg or z.
* **section\_size** ([*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.12)")) the size of every section, used in \_lwr\_cnot\_synth(), in the PatelMarkovHayes algorithm. section\_size must be a factor of num\_qubits.
**Returns**
the decomposed quantum circuit.
**Return type**
[QuantumCircuit](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")
**Raises**
[**QiskitError**](exceptions#qiskit.exceptions.QiskitError "qiskit.exceptions.QiskitError") when dimensions of cnots and angles dont align.
**References**
1. Matthew Amy, Parsiad Azimzadeh, and Michele Mosca. *On the controlled-NOT complexity of controlled-NOTphase circuits.*, Quantum Science and Technology 4.1 (2018): 015002. [arXiv:1712.01859](https://arxiv.org/abs/1712.01859)
</Function>
## Permutation Synthesis
### synth\_permutation\_depth\_lnn\_kms
<Function id="qiskit.synthesis.synth_permutation_depth_lnn_kms" github="https://github.com/qiskit/qiskit/tree/stable/0.46/qiskit/synthesis/permutation/permutation_lnn.py" signature="qiskit.synthesis.synth_permutation_depth_lnn_kms(pattern)">
Synthesize a permutation circuit for a linear nearest-neighbor architecture using the Kutin, Moulton, Smithline method.
This is the permutation synthesis algorithm from [https://arxiv.org/abs/quant-ph/0701194](https://arxiv.org/abs/quant-ph/0701194), Chapter 6. It synthesizes any permutation of n qubits over linear nearest-neighbor architecture using SWAP gates with depth at most n and size at most n(n-1)/2 (where both depth and size are measured with respect to SWAPs).
**Parameters**
**pattern** (*Union\[*[*list*](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.12)")*\[*[*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.12)")*], np.ndarray]*) permutation pattern, describing which qubits occupy the positions 0, 1, 2, etc. after applying the permutation. That is, `pattern[k] = m` when the permutation maps qubit `m` to position `k`. As an example, the pattern `[2, 4, 3, 0, 1]` means that qubit `2` goes to position `0`, qubit `4` goes to position `1`, etc.
**Returns**
the synthesized quantum circuit.
**Return type**
[QuantumCircuit](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")
</Function>
### synth\_permutation\_basic
<Function id="qiskit.synthesis.synth_permutation_basic" github="https://github.com/qiskit/qiskit/tree/stable/0.46/qiskit/synthesis/permutation/permutation_full.py" signature="qiskit.synthesis.synth_permutation_basic(pattern)">
Synthesize a permutation circuit for a fully-connected architecture using sorting.
More precisely, if the input permutation is a cycle of length `m`, then this creates a quantum circuit with `m-1` SWAPs (and of depth `m-1`); if the input permutation consists of several disjoint cycles, then each cycle is essentially treated independently.
**Parameters**
**pattern** (*Union\[*[*list*](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.12)")*\[*[*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.12)")*], np.ndarray]*) permutation pattern, describing which qubits occupy the positions 0, 1, 2, etc. after applying the permutation. That is, `pattern[k] = m` when the permutation maps qubit `m` to position `k`. As an example, the pattern `[2, 4, 3, 0, 1]` means that qubit `2` goes to position `0`, qubit `4` goes to position `1`, etc.
**Returns**
the synthesized quantum circuit.
**Return type**
[QuantumCircuit](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")
</Function>
### synth\_permutation\_acg
<Function id="qiskit.synthesis.synth_permutation_acg" github="https://github.com/qiskit/qiskit/tree/stable/0.46/qiskit/synthesis/permutation/permutation_full.py" signature="qiskit.synthesis.synth_permutation_acg(pattern)">
Synthesize a permutation circuit for a fully-connected architecture using the Alon, Chung, Graham method.
This produces a quantum circuit of depth 2 (measured in the number of SWAPs).
This implementation is based on the Theorem 2 in the paper “Routing Permutations on Graphs Via Matchings” (1993), available at [https://www.cs.tau.ac.il/\~nogaa/PDFS/r.pdf](https://www.cs.tau.ac.il/~nogaa/PDFS/r.pdf).
**Parameters**
**pattern** (*Union\[*[*list*](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.12)")*\[*[*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.12)")*], np.ndarray]*) permutation pattern, describing which qubits occupy the positions 0, 1, 2, etc. after applying the permutation. That is, `pattern[k] = m` when the permutation maps qubit `m` to position `k`. As an example, the pattern `[2, 4, 3, 0, 1]` means that qubit `2` goes to position `0`, qubit `4` goes to position `1`, etc.
**Returns**
the synthesized quantum circuit.
**Return type**
[QuantumCircuit](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")
</Function>
## Clifford Synthesis
### synth\_clifford\_full
<Function id="qiskit.synthesis.synth_clifford_full" github="https://github.com/qiskit/qiskit/tree/stable/0.46/qiskit/synthesis/clifford/clifford_decompose_full.py" signature="qiskit.synthesis.synth_clifford_full(clifford, method=None)">
Decompose a Clifford operator into a QuantumCircuit.
For N \<= 3 qubits this is based on optimal CX cost decomposition from reference \[1]. For N > 3 qubits this is done using the general non-optimal greedy compilation routine from reference \[3], which typically yields better CX cost compared to the AG method in \[2].
**Parameters**
* **clifford** ([*Clifford*](qiskit.quantum_info.Clifford "qiskit.quantum_info.Clifford")) a clifford operator.
* **method** ([*str*](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.12)")) Optional, a synthesis method (AG or greedy). If set this overrides optimal decomposition for N \<=3 qubits.
**Returns**
a circuit implementation of the Clifford.
**Return type**
[QuantumCircuit](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")
**References**
1. S. Bravyi, D. Maslov, *Hadamard-free circuits expose the structure of the Clifford group*, [arXiv:2003.09412 \[quant-ph\]](https://arxiv.org/abs/2003.09412)
2. S. Aaronson, D. Gottesman, *Improved Simulation of Stabilizer Circuits*, Phys. Rev. A 70, 052328 (2004). [arXiv:quant-ph/0406196](https://arxiv.org/abs/quant-ph/0406196)
3. Sergey Bravyi, Shaohan Hu, Dmitri Maslov, Ruslan Shaydulin, *Clifford Circuit Optimization with Templates and Symbolic Pauli Gates*, [arXiv:2105.02291 \[quant-ph\]](https://arxiv.org/abs/2105.02291)
</Function>
### synth\_clifford\_ag
<Function id="qiskit.synthesis.synth_clifford_ag" github="https://github.com/qiskit/qiskit/tree/stable/0.46/qiskit/synthesis/clifford/clifford_decompose_ag.py" signature="qiskit.synthesis.synth_clifford_ag(clifford)">
Decompose a Clifford operator into a QuantumCircuit based on Aaronson-Gottesman method.
**Parameters**
**clifford** ([*Clifford*](qiskit.quantum_info.Clifford "qiskit.quantum_info.Clifford")) a clifford operator.
**Returns**
a circuit implementation of the Clifford.
**Return type**
[QuantumCircuit](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")
**Reference:**
1. S. Aaronson, D. Gottesman, *Improved Simulation of Stabilizer Circuits*, Phys. Rev. A 70, 052328 (2004). [arXiv:quant-ph/0406196](https://arxiv.org/abs/quant-ph/0406196)
</Function>
### synth\_clifford\_bm
<Function id="qiskit.synthesis.synth_clifford_bm" github="https://github.com/qiskit/qiskit/tree/stable/0.46/qiskit/synthesis/clifford/clifford_decompose_bm.py" signature="qiskit.synthesis.synth_clifford_bm(clifford)">
Optimal CX-cost decomposition of a Clifford operator on 2-qubits or 3-qubits into a QuantumCircuit based on Bravyi-Maslov method.
**Parameters**
**clifford** ([*Clifford*](qiskit.quantum_info.Clifford "qiskit.quantum_info.Clifford")) a clifford operator.
**Returns**
a circuit implementation of the Clifford.
**Return type**
[QuantumCircuit](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")
**Raises**
[**QiskitError**](exceptions#qiskit.exceptions.QiskitError "qiskit.exceptions.QiskitError") if clifford is on more than 3 qubits.
**Reference:**
1. S. Bravyi, D. Maslov, *Hadamard-free circuits expose the structure of the Clifford group*, [arXiv:2003.09412 \[quant-ph\]](https://arxiv.org/abs/2003.09412)
</Function>
### synth\_clifford\_greedy
<Function id="qiskit.synthesis.synth_clifford_greedy" github="https://github.com/qiskit/qiskit/tree/stable/0.46/qiskit/synthesis/clifford/clifford_decompose_greedy.py" signature="qiskit.synthesis.synth_clifford_greedy(clifford)">
Decompose a Clifford operator into a QuantumCircuit based on the greedy Clifford compiler that is described in Appendix A of Bravyi, Hu, Maslov and Shaydulin.
This method typically yields better CX cost compared to the Aaronson-Gottesman method.
**Parameters**
**clifford** ([*Clifford*](qiskit.quantum_info.Clifford "qiskit.quantum_info.Clifford")) a clifford operator.
**Returns**
a circuit implementation of the Clifford.
**Return type**
[QuantumCircuit](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")
**Raises**
[**QiskitError**](exceptions#qiskit.exceptions.QiskitError "qiskit.exceptions.QiskitError") if symplectic Gaussian elimination fails.
**Reference:**
1. Sergey Bravyi, Shaohan Hu, Dmitri Maslov, Ruslan Shaydulin, *Clifford Circuit Optimization with Templates and Symbolic Pauli Gates*, [arXiv:2105.02291 \[quant-ph\]](https://arxiv.org/abs/2105.02291)
</Function>
### synth\_clifford\_layers
<Function id="qiskit.synthesis.synth_clifford_layers" github="https://github.com/qiskit/qiskit/tree/stable/0.46/qiskit/synthesis/clifford/clifford_decompose_layers.py" signature="qiskit.synthesis.synth_clifford_layers(cliff, cx_synth_func=<function _default_cx_synth_func>, cz_synth_func=<function _default_cz_synth_func>, cx_cz_synth_func=None, cz_func_reverse_qubits=False, validate=False)">
Synthesis of a Clifford into layers, it provides a similar decomposition to the synthesis described in Lemma 8 of Bravyi and Maslov.
For example, a 5-qubit Clifford circuit is decomposed into the following layers:
```python
┌─────┐┌─────┐┌────────┐┌─────┐┌─────┐┌─────┐┌─────┐┌────────┐
q_0: ┤0 ├┤0 ├┤0 ├┤0 ├┤0 ├┤0 ├┤0 ├┤0 ├
│ ││ ││ ││ ││ ││ ││ ││ │
q_1: ┤1 ├┤1 ├┤1 ├┤1 ├┤1 ├┤1 ├┤1 ├┤1 ├
│ ││ ││ ││ ││ ││ ││ ││ │
q_2: ┤2 S2 ├┤2 CZ ├┤2 CX_dg ├┤2 H2 ├┤2 S1 ├┤2 CZ ├┤2 H1 ├┤2 Pauli ├
│ ││ ││ ││ ││ ││ ││ ││ │
q_3: ┤3 ├┤3 ├┤3 ├┤3 ├┤3 ├┤3 ├┤3 ├┤3 ├
│ ││ ││ ││ ││ ││ ││ ││ │
q_4: ┤4 ├┤4 ├┤4 ├┤4 ├┤4 ├┤4 ├┤4 ├┤4 ├
└─────┘└─────┘└────────┘└─────┘└─────┘└─────┘└─────┘└────────┘
```
This decomposition is for the default cz\_synth\_func and cx\_synth\_func functions, with other functions one may see slightly different decomposition.
**Parameters**
* **cliff** ([*Clifford*](qiskit.quantum_info.Clifford "qiskit.quantum_info.Clifford")) a clifford operator.
* **cx\_synth\_func** (*Callable*) a function to decompose the CX sub-circuit. It gets as input a boolean invertible matrix, and outputs a QuantumCircuit.
* **cz\_synth\_func** (*Callable*) a function to decompose the CZ sub-circuit. It gets as input a boolean symmetric matrix, and outputs a QuantumCircuit.
* **cx\_cz\_synth\_func** (*Callable*) optional, a function to decompose both sub-circuits CZ and CX.
* **validate** (*Boolean*) if True, validates the synthesis process.
* **cz\_func\_reverse\_qubits** (*Boolean*) True only if cz\_synth\_func is synth\_cz\_depth\_line\_mr, since this function returns a circuit that reverts the order of qubits.
**Returns**
a circuit implementation of the Clifford.
**Return type**
[QuantumCircuit](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")
**Reference:**
1. S. Bravyi, D. Maslov, *Hadamard-free circuits expose the structure of the Clifford group*, [arXiv:2003.09412 \[quant-ph\]](https://arxiv.org/abs/2003.09412)
</Function>
### synth\_clifford\_depth\_lnn
<Function id="qiskit.synthesis.synth_clifford_depth_lnn" github="https://github.com/qiskit/qiskit/tree/stable/0.46/qiskit/synthesis/clifford/clifford_decompose_layers.py" signature="qiskit.synthesis.synth_clifford_depth_lnn(cliff)">
Synthesis of a Clifford into layers for linear-nearest neighbour connectivity.
The depth of the synthesized n-qubit circuit is bounded by 7\*n+2, which is not optimal. It should be replaced by a better algorithm that provides depth bounded by 7\*n-4 \[3].
**Parameters**
**cliff** ([*Clifford*](qiskit.quantum_info.Clifford "qiskit.quantum_info.Clifford")) a clifford operator.
**Returns**
a circuit implementation of the Clifford.
**Return type**
[QuantumCircuit](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")
**Reference:**
1. S. Bravyi, D. Maslov, *Hadamard-free circuits expose the structure of the Clifford group*, [arXiv:2003.09412 \[quant-ph\]](https://arxiv.org/abs/2003.09412)
2. Dmitri Maslov, Martin Roetteler, *Shorter stabilizer circuits via Bruhat decomposition and quantum circuit transformations*, [arXiv:1705.09176](https://arxiv.org/abs/1705.09176).
3. Dmitri Maslov, Willers Yang, *CNOT circuits need little help to implement arbitrary Hadamard-free Clifford transformations they generate*, [arXiv:2210.16195](https://arxiv.org/abs/2210.16195).
</Function>
## CNOTDihedral Synthesis
### synth\_cnotdihedral\_full
<Function id="qiskit.synthesis.synth_cnotdihedral_full" github="https://github.com/qiskit/qiskit/tree/stable/0.46/qiskit/synthesis/cnotdihedral/cnotdihedral_decompose_full.py" signature="qiskit.synthesis.synth_cnotdihedral_full(elem)">
Decompose a CNOTDihedral element into a QuantumCircuit. For N \<= 2 qubits this is based on optimal CX cost decomposition from reference \[1]. For N > 2 qubits this is done using the general non-optimal compilation routine from reference \[2].
**Parameters**
**elem** ([*CNOTDihedral*](qiskit.quantum_info.CNOTDihedral "qiskit.quantum_info.CNOTDihedral")) a CNOTDihedral element.
**Returns**
a circuit implementation of the CNOTDihedral element.
**Return type**
[QuantumCircuit](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")
**References**
1. Shelly Garion and Andrew W. Cross, *Synthesis of CNOT-Dihedral circuits with optimal number of two qubit gates*, [Quantum 4(369), 2020](https://quantum-journal.org/papers/q-2020-12-07-369/)
2. Andrew W. Cross, Easwar Magesan, Lev S. Bishop, John A. Smolin and Jay M. Gambetta, *Scalable randomised benchmarking of non-Clifford gates*, npj Quantum Inf 2, 16012 (2016).
</Function>
### synth\_cnotdihedral\_two\_qubits
<Function id="qiskit.synthesis.synth_cnotdihedral_two_qubits" github="https://github.com/qiskit/qiskit/tree/stable/0.46/qiskit/synthesis/cnotdihedral/cnotdihedral_decompose_two_qubits.py" signature="qiskit.synthesis.synth_cnotdihedral_two_qubits(elem)">
Decompose a CNOTDihedral element on a single qubit and two qubits into a QuantumCircuit. This decomposition has an optimal number of CX gates.
**Parameters**
**elem** ([*CNOTDihedral*](qiskit.quantum_info.CNOTDihedral "qiskit.quantum_info.CNOTDihedral")) a CNOTDihedral element.
**Returns**
a circuit implementation of the CNOTDihedral element.
**Return type**
[QuantumCircuit](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")
**Raises**
[**QiskitError**](exceptions#qiskit.exceptions.QiskitError "qiskit.exceptions.QiskitError") if the element in not 1-qubit or 2-qubit CNOTDihedral.
**Reference:**
1. Shelly Garion and Andrew W. Cross, *On the structure of the CNOT-Dihedral group*, [arXiv:2006.12042 \[quant-ph\]](https://arxiv.org/abs/2006.12042)
</Function>
### synth\_cnotdihedral\_general
<Function id="qiskit.synthesis.synth_cnotdihedral_general" github="https://github.com/qiskit/qiskit/tree/stable/0.46/qiskit/synthesis/cnotdihedral/cnotdihedral_decompose_general.py" signature="qiskit.synthesis.synth_cnotdihedral_general(elem)">
Decompose a CNOTDihedral element into a QuantumCircuit.
Decompose a general CNOTDihedral elements. The number of CNOT gates is not necessarily optimal. For a decomposition of a 1-qubit or 2-qubit element, call synth\_cnotdihedral\_two\_qubits.
**Parameters**
**elem** ([*CNOTDihedral*](qiskit.quantum_info.CNOTDihedral "qiskit.quantum_info.CNOTDihedral")) a CNOTDihedral element.
**Returns**
a circuit implementation of the CNOTDihedral element.
**Return type**
[QuantumCircuit](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")
**Raises**
[**QiskitError**](exceptions#qiskit.exceptions.QiskitError "qiskit.exceptions.QiskitError") if the element could not be decomposed into a circuit.
**Reference:**
1. Andrew W. Cross, Easwar Magesan, Lev S. Bishop, John A. Smolin and Jay M. Gambetta, *Scalable randomised benchmarking of non-Clifford gates*, npj Quantum Inf 2, 16012 (2016).
</Function>
## Stabilizer State Synthesis
### synth\_stabilizer\_layers
<Function id="qiskit.synthesis.synth_stabilizer_layers" github="https://github.com/qiskit/qiskit/tree/stable/0.46/qiskit/synthesis/stabilizer/stabilizer_decompose.py" signature="qiskit.synthesis.synth_stabilizer_layers(stab, cz_synth_func=<function _default_cz_synth_func>, cz_func_reverse_qubits=False, validate=False)">
Synthesis of a stabilizer state into layers.
It provides a similar decomposition to the synthesis described in Lemma 8 of Bravyi and Maslov, without the initial Hadamard-free sub-circuit which do not affect the stabilizer state.
For example, a 5-qubit stabilizer state is decomposed into the following layers:
```python
┌─────┐┌─────┐┌─────┐┌─────┐┌────────┐
q_0: ┤0 ├┤0 ├┤0 ├┤0 ├┤0 ├
│ ││ ││ ││ ││ │
q_1: ┤1 ├┤1 ├┤1 ├┤1 ├┤1 ├
│ ││ ││ ││ ││ │
q_2: ┤2 H2 ├┤2 S1 ├┤2 CZ ├┤2 H1 ├┤2 Pauli ├
│ ││ ││ ││ ││ │
q_3: ┤3 ├┤3 ├┤3 ├┤3 ├┤3 ├
│ ││ ││ ││ ││ │
q_4: ┤4 ├┤4 ├┤4 ├┤4 ├┤4 ├
└─────┘└─────┘└─────┘└─────┘└────────┘
```
**Parameters**
* **stab** ([*StabilizerState*](qiskit.quantum_info.StabilizerState "qiskit.quantum_info.StabilizerState")) a stabilizer state.
* **cz\_synth\_func** (*Callable*) a function to decompose the CZ sub-circuit. It gets as input a boolean symmetric matrix, and outputs a QuantumCircuit.
* **validate** (*Boolean*) if True, validates the synthesis process.
* **cz\_func\_reverse\_qubits** (*Boolean*) True only if cz\_synth\_func is synth\_cz\_depth\_line\_mr, since this function returns a circuit that reverts the order of qubits.
**Returns**
a circuit implementation of the stabilizer state.
**Return type**
[QuantumCircuit](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")
**Raises**
[**QiskitError**](exceptions#qiskit.exceptions.QiskitError "qiskit.exceptions.QiskitError") if the input is not a StabilizerState.
**Reference:**
1. S. Bravyi, D. Maslov, *Hadamard-free circuits expose the structure of the Clifford group*, [arXiv:2003.09412 \[quant-ph\]](https://arxiv.org/abs/2003.09412)
</Function>
### synth\_stabilizer\_depth\_lnn
<Function id="qiskit.synthesis.synth_stabilizer_depth_lnn" github="https://github.com/qiskit/qiskit/tree/stable/0.46/qiskit/synthesis/stabilizer/stabilizer_decompose.py" signature="qiskit.synthesis.synth_stabilizer_depth_lnn(stab)">
Synthesis of an n-qubit stabilizer state for linear-nearest neighbour connectivity, in 2-qubit depth 2\*n+2 and two distinct CX layers, using CX and phase gates (S, Sdg or Z).
**Parameters**
**stab** ([*StabilizerState*](qiskit.quantum_info.StabilizerState "qiskit.quantum_info.StabilizerState")) a stabilizer state.
**Returns**
a circuit implementation of the stabilizer state.
**Return type**
[QuantumCircuit](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")
**Reference:**
1. S. Bravyi, D. Maslov, *Hadamard-free circuits expose the structure of the Clifford group*, [arXiv:2003.09412 \[quant-ph\]](https://arxiv.org/abs/2003.09412)
2. Dmitri Maslov, Martin Roetteler, *Shorter stabilizer circuits via Bruhat decomposition and quantum circuit transformations*, [arXiv:1705.09176](https://arxiv.org/abs/1705.09176).
</Function>
## Discrete Basis Synthesis
| | |
| --------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------- |
| [`SolovayKitaevDecomposition`](qiskit.synthesis.SolovayKitaevDecomposition "qiskit.synthesis.SolovayKitaevDecomposition")(\[...]) | The Solovay Kitaev discrete decomposition algorithm. |
### generate\_basic\_approximations
<Function id="qiskit.synthesis.generate_basic_approximations" github="https://github.com/qiskit/qiskit/tree/stable/0.46/qiskit/synthesis/discrete_basis/generate_basis_approximations.py" signature="qiskit.synthesis.generate_basic_approximations(basis_gates, depth, filename=None)">
Generates a list of `GateSequence``s with the gates in ``basic_gates`.
**Parameters**
* **basis\_gates** ([*list*](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.12)")*\[*[*str*](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.12)") *|*[*Gate*](qiskit.circuit.Gate "qiskit.circuit.Gate")*]*) The gates from which to create the sequences of gates.
* **depth** ([*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.12)")) The maximum depth of the approximations.
* **filename** ([*str*](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.12)") *| None*) If provided, the basic approximations are stored in this file.
**Returns**
List of `GateSequences` using the gates in `basic_gates`.
**Raises**
[**ValueError**](https://docs.python.org/3/library/exceptions.html#ValueError "(in Python v3.12)") If `basis_gates` contains an invalid gate identifier.
**Return type**
[list](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.12)")\[GateSequence]
</Function>
## Unitary Synthesis
Decomposition of general $2^n \times 2^n$ unitary matrices for any number of qubits.
### qs\_decomposition
<Function id="qiskit.synthesis.qs_decomposition" github="https://github.com/qiskit/qiskit/tree/stable/0.46/qiskit/synthesis/unitary/qsd.py" signature="qiskit.synthesis.qs_decomposition(mat, opt_a1=True, opt_a2=True, decomposer_1q=None, decomposer_2q=None, *, _depth=0)">
Decomposes a unitary matrix into one and two qubit gates using Quantum Shannon Decomposition,
This decomposition is described in Shende et al. \[1].
```python
┌───┐ ┌───┐ ┌───┐ ┌───┐
─┤ ├─ ───────┤ Rz├─────┤ Ry├─────┤ Rz├─────
│ │ ≃ ┌───┐└─┬─┘┌───┐└─┬─┘┌───┐└─┬─┘┌───┐
/─┤ ├─ /─┤ ├──□──┤ ├──□──┤ ├──□──┤ ├
└───┘ └───┘ └───┘ └───┘ └───┘
```
The number of CX gates generated with the decomposition without optimizations is,
$$
\frac{9}{16} 4^n - \frac{3}{2} 2^n
$$
If opt\_a1 = True, the default, the CX count is reduced by,
$$
\frac{1}{3} 4^{n - 2} - 1.
$$
If opt\_a2 = True, the default, the CX count is reduced by,
$$
4^{n-2} - 1.
$$
**Parameters**
* **mat** (*np.ndarray*) unitary matrix to decompose
* **opt\_a1** ([*bool*](https://docs.python.org/3/library/functions.html#bool "(in Python v3.12)")) whether to try optimization A.1 from Shende et al. \[1]. This should eliminate 1 cx per call. If True CZ gates are left in the output. If desired these can be further decomposed to CX.
* **opt\_a2** ([*bool*](https://docs.python.org/3/library/functions.html#bool "(in Python v3.12)")) whether to try optimization A.2 from Shende et al. \[1]. This decomposes two qubit unitaries into a diagonal gate and a two cx unitary and reduces overall cx count by $4^{n-2} - 1$.
* **decomposer\_1q** (*Callable\[\[np.ndarray],* [*QuantumCircuit*](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")*] | None*) optional 1Q decomposer. If None, uses [`OneQubitEulerDecomposer`](qiskit.synthesis.OneQubitEulerDecomposer "qiskit.synthesis.OneQubitEulerDecomposer").
* **decomposer\_2q** (*Callable\[\[np.ndarray],* [*QuantumCircuit*](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")*] | None*) optional 2Q decomposer. If None, uses [`TwoQubitBasisDecomposer`](qiskit.synthesis.TwoQubitBasisDecomposer "qiskit.synthesis.TwoQubitBasisDecomposer").
**Returns**
Decomposed quantum circuit.
**Return type**
[QuantumCircuit](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")
**Reference:**
1. Shende, Bullock, Markov, *Synthesis of Quantum Logic Circuits*, [arXiv:0406176 \[quant-ph\]](https://arxiv.org/abs/quant-ph/0406176)
</Function>
The Approximate Quantum Compiler is available here: [`qiskit.synthesis.unitary.aqc`](synthesis_aqc#module-qiskit.synthesis.unitary.aqc "qiskit.synthesis.unitary.aqc")
## One-Qubit Synthesis
| | |
| ------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------- |
| [`OneQubitEulerDecomposer`](qiskit.synthesis.OneQubitEulerDecomposer "qiskit.synthesis.OneQubitEulerDecomposer")(\[basis, use\_dag]) | A class for decomposing 1-qubit unitaries into Euler angle rotations. |
## Two-Qubit Synthesis
| | |
| ------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`TwoQubitBasisDecomposer`](qiskit.synthesis.TwoQubitBasisDecomposer "qiskit.synthesis.TwoQubitBasisDecomposer")(gate\[, ...]) | A class for decomposing 2-qubit unitaries into minimal number of uses of a 2-qubit basis gate. |
| [`XXDecomposer`](qiskit.synthesis.XXDecomposer "qiskit.synthesis.XXDecomposer")(\[basis\_fidelity, euler\_basis, ...]) | A class for optimal decomposition of 2-qubit unitaries into 2-qubit basis gates of XX type (i.e., each locally equivalent to CAN(alpha, 0, 0) for a possibly varying alpha). |