Circuit Synthesis
qiskit.synthesis
Evolution Synthesis
EvolutionSynthesis ()  Interface for evolution synthesis algorithms. 
ProductFormula (order[, reps, ...])  Product formula base class for the decomposition of noncommuting operator exponentials. 
LieTrotter ([reps, insert_barriers, ...])  The LieTrotter product formula. 
SuzukiTrotter ([order, reps, ...])  The (higher order) SuzukiTrotter product formula. 
MatrixExponential ()  Exact operator evolution via matrix exponentiation and unitary 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
qiskit.synthesis.synth_cnot_count_full_pmh(state, section_size=2)
Synthesize linear reversible circuits for alltoall 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 alltoall architecture, as specified by an $n \times n$ matrix.
Parameters
 state (list(opens in a new tab)[list(opens in a new tab)[bool(opens in a new tab)]]  np.ndarray[bool(opens in a new tab)]) – $n \times n$ boolean invertible matrix, describing the state of the input circuit
 section_size (int(opens in a new tab)) – The size of each section in the Patel–Markov–Hayes algorithm [1].
Returns
a CXonly circuit implementing the linear transformation.
Return type
Raises
QiskitError – when variable state
isn’t of type numpy.ndarray
References
 Patel, Ketan N., Igor L. Markov, and John P. Hayes, Optimal synthesis of linear reversible circuits, Quantum Information & Computation 8.3 (2008): 282294. arXiv:quantph/0302002 [quantph](opens in a new tab)
synth_cnot_depth_line_kms
qiskit.synthesis.synth_cnot_depth_line_kms(mat)
Synthesize linear reversible circuit for linear nearestneighbor architectures using Kutin, Moulton, Smithline method.
Synthesis algorithm for linear reversible circuits from [1], section 7. This algorithm synthesizes any linear reversible circuit of $n$ qubits over a linear nearestneighbor architecture using CX gates with depth at most $5n$.
Parameters
mat (ndarray(opens in a new tab)[bool(opens in a new tab)]) – A boolean invertible matrix.
Returns
The synthesized quantum circuit.
Raises
QiskitError – if mat
is not invertible.
Return type
References
 Kutin, S., Moulton, D. P., Smithline, L., Computation at a distance, Chicago J. Theor. Comput. Sci., vol. 2007, (2007), arXiv:quantph/0701194(opens in a new tab)
LinearPhase Synthesis
synth_cz_depth_line_mr
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 CXGate
s and phase gates (SGate
, SdgGate
or ZGate
).
Parameters
mat (ndarray(opens in a new tab)) – an upperdiagonal 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 $2n+2$ for LNN connectivity.
Return type
References
 Dmitri Maslov, Martin Roetteler, Shorter stabilizer circuits via Bruhat decomposition and quantum circuit transformations, arXiv:1705.09176(opens in a new tab).
synth_cx_cz_depth_line_my
qiskit.synthesis.synth_cx_cz_depth_line_my(mat_x, mat_z)
Joint synthesis of a CZCX circuit for linear nearest neighbour (LNN) connectivity, with 2qubit 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(opens in a new tab)) – a boolean symmetric matrix representing a CZ circuit.
mat_z[i][j]=1
represents acz(i,j)
gate  mat_x (ndarray(opens in a new tab)) – a boolean invertible matrix representing a CX circuit.
Returns
A circuit implementation of a CX circuit following a CZ circuit, denoted as a CZCX circuit,in twoqubit depth at most 5n
, for LNN connectivity.
Return type
References
 Kutin, S., Moulton, D. P., Smithline, L., Computation at a distance, Chicago J. Theor. Comput. Sci., vol. 2007, (2007), arXiv:quantph/0701194(opens in a new tab)
 Dmitri Maslov, Willers Yang, CNOT circuits need little help to implement arbitrary Hadamardfree Clifford transformations they generate, arXiv:2210.16195(opens in a new tab).
