myQLM / myqlm-issues

4 stars 1 forks source link

How to make a multiple control ? #12

Closed Observeur closed 3 years ago

Observeur commented 3 years ago

Hello,

I search the command for apply multiple control on a gate :

exemple for CNOT, we have the tofoly for CCNOT, but how make a CCCNOT ?

I have try to use "prog.cc_apply(cbits[0], CCNOT, qbits[0], qbits[1], qbits[2])" but that seems to not working ...

Idealy, i would like to define a group of Qbits for control ...

Is there already a command for doing that ? (don't have find in the tutorial ... )

Thank you !

amitsaha2806 commented 3 years ago

Hello Observeur,

You need to first define a function for a multiple-controlled gate, which is as follows,

def MCT(nb_control): return CNOT.ctrl(nb_control-1) prog=Program() qbits=prog.qalloc(4) \\as you need a CCCNOT, you can generalize it as per your requirement N=3 \\ I have taken 3 as you need 3-controlled Toffoli, it can be generalized further prog.apply(MCT(N), qbits[0] , qbits[1], qbits[2], qbits[3])

Hope this will help you.

Best regards, Amit.

Observeur commented 3 years ago

Thank you !! it works !