Ask Your Question
3

sympy.physics.quantum Bra and Ket: orthonormal basis

asked 2017-03-29 08:52:02 +0100

hiro protagonist gravatar image

updated 2017-03-29 15:35:29 +0100

i would like to be able to tell qapply from sympy.physics.quantum that i have a set (2 in my example) of orthonormal vectors:

from sympy.physics.quantum import Bra, Ket, qapply, Dagger

e0 = Ket('e0')
e1 = Ket('e1')

X = e1*Dagger(e0) + e0*Dagger(e1)
qapply(X * e1)
# ->  <e0|e1>*|e1> + <e1|e1>*|e0>

is there a way to tell sage (or sympy in that case) that $\langle e_i|e_j \rangle = \delta_{ij}$?

the best i could come up with is a substituion rule:

# e_rules = [(Dagger(e0)*e0, 1), (Dagger(e1)*e1, 1), (Dagger(e0)*e1, 0), (Dagger(e1)*e0, 0)]
e_rules = {Dagger(e0)*e0: 1, Dagger(e1)*e1: 1, Dagger(e0)*e1: 0, Dagger(e1)*e0: 0}
qapply(X * e1).subs(e_rules)
# ->  |e0>

isn't there something more elegant?

edit retag flag offensive close merge delete

Comments

1

thanks for pointing out this package ! there are some explanations here

mforets gravatar imagemforets ( 2017-03-29 19:07:43 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
3

answered 2017-03-29 19:09:45 +0100

mforets gravatar image

updated 2017-04-03 07:48:17 +0100

The Qubit constructor can be used to define an orthonormal basis. The scalar product can be actually computed with the doit() method. For example:

sage: from sympy.physics.quantum.qubit import Qubit
sage: from sympy.physics.quantum import Dagger
sage: e0 = Qubit('0'); e1 = Qubit('1')
sage: c = Dagger(e0)*e1; c
<0|1>
sage: c.doit()
0
sage: (Dagger(e1)*e1).doit()
1
sage: (Dagger(e1)*e0).doit()
0

Edit: The functionality actually exists, but it requires a systematic use of qapply.

First, suppose that we want to just rotate the qubit. We can apply the Hadamard coin as follows:

sage: from sympy.physics.quantum import qapply
sage: from sympy.physics.quantum.gate import H

sage: # the argument passed to H is the target qubit (starting at 0, as usual)
sage: [e0r, e1r] = [qapply(H(0)*ei) for ei in [e0, e1]]    
sage: e0r, e1r
(sqrt(2)*|0>/2 + sqrt(2)*|1>/2, sqrt(2)*|0>/2 - sqrt(2)*|1>/2)

and

sage: qapply(Dagger(e0r)*e0r)
1
sage: qapply(Dagger(e0r)*e1r) 
0
sage: qapply(Dagger(e1r)*e0r) 
0
sage: qapply(Dagger(e1r)*e1r) 
1

Linear combinations are also valid (but remember to qapply):

sage: from sympy import Symbol, cos, sin, exp, I
sage: theta = Symbol('theta', real=True); phi = Symbol('varphi', real=True)
sage: Q = cos(theta)*e0 + exp(I*phi)*sin(theta)*e1; Q
exp(I*phi)*sin(theta)*|1> + cos(theta)*|0>
sage: simplify(qapply(Dagger(Q)*Q))
1

Those imports are to avoid the missing conversion (AttributeError) for the Qubit class, for instance if you type qapply(x*e0). Alternatively, you may sympify the Sage expressions.

Since the Pauli matrices X, Y, Z can also be imported, it is possible to perform an arbitrary operation on a qubit. Multiple qubits can be handled similarly; there are some examples in the package documentation.

edit flag offensive delete link more

Comments

thanks, i saw that. but what if i want to rotate the basis vectors and create a new set of orthonormal vectors that are not in the computational basis? (something like |+> = n(|0> +|1>) ; |-> = n(|0>-|1> ; $n=1/\sqrt(2) $; how do i tell sage now that $|+\rangle $ and $|-\rangle $ are orthonormal)?

hiro protagonist gravatar imagehiro protagonist ( 2017-03-30 14:45:54 +0100 )edit

i would attempt to define them via superposition over the canonical basis. but it doesn't work as expected, since it produces things like <0|*|0>/2 + <0|*|1>/2 - <1|*|0>/2 - <1|*|1>/2 .

mforets gravatar imagemforets ( 2017-03-30 18:52:40 +0100 )edit

well... i would very much like to demonstrate a basis change. the new basis vectors should have the same simple form as the original ones... in any case: thanks a lot for your effort! +1 anyway. should you find some other way, i'd be really happy!

hiro protagonist gravatar imagehiro protagonist ( 2017-03-30 19:25:00 +0100 )edit

that looks good! thanks for the update!

hiro protagonist gravatar imagehiro protagonist ( 2017-04-03 21:57:16 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-03-29 08:52:02 +0100

Seen: 2,260 times

Last updated: Apr 03 '17