iqsharp icon indicating copy to clipboard operation
iqsharp copied to clipboard

Add DumpMachine %config option to print ket notation of state

Open tcNickolas opened this issue 4 years ago • 2 comments

Describe the solution you'd like It would be great to have a %config option to set DumpMachine to print the quantum state of the program as an expression in ket notation. This would allow to replace the following display

image

with a shorter and often more readable formula image

Additional context Tagging @guenp per offline discussion to see whether the quantum calculator or its fragments can be used for this.

tcNickolas avatar Jun 02 '21 22:06 tcNickolas

Some more details as per @anjbur's request. This is a project I prototyped in Python. The idea is to output the results of a calculation in ket notation, as shown in the screenshot above. To do so, you'll need the following elements:

  • [ ] a function that estimates the closest square root of a floating point number. For instance, estimate_squareroot(0.7071) should return sqrt(2).
  • [ ] a data structure that represents a complex number with square root constants.
  • [ ] a function that formats the above data structure into LaTeX/MathJax notation to output as HTML.

guenp avatar Sep 30 '21 22:09 guenp

If it's helpful to anyone working on this, I took a quick stab at writing out the first part (approximating floating point numbers) a little while ago, and it turns out not too hard to do in C#:

image

To integrate into IQ# would take modifying the StateVectorToHtmlEncoder class. Its constructor takes an object that can be used to look at configuration options: https://github.com/microsoft/iqsharp/blob/d75f203ef70910b92500b861f34fd3fdad1f0944/src/Jupyter/Visualization/StateDisplayEncoders.cs#L260-L263 From there, would need to then use a new option where the amplitude is formatted as a string: https://github.com/microsoft/iqsharp/blob/d75f203ef70910b92500b861f34fd3fdad1f0944/src/Jupyter/Visualization/StateDisplayEncoders.cs#L374-L374

cgranade avatar Oct 01 '21 00:10 cgranade