Qiskit / qiskit

Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.
https://www.ibm.com/quantum/qiskit
Apache License 2.0
5.21k stars 2.36k forks source link

Improve Latex visualisation error message for xypic, qcircuit and standalone #7664

Open javabster opened 2 years ago

javabster commented 2 years ago

What is the expected enhancement?

Recently when trying to run the latex circuit drawer in a new environment I encountered a vague error that took some digging through the latex logs to find what the actual problem was. In the end all I needed was to install xypic, qcircuit and standalone. It would be good if we had a better error message like we have for pillow and pdflatex.

Suggested implementation

Update qiskit/visualization/circuit_vizualization to throw an error if xypic, qcircuit or standalone are not installed. They can all be installed with tlmgr install

mtreinish commented 2 years ago

This is not trivial to do, mostly because those error messages get raised by an external process. Mainly we can't know this until we try to run latex to generate the visualization. The missing package is part of your latex distribution and only the latex compiler can tell if it's missing. We're not really in a place to detect whether the latex packages are installed because it's specific to each individual latex distribution. The best we can do is really just parrot what latex tells us when we call out to the external program. This was actually one of the first issues I worked on in qiskit: https://github.com/Qiskit/qiskit-terra/issues/792 which was fixed in: https://github.com/Qiskit/qiskit-terra/pull/808

I'm not sure what else we can realistically do here, the exception message explicitly says that latex compilation failed look at the latex error log for the details: https://github.com/Qiskit/qiskit-terra/blob/main/qiskit/visualization/circuit_visualization.py#L424-L430

As for the tlmgr step that's not actually a general solution, it depends on how you have latex installed and which latex distribution you're using.

jakelishman commented 2 years ago

There are ways we could potentially improve the error message, still - if raising an error is expected to be a termination point of a program (i.e. we don't expect anybody to try/catch it), then we could do some extra checks to provide better errors if we wanted.

For example, we could take a leaf out of C build processes, and try to do things like LaTeX-compile three dummy files that simply try to \usepackage the right thing, without actually typesetting anything - regardless of the TeX distribution, we already assume that the compiler is pdflatex.