Qiskit / qiskit-tutorials

A collection of Jupyter notebooks showing how to use the Qiskit SDK
Apache License 2.0
2.3k stars 1.29k forks source link

How to use multiple .c_if in qiskit #1389

Closed takkie-snoekie closed 1 year ago

takkie-snoekie commented 1 year ago

We want to apply a x gate only if 3 qubits are in a certain configuration. We used .c_if to achieve this. We correspond the qubits to the classical bits (q1 to c1 and so on). However it does not work how we expect.

circ.x(target).c_if(c1,val1).c_if(c2,val2).c_if(c3,val3)

For example when all classical bits are 0 and val1 = 1 it performs the X gate on the target even though we would expect that nothing would happen and X gate would not be applied. WhatsApp Image 2023-01-11 at 10 06 38 AM

filippotramonto commented 1 year ago

To which tutorial are you referring? Have you had a look at this tutorial Iterative Quantum Phase Estimation Algorithm? In the section Conditioned gates: the c_if method it is explained how to use c_if with multiple qubits and bits. I hope this help you

javabster commented 1 year ago

I'm not really sure what is being requested in this issue but anyway the c_if syntax has been replaced by if_test in Qiskit so I believe this is no longer relevant.