convert_to_cx#
- convert_to_cx(strict: bool = False) Callable[[QuantumCircuit], QuantumCircuit][source]#
Create a pass that converts two-qubit gates to CX-based decompositions.
This pass converts CZ, CY, and SWAP gates to their CX-based equivalents using single-qubit gate decompositions. CX gates are native to many quantum computing platforms.
Two-qubit gates that are already CX or barrier instructions are always left unchanged. Any other two-qubit gate that has no known CX decomposition is either passed through silently (
strict=False, the default) or causes the pass to raise an exception (strict=True).Note
This pass does not decompose composite (wrapped) gates. Use the
decompose()pass to expand composite gates into elementary operations before applying this pass.- Parameters:
- strictbool, optional
When
True, anExceptionis raised if a two-qubit gate with no known CX decomposition is encountered. WhenFalse(the default), such gates are left unchanged in the output circuit.
- Returns:
- Callable[[QuantumCircuit], QuantumCircuit]
A pass function suitable for
PassManager.add_pass().
Examples
Convert a CZ gate to H—CX—H:
>>> from qrisp import QuantumCircuit, PassManager >>> from qrisp import convert_to_cx >>> qc = QuantumCircuit(2) >>> qc.cz(0, 1) >>> print(qc) qb_69: ──■── │ qb_70: ──■── >>> pm = PassManager() >>> pm += convert_to_cx() >>> optimized_qc = pm.run(qc) >>> print(optimized_qc) qb_69: ──────■────── ┌───┐ │ ┌───┐ qb_70: ┤ H ├─■─┤ H ├ └───┘ └───┘