niazalikhan87 / qutip

Automatically exported from code.google.com/p/qutip
2 stars 1 forks source link

Minor errors in the coherent state fock expansion #15

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. C5 = coherent(5,1)
2. C20 = coherent(20,1)

What is the expected output? What do you see instead?
The coefficients for the first few terms are slightly off from each other. I 
had written a bunch of similar code in Matlab and was checking my answers 
against QuTIP's, but the coherent state expansions always seem a little off 
when you use a low photon number basis. I realize that you don't want to do 
this anyways since there's information in the tails that gets lost, but 
coherent() doesn't give the analytical result. I think it's because you're 
using the displacement operator to generate the coefficients, but expm seems to 
be sensitive to the basis size and we start to see errors in the tails rather 
easily. I'm finding that for small coherent states (alpha = 1-2), I need a 
basis up to N = 20 to get everything to agree at a part in 10^3-10^4. 

The advantage of your method is that the coefficients seem to be normalized 
properly automatically, whereas if you derived the coefficients from the 
analytical formula you would be missing probability in the tails. In any case, 
it might be worth a note in the code (I may have missed it). It threw me for a 
loop trying to figure out why there were small differences in the coefficients 
your code generated vs the exact answer, but I think it makes sense now.

What version of the product are you using? On what operating system?
v2 on OSX 10.7

Please provide any additional information below.
THIS IS INCREDIBLE WORK! You guys should be commended for putting so much 
detailed effort into this. My only complaint is that I'm a Matlab user and I 
still can't learn to love matplotlib. I am trying to reproduce your Wigner 
function algorithm in Matlab. I haven't seen anyone calculate it this way 
before--- is there a reference somewhere?

Original issue reported on code.google.com by riotnr...@gmail.com on 19 Aug 2012 at 8:17

GoogleCodeExporter commented 8 years ago
Hi 

Thanks for your feedback, you have a very good point. In an earlier version of 
qutip we used the analytical formula to generate, but we changed to using the 
displacement operator for exactly the reason you point out (it guarantees unit 
normalization). But this is not well described in the documentation, and that 
should definitely be fixed. Also, it might be a good idea to have an optional 
flag to the coherent function that selects which method to use, because in some 
cases one might care more about having as accurate coefficient for small photon 
numbers than normalization. I'll look into adding this and adjusting the 
documentation accordingly.

The matplotlib software is really amazing and in my opinion it produces 
graphics of much better quality than matlab, so I think when you get used to it 
that alone will keep you away from matlab forever :-) My advice would be to 
dive directly into the object-oriented API for matplotlib (and avoiding matlab 
combability functions), then you exposed to a really powerful and flexible 
plotting API.

The Wigner function implementation in qutip is basically a port of the same 
function in the quantum optics toolbox for matlab to python/scipy. 

Original comment by jrjohans...@gmail.com on 20 Aug 2012 at 1:47

GoogleCodeExporter commented 8 years ago
Thank you for your nice comments!

I think the main issue here is the representation of a coherent state, which is 
naturally defined in the infinite Hilbert space of a harmonic oscillator (HO), 
in a truncated Hilbert space.  Since we are using the Fock basis in QuTiP, the 
displacement operator is naturally defined by exponentiating the linear 
combination of raising a lowering operators.  As such, the coherent state, 
defined as a displaced vacuum state, should be generated in this way.  Of 
course, this will not be identical to the probabilities obtained from the 
analytic formula over the entire HO Hilbert space.  We could just use the 
analytic values, but then we run into an inconsistency where the displacement 
operator gives a different coherent state than the builtin function.  
Furthermore, if you want a valid state vector, you would need to normalize the 
truncated coherent state that would lead to differences with the analytic 
formula as well.  If you didn't normalize, then I would expect many things to 
give erroneous results.

Plotting the probability distribution over the number states shows that the 
results are quite similar for all the cases considered here.  Of course the 
more states considered the better.

-Paul

Original comment by nonhermitian on 20 Aug 2012 at 2:35

Attachments:

GoogleCodeExporter commented 8 years ago
Thanks for the response guys!
I suppose that in either the analytical expression (after normalization) or the 
displacement version in QuTiP, you have errors when truncating the Fock space. 
I don't know which is preferable, but I know in practice that I truncate to 
pretty low N to speed things up and look for interesting behavior, then crank 
up Fock basis when I want to verify and get more accuracy.

EIther way, I think that putting the code up at code.google.com is a great 
idea, especially for users like me to ask dumb questions!

Original comment by riotnr...@gmail.com on 20 Aug 2012 at 4:08

GoogleCodeExporter commented 8 years ago
After Robert added the analytic formula to QuTiP I ran the coherent(5,1.0) 
function vs. the new coherent(5,1.0,"analytic) and found that, at least for the 
number operator expectation value, the analytic way is in fact worse than the 
displacement operator method, 0.981 vs 0.997, respectively.  

However, my main complaint with using this method is that it breaks logical 
consistency in the program.  Given the fundamental assumption of a truncated 
Hilbert space, one can built up all of the operators assuming this alone.  This 
consistency is broken when we start to say that one particular function should 
be calculated in a different manner.  We now run into the issue where 
constructing the coherent state from the basic operator definition is no longer 
equal to the convenience function coherent().  Assuming an infinite Hilbert 
space, normalizing, and then truncating and renormalizing again seems wrong to 
me.  Sadly, after this discussion came up, I realized that I did the same thing 
for the thermal state.  I used the infinite state probabilities rather than 
using the truncated operator method.  I think I will change this to make it 
more consistent.

That being said, if people really want to use the analytical values in the 
truncated space, then having that available in QuTiP will be done.

Original comment by nonhermitian on 21 Aug 2012 at 3:07

GoogleCodeExporter commented 8 years ago

Original comment by nonhermitian on 21 Aug 2012 at 3:08

GoogleCodeExporter commented 8 years ago
I agree that in most cases it is more useful to use the displacement method so 
that the state is normalized and a "real quantum state" in the truncated 
Hilbert space, but I can also see use-cases for the analytic formulas. For 
example, one might want to do the following:

>> coherent(5, 1.0, 'analytic').norm()
0.9981683992055931

to see how suitable the truncation to 5 Fock states is when one want to 
describe a coherent state with alpha=1.0. At least I don't think it hurts to 
have the option there (as non-default).

Original comment by jrjohans...@gmail.com on 21 Aug 2012 at 3:27

GoogleCodeExporter commented 8 years ago

Original comment by nonhermitian on 5 Sep 2012 at 1:58