When initially writing an operator
in Q#, I often want to see intermediate values of registers during the computation. This allows me to check that I haven't made mistakes. For example, if I was writing an addition circuit I would input a computational basis state and print out the computational basis states of qubits at particular key points.
I am not aware of a way to do this conveniently. If I print out the qubits like Message($"{qubit}")
then I get their IDs instead of their values. That makes sense. I have to do a measurement to access their value. But if I do a measurement, then Q# will e.g. not automatically generate an adjoint operation and this tends to cause compilation failures. Also, I don't actually want to perform a measurement (which may have side effects) I just want to peek at the simulator state.
(I originally thought I could package the concept of "peeking" at a value into an operation that did a hidden measurement, which would have resolved the issue. But Q# doesn't allow operations with an adjoint to have a return type.)
Is there some built-in way to get at the computational basis value of some qubits, and print it to the console during simulation under the Toffoli simulator?