projekter / yquant

Typesetting quantum circuits in a human-readable language
LaTeX Project Public License v1.3c
56 stars 5 forks source link

Subcircuit using `nobit` produces error #16

Closed till-m closed 2 years ago

till-m commented 2 years ago

Thanks for the package @projekter, I really like it. I also realize that this error is most likely due to a mistake on my part and not a bug in the package.

Describe the bug I am trying to draw a circuit for Grover's algorithm. To that end, I would like the gates in the Grover operator to be encapsulated in a box such that I can let the reader know that the subcircuit needs to be repeated several times.

To Reproduce

\begin{figure}[h]
    \centering
    \begin{tikzpicture}
        \begin{yquant}
            qubit {} q[4];

            init {$\ket{0}$} (q);

            discard q[2];
            dots q[2];
            h q[0], q[1], q[3];

            [this subcircuit box style={inner ysep=6pt, "repeat $r$-times"}]
            subcircuit {
                qubit {} q0;
                qubit {} q1;
                nobit {} q2;
                qubit {} q3;
                box {$U_f$} (-);
                h q0, q1, q3;
                dots q2;
                box {$-U_0$} (-);
                h q0, q1, q3;
                dots q2;
            } (-);
            measure q[0], q[1], q[3];

            dots q[2];
        \end{yquant}
    \end{tikzpicture}
    \caption{Grover's algorithm in circuit form}
    \label{fig:grover_circuit}
\end{figure}

Log: Package yquant.sty Error: Placeholder initialization must not have value. } (-);

Expected output The circuit that yquant renders is in fact the circuit I want to produce. Essentially I would just like to get rid of the error which I assume comes from the nobit in the middle of the circuit.

Screenshots image

Environment Compiled using PdfLaTeX with yquant 0.4 and tikz v3.1.8b.

projekter commented 2 years ago

You write nobit {} q2;, but as the error message says, the nobit initializer does not allow for a value parameter (nobit does not really draw anything, so you cannot put a text at the "position where nothing is drawn"). Just remove it and the error should go away (nobit q2;).

By the way, I always recommend using the latest version, which currently is 0.5 (and I'm working on 0.6 currently).

till-m commented 2 years ago

Thank you, that was easier than expected and makes a lot of sense. What was tripping me up was the the compiler noted that the error occurred on a different line.

projekter commented 2 years ago

Yes, this is indeed an issue. I'll have to look into whether there is any way at all to make TeX error messages more helpful, but I don't have too much hope. Somehow, I'd have to capture the file and line before TeX gives control to yquant (while still also giving the original information, as everything might also be due to a bug). I don't know whether this is possible (perhaps there are some 2e commands), but I'll look into it.