• Members 17 posts
    Sept. 6, 2021, 9:15 a.m.

    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?

  • Members 19 posts
    Sept. 6, 2021, 9:20 a.m.

    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)
    

    output:
    Capture.PNG

    Capture.PNG

    PNG, 4.8 KB, uploaded by JXW on Sept. 6, 2021.