• CattyMpanorama_fish_eye
    17 posts
    4 years

    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?

  • JXWpanorama_fish_eye
    19 posts
    4 years

    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 4 years ago.

There are no more posts in this thread.

first_page
chevron_left
chevron_right
last_page