Your code is always takes the else branch because you are branching on a == 1
where a
is 0
(as you mentioned in your comment selector(fcircuit,0,1,2)
).
I have the feeling that you are confusing circuit construction and execution time. In your code measure
runs at circuit-execution-time, while your conditional is at circuit-construction-time.
Running a conditional at execution time requires dynamic circuits. In this case:
qc.measure(a, 0) # measures a into classical bit 0
with qc.if_test((0, 0)) as else_: # tests if classical bit 0 is 0
qc.cswap(a, b, c) # then branch
with else_:
qc.id(b) # else branch
qc.id(c) #
This condition (if_test
) is not a Python branching, but a conditional that will run as the circuit is being executed.