API Reference: qiskit.circuit.QuantumCircuit.cx
The QuantumCircuit.cx method appends a controlled-X operation, also known as a CNOT gate. The primary parameters are control_qubit and target_qubit. The control qubit determines whether the X operation is applied to the target qubit.
This method is used to create entanglement, implement reversible Boolean logic, and construct larger controlled operations. The operation is unitary and self-inverse, so two adjacent identical CNOT operations cancel mathematically.
Parameters
| Parameter Name | Type | Description |
|---|---|---|
control_qubit |
int | Qubit |
The qubit that controls whether the X operation is applied. |
target_qubit |
int | Qubit |
The qubit that receives the X operation when the control is active. |
from qiskit import QuantumCircuit
qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)
Example Output
{
"status": "success",
"operation": "Controlled-X",
"control": 0,
"target": 1
}
Used In Technical Article
Qiskit v1.2 Quantum Circuit Optimization via Shannon Decomposition