I'm learning Q#. Is there any way to see the QASM code of a Q# function I write, the same way I can see the disassembly of a C# function?


1 Answer 1


Q# is not compiled into QASM, so that would be tricky. Q# compilation and execution process is approximately as follows:

  • Q# code is parsed into an internal data structure representing an abstract syntax tree. This data structure undergoes some transformations (for example, to generate adjoint and controlled versions of operations used in the code). I don't know a way to see this representation directly.
  • Next, to execute the code on a simulator this data structure is used to generate C# code. This code doesn't look particularly assembly-like, since it maintains a lot of high-level language constructs. If your Q# code was stored in file MyCode.qs in folder A, the C# result of code generation will be found in A\obj\qsharp\src\MyCode.g.cs.
  • C# compiler compiles this generated code into a classical executable and runs it.

Having said that, it is possible to write a separate tool that will convert a subset of Q# operations into OpenQasm; this example by Rolf Huisman shows a way to do that.

  • $\begingroup$ thanks, I'll send MS a suggestion to add QASM, I think you should too. $\endgroup$
    – GideonMax
    Jun 5, 2019 at 12:00

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.