convert_to_cz#
- convert_to_cz(strict: bool = False) Callable[[QuantumCircuit], QuantumCircuit][source]#
Create a pass that converts two-qubit gates to CZ-based decompositions.
This pass converts CX (CNOT), CY, and SWAP gates to their CZ-based equivalents using single-qubit gate decompositions. CZ gates are native to many superconducting quantum computers.
Two-qubit gates that are already CZ or barrier instructions are always left unchanged. Any other two-qubit gate that has no known CZ 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 CZ 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 CX gate to H—CZ—H:
>>> from qrisp import QuantumCircuit, PassManager >>> from qrisp import convert_to_cz >>> qc = QuantumCircuit(2) >>> qc.cx(0, 1) >>> print(qc) qb_69: ──■── ┌─┴─┐ qb_70: ┤ X ├ └───┘ >>> pm = PassManager() >>> pm += convert_to_cz() >>> optimized_qc = pm.run(qc) >>> print(optimized_qc) qb_69: ──────■────── ┌───┐ │ ┌───┐ qb_70: ┤ H ├─■─┤ H ├ └───┘ └───┘