qiskit-documentation/docs/api/qiskit/1.2/qiskit.synthesis.TwoQubitBa...

110 lines
7.0 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

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: TwoQubitBasisDecomposer (v1.2)
description: API reference for qiskit.synthesis.TwoQubitBasisDecomposer in qiskit v1.2
in_page_toc_min_heading_level: 1
python_api_type: class
python_api_name: qiskit.synthesis.TwoQubitBasisDecomposer
---
# TwoQubitBasisDecomposer
<Class id="qiskit.synthesis.TwoQubitBasisDecomposer" isDedicatedPage={true} github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/synthesis/two_qubit/two_qubit_decompose.py#L497-L699" signature="qiskit.synthesis.TwoQubitBasisDecomposer(gate, basis_fidelity=1.0, euler_basis='U', pulse_optimize=None)" modifiers="class">
Bases: [`object`](https://docs.python.org/3/library/functions.html#object "(in Python v3.13)")
A class for decomposing 2-qubit unitaries into minimal number of uses of a 2-qubit basis gate.
**Parameters**
* **gate** ([*Gate*](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 "(in Python v3.13)")) 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 "(in Python v3.13)")) Basis string to be provided to [`OneQubitEulerDecomposer`](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 "(in Python v3.13)") *| 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`, dont attempt optimization. If `None`, attempt optimization but dont raise if unknown.
### \_\_call\_\_
<Function id="qiskit.synthesis.TwoQubitBasisDecomposer.__call__" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/synthesis/two_qubit/two_qubit_decompose.py#L613-L692" signature="__call__(unitary, basis_fidelity=None, approximate=True, use_dag=False, *, _num_basis_uses=None)">
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*](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 "(in Python v3.13)") *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 "(in Python v3.13)")) Approximates if basis fidelities are less than 1.0.
* **use\_dag** ([*bool*](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)")) If true a [`DAGCircuit`](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 "(in Python v3.13)")) force a particular approximation by passing a number in \[0, 3].
**Returns**
Synthesized quantum circuit.
**Return type**
[QuantumCircuit](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")
**Raises**
[**QiskitError**](exceptions#qiskit.exceptions.QiskitError "qiskit.exceptions.QiskitError") if `pulse_optimize` is True but we dont know how to do it.
</Function>
## Methods
### decomp0
<Function id="qiskit.synthesis.TwoQubitBasisDecomposer.decomp0" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/synthesis/two_qubit/two_qubit_decompose.py#L556-L570" signature="decomp0(target)" modifiers="static">
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
</Function>
### decomp1
<Function id="qiskit.synthesis.TwoQubitBasisDecomposer.decomp1" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/synthesis/two_qubit/two_qubit_decompose.py#L572-L584" signature="decomp1(target)">
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`.
</Function>
### decomp2\_supercontrolled
<Function id="qiskit.synthesis.TwoQubitBasisDecomposer.decomp2_supercontrolled" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/synthesis/two_qubit/two_qubit_decompose.py#L586-L603" signature="decomp2_supercontrolled(target)">
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.
</Function>
### decomp3\_supercontrolled
<Function id="qiskit.synthesis.TwoQubitBasisDecomposer.decomp3_supercontrolled" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/synthesis/two_qubit/two_qubit_decompose.py#L605-L611" signature="decomp3_supercontrolled(target)">
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.
</Function>
### num\_basis\_gates
<Function id="qiskit.synthesis.TwoQubitBasisDecomposer.num_basis_gates" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/synthesis/two_qubit/two_qubit_decompose.py#L549-L554" signature="num_basis_gates(unitary)">
Computes the number of basis gates needed in a decomposition of input unitary
</Function>
### traces
<Function id="qiskit.synthesis.TwoQubitBasisDecomposer.traces" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/synthesis/two_qubit/two_qubit_decompose.py#L694-L699" signature="traces(target)">
Give the expected traces $\Big\vert\text{Tr}(U \cdot U_\text{target}^{\dag})\Big\vert$ for a different number of basis gates.
</Function>
</Class>