quantum.gates.CNOT does not appear to work as advertised

9 views
Skip to first unread message

Connor Connor

unread,
Aug 21, 2014, 2:41:06 PM8/21/14
to sy...@googlegroups.com
The doc string of sympy.physics.quantum.gate.CNOT contains:
"""
Two qubit controlled-NOT.

This gate performs the NOT or X gate on the target qubit if the control
qubits all have the value 1.    
"""

Which I find slightly confusing.  Does this gate work on only two qubits as the
first line indicates, or two sets of qubits, the control bits and the singleton
target?

It *appears* that it only works on two qubits: a single control and a single
target.  However the method signatures and docs seem to indicate that it is capable of
more.  I tried delving into the code, but got tangled up, so I thought I would
just ask here instead.

There is example code below.  Can any one tell me if I'm reading the docs wrong, or if CNOT is broken?


from sympy import Matrix
from sympy.physics.quantum import gate
from sympy.physics.quantum.qubit import Qubit
from sympy.physics.quantum.qapply import qapply 

q = Qubit('111')
cn = gate.CNOT(2, 1, 0)
print(qapply(cn*q)) # |101> but I expected |011>, or possibly |110>

v = Matrix([0, 0, 0, 0, 0, 0, 0, 1])

## This matrix is equivalent to what the documentation implies CNOT(2, 1, 0) is
g = Matrix([[1, 0, 0, 0, 0, 0, 0, 0],
            [0, 1, 0, 0, 0, 0, 0, 0],
            [0, 0, 1, 0, 0, 0, 0, 0], 
            [0, 0, 0, 0, 0, 0, 0, 1], 
            [0, 0, 0, 0, 1, 0, 0, 0], 
            [0, 0, 0, 0, 0, 1, 0, 0], 
            [0, 0, 0, 0, 0, 0, 1, 0], 
            [0, 0, 0, 1, 0, 0, 0, 0]])

print(repr(g*v)) # 0,0,0,1,0,0,0,0 which is equivalent to |011>

Reply all
Reply to author
Forward
0 new messages