Now, I can ask my second question. :-)
Are the states and operators aware of their Hilbert spaces? For example,
say, I'm working on a two particle system. I'm only looking at their spin
states, described by qubits. First particle lives in Hilbert space H1, and
second one in H2. So the combined state lives in H1xH2. I want to apply
projection operators which works on either H1 or H2 to this state.
I tried this:
H1=HilbertSpace() # Hilbert space for first particle
H2=HilbertSpace() # Hilbert space for second particle
qb1 = Qubit('0') # first particle's state
qb2 = Qubit('1') # second particle's state
state = TensorProduct(qb1,qb2) # state of combined system
# state.hilbert_space # gave an error: no such attribute
proj = qb2*qb2.dual # projection operator which works on H2
proj*state
(proj*state).doit()
qapply(proj*state)
The result was: "|1><1|*|0>x|1>" Is it possible to convert this expression
into "|0>x(|1><1|1>)" which can be further simplified to "|0>x|1>"?
vug
2011/11/4 Uğur Güney <[email protected]>
> Hi!
>
> Thanks for the clear explanation!
>
> On Fri, Nov 4, 2011 at 1:27 AM, Brian Granger <[email protected]> wrote:
>
>> Ugur,
>>
>> Welcome!
>>
>> 2011/11/3 Uğur Güney <[email protected]>:
>> > Dear Sympy users,
>> > I'm a physics PhD student, doing research on differences between
>> classical
>> > and quantum correlations.
>> > I was in need of a simple calculator which works with quantum states
>> etc.
>> > While searching for quantum simulators in Python I came to know that
>> there
>> > is already a quantum module in SymPy. Because I couldn't find an
>> explicit
>> > documentation I looked at the source files to understand how basic
>> > calculations can be done using the quantum module.
>>
>> Great, currently this is the best way to learn about how it all works.
>>
>> > Can you please help me in applying a projection operator on a general
>> state.
>> > This is the code that I tried:
>> > from sympy import *
>> > from sympy.physics.quantum import *
>> > from sympy.physics.quantum.qubit import *
>> > [c00,c01,c10,c11]=var('c00,c01,c10,c11') # coefficients
>> > state = c00*Qubit('00')+c01*Qubit('01')+c10*Qubit('10')+c11*Qubit('11')
>> #
>> > most general two-qubit state
>> > qbt=Qubit('01') # a qubit
>> > proj = qbt*qbt.dual # projection operator
>> > # proj*state # operator applied on the state
>>
>> The following will work:
>>
>> qapply(proj*state)
>>
>> The need for qapply ("quantum apply") is as follows. Because of how
>> python/sympy handle multiplication, we are only able to detect inner
>> products in very simple situations like Qubit('01').dual*Qubit('01').
>> For more complex situations, we just leave it as a general
>> "multiplication" operation. The qapply function walks through a
>> general quantum expression and does a couple of things:
>>
>> * Applies any operators to states.
>> * Looks for <bra|*|ket> expressions and turns them into inner products.
>>
>> This is why you need to call qapply by hand after creating a general
>> quantum expression.
>>
>
> Now I realized that even the simplest calculation that is made with pencil
> and paper involves these kind of background processes that we
> do unconsciously. Dirac notation is too intuitive for a computer. :-)
>
>
>> Hope this helps. Also, we would love to know how you end up using
>> this stuff. It is pretty new, so there is a ton left to do. Also, if
>> you are looking at classical/quantum correlations, you may be
>> interested in the work we have done on density matrices. That has not
>> yet been merged into sympy's master branch, but we plan on doing
>> that....always looking for help.
>>
>
> Thanks! OK, I will inform the group about how and where I used Sympy. I'll
> definitely look at density matrices because I want to work on both pure
> states and mixed states.
>
> vug
>
>
>> Cheers,
>>
>> Brian
>>
>> > # (proj*state).expand() operator applied on each term in the expansion
>> > print (proj*state).expand().doit() # try to do the inner-products
>> > In the last step "doit()" did not work as I expected, it did not do the
>> > inner products. I suspect that the expression involving TensorProduct
>> is not
>> > converted to InnerProduct automatically. But normally
>> > "(Qubit('01').dual*Qubit('01')).doit()" and
>> > "(Qubit('00').dual*Qubit('01')).doit()" work as expected and give 1 and
>> 0.
>> > I'll be happy if you can guide me how to use this beautiful tool.
>> > Best,
>> > ugur guney
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> Groups
>> > "sympy" group.
>> > To post to this group, send email to [email protected].
>> > To unsubscribe from this group, send email to
>> > [email protected].
>> > For more options, visit this group at
>> > http://groups.google.com/group/sympy?hl=en.
>> >
>>
>>
>>
>> --
>> Brian E. Granger
>> Cal Poly State University, San Luis Obispo
>> [email protected] and [email protected]
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "sympy" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/sympy?hl=en.
>>
>>
>
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sympy?hl=en.