microsoft / qsharp

Azure Quantum Development Kit, including the Q# programming language, resource estimator, and Quantum Katas
https://microsoft.github.io/qsharp/
MIT License
438 stars 86 forks source link

LaTeX in EstimatorResult._repr_html_() is not rendered correctly #1958

Open billti opened 1 week ago

billti commented 1 week ago

In fixing #1880, I noticed that many of our notebooks (e.g. estimation-hardcoded-circuit, estimation-random-circuit and others) don't render resource estimation details using the widget, but just directly using a pattern such as:

result = qsharp.estimate("RunHardcodedCircuit()")
result

This shows a table where the markdown isn't rendered correctly even with the linked fix in place (as that only applies to widgets), e.g.

Image

In investigating the root cause for this, there are two issues to address:

Firstly, we have the below code in our pip package, but nothing in our docs or samples mentions requiring these packages, and no error or output is displayed to tell users to install them. We should document or provide output on this requirement if needed.

try:
    # Both markdown and mdx_math (from python-markdown-math) must be present for our markdown
    # rendering logic to work. If either is missing, we'll fall back to plain text.
    import markdown
    import mdx_math

    has_markdown = True
except ImportError:
    has_markdown = False

Secondly, even installing those packages didn't resolve the markdown rending in the table as shown in the screen shot above, so that needs to be fixed anyway.

CC @msoeken and @ivanbasov

sezna commented 5 days ago

One approach would be to move fully to widgets, which don't have this issue. If _repr_html() is to continue to be used, then there's a bug, though.