How can we get rid of runtime next error:

Traceback (most recent call last):
  File "C:\Users\Marija\Anaconda3\lib\site-packages\projectq\types\_qubit.py", line 135, in __del__
  File "C:\Users\Marija\Anaconda3\lib\site-packages\projectq\cengines\_basics.py", line 153, in deallocate_qubit
    tags=[DirtyQubitTag()] if is_dirty else [])])
  File "C:\Users\Marija\Anaconda3\lib\site-packages\projectq\cengines\_main.py", line 288, in send
    raise compact_exception  # use verbose=True for more info
RuntimeError: Qubit has not been measured / uncomputed. Cannot access its classical value and/or deallocate a qubit in superposition!
 raised in:
'  File "C:\\Users\\Marija\\Anaconda3\\lib\\site-packages\\projectq\\backends\\_sim\\_pysim.py", line 139, in get_classical_value'
'    raise RuntimeError("Qubit has not been measured / "'```

  • $\begingroup$ Are you asking to return a measurement value in your program? If it does then you need to make measurements in your circuit... otherwise there is nothing to be returned. $\endgroup$
    – KAJ226
    Dec 11, 2020 at 15:46
  • $\begingroup$ No, I'm not asking to return the measured value. I want to use the simulator and the "get_amplitude" function after measuring and applying the gate. $\endgroup$ Dec 15, 2020 at 22:17
  • $\begingroup$ Do you have an example of the code that causes this error? $\endgroup$
    – Mithrandir24601
    Dec 16, 2020 at 13:18
  • $\begingroup$ I realized that the rotation Ry causes that error, not after the first execution, but after the second, third (etc.) execution of that same code. I'm sending you an example : i.stack.imgur.com/dYShm.png . Also, I am sending you the same code after the first execution without error: i.stack.imgur.com/VoAIw.png . $\endgroup$ Dec 26, 2020 at 23:03

1 Answer 1


By measuring all the qubits at the end of the code, I avoided the above-mentioned error message.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.