Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable emitting circuit diagrams for unitary quantum kernels in LaTeX #1638

Open
bettinaheim opened this issue May 8, 2024 · 2 comments · May be fixed by #1723
Open

Enable emitting circuit diagrams for unitary quantum kernels in LaTeX #1638

bettinaheim opened this issue May 8, 2024 · 2 comments · May be fixed by #1723
Labels
UnitaryHack Good issue for UnitaryHack

Comments

@bettinaheim
Copy link
Collaborator

Description

The CUDA-Q platform allows users to build and execute hybrid quantum-classical kernels. While learning CUDA-Q and also while developing with CUDA-Q, it is helpful to visualize quantum circuits and states to gain intuition, to spot check code, and to communicate with others. We need to expand the visualization functionality into CUDA-Q. CUDA-Q currently contains the ability to visualize unitary quantum kernels as circuit diagrams. These diagrams are emitted in ASCII. To facilitate incorporating such diagrams in papers and other materials, we would like to add support for emitting them in LaTeX instead.

Details

The documentation of the current draw function can be found here (Python) and here (C++).
The API is defined in draw.h, with the corresponding implementation of this functionality is in draw.cpp. This implementation should be extended to take an optional argument format , i.e. an additional overload

template<typename QuantumKernel, typename ...Args>
std::string cudaq::draw(std::string format, QuantumKernel &&kernel, Args&&... args)

should be created, where valid values for format are "ascii" or "latex", and a new Python binding should be created for that overload in py_draw.cpp.

Possible options for LaTeX package to generate circuit diagrams are qcircuit and yquant.

@bettinaheim bettinaheim added the UnitaryHack Good issue for UnitaryHack label May 8, 2024
@freifrauvonbleifrei
Copy link

freifrauvonbleifrei commented May 29, 2024

Hi, I have started working on this for unitary hack!
I would lean towards quantikz for the LaTeX output; I believe it is the most commonly used package. Is there a specific reason why you would prefer the other packages?

@bmhowe23 bmhowe23 linked a pull request May 29, 2024 that will close this issue
@boschmitt
Copy link
Collaborator

Hi, thanks for working on this!

I would lean towards quantikz for the LaTeX output; I believe it is the most commonly used package. Is there a specific reason why you would prefer the other packages?

I'm unsure which of the various packages is the most commonly used. I have tried most of them. The main disadvantage of quantikz is its syntax: the readability of the latex degrades rapidly as circuits become bigger.

Compare the code to generate:

image

(Image taken from yquant docs)

The following are the code taken from the documentation of each package:

  • quantikz:
\begin{quantikz}
& \gate{H} & \ctrl{1} & \gate{H}\gategroup[2,steps=3,style={innersep=6pt}]{reversed c-{\sc not}} & \ctrl{1} & \gate{H} & \ctrl{1} & & \\
& & \targ{} & \gate{H} & \targ{} & \gate{H} & \targ{} & \gate{H} &
\end{quantikz}
  • yquant:
\begin{tikzpicture}
   \begin{yquant*}
      h a;
      cnot b | a;
      [name=left]
      h -;
      cnot b | a;
      [name=right]
      h -;
      cnot b|a;
      h b;
  \end{yquant*}
  \node[fit=(left-0) (left-1) (right-0) (right-1),draw, inner sep=6pt, "reversed c\textsc{not}"] {}; 
\end{tikzpicture}

If there a need to analyze the output latex in order to solve a bug, quantikz syntax will make this debugging process much more difficult.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
UnitaryHack Good issue for UnitaryHack
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants