Comments (3)
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.
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.
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)
- The code of QPE. HOT 2
- No Python, can projectq be used online? HOT 10
- About Time Evolution gate
- REST API update HOT 1
- Qasm interface HOT 5
- Install fails on macOS Big Sur
- Problems running an example notebook HOT 10
- Version 0.6.1 crashes on Linux HOT 2
- Probability distribution of qubits' classical value HOT 2
- How to check if projectq is running on C++ Simulator HOT 8
- not work on macbook with M1 Chip HOT 21
- No mapper is present in the compiler engine list! HOT 1
- IonQ uses incorrect path for backend lookup in v0.7.2 HOT 1
- Implement IonQ native gates support HOT 2
- Script runs on the simulator but encounters error on real IBM QE backend regarding a non-existent 'u2' gate HOT 8
- Python 3.9.12 on OSX HOT 6
- Minor : MacOSX 3.9 Intel work but need to use python3 HOT 1
- Issue with pip installation for version 0.8.0 HOT 3
- Reporting a vulnerability HOT 1
- Breaking changes in the AQT API
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from projectq.