synth_cnot_phase_aam
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 cofactors $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, cx
gates are applied so that a designated target bit contains the (partial) parity $\chi_y(x)$ where $y_i = 1$ if and only if $y'_i = 1$ for all $y' \in S$. If $S$ contains a single element $\{y'\}$, then $y = y'$, and the target bit contains the value $\chi_{y'}(x)$ as desired.
Notably, rather than uncomputing this sequence of cx
(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 uncomputingbased methods.
The algorithm is described in detail in section 4 of [1].
Parameters

cnots (list(opens in a new tab)[list(opens in a new tab)[int(opens in a new tab)]]) –
A matrix whose columns are the parities to be synthesized e.g.:
[[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:
x1^x2 + x0 + x0^x3 + x0^x1^x2 + x0^x1^x3 + x0^x1

angles (list(opens in a new tab)[str(opens in a new tab)]) – A list containing all the phaseshift 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(opens in a new tab)) – The size of every section in the Patel–Markov–Hayes algorithm.
section_size
must be a factor of the number of qubits.
Returns
The decomposed quantum circuit.
Raises
QiskitError – when dimensions of cnots
and angles
don’t align.
Return type
References
 Matthew Amy, Parsiad Azimzadeh, and Michele Mosca. On the controlledNOT complexity of controlledNOT–phase circuits., Quantum Science and Technology 4.1 (2018): 015002. arXiv:1712.01859(opens in a new tab)
Permutation Synthesis
synth_permutation_depth_lnn_kms
qiskit.synthesis.synth_permutation_depth_lnn_kms(pattern)
Synthesize a permutation circuit for a linear nearestneighbor architecture using the Kutin, Moulton, Smithline method.
This is the permutation synthesis algorithm from [1], section 6. It synthesizes any permutation of n qubits over linear nearestneighbor architecture using SWAP gates with depth at most $n$ and size at most $n(n1)/2$ (where both depth and size are measured with respect to SWAPs).
Parameters
pattern (list(opens in a new tab)[int(opens in a new tab)]  np.ndarray[int(opens in a new tab)]) – 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
References
 Samuel A. Kutin, David Petrie Moulton and Lawren M. Smithline. Computation at a distance., arXiv:quantph/0701194v1(opens in a new tab)
synth_permutation_basic
qiskit.synthesis.synth_permutation_basic(pattern)
Synthesize a permutation circuit for a fullyconnected architecture using sorting.
More precisely, if the input permutation is a cycle of length m
, then this creates a quantum circuit with m1
SWAPs (and of depth m1
); if the input permutation consists of several disjoint cycles, then each cycle is essentially treated independently.
Parameters
pattern (list(opens in a new tab)[int(opens in a new tab)]  np.ndarray[int(opens in a new tab)]) – 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
synth_permutation_acg
qiskit.synthesis.synth_permutation_acg(pattern)
Synthesize a permutation circuit for a fullyconnected 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 Proposition 4.1 in reference [1] with the detailed proof given in Theorem 2 in reference [2]
Parameters
pattern (list(opens in a new tab)[int(opens in a new tab)]  np.ndarray[int(opens in a new tab)]) – 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
References
 N. Alon, F. R. K. Chung, and R. L. Graham. Routing Permutations on Graphs Via Matchings., Proceedings of the TwentyFifth Annual ACM Symposium on Theory of Computing(1993). Pages 583–591. (Extended abstract) 10.1145/167088.167239(opens in a new tab)
 N. Alon, F. R. K. Chung, and R. L. Graham. Routing Permutations on Graphs Via Matchings., (Full paper)(opens in a new tab)
synth_permutation_reverse_lnn_kms
qiskit.synthesis.synth_permutation_reverse_lnn_kms(num_qubits)
Synthesize reverse permutation for linear nearestneighbor architectures using Kutin, Moulton, Smithline method.
Synthesis algorithm for reverse permutation from [1], section 5. This algorithm synthesizes the reverse permutation on $n$ qubits over a linear nearestneighbor architecture using CX gates with depth $2 * n + 2$.
Parameters
num_qubits (int(opens in a new tab)) – The number of qubits.
Returns
The synthesized quantum circuit.
Return type
References
 Kutin, S., Moulton, D. P., Smithline, L., Computation at a distance, Chicago J. Theor. Comput. Sci., vol. 2007, (2007), arXiv:quantph/0701194(opens in a new tab)
Clifford Synthesis
synth_clifford_full
qiskit.synthesis.synth_clifford_full(clifford, method=None)
Decompose a Clifford
operator into a QuantumCircuit
.
For $N \leq 3$ qubits this is based on optimal CXcost decomposition from reference [1]. For $N > 3$ qubits this is done using the general nonoptimal greedy compilation routine from reference [3], which typically yields better CX cost compared to the AG method in [2].
Parameters
 clifford (Clifford) – A Clifford operator.
 method (str(opens in a new tab)  None) – Optional, a synthesis method (
'AG'
or'greedy'
). If set this overrides optimal decomposition for $N \leq 3$ qubits.
Returns
A circuit implementation of the Clifford.
Return type
References
 S. Bravyi, D. Maslov, Hadamardfree circuits expose the structure of the Clifford group, arXiv:2003.09412 [quantph](opens in a new tab)
 S. Aaronson, D. Gottesman, Improved Simulation of Stabilizer Circuits, Phys. Rev. A 70, 052328 (2004). arXiv:quantph/0406196(opens in a new tab)
 Sergey Bravyi, Shaohan Hu, Dmitri Maslov, Ruslan Shaydulin, Clifford Circuit Optimization with Templates and Symbolic Pauli Gates, arXiv:2105.02291 [quantph](opens in a new tab)
synth_clifford_ag
qiskit.synthesis.synth_clifford_ag(clifford)
Decompose a Clifford
operator into a QuantumCircuit
based on AaronsonGottesman method [1].
Parameters
clifford (Clifford) – A Clifford operator.
Returns
A circuit implementation of the Clifford.
Return type
References
 S. Aaronson, D. Gottesman, Improved Simulation of Stabilizer Circuits, Phys. Rev. A 70, 052328 (2004). arXiv:quantph/0406196(opens in a new tab)
synth_clifford_bm
qiskit.synthesis.synth_clifford_bm(clifford)
Optimal CXcost decomposition of a Clifford
operator on 2 qubits or 3 qubits into a QuantumCircuit
based on the BravyiMaslov method [1].
Parameters
clifford (Clifford) – A Clifford operator.
Returns
A circuit implementation of the Clifford.
Raises
QiskitError – if Clifford is on more than 3 qubits.
Return type
References
 S. Bravyi, D. Maslov, Hadamardfree circuits expose the structure of the Clifford group, arXiv:2003.09412 [quantph](opens in a new tab)
synth_clifford_greedy
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 [1].
This method typically yields better CX cost compared to the AaronsonGottesman method.
Note that this function only implements the greedy Clifford compiler from Appendix A of [1], and not the templates and symbolic Pauli gates optimizations that are mentioned in the same paper.
Parameters
clifford (Clifford) – A Clifford operator.
Returns
A circuit implementation of the Clifford.
Raises
QiskitError – if symplectic Gaussian elimination fails.
Return type
References
 Sergey Bravyi, Shaohan Hu, Dmitri Maslov, Ruslan Shaydulin, Clifford Circuit Optimization with Templates and Symbolic Pauli Gates, arXiv:2105.02291 [quantph](opens in a new tab)
synth_clifford_layers
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 [1].
For example, a 5qubit Clifford circuit is decomposed into the following layers:
┌─────┐┌─────┐┌────────┐┌─────┐┌─────┐┌─────┐┌─────┐┌────────┐
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) – A Clifford operator.
 cx_synth_func (Callable[[np.ndarray], QuantumCircuit]) – A function to decompose the CX subcircuit. It gets as input a boolean invertible matrix, and outputs a
QuantumCircuit
.  cz_synth_func (Callable[[np.ndarray], QuantumCircuit]) – A function to decompose the CZ subcircuit. It gets as input a boolean symmetric matrix, and outputs a
QuantumCircuit
.  cx_cz_synth_func (Callable) – optional, a function to decompose both subcircuits CZ and CX.
 validate (Boolean) – if True, validates the synthesis process.
 cz_func_reverse_qubits (Boolean) – True only if
cz_synth_func
issynth_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
References
 S. Bravyi, D. Maslov, Hadamardfree circuits expose the structure of the Clifford group, arXiv:2003.09412 [quantph](opens in a new tab)
synth_clifford_depth_lnn
qiskit.synthesis.synth_clifford_depth_lnn(cliff)
Synthesis of a Clifford
into layers for linearnearest neighbour connectivity.
The depth of the synthesized nqubit circuit is bounded by $7n+2$, which is not optimal. It should be replaced by a better algorithm that provides depth bounded by $7n4$ [3].
Parameters
cliff (Clifford) – a Clifford operator.
Returns
a circuit implementation of the Clifford.
Return type
References
 S. Bravyi, D. Maslov, Hadamardfree circuits expose the structure of the Clifford group, arXiv:2003.09412 [quantph](opens in a new tab)
 Dmitri Maslov, Martin Roetteler, Shorter stabilizer circuits via Bruhat decomposition and quantum circuit transformations, arXiv:1705.09176(opens in a new tab).
 Dmitri Maslov, Willers Yang, CNOT circuits need little help to implement arbitrary Hadamardfree Clifford transformations they generate, arXiv:2210.16195(opens in a new tab).
CNOTDihedral Synthesis
synth_cnotdihedral_full
qiskit.synthesis.synth_cnotdihedral_full(elem)
Decompose a CNOTDihedral
element into a QuantumCircuit
.
For $N \leq 2$ qubits this is based on optimal CXcost decomposition from reference [1]. For $N > 2$ qubits this is done using the general nonoptimal compilation routine from reference [2].
Parameters
elem (CNOTDihedral) – A CNOTDihedral
element.
Returns
A circuit implementation of the CNOTDihedral
element.
Return type
References
 Shelly Garion and Andrew W. Cross, Synthesis of CNOTDihedral circuits with optimal number of two qubit gates, Quantum 4(369), 2020(opens in a new tab)
 Andrew W. Cross, Easwar Magesan, Lev S. Bishop, John A. Smolin and Jay M. Gambetta, Scalable randomised benchmarking of nonClifford gates, npj Quantum Inf 2, 16012 (2016).
synth_cnotdihedral_two_qubits
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 CXGate
s.
Parameters
elem (CNOTDihedral) – A CNOTDihedral
element.
Returns
A circuit implementation of the CNOTDihedral
element.
Raises
QiskitError – if the element in not 1qubit or 2qubit CNOTDihedral
.
Return type
References
 Shelly Garion and Andrew W. Cross, On the structure of the CNOTDihedral group, arXiv:2006.12042 [quantph](opens in a new tab)
synth_cnotdihedral_general
qiskit.synthesis.synth_cnotdihedral_general(elem)
Decompose a CNOTDihedral
element into a QuantumCircuit
.
Decompose a general CNOTDihedral
elements. The number of CX gates is not necessarily optimal. For a decomposition of a 1qubit or 2qubit element, call synth_cnotdihedral_two_qubits()
.
Parameters
elem (CNOTDihedral) – A CNOTDihedral
element.
Returns
A circuit implementation of the CNOTDihedral
element.
Raises
QiskitError – if the element could not be decomposed into a circuit.
Return type
References
 Andrew W. Cross, Easwar Magesan, Lev S. Bishop, John A. Smolin and Jay M. Gambetta, Scalable randomised benchmarking of nonClifford gates, npj Quantum Inf 2, 16012 (2016).
Stabilizer State Synthesis
synth_stabilizer_layers
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 reference [1], without the initial Hadamardfree subcircuit which do not affect the stabilizer state.
For example, a 5qubit stabilizer state is decomposed into the following layers:
┌─────┐┌─────┐┌─────┐┌─────┐┌────────┐
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) – A stabilizer state.
 cz_synth_func (Callable(opens in a new tab)[[ndarray(opens in a new tab)], QuantumCircuit]) – A function to decompose the CZ subcircuit. It gets as input a boolean symmetric matrix, and outputs a
QuantumCircuit
.  cz_func_reverse_qubits (bool(opens in a new tab)) –
True
only ifcz_synth_func
issynth_cz_depth_line_mr()
, since this function returns a circuit that reverts the order of qubits.  validate (bool(opens in a new tab)) – If
True
, validates the synthesis process.
Returns
A circuit implementation of the stabilizer state.
Raises
QiskitError – if the input is not a StabilizerState
.
Return type
References
 S. Bravyi, D. Maslov, Hadamardfree circuits expose the structure of the Clifford group, arXiv:2003.09412 [quantph](opens in a new tab)
synth_stabilizer_depth_lnn
qiskit.synthesis.synth_stabilizer_depth_lnn(stab)
Synthesis of an nqubit stabilizer state for linearnearest neighbour connectivity, in 2qubit depth $2n+2$ and two distinct CX layers, using CXGate
s and phase gates (SGate
, SdgGate
or ZGate
).
Parameters
stab (StabilizerState) – A stabilizer state.
Returns
A circuit implementation of the stabilizer state.
Return type
References
 S. Bravyi, D. Maslov, Hadamardfree circuits expose the structure of the Clifford group, arXiv:2003.09412 [quantph](opens in a new tab)
 Dmitri Maslov, Martin Roetteler, Shorter stabilizer circuits via Bruhat decomposition and quantum circuit transformations, arXiv:1705.09176(opens in a new tab).
synth_circuit_from_stabilizers
qiskit.synthesis.synth_circuit_from_stabilizers(stabilizers, allow_redundant=False, allow_underconstrained=False, invert=False)
Synthesis of a circuit that generates a state stabilized by the stabilizers using Gaussian elimination with Clifford gates. If the stabilizers are underconstrained, and allow_underconstrained
is True
, the circuit will output one of the states stabilized by the stabilizers. Based on stim implementation.
Parameters
 stabilizers (Collection(opens in a new tab)[str(opens in a new tab)]) – List of stabilizer strings
 allow_redundant (bool(opens in a new tab)) – Allow redundant stabilizers (i.e., some stabilizers can be products of the others)
 allow_underconstrained (bool(opens in a new tab)) – Allow underconstrained set of stabilizers (i.e., the stabilizers do not specify a unique state)
 invert (bool(opens in a new tab)) – Return inverse circuit
Returns
A circuit that generates a state stabilized by stabilizers
.
Raises
QiskitError – if the stabilizers are invalid, do not commute, or contradict each other, if the list is underconstrained and allow_underconstrained
is False
, or if the list is redundant and allow_redundant
is False
.
Return type
References
Discrete Basis Synthesis
SolovayKitaevDecomposition ([...])  The Solovay Kitaev discrete decomposition algorithm. 
generate_basic_approximations
qiskit.synthesis.generate_basic_approximations(basis_gates, depth, filename=None)
Generates a list of GateSequence
s with the gates in basis_gates
.
Parameters
 basis_gates (list(opens in a new tab)[str(opens in a new tab) Gate]) – The gates from which to create the sequences of gates.
 depth (int(opens in a new tab)) – The maximum depth of the approximations.
 filename (str(opens in a new tab)  None) – If provided, the basic approximations are stored in this file.
Returns
List of GateSequence
s using the gates in basis_gates
.
Raises
ValueError(opens in a new tab) – If basis_gates
contains an invalid gate identifier.
Return type
list(opens in a new tab)[GateSequence]
Basis Change Synthesis
synth_qft_line
qiskit.synthesis.synth_qft_line(num_qubits, do_swaps=True, approximation_degree=0)
Synthesis of a QFT circuit for a linear nearest neighbor connectivity. Based on Fig 2.b in Fowler et al. [1].
Note that this method reverts the order of qubits in the circuit, compared to the original QFT
code. Hence, the default value of the do_swaps
parameter is True
since it produces a circuit with fewer CX gates.
Parameters
 num_qubits (int(opens in a new tab)) – The number of qubits on which the QFT acts.
 approximation_degree (int(opens in a new tab)) – The degree of approximation (0 for no approximation).
 do_swaps (bool(opens in a new tab)) – Whether to include the final swaps in the QFT.
Returns
A circuit implementation of the QFT circuit.
Return type
References
 A. G. Fowler, S. J. Devitt, and L. C. L. Hollenberg, Implementation of Shor’s algorithm on a linear nearest neighbour qubit array, Quantum Info. Comput. 4, 4 (July 2004), 237–251. arXiv:quantph/0402196 [quantph](opens in a new tab)
Unitary Synthesis
Decomposition of general $2^n \times 2^n$ unitary matrices for any number of qubits.
qs_decomposition
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].
┌───┐ ┌───┐ ┌───┐ ┌───┐
─┤ ├─ ───────┤ Rz├─────┤ Ry├─────┤ Rz├─────
│ │ ≃ ┌───┐└─┬─┘┌───┐└─┬─┘┌───┐└─┬─┘┌───┐
/─┤ ├─ /─┤ ├──□──┤ ├──□──┤ ├──□──┤ ├
└───┘ └───┘ └───┘ └───┘ └───┘
The number of CXGate
s generated with the decomposition without optimizations is:
If opt_a1 = True
, the default, the CX count is reduced by:
If opt_a2 = True
, the default, the CX count is reduced by:
Parameters
 mat (np.ndarray) – unitary matrix to decompose
 opt_a1 (bool(opens in a new tab)) – whether to try optimization A.1 from Shende et al. [1]. This should eliminate 1
cx
per call. IfTrue
,CZGate
s are left in the output. If desired these can be further decomposed toCXGate
s.  opt_a2 (bool(opens in a new tab)) – 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^{n2}  1$.
 decomposer_1q (Callable[[np.ndarray], QuantumCircuit]  None) – optional 1Q decomposer. If None, uses
OneQubitEulerDecomposer
.  decomposer_2q (Callable[[np.ndarray], QuantumCircuit]  None) – optional 2Q decomposer. If None, uses
TwoQubitBasisDecomposer
.
Returns
Decomposed quantum circuit.
Return type
References
 Shende, Bullock, Markov, Synthesis of Quantum Logic Circuits, arXiv:0406176 [quantph](opens in a new tab)
The Approximate Quantum Compiler is available as the module qiskit.synthesis.unitary.aqc
.
OneQubit Synthesis
OneQubitEulerDecomposer ([basis, use_dag])  A class for decomposing 1qubit unitaries into Euler angle rotations. 
TwoQubit Synthesis
TwoQubitBasisDecomposer (gate[, ...])  A class for decomposing 2qubit unitaries into minimal number of uses of a 2qubit basis gate. 
XXDecomposer ([basis_fidelity, euler_basis, ...])  A class for optimal decomposition of 2qubit unitaries into 2qubit basis gates of XX type (i.e., each locally equivalent to $CAN(\alpha, 0, 0)$ for a possibly varying $alpha$). 
TwoQubitWeylDecomposition (unitary_matrix[, ...])  Twoqubit Weyl decomposition. 
two_qubit_cnot_decompose
qiskit.synthesis.two_qubit_cnot_decompose(*args, **kwargs)
This is an instance of TwoQubitBasisDecomposer
that always uses cx
as the KAK gate for the basis decomposition. You can use this function as a quick access to cx
based 2qubit decompositions.
Parameters
 unitary (Operator or np.ndarray) – The 4x4 unitary to synthesize.
 basis_fidelity (float(opens in a new tab) or None) – If given the assumed fidelity for applications of
CXGate
.  approximate (bool(opens in a new tab)) – If
True
approximate ifbasis_fidelity
is less than 1.0.
Returns
The synthesized circuit of the input unitary.
Return type