qsharp
qsharp copied to clipboard
Add DumpOperation to Q# library M.Q.Diagnostics
Is your feature request related to a problem? Please describe. It is very useful to be able to print the matrix of the operation directly from Q#, like we could in Classic QDK. This would enable me to provide better feedback on learner's solutions in the katas on quantum.microsoft.com, as well as allow users of VS Code and VS Code Online see the matrices of their code without having to go through Python (and all the setup for multi-file Q# project required for that).
Describe the solution you'd like
DumpOperation operation, similar to the one we had in Classic QDK.
Describe alternatives you've considered
In some scenarios, I can use Python dump_operation API. However, it is not available on quantum.microsoft.com or on VS Code online, and it is somewhat painful to set up all the moving pieces required for Python-Q# integration just to print an operation matrix.
I believe @swernli already had some thoughts around this.
I think now that we have DumpRegister this becomes easier to implement. The key thing that I'm missing is some preference on what the output format should be and how much we want to integrate it through the stack. If it just gets printed like a message with some ascii delimiters then that's easier, but if we want to pretty-print it like state output in different ecosystems then we will need to make it an additional output type in the APIs throughout the layers (traits in Rust, callbacks in WASM, TypeScript, and Python), which is a bigger design.
For VS Code, I'm happy to for it to be a message, like DumpMachine output is. But it we want to make it available on the website, plain text would look very odd, since everything else is pretty-printed there, so it would need to be an additional output type for that goal.
But it we want to make it available on the website, plain text would look very odd, since everything else is pretty-printed there, so it would need to be an additional output type for that goal.
Note that for the web, such as QCOM, they implement their own UX for output. We just fire an event with data, and they draw that how they like. We have example code in the playground (e.g. see https://github.com/microsoft/qsharp/blob/main/playground/src/state.tsx for how we render DumpMachine) which they are welcome to copy, but it would be UX work on the QCOM team to show any DumpOperation output in katas etc.
(Looking at how closely QCOM models the playground for DumpMachine, I'm guessing it is largely still just a copy. Regardless, we can implement 'pretty' output for Jupyter and the playground, but there will be coordination and porting work on QCOM before it would show up in the katas).