I'm trying to write unit tests for some small Q# operations. It would be ideal if I could access the wavefunction. Is there a way to get it?

I found Microsoft.Quantum.Extensions.Diagnostics.DumpRegister, but it writes its output to the console or a file in a format intended for humans. I don't want to parse a non-trivial file format as part of writing a unit test.

• Its access is made opaque. The DumpRegister seems unavoidable. – cnada Dec 29 '18 at 4:07

For unit testing, you can use Assert* operations which allow you to verify that certain properties of the wavefunction match your expectations, for example, AssertProbInt operation or Microsoft.Quantum.Diagnostics namespace. The documentation mentions some of them here; you can also do "Filter by title" for library reference using "Assert" query and check which ones fit your specific goal best.
• Those are much closer to what I need than I was able to find, but they all still need me to specify some additional operation (e.g. to use AssertAllZero I need to map the expected state to the 0 state). – Craig Gidney Dec 29 '18 at 5:28
• Not necessarily; AssertProbInt checks that the amplitude of a certain basis state has the expected absolute value - if you have a state you don't need anything additional. If you can provide a more specific example of what you need I might be able to point you to the best Assert operation for that, I use a lot of them for my katas. – Mariia Mykhailova Dec 29 '18 at 5:34