---
title: TwoQubitBasisDecomposer (v1.2)
description: API reference for qiskit.synthesis.TwoQubitBasisDecomposer in qiskit v1.2
source: https://eu-de.quantum.cloud.ibm.com/docs/en/api/qiskit/1.2/qiskit.synthesis.TwoQubitBasisDecomposer
---

# TwoQubitBasisDecomposer

*class* `qiskit.synthesis.TwoQubitBasisDecomposer(gate, basis_fidelity=1.0, euler_basis='U', pulse_optimize=None)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/synthesis/two_qubit/two_qubit_decompose.py#L497-L699)

Bases: [`object`](https://docs.python.org/3/library/functions.html#object)

A class for decomposing 2-qubit unitaries into minimal number of uses of a 2-qubit basis gate.

**Parameters**

- **gate** ([*Gate*](/docs/api/qiskit/1.2/qiskit.circuit.Gate "qiskit.circuit.Gate")) – Two-qubit gate to be used in the KAK decomposition.
- **basis\_fidelity** ([*float*](https://docs.python.org/3/library/functions.html#float)) – Fidelity to be assumed for applications of KAK Gate. Defaults to `1.0`.
- **euler\_basis** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)) – Basis string to be provided to [`OneQubitEulerDecomposer`](/docs/api/qiskit/1.2/qiskit.synthesis.OneQubitEulerDecomposer "qiskit.synthesis.OneQubitEulerDecomposer") for 1Q synthesis. Valid options are \[`'ZYZ'`, `'ZXZ'`, `'XYX'`, `'U'`, `'U3'`, `'U1X'`, `'PSX'`, `'ZSX'`, `'RR'`].
- **pulse\_optimize** ([*bool*](https://docs.python.org/3/library/functions.html#bool) *| None*) – If `True`, try to do decomposition which minimizes local unitaries in between entangling gates. This will raise an exception if an optimal decomposition is not implemented. Currently, only \[\{CX, SX, RZ}] is known. If `False`, don’t attempt optimization. If `None`, attempt optimization but don’t raise if unknown.

### \_\_call\_\_

`__call__(unitary, basis_fidelity=None, approximate=True, use_dag=False, *, _num_basis_uses=None)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/synthesis/two_qubit/two_qubit_decompose.py#L613-L692)

Decompose a two-qubit `unitary` over fixed basis and $SU(2)$ using the best approximation given that each basis application has a finite `basis_fidelity`.

**Parameters**

- **unitary** ([*Operator*](/docs/api/qiskit/1.2/qiskit.quantum_info.Operator "qiskit.quantum_info.Operator") *or ndarray*) – $4 \times 4$ unitary to synthesize.
- **basis\_fidelity** ([*float*](https://docs.python.org/3/library/functions.html#float) *or None*) – Fidelity to be assumed for applications of KAK Gate. If given, overrides `basis_fidelity` given at init.
- **approximate** ([*bool*](https://docs.python.org/3/library/functions.html#bool)) – Approximates if basis fidelities are less than 1.0.
- **use\_dag** ([*bool*](https://docs.python.org/3/library/functions.html#bool)) – If true a [`DAGCircuit`](/docs/api/qiskit/1.2/qiskit.dagcircuit.DAGCircuit "qiskit.dagcircuit.DAGCircuit") is returned instead of a `QuantumCircuit` when this class is called.
- **\_num\_basis\_uses** ([*int*](https://docs.python.org/3/library/functions.html#int)) – force a particular approximation by passing a number in \[0, 3].

**Returns**

Synthesized quantum circuit.

**Return type**

[QuantumCircuit](/docs/api/qiskit/1.2/qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")

**Raises**

[**QiskitError**](/docs/api/qiskit/1.2/exceptions#qiskit.exceptions.QiskitError "qiskit.exceptions.QiskitError") – if `pulse_optimize` is True but we don’t know how to do it.

## Methods

### decomp0

*static* `decomp0(target)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/synthesis/two_qubit/two_qubit_decompose.py#L556-L570)

Decompose target $\sim U_d(x, y, z)$ with $0$ uses of the basis gate. Result $U_r$ has trace:

$$
\Big\vert\text{Tr}(U_r\cdot U_\text{target}^{\dag})\Big\vert =
4\Big\vert (\cos(x)\cos(y)\cos(z)+ j \sin(x)\sin(y)\sin(z)\Big\vert
$$

which is optimal for all targets and bases

### decomp1

`decomp1(target)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/synthesis/two_qubit/two_qubit_decompose.py#L572-L584)

Decompose target $\sim U_d(x, y, z)$ with $1$ use of the basis gate $\sim U_d(a, b, c)$. Result $U_r$ has trace:

$$
\Big\vert\text{Tr}(U_r \cdot U_\text{target}^{\dag})\Big\vert =
4\Big\vert \cos(x-a)\cos(y-b)\cos(z-c) + j \sin(x-a)\sin(y-b)\sin(z-c)\Big\vert
$$

which is optimal for all targets and bases with `z==0` or `c==0`.

### decomp2\_supercontrolled

`decomp2_supercontrolled(target)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/synthesis/two_qubit/two_qubit_decompose.py#L586-L603)

Decompose target $\sim U_d(x, y, z)$ with $2$ uses of the basis gate.

For supercontrolled basis $\sim U_d(\pi/4, b, 0)$, all b, result $U_r$ has trace

$$
\Big\vert\text{Tr}(U_r \cdot U_\text{target}^\dag) \Big\vert = 4\cos(z)
$$

which is the optimal approximation for basis of CNOT-class $\sim U_d(\pi/4, 0, 0)$ or DCNOT-class $\sim U_d(\pi/4, \pi/4, 0)$ and any target. It may be sub-optimal for $b \neq 0$ (i.e. there exists an exact decomposition for any target using $B \sim U_d(\pi/4, \pi/8, 0)$, but it may not be this decomposition). This is an exact decomposition for supercontrolled basis and target $\sim U_d(x, y, 0)$. No guarantees for non-supercontrolled basis.

### decomp3\_supercontrolled

`decomp3_supercontrolled(target)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/synthesis/two_qubit/two_qubit_decompose.py#L605-L611)

Decompose target with $3$ uses of the basis. This is an exact decomposition for supercontrolled basis $\sim U_d(\pi/4, b, 0)$, all b, and any target. No guarantees for non-supercontrolled basis.

### num\_basis\_gates

`num_basis_gates(unitary)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/synthesis/two_qubit/two_qubit_decompose.py#L549-L554)

Computes the number of basis gates needed in a decomposition of input unitary

### traces

`traces(target)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/synthesis/two_qubit/two_qubit_decompose.py#L694-L699)

Give the expected traces $\Big\vert\text{Tr}(U \cdot U_\text{target}^{\dag})\Big\vert$ for a different number of basis gates.
