Coder Social home page Coder Social logo

Comments (5)

david-pl avatar david-pl commented on July 29, 2024

Hi there!

Thanks for pointing that out. You are right, the example is wrong. Like you said, due to the symmetry that was quite easy to miss. Sorry about that.

You also were right about the solution to the problem: the nesting of the loops should be reversed:

V = diagonaloperator(b_comp_x, [potential(x, y) for y in ysample for x in xsample])

It's easy to check that this is correct in the example. In order to ensure that things come out correct, we can break the symmetry (that checks out even though there's an error) by simply changing the potential function to

potential(x,y) = exp(-x^2/30.0-y^2/10.)

The Gaussian potential function can separated, i.e. e^(-x^2/30-y^2/10)=e^(-x^2/30)*e^(-y^2/10). Due to this special property, the potential operator can be written as a tensor product, like so

potential_x(x) = exp(-x^2/30.0)
potential_y(y) = exp(-y^2/10.0)
Vx = potentialoperator(b_position, potential_x)
Vy = potentialoperator(b_positiony, potential_y)
Vcomp = Vx  Vy

We can then compare the Vcomp operator to V which tells us that they are identical (up to rounding errors).

It might not be as easy to check this when the potential function is non-separable. Let me know if you are still having trouble in your use-case.

In the meantime I will correct the example.

from quantumoptics.jl-examples.

liuzheng1990 avatar liuzheng1990 commented on July 29, 2024

Right. Simply swapping the two for-loops will do. Right, usually the potential is not separable, but the "diagonaloperator" trick should work in general, as long as we are careful of this ordering. Thanks very much!

from quantumoptics.jl-examples.

david-pl avatar david-pl commented on July 29, 2024

Agreed. Actually I think you shouldn't be bothered with keeping this in mind. This is why I implemented the potentialoperator for composite bases. You can check out the master branch to use it.

Now you can just do

potential(x,y) = exp(-(x^2 + y^2)/30.0)
V = potentialoperator(b_comp_x, potential)

The only thing to keep in mind here is that the potential function has to accept as many arguments as there are bases constituting the composite basis b_comp_x and that the arguments must have the same order as the tensor product. So, in the example since b_comp_x = b_position ⊗ b_positiony the function has to be potential(x, y) and not potential(y, x) (of course in the wavepacket2D example this wouldn't matter due to symmetry).

from quantumoptics.jl-examples.

liuzheng1990 avatar liuzheng1990 commented on July 29, 2024

Great. This change is definitely more friendly to our intuition. Now everything about the lazy operators should be easy to use. I'll go on playing with them. Thanks very much, David!

from quantumoptics.jl-examples.

david-pl avatar david-pl commented on July 29, 2024

The updated example and the new API docs for the potentialoperator function are now on-line in the documentation so I'm closing this.

from quantumoptics.jl-examples.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.