Code Monkey home page Code Monkey logo

Comments (7)

thomashaener avatar thomashaener commented on June 7, 2024

We were thinking about adding such a parameter to the MainEngine, similar to the -Wall gcc flag. One could then also provide different levels of verbosity, e.g., displaying full trace-backs or only partial ones (just the line number where the ancilla was allocated for example).

from projectq.

Strilanc avatar Strilanc commented on June 7, 2024

The issue with applying it to the engine is that whether or not you expect decoherence is more of a method-by-method property than a global program property. For example, if you import a library you don't want to share warning settings with them.

from projectq.

damiansteiger avatar damiansteiger commented on June 7, 2024

Which warning are you referring to in the context of compute/uncompute and what example do you have in mind?

  1. QubitManagementError is raised if there is an error in allocating or deallocating ancilla qubits. It is necessary to make sure the compute section is unitary and we can appy the complex conjugate in the uncompute section.

  2. RuntimeError("Qubit has not been measured / uncomputed. Cannot access its classical value and/or deallocate a qubit in superposition!") is raised only by the simulator back-end if qubits are just thrown away (without being in a classical state or measured). This warning is useful for debugging algorithms when you run them with the noiseless simulator. A hardware back-end with decoherence cannot throw such an error and the planned noise simulator would turn this feature off as it wouldn't make sense because all deallocated qubits (not just within compute/uncompute) which are not measured would otherwise potentially throw such an error.

from projectq.

Strilanc avatar Strilanc commented on June 7, 2024

Either one, really, but in this case I was actually talking abut QubitManagementError. Sometimes you just want to apply an operation and then its inverse, but will do something in between that breaks the ancilla uncomputation.

from projectq.

damiansteiger avatar damiansteiger commented on June 7, 2024

Regarding the QubitManagementError:
It only enforces the concept of compute/action/uncompute which is that compute and uncompute sections don't need to be controlled if that whole code block (compute/action/uncompute) is controlled on some other qubits (only the action parts needs to be controlled). For this to work correctly, it requires that ancilla qubits are deallocated before the end of the uncompute section (automatically done with uncompute, but needs to be manually done if using CustomUncompute). This ensures the compute section is the inverse of the uncompute section.

Let me know if you have a specific example where it doesn't work.

You can still use a noise simulator without ever running into a problem with QubitManagmentError as it only checks if you deallocate the qubit, but not if the qubit has been correctly uncomputed.

The RuntimeError from the simulator is the only one which cares about correct uncomputation in all contexts not just within uncompute and this one we turn off for a noise simulator where we have decoherence.

By the way if you just want the inverse of a previous function, you could use

my_func(qureg)
# Do sth else on qureg
with Dagger(eng):
    my_func(qureg)

from projectq.

thomashaener avatar thomashaener commented on June 7, 2024

@Strilanc Did you come up with an example for a use case? Or does with Dagger(eng) do the job?

from projectq.

Strilanc avatar Strilanc commented on June 7, 2024

I think it addresses the use case.

from projectq.

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.