Code Monkey home page Code Monkey logo

Comments (3)

thomashaener avatar thomashaener commented on June 14, 2024

Hi! This is actually a feature of the simulator: All qubits must either be measured or uncomputed before they can be deallocated; otherwise an exception is raised (above it says "RuntimeError: Error: Qubit has not been measured / uncomputed! There is most likely a bug in your code.").
The last few errors are due to the Python garbage collection: When Python is exiting, it assigns None to all variables, including, e.g., imported modules such as copy. This leads to errors such as "TypeError: 'NoneType' object is not iterable".
If you delay the final clean-up by putting the code into a function and catching your Exception("...") in the main program, only the exception thrown by the simulator would show up (namely as an ignored exception which occurred when dealing with your Exception("...")).

from projectq.

silky avatar silky commented on June 14, 2024

i think it's a mistake to consider this a feature; it makes programming with this framework not particularly enjoyable.

i agree that it is good to do some cleanup of resources when the application exits, but the resource clean-up should be very robust.

imagine if the same thing happened when you exited a database-reading application before closing all connections - that code doesn't emit a new exception per connection you had open, informing you that you should've closed it.

from projectq.

damiansteiger avatar damiansteiger commented on June 14, 2024

Programming in this framework is particularly nice as it supports automatic management of qubits (no need to explicitly deallocate qubits).

Any back-end can expect the following:
It receives an allocate qubit command for each qubit you allocate in your quantum program and also receives a deallocate qubit (at the latest when your program finishes). This is implemented using atexit...

Different back-ends can have their own implementation of what happens when a qubit is deallocated.

The simulator for example checks that your qubit is either measured or in a computational basis state (otherwise an exception is thrown as you have seen above). For example, if your program contains with Compute(eng) and with CustomUncompute(eng) statements, it will check that you implemented them correctly. (I also like the -Wpedantic flag when programming in C++ :)

The main purpose of a quantum simulator is to test and debug quantum programs and hence we think this is an actual feature.

A hardware back-end will not throw you such an error (as it cannot figure out that you made a mistake) but just return the wrong result...

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.