Loading [MathJax]/jax/output/HTML-CSS/jax.js

First time here? Check out the FAQ!

Ask Your Question
3

sympy.physics.quantum Bra and Ket: orthonormal basis

asked 8 years ago

hiro protagonist gravatar image

updated 8 years ago

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 ei|ej=δ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?

Preview: (hide)

Comments

1

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

mforets gravatar imagemforets ( 8 years ago )

1 Answer

Sort by » oldest newest most voted
3

answered 8 years ago

mforets gravatar image

updated 7 years ago

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.

Preview: (hide)
link

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/(2); how do i tell sage now that |+ and | are orthonormal)?

hiro protagonist gravatar imagehiro protagonist ( 7 years ago )

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 ( 7 years ago )

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 ( 7 years ago )

that looks good! thanks for the update!

hiro protagonist gravatar imagehiro protagonist ( 7 years ago )

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: 8 years ago

Seen: 2,435 times

Last updated: Apr 03 '17