Giter Site home page Giter Site logo

Comments (5)

cgogolin avatar cgogolin commented on August 20, 2024 1

I might be wrong, as I don't have the time to look into the code carefully, but I think we can get rid of the pre_execute_queued() and post_execute_queued() methods altogether, and just keep the pre/post apply/expectation methods.

I would however suggest to keep all four of the pre/post apply/expectation methods, for symmetry and also because for a plugin developer it can be more logical to put some code in post apply() and some in pre_expectation().

from pennylane.

josh146 avatar josh146 commented on August 20, 2024 1

That's true, I can't really think of anything off the top of my head in SF that needs to be executed outside the context.

So how about this proposal for plugin API simplification? Will this work for the projectQ plugin?

with execution_context():
    pre_apply()

    for operation in queue:
        apply(operation)

    post_apply()
    
    pre_expectations()

    for observable in observe:
        expectation(observable)

    post_expectations()

from pennylane.

cgogolin avatar cgogolin commented on August 20, 2024 1

from pennylane.

co9olguy avatar co9olguy commented on August 20, 2024

Generally I'm on board with clarifying the names as suggested. However, will it be clear what the difference is between pre_execute and pre_apply?

from pennylane.

josh146 avatar josh146 commented on August 20, 2024

The user has to define the apply method for how operations are applied to the device during execution, so perhaps that makes it clearer?

Here is the current execution order, using the suggested new nomenclature:

pre_execute()
with execution_context():
    pre_apply()

    for operation in queue:
        apply(operation)

    post_apply()

    for observable in observe:
        expectation(observable)

    post_expectations()
post_execute()

Actually, on reading that back, I agree it's a bit confusing.

The key issue here is the context manager, which is only really used by Strawberry Fields and ProjectQ. Without the context manager (i.e. if execution_context is not overloaded), pre_apply is the same as pre_execute, and post_expectations is the same as post_execute.

from pennylane.

Related Issues (20)

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.