In qiskit, I know that I can implement CX and CCX gates using cx()
and ccx()
. Is there any way to write a n-bit generalization, for example a control not gate with 5 qubits as control and 1 qubit as target?
In qiskit, I know that I can implement CX and CCX gates using cx()
and ccx()
. Is there any way to write a n-bit generalization, for example a control not gate with 5 qubits as control and 1 qubit as target?
You can use the mcx
gate, which can take an arbitrary number of qubits as control. As an example:
from qiskit import QuantumCircuit, QuantumRegister
controls = QuantumRegister(3, "c_qb")
target = QuantumRegister(1, "t_qb")
circuit = QuantumCircuit(controls, target)
circuit.mcx(controls, target[0])
print(circuit)