from geqo.visualization.latex import tolatex

from geqo.core.basic import BasicGate, InverseBasicGate
from geqo.core.quantum_circuit import Sequence
from geqo.gates.fundamental_gates import (
    PauliX,
    PauliY,
    PauliZ,
    SwapQubits,
    Hadamard,
    Phase,
    InversePhase,
    CNOT,
    SGate,
    InverseSGate,
)
from geqo.gates.multi_qubit_gates import Toffoli
from geqo.gates.rotation_gates import (
    Rx,
    Ry,
    Rz,
    Rzz,
    InverseRx,
    InverseRy,
    InverseRz,
    InverseRzz,
)
from geqo.algorithms.algorithms import (
    PCCM,
    QFT,
    InversePCCM,
    InverseQFT,
    PermuteQubits,
    QubitReversal,
)
from geqo.initialization.state import SetBits, SetQubits, SetDensityMatrix
from geqo.operations.controls import ClassicalControl, QuantumControl
from geqo.operations.measurement import Measure, DropQubits
from geqo.simulators.sympy.implementation import ensembleSimulatorSymPy

import pytest
import random
from sympy import Symbol

jos = BasicGate("JoS", 2)
wow = InverseBasicGate("WoW", 3)
geqo = BasicGate("geqo", 3)
single = BasicGate("sin", 1)
cjos = QuantumControl([1, 0], jos)
cccx = QuantumControl([0, 1, 0], PauliX())
ch = QuantumControl([0], Hadamard())
cs = QuantumControl([1], SGate())
cry = QuantumControl([1], InverseRy("alpha"))
crx = QuantumControl([0], Rx("alpha"))
crz = QuantumControl([1], Rz("sigma"))
crzz = QuantumControl([0, 1, 0], Rzz("nu"))
cwow = QuantumControl([1, 0], wow)
cgeqo = QuantumControl([1, 0, 1], geqo)
ccjos = QuantumControl([0, 1], cjos)
ccnot = QuantumControl([1], CNOT())
ctoffoli = QuantumControl([0], Toffoli())
measure = Measure(4)
perm = PermuteQubits([2, 1, 0])
drop = DropQubits(2)
s1 = SetBits("set1", 3)
s2 = SetBits("set2", 2)
s3 = SetBits("set3", 1)
sq = SetQubits("sq", 3)
sq2 = SetQubits("sq2", 1)
sden = SetDensityMatrix("d", 3)
sden2 = SetDensityMatrix("d222", 1)
cr = QuantumControl([0, 1], QubitReversal(3))
cswap = QuantumControl([1, 0], SwapQubits())
cpcm = QuantumControl([0, 1], InversePCCM("sigma"))
cp = QuantumControl([0, 1], Phase("deltaaa"))
cqft = QuantumControl([1, 1, 0], QFT(3))
cperm = QuantumControl([1], PermuteQubits([1, 0, 2]))
classical_jos = ClassicalControl([1, 0, 1], jos)
classical_h = ClassicalControl([1], Hadamard())
classical_s = ClassicalControl([0], InverseSGate())
classical_p = ClassicalControl([1], Phase("nu"))
classical_rx = ClassicalControl([1], Rx("nu"))
classical_ry = ClassicalControl([1], Ry("nu"))
classical_rz = ClassicalControl([1], Rz("nu"))
classical_not = ClassicalControl([0, 1], PauliX())
classical_cnot = ClassicalControl([1], CNOT())
classical_toffoli = ClassicalControl([0], Toffoli())
classical_swap = ClassicalControl([0], SwapQubits())
classical_qctrl = ClassicalControl([1, 0], cqft)
classical_qctrl2 = ClassicalControl([1, 0], ch)
subseq = Sequence(
    [0, 1, 2],
    [0, 1, 2],
    [(Hadamard(), [2]), (CNOT(), [1, 0]), (SwapQubits(), [0, 2])],
    name="sbsq",
)


operations = [
    (single, [0]),
    (PauliZ(), [4]),
    (PauliY(), [3]),
    (PauliX(), [2]),
    (ch, [3, 0]),
    (SGate(), [4]),
    (InverseSGate(), [5]),
    (Phase("alpha"), [1]),
    (InversePhase("beta"), [0]),
    (cp, [1, 4, 5]),
    (Rx("gamma"), [0]),
    (Ry("lambda"), [1]),
    (Rz("kappa"), [2]),
    (crx, [4, 1]),
    (cry, [4, 1]),
    (crz, [4, 1]),
    (InverseRx("x"), [5]),
    (InverseRz("z"), [0]),
    (InverseRzz("g"), [5, 3]),
    (crzz, [0, 3, 5, 1, 4]),
    (CNOT(), [3, 0]),
    (Toffoli(), [0, 4, 2]),
    (Toffoli(), [1, 3, 5]),
    (Toffoli(), [4, 5, 1]),
    (cccx, [0, 1, 4, 3]),
    (SwapQubits(), [2, 5]),
    (QubitReversal(5), [2, 3, 0, 4, 1]),
    (cswap, [0, 3, 2, 5]),
    (cr, [5, 2, 0, 4, 1]),
    (perm, [1, 3, 5]),
    (QFT(3), [2, 3, 0]),
    (InverseQFT(2), [4, 5]),
    (cqft, [0, 1, 5, 4, 2, 3]),
    (jos, [0, 1]),
    (cjos, [4, 0, 3, 2]),
    (cjos, [0, 2, 1, 3]),
    (cwow, [4, 2, 3, 0, 1]),
    (cwow, [0, 3, 1, 2, 5]),
    (cgeqo, [5, 0, 2, 4, 3, 1]),
    (PCCM("psi"), [4, 1]),
    (InversePCCM("omega"), [1, 2]),
    (cpcm, [0, 3, 2, 5]),
    (cperm, [2, 3, 4, 5]),
    (drop, [2, 4]),
    (s1, [1, 3, 4]),
    (s2, [0, 5]),
    (s3, [2]),
    (sq, [1, 4, 5]),
    (sq2, [3]),
    (sden, [0, 3, 2]),
    (sden2, [5]),
    (subseq, [4, 2, 3]),
    (classical_jos, [0, 3, 5, 0, 4]),
    (classical_h, [2, 2]),
    (measure, [0, 2, 3, 5], [0, 2, 3, 5]),
    (ccjos, [0, 1, 2, 3, 4, 5]),
    (ccnot, [2, 4, 1]),
    (ctoffoli, [5, 0, 3, 2]),
    (ctoffoli, [0, 1, 3, 2]),
    (classical_not, [0, 1, 4]),
    (classical_not, [0, 3, 2]),
    (classical_not, [0, 3, 0]),
    (classical_cnot, [3, 5, 2]),
    (classical_toffoli, [2, 1, 0, 5]),
    (classical_swap, [1, 2, 3]),
    (classical_qctrl, [2, 4, 3, 1, 2, 0, 4, 5]),
    (classical_qctrl, [1, 3, 0, 3, 2, 1, 4, 5]),
    (classical_qctrl, [0, 3, 0, 3, 2, 1, 4, 5]),
    (classical_qctrl2, [0, 3, 5]),
    (classical_qctrl2, [0, 3, 3]),
    (Measure(1), [3], [4]),
    (DropQubits(1), [0]),
    (cs, [3, 5]),
    (classical_s, [4, 1]),
    (classical_p, [0, 2]),
    (classical_rx, [0, 0]),
    (classical_ry, [5, 2]),
    (classical_rz, [3, 1]),
]

qubits = [f"q_{i}" for i in range(6)]
seq = Sequence([0, 1, 2, 3, 4, 5], qubits, operations)


class TestVisualization:
    def test_plot_latex_backend_greek(self):
        sim = ensembleSimulatorSymPy(6, 6)
        sim.setValue("alpha", Symbol("θ"))
        sim.setValue("omega", 1.5677)
        sim.setValue("sigma", 0.66)
        sim.setValue("set2", [0, 1])
        sim.setValue("set3", [1])
        sim.setValue("sq", [1, 0, 1])

        code = tolatex(
            seq,
            backend=sim,
            decompose_subseq=True,
            pack=True,
            fold=9,
            greek_symbol=True,
            filename=None,
            return_quantikz=True,
        )

        expect = "\\begin{quantikz}[color=black,background color=white]\n\\lstick{$q_0$}&\\gate[style={draw=black,fill=white!20},label style=black]{sin}&\\gate[style={draw=black,fill=white!20},label style=black]{H}&\\gate[style={draw=black,fill=white!20},label style=black]{P^\\dagger(\\beta)}&\\gate[style={draw=black,fill=white!20},label style=black]{Rx(\\gamma)}&\\gate[style={draw=black,fill=white!20},label style=black]{Rz^\\dagger(z)}&\\qw &\\qw &\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_1$}&\\qw &\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{P(\\alpha)}&\\octrl{3}&\\gate[style={draw=black,fill=white!20},label style=black]{Ry(\\lambda)}&\\gate[style={draw=black,fill=white!20},label style=black]{Rx(\\alpha)}&\\gate[style={draw=black,fill=white!20},label style=black]{Ry^\\dagger(\\alpha)}&\\gate[style={draw=black,fill=white!20},label style=black]{Rz(0.66)}&\\qw &\\qw & \\\\\n\\lstick{$q_2$}&\\gate[style={draw=black,fill=white!20},label style=black]{X}&\\qw &\\qw &\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{Rz(\\kappa)}&\\qw &\\qw &\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_3$}&\\gate[style={draw=black,fill=white!20},label style=black]{Y}&\\octrl{-3}&\\qw &\\qw &\\qw &\\qw &\\qw &\\qw &\\gate[3,style={draw=black,fill=white!20},label style=black]{Rzz^\\dagger(g)}\\gateinput[label style=black]{1}&\\qw & \\\\\n\\lstick{$q_4$}&\\gate[style={draw=black,fill=white!20},label style=black]{Z}&\\gate[style={draw=black,fill=white!20},label style=black]{S}&\\qw &\\ctrl{1}&\\qw &\\octrl{-3}&\\ctrl{-3}&\\ctrl{-3}&\\qw &\\qw & \\\\\n\\lstick{$q_5$}&\\gate[style={draw=black,fill=white!20},label style=black]{S^\\dagger}&\\qw &\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{P(de)}&\\gate[style={draw=black,fill=white!20},label style=black]{Rx^\\dagger(x)}&\\qw &\\qw &\\qw &\\qw \\gateinput[label style=black]{0}&\\qw & \\\\\n\\\\\n\\lstick{$q_0$}&\\octrl{1}&\\targ{}&\\ctrl{2}&\\qw &\\qw &\\octrl{1}&\\qw &\\gate[5,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{$\\mathbb{R}\\text{vrs}$}}\\gateinput[label style=black]{2}&\\ctrl{5}&\\qw & \\\\\n\\lstick{$q_1$}&\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{Rzz($\\nu$)}}\\gateinput[label style=black]{0}&\\qw &\\qw &\\ctrl{2}&\\targ{}&\\ctrl{2}&\\qw &\\qw \\gateinput[label style=black]{4} &\\qw &\\qw & \\\\\n\\lstick{$q_2$}&\\qw &\\qw &\\targ{}&\\qw &\\qw &\\qw &\\swap{3}&\\qw \\gateinput[label style=black]{0} &\\targX{}&\\qw & \\\\\n\\lstick{$q_3$}&\\qw \\gateinput{$\\bullet$} &\\ctrl{-3}&\\qw &\\ctrl{2}&\\qw &\\targ{}&\\qw &\\qw \\gateinput[label style=black]{1} &\\ocontrol{}&\\qw & \\\\\n\\lstick{$q_4$}&\\qw \\gateinput[label style=black]{1} &\\qw &\\ctrl{-2}&\\qw &\\ctrl{-3}&\\octrl{-1}&\\qw &\\qw \\gateinput[label style=black]{3} &\\qw &\\qw & \\\\\n\\lstick{$q_5$}&\\octrl{-1}&\\qw &\\qw &\\targ{}&\\ctrl{-1}&\\qw &\\targX{}&\\qw &\\targX{}&\\qw & \\\\\n\\\\\n\\lstick{$q_0$}&\\gate[5,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{$\\mathbb{R}\\text{vrs}$}}\\gateinput[label style=black]{0}&\\qw &\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{QFT}}\\gateinput[label style=black]{2}&\\ctrl{1}&\\gate[2,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{JoS}}\\gateinput[label style=black]{0}&\\octrl{2}&\\ctrl{1}&\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{WoW}}\\gateinput[label style=black]{1}&\\ctrl{1}&\\qw & \\\\\n\\lstick{$q_1$}&\\qw \\gateinput[label style=black]{2} &\\gate[5,style={draw=black,fill=white!20},label style=black]{\\makebox[6em]{$\\mathbb{P}\\text{rmt}$}}\\gateinput[label style=black]{$q_5$}&\\qw &\\ctrl{1}&\\qw \\gateinput[label style=black]{1}&\\qw &\\gate[3,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{JoS}}\\gateinput[label style=black]{0}&\\qw \\gateinput[label style=black]{2} &\\gate[5,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{WoW}}\\gateinput[label style=black]{0}&\\qw & \\\\\n\\lstick{$q_2$}&\\qw \\gateinput{$\\bullet$} &\\qw &\\qw \\gateinput[label style=black]{0}&\\gate[3,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{QFT}}\\gateinput[label style=black]{1}&\\qw &\\gate[2,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{JoS}}\\gateinput[label style=black]{1}&\\qw \\gateinput{$\\circ$} &\\qw \\gateinput{$\\circ$} &\\qw \\gateinput[label style=black]{1} &\\qw & \\\\\n\\lstick{$q_3$}&\\qw &\\qw \\gateinput[label style=black]{$q_3$}&\\qw \\gateinput[label style=black]{1}&\\qw \\gateinput[label style=black]{2} &\\qw &\\qw \\gateinput[label style=black]{0} &\\qw \\gateinput[label style=black]{1} &\\qw \\gateinput[label style=black]{0} &\\qw \\gateinput{$\\circ$} &\\qw & \\\\\n\\lstick{$q_4$}&\\qw \\gateinput[label style=black]{1} &\\qw &\\gate[2,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{QFT$^\\dagger$}}\\gateinput[label style=black]{0}&\\qw \\gateinput[label style=black]{0} &\\qw &\\ctrl{-1}&\\qw &\\ctrl{-1}&\\qw &\\qw & \\\\\n\\lstick{$q_5$}&\\octrl{-1}&\\qw \\gateinput[label style=black]{$q_1$}&\\qw \\gateinput[label style=black]{1}&\\octrl{-1}&\\qw &\\qw &\\qw &\\qw &\\qw \\gateinput[label style=black]{2} &\\qw & \\\\\n\\\\\n\\lstick{$q_0$}&\\octrl{1}&\\qw &\\qw &\\octrl{2}&\\qw &\\qw &\\qw &\\push{\\textcolor{black}{\\textcircled{\\raisebox{-0.2ex}{0}}}}&\\qw &\\qw & \\\\\n\\lstick{$q_1$}&\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{geqo}}\\gateinput[label style=black]{2}&\\gate[4,style={draw=black,fill=white!20},label style=black]{PCCM(\\psi)}\\gateinput[label style=black]{1}&\\gate[2,style={draw=black,fill=white!20},label style=black]{PCCM^\\dagger(1.57)}\\gateinput[label style=black]{0}&\\qw &\\qw &\\qw &\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{set1}}\\gateinput[label style=black]{0}&\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_2$}&\\qw \\gateinput{$\\bullet$} &\\qw &\\qw \\gateinput[label style=black]{1}&\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[8.5em]{PCCM$^\\dagger$(0.66)}}\\gateinput[label style=black]{0}&\\ctrl{1}&\\push{\\text{\\Large \\textcolor{black}{X}}}&\\qw &\\qw &\\push{\\textcolor{black}{\\textcircled{\\raisebox{-0.2ex}{1}}}}&\\qw & \\\\\n\\lstick{$q_3$}&\\qw \\gateinput[label style=black]{1} &\\qw &\\qw &\\qw \\gateinput{$\\bullet$} &\\gate[3,style={draw=black,fill=white!20},label style=black]{\\makebox[6em]{$\\mathbb{P}\\text{rmt}$}}\\gateinput[label style=black]{$q_4$}&\\qw &\\qw \\gateinput[label style=black]{1}&\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_4$}&\\qw \\gateinput[label style=black]{0} &\\qw \\gateinput[label style=black]{0}&\\qw &\\qw &\\qw \\gateinput[label style=black]{$q_3$} &\\push{\\text{\\Large \\textcolor{black}{X}}}&\\qw \\gateinput[label style=black]{2}&\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_5$}&\\ctrl{-1}&\\qw &\\qw &\\qw \\gateinput[label style=black]{1} &\\qw \\gateinput[label style=black]{$q_5$} &\\qw &\\qw &\\push{\\textcolor{black}{\\textcircled{\\raisebox{-0.2ex}{1}}}}&\\qw &\\qw & \\\\\n\\\\\n\\lstick{$q_0$}&\\qw &\\qw &\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{$\\rho[d]$}}\\gateinput[label style=black]{0}&\\qw &\\qw &\\qw &\\gate[6,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{JoS}}\\gateinput[label style=black]{0}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw &\\meter[style={draw=black,fill=white!20}]{0}&\\qw & \\\\\n\\lstick{$q_1$}&\\push{\\text{\\Large \\textcolor{black}{$\\ket{1}$}}}&\\qw &\\qw &\\qw &\\qw &\\qw &\\qw &\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_2$}&\\qw &\\qw &\\qw \\gateinput[label style=black]{2}&\\qw &\\ctrl{2}&\\qw &\\qw &\\gate[1,style={draw=black,fill=white!20},label style=black]{\\makebox[4.5em]{H}}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\meter[style={draw=black,fill=white!20}]{2}&\\qw & \\\\\n\\lstick{$q_3$}&\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{sq2}&\\qw \\gateinput[label style=black]{1}&\\gate[style={draw=black,fill=white!20},label style=black]{H}&\\qw &\\swap{1}&\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\qw &\\meter[style={draw=black,fill=white!20}]{3}&\\qw & \\\\\n\\lstick{$q_4$}&\\push{\\text{\\Large \\textcolor{black}{$\\ket{0}$}}}&\\qw &\\qw &\\qw &\\targ{}&\\targX{}&\\qw \\gateinput[label style=black]{1}&\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_5$}&\\push{\\text{\\Large \\textcolor{black}{$\\ket{1}$}}}&\\gate[style={draw=black,fill=white!20},label style=black]{\\rho[d222]}&\\qw &\\qw &\\qw &\\qw &\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw &\\meter[style={draw=black,fill=white!20}]{5}&\\qw & \\\\\n\\\\\n\\lstick{$q_0$}&\\octrl{1}&\\qw &\\ctrl{2}&\\octrl{1}&\\gate[5,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{X}}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{X}}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[4.5em]{X}}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\qw &\\gate[6,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{CCX}}\\gateinput[label style=black]{1}&\\qw & \\\\\n\\lstick{$q_1$}&\\ctrl{1}&\\targ{}&\\qw &\\ctrl{1}&\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw &\\qw &\\qw &\\qw \\gateinput[label style=black]{0}&\\qw & \\\\\n\\lstick{$q_2$}&\\ctrl{1}&\\ctrl{-1}&\\targ{}&\\targ{}&\\qw &\\qw \\gateinput[label style=black]{0}&\\qw &\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{CX}}\\gateinput[label style=black]{1}&\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\qw & \\\\\n\\lstick{$q_3$}&\\octrl{1}&\\qw &\\ctrl{-1}&\\ctrl{-1}&\\qw &\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw &\\qw & \\\\\n\\lstick{$q_4$}&\\gate[2,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{JoS}}\\gateinput[label style=black]{0}&\\ctrl{-2}&\\qw &\\qw &\\qw \\gateinput[label style=black]{0}&\\qw &\\qw &\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_5$}&\\qw \\gateinput[label style=black]{1} &\\qw &\\octrl{-2}&\\qw &\\qw &\\qw &\\qw &\\qw \\gateinput[label style=black]{0}&\\qw \\gateinput[label style=black]{2}&\\qw & \\\\\n\\\\\n\\lstick{$q_0$}&\\qw &\\gate[6,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{QFT}}\\gateinput[label style=black]{0}&\\gate[6,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{QFT}}\\gateinput[label style=black]{$\\bullet$}&\\gate[6,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{QFT}}\\gateinput[label style=black]{$\\bullet$}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\gate[6,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{H}}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{H}}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\push{\\text{\\Large \\textcolor{black}{X}}}&\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_1$}&\\gate[3,style={draw=black,fill=white!20},label style=black]{\\makebox[6em]{SWAP}}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\qw \\gateinput[label style=black]{$\\bullet$}&\\qw \\gateinput[label style=black]{0} \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw \\gateinput[label style=black]{0}&\\qw &\\qw &\\qw &\\qw &\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{S$^\\dagger$}}\\gateinput[label style=black]{0}&\\qw & \\\\\n\\lstick{$q_2$}&\\qw \\gateinput[label style=black]{0}&\\qw \\gateinput[label style=black]{$\\circ$} \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw \\gateinput[label style=black]{$\\circ$}&\\qw \\gateinput[label style=black]{$\\circ$}&\\qw &\\qw &\\qw &\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_3$}&\\qw \\gateinput[label style=black]{1}&\\qw \\gateinput[label style=black]{$\\bullet$}&\\qw \\gateinput[label style=black]{$\\bullet$} \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\qw \\gateinput[label style=black]{$\\bullet$} \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\qw \\gateinput[label style=black]{0} \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\meter[style={draw=black,fill=white!20}]{4}&\\ctrl{2}&\\qw &\\qw & \\\\\n\\lstick{$q_4$}&\\qw &\\qw \\gateinput[label style=black]{1} \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\qw \\gateinput[label style=black]{1}&\\qw \\gateinput[label style=black]{1}&\\qw &\\qw &\\qw &\\qw &\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\qw & \\\\\n\\lstick{$q_5$}&\\qw &\\qw \\gateinput[label style=black]{2}&\\qw \\gateinput[label style=black]{2}&\\qw \\gateinput[label style=black]{2}&\\qw \\gateinput[label style=black]{0}&\\qw &\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{S}&\\qw &\\qw & \\\\\n\\\\\n\\lstick{$q_0$}&\\gate[3,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{P($\\nu$)}}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\gate[1,style={draw=black,fill=white!20},label style=black]{\\makebox[4.5em]{Rx($\\nu$)}}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw &\\qw & \\\\\n\\lstick{$q_1$}&\\qw &\\qw &\\gate[3,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{Rz($\\nu$)}}\\gateinput[label style=black]{0}&\\qw & \\\\\n\\lstick{$q_2$}&\\qw \\gateinput[label style=black]{0}&\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{Ry($\\nu$)}}\\gateinput[label style=black]{0}&\\qw &\\qw & \\\\\n\\lstick{$q_3$}&\\qw &\\qw &\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw & \\\\\n\\lstick{$q_4$}&\\qw &\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_5$}&\\qw &\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw &\\qw & \\\\\n\\end{quantikz}"

        assert code == expect

    def test_plot_latex_no_backend_greek(self):
        code = tolatex(
            seq,
            backend=None,
            decompose_subseq=False,
            pack=False,
            fold=9,
            greek_symbol=True,
            filename=None,
            return_quantikz=None,
        )
        expect = "\\begin{quantikz}[color=black,background color=white]\n\\lstick{$q_0$}&\\gate[style={draw=black,fill=white!20},label style=black]{sin}&\\qw &\\qw &\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{H}&\\qw &\\qw &\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{P^\\dagger(\\beta)}&\\qw & \\\\\n\\lstick{$q_1$}&\\qw &\\qw &\\qw &\\qw &\\qw &\\qw &\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{P(\\alpha)}&\\qw &\\qw & \\\\\n\\lstick{$q_2$}&\\qw &\\qw &\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{X}&\\qw &\\qw &\\qw &\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_3$}&\\qw &\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{Y}&\\qw &\\octrl{-3}&\\qw &\\qw &\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_4$}&\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{Z}&\\qw &\\qw &\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{S}&\\qw &\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_5$}&\\qw &\\qw &\\qw &\\qw &\\qw &\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{S^\\dagger}&\\qw &\\qw &\\qw & \\\\\n\\\\\n\\lstick{$q_0$}&\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{Rx(\\gamma)}&\\qw &\\qw &\\qw &\\qw &\\qw &\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{Rz^\\dagger(z)}&\\qw & \\\\\n\\lstick{$q_1$}&\\octrl{3}&\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{Ry(\\lambda)}&\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{Rx(\\alpha)}&\\gate[style={draw=black,fill=white!20},label style=black]{Ry^\\dagger(\\alpha)}&\\gate[style={draw=black,fill=white!20},label style=black]{Rz(\\sigma)}&\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_2$}&\\qw &\\qw &\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{Rz(\\kappa)}&\\qw &\\qw &\\qw &\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_3$}&\\qw &\\qw &\\qw &\\qw &\\qw &\\qw &\\qw &\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_4$}&\\ctrl{1}&\\qw &\\qw &\\qw &\\octrl{-3}&\\ctrl{-3}&\\ctrl{-3}&\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_5$}&\\gate[style={draw=black,fill=white!20},label style=black]{P(de)}&\\qw &\\qw &\\qw &\\qw &\\qw &\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{Rx^\\dagger(x)}&\\qw &\\qw & \\\\\n\\\\\n\\lstick{$q_0$}&\\qw &\\octrl{1}&\\targ{}&\\ctrl{2}&\\qw &\\qw &\\octrl{1}&\\qw &\\gate[5,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{$\\mathbb{R}\\text{vrs}$}}\\gateinput[label style=black]{2}&\\qw & \\\\\n\\lstick{$q_1$}&\\qw &\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{Rzz($\\nu$)}}\\gateinput[label style=black]{0}&\\qw &\\qw &\\ctrl{2}&\\targ{}&\\ctrl{2}&\\qw &\\qw \\gateinput[label style=black]{4} &\\qw & \\\\\n\\lstick{$q_2$}&\\qw &\\qw &\\qw &\\targ{}&\\qw &\\qw &\\qw &\\swap{3}&\\qw \\gateinput[label style=black]{0} &\\qw & \\\\\n\\lstick{$q_3$}&\\gate[3,style={draw=black,fill=white!20},label style=black]{Rzz^\\dagger(g)}\\gateinput[label style=black]{1}&\\qw \\gateinput{$\\bullet$} &\\ctrl{-3}&\\qw &\\ctrl{2}&\\qw &\\targ{}&\\qw &\\qw \\gateinput[label style=black]{1} &\\qw & \\\\\n\\lstick{$q_4$}&\\qw &\\qw \\gateinput[label style=black]{1} &\\qw &\\ctrl{-2}&\\qw &\\ctrl{-3}&\\octrl{-1}&\\qw &\\qw \\gateinput[label style=black]{3} &\\qw & \\\\\n\\lstick{$q_5$}&\\qw \\gateinput[label style=black]{0}&\\octrl{-1}&\\qw &\\qw &\\targ{}&\\ctrl{-1}&\\qw &\\targX{}&\\qw &\\qw & \\\\\n\\\\\n\\lstick{$q_0$}&\\ctrl{5}&\\gate[5,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{$\\mathbb{R}\\text{vrs}$}}\\gateinput[label style=black]{0}&\\qw &\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{QFT}}\\gateinput[label style=black]{2}&\\qw &\\ctrl{1}&\\gate[2,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{JoS}}\\gateinput[label style=black]{0}&\\octrl{2}&\\ctrl{1}&\\qw & \\\\\n\\lstick{$q_1$}&\\qw &\\qw \\gateinput[label style=black]{2} &\\gate[5,style={draw=black,fill=white!20},label style=black]{\\makebox[6em]{$\\mathbb{P}\\text{rmt}$}}\\gateinput[label style=black]{$q_5$}&\\qw &\\qw &\\ctrl{1}&\\qw \\gateinput[label style=black]{1}&\\qw &\\gate[3,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{JoS}}\\gateinput[label style=black]{0}&\\qw & \\\\\n\\lstick{$q_2$}&\\targX{}&\\qw \\gateinput{$\\bullet$} &\\qw &\\qw \\gateinput[label style=black]{0}&\\qw &\\gate[3,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{QFT}}\\gateinput[label style=black]{1}&\\qw &\\gate[2,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{JoS}}\\gateinput[label style=black]{1}&\\qw \\gateinput{$\\circ$} &\\qw & \\\\\n\\lstick{$q_3$}&\\ocontrol{}&\\qw &\\qw \\gateinput[label style=black]{$q_3$}&\\qw \\gateinput[label style=black]{1}&\\qw &\\qw \\gateinput[label style=black]{2} &\\qw &\\qw \\gateinput[label style=black]{0} &\\qw \\gateinput[label style=black]{1} &\\qw & \\\\\n\\lstick{$q_4$}&\\qw &\\qw \\gateinput[label style=black]{1} &\\qw &\\qw &\\gate[2,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{QFT$^\\dagger$}}\\gateinput[label style=black]{0}&\\qw \\gateinput[label style=black]{0} &\\qw &\\ctrl{-1}&\\qw &\\qw & \\\\\n\\lstick{$q_5$}&\\targX{}&\\octrl{-1}&\\qw \\gateinput[label style=black]{$q_1$}&\\qw &\\qw \\gateinput[label style=black]{1}&\\octrl{-1}&\\qw &\\qw &\\qw &\\qw & \\\\\n\\\\\n\\lstick{$q_0$}&\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{WoW}}\\gateinput[label style=black]{1}&\\ctrl{1}&\\octrl{1}&\\qw &\\qw &\\octrl{2}&\\qw &\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_1$}&\\qw \\gateinput[label style=black]{2} &\\gate[5,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{WoW}}\\gateinput[label style=black]{0}&\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{geqo}}\\gateinput[label style=black]{2}&\\gate[4,style={draw=black,fill=white!20},label style=black]{PCCM(\\psi)}\\gateinput[label style=black]{1}&\\gate[2,style={draw=black,fill=white!20},label style=black]{PCCM^\\dagger(\\omega)}\\gateinput[label style=black]{0}&\\qw &\\qw &\\qw &\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{set1}}\\gateinput[label style=black]{0}&\\qw & \\\\\n\\lstick{$q_2$}&\\qw \\gateinput{$\\circ$} &\\qw \\gateinput[label style=black]{1} &\\qw \\gateinput{$\\bullet$} &\\qw &\\qw \\gateinput[label style=black]{1}&\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[8.5em]{PCCM$^\\dagger$($\\sigma$)}}\\gateinput[label style=black]{0}&\\ctrl{1}&\\push{\\text{\\Large \\textcolor{black}{X}}}&\\qw &\\qw & \\\\\n\\lstick{$q_3$}&\\qw \\gateinput[label style=black]{0} &\\qw \\gateinput{$\\circ$} &\\qw \\gateinput[label style=black]{1} &\\qw &\\qw &\\qw \\gateinput{$\\bullet$} &\\gate[3,style={draw=black,fill=white!20},label style=black]{\\makebox[6em]{$\\mathbb{P}\\text{rmt}$}}\\gateinput[label style=black]{$q_4$}&\\qw &\\qw \\gateinput[label style=black]{1}&\\qw & \\\\\n\\lstick{$q_4$}&\\ctrl{-1}&\\qw &\\qw \\gateinput[label style=black]{0} &\\qw \\gateinput[label style=black]{0}&\\qw &\\qw &\\qw \\gateinput[label style=black]{$q_3$} &\\push{\\text{\\Large \\textcolor{black}{X}}}&\\qw \\gateinput[label style=black]{2}&\\qw & \\\\\n\\lstick{$q_5$}&\\qw &\\qw \\gateinput[label style=black]{2} &\\ctrl{-1}&\\qw &\\qw &\\qw \\gateinput[label style=black]{1} &\\qw \\gateinput[label style=black]{$q_5$} &\\qw &\\qw &\\qw & \\\\\n\\\\\n\\lstick{$q_0$}&\\gate[6,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{set2}}\\gateinput[label style=black]{0}&\\qw &\\qw &\\qw &\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{$\\rho[d]$}}\\gateinput[label style=black]{0}&\\qw &\\qw &\\gate[6,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{JoS}}\\gateinput[label style=black]{0}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw &\\qw & \\\\\n\\lstick{$q_1$}&\\qw &\\qw &\\gate[5,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{sq}}\\gateinput[label style=black]{0}&\\qw &\\qw &\\qw &\\qw &\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_2$}&\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{set3}&\\qw &\\qw &\\qw \\gateinput[label style=black]{2}&\\qw &\\gate[3,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{sbsq}}\\gateinput[label style=black]{1}&\\qw &\\gate[1,style={draw=black,fill=white!20},label style=black]{\\makebox[4.5em]{H}}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw & \\\\\n\\lstick{$q_3$}&\\qw &\\qw &\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{sq2}&\\qw \\gateinput[label style=black]{1}&\\qw &\\qw \\gateinput[label style=black]{2}&\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\qw &\\qw & \\\\\n\\lstick{$q_4$}&\\qw &\\qw &\\qw \\gateinput[label style=black]{1}&\\qw &\\qw &\\qw &\\qw \\gateinput[label style=black]{0}&\\qw \\gateinput[label style=black]{1}&\\qw &\\qw & \\\\\n\\lstick{$q_5$}&\\qw \\gateinput[label style=black]{1}&\\qw &\\qw \\gateinput[label style=black]{2}&\\qw &\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{\\rho[d222]}&\\qw &\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw &\\qw & \\\\\n\\\\\n\\lstick{$q_0$}&\\meter[style={draw=black,fill=white!20}]{0}&\\octrl{1}&\\qw &\\ctrl{2}&\\octrl{1}&\\gate[5,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{X}}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{X}}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[4.5em]{X}}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\qw &\\qw & \\\\\n\\lstick{$q_1$}&\\qw &\\ctrl{1}&\\targ{}&\\qw &\\ctrl{1}&\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw &\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_2$}&\\meter[style={draw=black,fill=white!20}]{2}&\\ctrl{1}&\\ctrl{-1}&\\targ{}&\\targ{}&\\qw &\\qw \\gateinput[label style=black]{0}&\\qw &\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{CX}}\\gateinput[label style=black]{1}&\\qw & \\\\\n\\lstick{$q_3$}&\\meter[style={draw=black,fill=white!20}]{3}&\\octrl{1}&\\qw &\\ctrl{-1}&\\ctrl{-1}&\\qw &\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw & \\\\\n\\lstick{$q_4$}&\\qw &\\gate[2,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{JoS}}\\gateinput[label style=black]{0}&\\ctrl{-2}&\\qw &\\qw &\\qw \\gateinput[label style=black]{0}&\\qw &\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_5$}&\\meter[style={draw=black,fill=white!20}]{5}&\\qw \\gateinput[label style=black]{1} &\\qw &\\octrl{-2}&\\qw &\\qw &\\qw &\\qw &\\qw \\gateinput[label style=black]{0}&\\qw & \\\\\n\\\\\n\\lstick{$q_0$}&\\gate[6,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{CCX}}\\gateinput[label style=black]{1}&\\qw &\\gate[6,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{QFT}}\\gateinput[label style=black]{0}&\\gate[6,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{QFT}}\\gateinput[label style=black]{$\\bullet$}&\\gate[6,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{QFT}}\\gateinput[label style=black]{$\\bullet$}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\gate[6,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{H}}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{H}}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw &\\push{\\text{\\Large \\textcolor{black}{X}}}&\\qw & \\\\\n\\lstick{$q_1$}&\\qw \\gateinput[label style=black]{0}&\\gate[3,style={draw=black,fill=white!20},label style=black]{\\makebox[6em]{SWAP}}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\qw \\gateinput[label style=black]{$\\bullet$}&\\qw \\gateinput[label style=black]{0} \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw \\gateinput[label style=black]{0}&\\qw &\\qw &\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_2$}&\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\qw \\gateinput[label style=black]{0}&\\qw \\gateinput[label style=black]{$\\circ$} \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw \\gateinput[label style=black]{$\\circ$}&\\qw \\gateinput[label style=black]{$\\circ$}&\\qw &\\qw &\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_3$}&\\qw &\\qw \\gateinput[label style=black]{1}&\\qw \\gateinput[label style=black]{$\\bullet$}&\\qw \\gateinput[label style=black]{$\\bullet$} \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\qw \\gateinput[label style=black]{$\\bullet$} \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\qw \\gateinput[label style=black]{0} \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\meter[style={draw=black,fill=white!20}]{4}&\\qw &\\qw & \\\\\n\\lstick{$q_4$}&\\qw &\\qw &\\qw \\gateinput[label style=black]{1} \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\qw \\gateinput[label style=black]{1}&\\qw \\gateinput[label style=black]{1}&\\qw &\\qw &\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_5$}&\\qw \\gateinput[label style=black]{2}&\\qw &\\qw \\gateinput[label style=black]{2}&\\qw \\gateinput[label style=black]{2}&\\qw \\gateinput[label style=black]{2}&\\qw \\gateinput[label style=black]{0}&\\qw &\\qw &\\qw &\\qw & \\\\\n\\\\\n\\lstick{$q_0$}&\\qw &\\qw &\\gate[3,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{P($\\nu$)}}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\gate[1,style={draw=black,fill=white!20},label style=black]{\\makebox[4.5em]{Rx($\\nu$)}}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_1$}&\\qw &\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{S$^\\dagger$}}\\gateinput[label style=black]{0}&\\qw &\\qw &\\qw &\\gate[3,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{Rz($\\nu$)}}\\gateinput[label style=black]{0}&\\qw & \\\\\n\\lstick{$q_2$}&\\qw &\\qw &\\qw \\gateinput[label style=black]{0}&\\qw &\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{Ry($\\nu$)}}\\gateinput[label style=black]{0}&\\qw &\\qw & \\\\\n\\lstick{$q_3$}&\\ctrl{2}&\\qw &\\qw &\\qw &\\qw &\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw & \\\\\n\\lstick{$q_4$}&\\qw &\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\qw &\\qw &\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_5$}&\\gate[style={draw=black,fill=white!20},label style=black]{S}&\\qw &\\qw &\\qw &\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw &\\qw & \\\\\n\\end{quantikz}"

        assert code == expect

    def test_plot_latex_backend_no_greek(self):
        sim = ensembleSimulatorSymPy(6, 6)
        sim.setValue("alpha", Symbol("θ"))
        sim.setValue("omega", Symbol("omega"))
        sim.setValue("set2", [0, 1])
        sim.setValue("sq2", [1])
        code = tolatex(
            seq,
            backend=sim,
            decompose_subseq=True,
            pack=True,
            fold=9,
            greek_symbol=False,
            filename=None,
            return_quantikz=False,
        )

        expect = "\\begin{quantikz}[color=black,background color=white]\n\\lstick{$q_0$}&\\gate[style={draw=black,fill=white!20},label style=black]{sin}&\\gate[style={draw=black,fill=white!20},label style=black]{H}&\\gate[style={draw=black,fill=white!20},label style=black]{P^\\dagger(be)}&\\gate[style={draw=black,fill=white!20},label style=black]{Rx(ga)}&\\gate[style={draw=black,fill=white!20},label style=black]{Rz^\\dagger(z)}&\\qw &\\qw &\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_1$}&\\qw &\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{P(al)}&\\octrl{3}&\\gate[style={draw=black,fill=white!20},label style=black]{Ry(la)}&\\gate[style={draw=black,fill=white!20},label style=black]{Rx(al)}&\\gate[style={draw=black,fill=white!20},label style=black]{Ry^\\dagger(al)}&\\gate[style={draw=black,fill=white!20},label style=black]{Rz(si)}&\\qw &\\qw & \\\\\n\\lstick{$q_2$}&\\gate[style={draw=black,fill=white!20},label style=black]{X}&\\qw &\\qw &\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{Rz(ka)}&\\qw &\\qw &\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_3$}&\\gate[style={draw=black,fill=white!20},label style=black]{Y}&\\octrl{-3}&\\qw &\\qw &\\qw &\\qw &\\qw &\\qw &\\gate[3,style={draw=black,fill=white!20},label style=black]{Rzz^\\dagger(g)}\\gateinput[label style=black]{1}&\\qw & \\\\\n\\lstick{$q_4$}&\\gate[style={draw=black,fill=white!20},label style=black]{Z}&\\gate[style={draw=black,fill=white!20},label style=black]{S}&\\qw &\\ctrl{1}&\\qw &\\octrl{-3}&\\ctrl{-3}&\\ctrl{-3}&\\qw &\\qw & \\\\\n\\lstick{$q_5$}&\\gate[style={draw=black,fill=white!20},label style=black]{S^\\dagger}&\\qw &\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{P(de)}&\\gate[style={draw=black,fill=white!20},label style=black]{Rx^\\dagger(x)}&\\qw &\\qw &\\qw &\\qw \\gateinput[label style=black]{0}&\\qw & \\\\\n\\\\\n\\lstick{$q_0$}&\\octrl{1}&\\targ{}&\\ctrl{2}&\\qw &\\qw &\\octrl{1}&\\qw &\\gate[5,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{$\\mathbb{R}\\text{vrs}$}}\\gateinput[label style=black]{2}&\\ctrl{5}&\\qw & \\\\\n\\lstick{$q_1$}&\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{Rzz(nu)}}\\gateinput[label style=black]{0}&\\qw &\\qw &\\ctrl{2}&\\targ{}&\\ctrl{2}&\\qw &\\qw \\gateinput[label style=black]{4} &\\qw &\\qw & \\\\\n\\lstick{$q_2$}&\\qw &\\qw &\\targ{}&\\qw &\\qw &\\qw &\\swap{3}&\\qw \\gateinput[label style=black]{0} &\\targX{}&\\qw & \\\\\n\\lstick{$q_3$}&\\qw \\gateinput{$\\bullet$} &\\ctrl{-3}&\\qw &\\ctrl{2}&\\qw &\\targ{}&\\qw &\\qw \\gateinput[label style=black]{1} &\\ocontrol{}&\\qw & \\\\\n\\lstick{$q_4$}&\\qw \\gateinput[label style=black]{1} &\\qw &\\ctrl{-2}&\\qw &\\ctrl{-3}&\\octrl{-1}&\\qw &\\qw \\gateinput[label style=black]{3} &\\qw &\\qw & \\\\\n\\lstick{$q_5$}&\\octrl{-1}&\\qw &\\qw &\\targ{}&\\ctrl{-1}&\\qw &\\targX{}&\\qw &\\targX{}&\\qw & \\\\\n\\\\\n\\lstick{$q_0$}&\\gate[5,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{$\\mathbb{R}\\text{vrs}$}}\\gateinput[label style=black]{0}&\\qw &\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{QFT}}\\gateinput[label style=black]{2}&\\ctrl{1}&\\gate[2,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{JoS}}\\gateinput[label style=black]{0}&\\octrl{2}&\\ctrl{1}&\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{WoW}}\\gateinput[label style=black]{1}&\\ctrl{1}&\\qw & \\\\\n\\lstick{$q_1$}&\\qw \\gateinput[label style=black]{2} &\\gate[5,style={draw=black,fill=white!20},label style=black]{\\makebox[6em]{$\\mathbb{P}\\text{rmt}$}}\\gateinput[label style=black]{$q_5$}&\\qw &\\ctrl{1}&\\qw \\gateinput[label style=black]{1}&\\qw &\\gate[3,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{JoS}}\\gateinput[label style=black]{0}&\\qw \\gateinput[label style=black]{2} &\\gate[5,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{WoW}}\\gateinput[label style=black]{0}&\\qw & \\\\\n\\lstick{$q_2$}&\\qw \\gateinput{$\\bullet$} &\\qw &\\qw \\gateinput[label style=black]{0}&\\gate[3,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{QFT}}\\gateinput[label style=black]{1}&\\qw &\\gate[2,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{JoS}}\\gateinput[label style=black]{1}&\\qw \\gateinput{$\\circ$} &\\qw \\gateinput{$\\circ$} &\\qw \\gateinput[label style=black]{1} &\\qw & \\\\\n\\lstick{$q_3$}&\\qw &\\qw \\gateinput[label style=black]{$q_3$}&\\qw \\gateinput[label style=black]{1}&\\qw \\gateinput[label style=black]{2} &\\qw &\\qw \\gateinput[label style=black]{0} &\\qw \\gateinput[label style=black]{1} &\\qw \\gateinput[label style=black]{0} &\\qw \\gateinput{$\\circ$} &\\qw & \\\\\n\\lstick{$q_4$}&\\qw \\gateinput[label style=black]{1} &\\qw &\\gate[2,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{QFT$^\\dagger$}}\\gateinput[label style=black]{0}&\\qw \\gateinput[label style=black]{0} &\\qw &\\ctrl{-1}&\\qw &\\ctrl{-1}&\\qw &\\qw & \\\\\n\\lstick{$q_5$}&\\octrl{-1}&\\qw \\gateinput[label style=black]{$q_1$}&\\qw \\gateinput[label style=black]{1}&\\octrl{-1}&\\qw &\\qw &\\qw &\\qw &\\qw \\gateinput[label style=black]{2} &\\qw & \\\\\n\\\\\n\\lstick{$q_0$}&\\octrl{1}&\\qw &\\qw &\\octrl{2}&\\qw &\\qw &\\qw &\\push{\\textcolor{black}{\\textcircled{\\raisebox{-0.2ex}{0}}}}&\\qw &\\qw & \\\\\n\\lstick{$q_1$}&\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{geqo}}\\gateinput[label style=black]{2}&\\gate[4,style={draw=black,fill=white!20},label style=black]{PCCM(p)}\\gateinput[label style=black]{1}&\\gate[2,style={draw=black,fill=white!20},label style=black]{PCCM^\\dagger(o)}\\gateinput[label style=black]{0}&\\qw &\\qw &\\qw &\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{set1}}\\gateinput[label style=black]{0}&\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_2$}&\\qw \\gateinput{$\\bullet$} &\\qw &\\qw \\gateinput[label style=black]{1}&\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[8.5em]{PCCM$^\\dagger$(s)}}\\gateinput[label style=black]{0}&\\ctrl{1}&\\push{\\text{\\Large \\textcolor{black}{X}}}&\\qw &\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{set3}&\\qw & \\\\\n\\lstick{$q_3$}&\\qw \\gateinput[label style=black]{1} &\\qw &\\qw &\\qw \\gateinput{$\\bullet$} &\\gate[3,style={draw=black,fill=white!20},label style=black]{\\makebox[6em]{$\\mathbb{P}\\text{rmt}$}}\\gateinput[label style=black]{$q_4$}&\\qw &\\qw \\gateinput[label style=black]{1}&\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_4$}&\\qw \\gateinput[label style=black]{0} &\\qw \\gateinput[label style=black]{0}&\\qw &\\qw &\\qw \\gateinput[label style=black]{$q_3$} &\\push{\\text{\\Large \\textcolor{black}{X}}}&\\qw \\gateinput[label style=black]{2}&\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_5$}&\\ctrl{-1}&\\qw &\\qw &\\qw \\gateinput[label style=black]{1} &\\qw \\gateinput[label style=black]{$q_5$} &\\qw &\\qw &\\push{\\textcolor{black}{\\textcircled{\\raisebox{-0.2ex}{1}}}}&\\qw &\\qw & \\\\\n\\\\\n\\lstick{$q_0$}&\\qw &\\qw &\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{$\\rho[d]$}}\\gateinput[label style=black]{0}&\\qw &\\qw &\\qw &\\gate[6,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{JoS}}\\gateinput[label style=black]{0}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw &\\meter[style={draw=black,fill=white!20}]{0}&\\qw & \\\\\n\\lstick{$q_1$}&\\gate[5,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{sq}}\\gateinput[label style=black]{0}&\\qw &\\qw &\\qw &\\qw &\\qw &\\qw &\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_2$}&\\qw &\\qw &\\qw \\gateinput[label style=black]{2}&\\qw &\\ctrl{2}&\\qw &\\qw &\\gate[1,style={draw=black,fill=white!20},label style=black]{\\makebox[4.5em]{H}}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\meter[style={draw=black,fill=white!20}]{2}&\\qw & \\\\\n\\lstick{$q_3$}&\\qw &\\push{\\text{\\Large \\textcolor{black}{$\\ket{1}$}}}&\\qw \\gateinput[label style=black]{1}&\\gate[style={draw=black,fill=white!20},label style=black]{H}&\\qw &\\swap{1}&\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\qw &\\meter[style={draw=black,fill=white!20}]{3}&\\qw & \\\\\n\\lstick{$q_4$}&\\qw \\gateinput[label style=black]{1}&\\qw &\\qw &\\qw &\\targ{}&\\targX{}&\\qw \\gateinput[label style=black]{1}&\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_5$}&\\qw \\gateinput[label style=black]{2}&\\gate[style={draw=black,fill=white!20},label style=black]{\\rho[d222]}&\\qw &\\qw &\\qw &\\qw &\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw &\\meter[style={draw=black,fill=white!20}]{5}&\\qw & \\\\\n\\\\\n\\lstick{$q_0$}&\\octrl{1}&\\qw &\\ctrl{2}&\\octrl{1}&\\gate[5,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{X}}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{X}}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[4.5em]{X}}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\qw &\\gate[6,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{CCX}}\\gateinput[label style=black]{1}&\\qw & \\\\\n\\lstick{$q_1$}&\\ctrl{1}&\\targ{}&\\qw &\\ctrl{1}&\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw &\\qw &\\qw &\\qw \\gateinput[label style=black]{0}&\\qw & \\\\\n\\lstick{$q_2$}&\\ctrl{1}&\\ctrl{-1}&\\targ{}&\\targ{}&\\qw &\\qw \\gateinput[label style=black]{0}&\\qw &\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{CX}}\\gateinput[label style=black]{1}&\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\qw & \\\\\n\\lstick{$q_3$}&\\octrl{1}&\\qw &\\ctrl{-1}&\\ctrl{-1}&\\qw &\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw &\\qw & \\\\\n\\lstick{$q_4$}&\\gate[2,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{JoS}}\\gateinput[label style=black]{0}&\\ctrl{-2}&\\qw &\\qw &\\qw \\gateinput[label style=black]{0}&\\qw &\\qw &\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_5$}&\\qw \\gateinput[label style=black]{1} &\\qw &\\octrl{-2}&\\qw &\\qw &\\qw &\\qw &\\qw \\gateinput[label style=black]{0}&\\qw \\gateinput[label style=black]{2}&\\qw & \\\\\n\\\\\n\\lstick{$q_0$}&\\qw &\\gate[6,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{QFT}}\\gateinput[label style=black]{0}&\\gate[6,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{QFT}}\\gateinput[label style=black]{$\\bullet$}&\\gate[6,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{QFT}}\\gateinput[label style=black]{$\\bullet$}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\gate[6,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{H}}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{H}}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\push{\\text{\\Large \\textcolor{black}{X}}}&\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_1$}&\\gate[3,style={draw=black,fill=white!20},label style=black]{\\makebox[6em]{SWAP}}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\qw \\gateinput[label style=black]{$\\bullet$}&\\qw \\gateinput[label style=black]{0} \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw \\gateinput[label style=black]{0}&\\qw &\\qw &\\qw &\\qw &\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{S$^\\dagger$}}\\gateinput[label style=black]{0}&\\qw & \\\\\n\\lstick{$q_2$}&\\qw \\gateinput[label style=black]{0}&\\qw \\gateinput[label style=black]{$\\circ$} \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw \\gateinput[label style=black]{$\\circ$}&\\qw \\gateinput[label style=black]{$\\circ$}&\\qw &\\qw &\\qw &\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_3$}&\\qw \\gateinput[label style=black]{1}&\\qw \\gateinput[label style=black]{$\\bullet$}&\\qw \\gateinput[label style=black]{$\\bullet$} \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\qw \\gateinput[label style=black]{$\\bullet$} \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\qw \\gateinput[label style=black]{0} \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\meter[style={draw=black,fill=white!20}]{4}&\\ctrl{2}&\\qw &\\qw & \\\\\n\\lstick{$q_4$}&\\qw &\\qw \\gateinput[label style=black]{1} \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\qw \\gateinput[label style=black]{1}&\\qw \\gateinput[label style=black]{1}&\\qw &\\qw &\\qw &\\qw &\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\qw & \\\\\n\\lstick{$q_5$}&\\qw &\\qw \\gateinput[label style=black]{2}&\\qw \\gateinput[label style=black]{2}&\\qw \\gateinput[label style=black]{2}&\\qw \\gateinput[label style=black]{0}&\\qw &\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{S}&\\qw &\\qw & \\\\\n\\\\\n\\lstick{$q_0$}&\\gate[3,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{P(nu)}}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\gate[1,style={draw=black,fill=white!20},label style=black]{\\makebox[4.5em]{Rx(nu)}}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw &\\qw & \\\\\n\\lstick{$q_1$}&\\qw &\\qw &\\gate[3,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{Rz(nu)}}\\gateinput[label style=black]{0}&\\qw & \\\\\n\\lstick{$q_2$}&\\qw \\gateinput[label style=black]{0}&\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{Ry(nu)}}\\gateinput[label style=black]{0}&\\qw &\\qw & \\\\\n\\lstick{$q_3$}&\\qw &\\qw &\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw & \\\\\n\\lstick{$q_4$}&\\qw &\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_5$}&\\qw &\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw &\\qw & \\\\\n\\end{quantikz}"

        assert code == expect

    def test_plot_latex_no_backend_no_greek(self):
        code = tolatex(
            seq,
            backend=None,
            decompose_subseq=False,
            pack=False,
            fold=13,
            greek_symbol=False,
            filename=None,
            return_quantikz=None,
        )

        expect = "\\begin{quantikz}[color=black,background color=white]\n\\lstick{$q_0$}&\\gate[style={draw=black,fill=white!20},label style=black]{sin}&\\qw &\\qw &\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{H}&\\qw &\\qw &\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{P^\\dagger(be)}&\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{Rx(ga)}&\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_1$}&\\qw &\\qw &\\qw &\\qw &\\qw &\\qw &\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{P(al)}&\\qw &\\octrl{3}&\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{Ry(la)}&\\qw &\\qw & \\\\\n\\lstick{$q_2$}&\\qw &\\qw &\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{X}&\\qw &\\qw &\\qw &\\qw &\\qw &\\qw &\\qw &\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{Rz(ka)}&\\qw & \\\\\n\\lstick{$q_3$}&\\qw &\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{Y}&\\qw &\\octrl{-3}&\\qw &\\qw &\\qw &\\qw &\\qw &\\qw &\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_4$}&\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{Z}&\\qw &\\qw &\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{S}&\\qw &\\qw &\\qw &\\ctrl{1}&\\qw &\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_5$}&\\qw &\\qw &\\qw &\\qw &\\qw &\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{S^\\dagger}&\\qw &\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{P(de)}&\\qw &\\qw &\\qw &\\qw & \\\\\n\\\\\n\\lstick{$q_0$}&\\qw &\\qw &\\qw &\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{Rz^\\dagger(z)}&\\qw &\\octrl{1}&\\targ{}&\\ctrl{2}&\\qw &\\qw &\\octrl{1}&\\qw &\\qw & \\\\\n\\lstick{$q_1$}&\\gate[style={draw=black,fill=white!20},label style=black]{Rx(al)}&\\gate[style={draw=black,fill=white!20},label style=black]{Ry^\\dagger(al)}&\\gate[style={draw=black,fill=white!20},label style=black]{Rz(si)}&\\qw &\\qw &\\qw &\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{Rzz(nu)}}\\gateinput[label style=black]{0}&\\qw &\\qw &\\ctrl{2}&\\targ{}&\\ctrl{2}&\\qw &\\qw & \\\\\n\\lstick{$q_2$}&\\qw &\\qw &\\qw &\\qw &\\qw &\\qw &\\qw &\\qw &\\targ{}&\\qw &\\qw &\\qw &\\swap{3}&\\qw & \\\\\n\\lstick{$q_3$}&\\qw &\\qw &\\qw &\\qw &\\qw &\\gate[3,style={draw=black,fill=white!20},label style=black]{Rzz^\\dagger(g)}\\gateinput[label style=black]{1}&\\qw \\gateinput{$\\bullet$} &\\ctrl{-3}&\\qw &\\ctrl{2}&\\qw &\\targ{}&\\qw &\\qw & \\\\\n\\lstick{$q_4$}&\\octrl{-3}&\\ctrl{-3}&\\ctrl{-3}&\\qw &\\qw &\\qw &\\qw \\gateinput[label style=black]{1} &\\qw &\\ctrl{-2}&\\qw &\\ctrl{-3}&\\octrl{-1}&\\qw &\\qw & \\\\\n\\lstick{$q_5$}&\\qw &\\qw &\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{Rx^\\dagger(x)}&\\qw &\\qw \\gateinput[label style=black]{0}&\\octrl{-1}&\\qw &\\qw &\\targ{}&\\ctrl{-1}&\\qw &\\targX{}&\\qw & \\\\\n\\\\\n\\lstick{$q_0$}&\\gate[5,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{$\\mathbb{R}\\text{vrs}$}}\\gateinput[label style=black]{2}&\\ctrl{5}&\\gate[5,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{$\\mathbb{R}\\text{vrs}$}}\\gateinput[label style=black]{0}&\\qw &\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{QFT}}\\gateinput[label style=black]{2}&\\qw &\\ctrl{1}&\\gate[2,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{JoS}}\\gateinput[label style=black]{0}&\\octrl{2}&\\ctrl{1}&\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{WoW}}\\gateinput[label style=black]{1}&\\ctrl{1}&\\octrl{1}&\\qw & \\\\\n\\lstick{$q_1$}&\\qw \\gateinput[label style=black]{4} &\\qw &\\qw \\gateinput[label style=black]{2} &\\gate[5,style={draw=black,fill=white!20},label style=black]{\\makebox[6em]{$\\mathbb{P}\\text{rmt}$}}\\gateinput[label style=black]{$q_5$}&\\qw &\\qw &\\ctrl{1}&\\qw \\gateinput[label style=black]{1}&\\qw &\\gate[3,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{JoS}}\\gateinput[label style=black]{0}&\\qw \\gateinput[label style=black]{2} &\\gate[5,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{WoW}}\\gateinput[label style=black]{0}&\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{geqo}}\\gateinput[label style=black]{2}&\\qw & \\\\\n\\lstick{$q_2$}&\\qw \\gateinput[label style=black]{0} &\\targX{}&\\qw \\gateinput{$\\bullet$} &\\qw &\\qw \\gateinput[label style=black]{0}&\\qw &\\gate[3,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{QFT}}\\gateinput[label style=black]{1}&\\qw &\\gate[2,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{JoS}}\\gateinput[label style=black]{1}&\\qw \\gateinput{$\\circ$} &\\qw \\gateinput{$\\circ$} &\\qw \\gateinput[label style=black]{1} &\\qw \\gateinput{$\\bullet$} &\\qw & \\\\\n\\lstick{$q_3$}&\\qw \\gateinput[label style=black]{1} &\\ocontrol{}&\\qw &\\qw \\gateinput[label style=black]{$q_3$}&\\qw \\gateinput[label style=black]{1}&\\qw &\\qw \\gateinput[label style=black]{2} &\\qw &\\qw \\gateinput[label style=black]{0} &\\qw \\gateinput[label style=black]{1} &\\qw \\gateinput[label style=black]{0} &\\qw \\gateinput{$\\circ$} &\\qw \\gateinput[label style=black]{1} &\\qw & \\\\\n\\lstick{$q_4$}&\\qw \\gateinput[label style=black]{3} &\\qw &\\qw \\gateinput[label style=black]{1} &\\qw &\\qw &\\gate[2,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{QFT$^\\dagger$}}\\gateinput[label style=black]{0}&\\qw \\gateinput[label style=black]{0} &\\qw &\\ctrl{-1}&\\qw &\\ctrl{-1}&\\qw &\\qw \\gateinput[label style=black]{0} &\\qw & \\\\\n\\lstick{$q_5$}&\\qw &\\targX{}&\\octrl{-1}&\\qw \\gateinput[label style=black]{$q_1$}&\\qw &\\qw \\gateinput[label style=black]{1}&\\octrl{-1}&\\qw &\\qw &\\qw &\\qw &\\qw \\gateinput[label style=black]{2} &\\ctrl{-1}&\\qw & \\\\\n\\\\\n\\lstick{$q_0$}&\\qw &\\qw &\\octrl{2}&\\qw &\\qw &\\qw &\\gate[6,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{set2}}\\gateinput[label style=black]{0}&\\qw &\\qw &\\qw &\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{$\\rho[d]$}}\\gateinput[label style=black]{0}&\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_1$}&\\gate[4,style={draw=black,fill=white!20},label style=black]{PCCM(p)}\\gateinput[label style=black]{1}&\\gate[2,style={draw=black,fill=white!20},label style=black]{PCCM^\\dagger(o)}\\gateinput[label style=black]{0}&\\qw &\\qw &\\qw &\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{set1}}\\gateinput[label style=black]{0}&\\qw &\\qw &\\gate[5,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{sq}}\\gateinput[label style=black]{0}&\\qw &\\qw &\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_2$}&\\qw &\\qw \\gateinput[label style=black]{1}&\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[8.5em]{PCCM$^\\dagger$(s)}}\\gateinput[label style=black]{0}&\\ctrl{1}&\\push{\\text{\\Large \\textcolor{black}{X}}}&\\qw &\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{set3}&\\qw &\\qw &\\qw \\gateinput[label style=black]{2}&\\qw &\\gate[3,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{sbsq}}\\gateinput[label style=black]{1}&\\qw & \\\\\n\\lstick{$q_3$}&\\qw &\\qw &\\qw \\gateinput{$\\bullet$} &\\gate[3,style={draw=black,fill=white!20},label style=black]{\\makebox[6em]{$\\mathbb{P}\\text{rmt}$}}\\gateinput[label style=black]{$q_4$}&\\qw &\\qw \\gateinput[label style=black]{1}&\\qw &\\qw &\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{sq2}&\\qw \\gateinput[label style=black]{1}&\\qw &\\qw \\gateinput[label style=black]{2}&\\qw & \\\\\n\\lstick{$q_4$}&\\qw \\gateinput[label style=black]{0}&\\qw &\\qw &\\qw \\gateinput[label style=black]{$q_3$} &\\push{\\text{\\Large \\textcolor{black}{X}}}&\\qw \\gateinput[label style=black]{2}&\\qw &\\qw &\\qw \\gateinput[label style=black]{1}&\\qw &\\qw &\\qw &\\qw \\gateinput[label style=black]{0}&\\qw & \\\\\n\\lstick{$q_5$}&\\qw &\\qw &\\qw \\gateinput[label style=black]{1} &\\qw \\gateinput[label style=black]{$q_5$} &\\qw &\\qw &\\qw \\gateinput[label style=black]{1}&\\qw &\\qw \\gateinput[label style=black]{2}&\\qw &\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{\\rho[d222]}&\\qw &\\qw & \\\\\n\\\\\n\\lstick{$q_0$}&\\gate[6,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{JoS}}\\gateinput[label style=black]{0}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw &\\meter[style={draw=black,fill=white!20}]{0}&\\octrl{1}&\\qw &\\ctrl{2}&\\octrl{1}&\\gate[5,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{X}}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{X}}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[4.5em]{X}}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\qw &\\gate[6,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{CCX}}\\gateinput[label style=black]{1}&\\qw &\\qw & \\\\\n\\lstick{$q_1$}&\\qw &\\qw &\\qw &\\ctrl{1}&\\targ{}&\\qw &\\ctrl{1}&\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw &\\qw &\\qw &\\qw \\gateinput[label style=black]{0}&\\gate[3,style={draw=black,fill=white!20},label style=black]{\\makebox[6em]{SWAP}}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\qw & \\\\\n\\lstick{$q_2$}&\\qw &\\gate[1,style={draw=black,fill=white!20},label style=black]{\\makebox[4.5em]{H}}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\meter[style={draw=black,fill=white!20}]{2}&\\ctrl{1}&\\ctrl{-1}&\\targ{}&\\targ{}&\\qw &\\qw \\gateinput[label style=black]{0}&\\qw &\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{CX}}\\gateinput[label style=black]{1}&\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\qw \\gateinput[label style=black]{0}&\\qw & \\\\\n\\lstick{$q_3$}&\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\qw &\\meter[style={draw=black,fill=white!20}]{3}&\\octrl{1}&\\qw &\\ctrl{-1}&\\ctrl{-1}&\\qw &\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw &\\qw \\gateinput[label style=black]{1}&\\qw & \\\\\n\\lstick{$q_4$}&\\qw \\gateinput[label style=black]{1}&\\qw &\\qw &\\gate[2,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{JoS}}\\gateinput[label style=black]{0}&\\ctrl{-2}&\\qw &\\qw &\\qw \\gateinput[label style=black]{0}&\\qw &\\qw &\\qw &\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_5$}&\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw &\\meter[style={draw=black,fill=white!20}]{5}&\\qw \\gateinput[label style=black]{1} &\\qw &\\octrl{-2}&\\qw &\\qw &\\qw &\\qw &\\qw \\gateinput[label style=black]{0}&\\qw \\gateinput[label style=black]{2}&\\qw &\\qw & \\\\\n\\\\\n\\lstick{$q_0$}&\\gate[6,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{QFT}}\\gateinput[label style=black]{0}&\\gate[6,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{QFT}}\\gateinput[label style=black]{$\\bullet$}&\\gate[6,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{QFT}}\\gateinput[label style=black]{$\\bullet$}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\gate[6,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{H}}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{H}}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw &\\push{\\text{\\Large \\textcolor{black}{X}}}&\\qw &\\qw &\\gate[3,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{P(nu)}}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\gate[1,style={draw=black,fill=white!20},label style=black]{\\makebox[4.5em]{Rx(nu)}}\\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_1$}&\\qw \\gateinput[label style=black]{$\\bullet$}&\\qw \\gateinput[label style=black]{0} \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw \\gateinput[label style=black]{0}&\\qw &\\qw &\\qw &\\qw &\\qw &\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{S$^\\dagger$}}\\gateinput[label style=black]{0}&\\qw &\\qw &\\qw &\\gate[3,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{Rz(nu)}}\\gateinput[label style=black]{0}&\\qw & \\\\\n\\lstick{$q_2$}&\\qw \\gateinput[label style=black]{$\\circ$} \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw \\gateinput[label style=black]{$\\circ$}&\\qw \\gateinput[label style=black]{$\\circ$}&\\qw &\\qw &\\qw &\\qw &\\qw &\\qw &\\qw \\gateinput[label style=black]{0}&\\qw &\\gate[4,style={draw=black,fill=white!20},label style=black]{\\makebox[3.5em]{Ry(nu)}}\\gateinput[label style=black]{0}&\\qw &\\qw & \\\\\n\\lstick{$q_3$}&\\qw \\gateinput[label style=black]{$\\bullet$}&\\qw \\gateinput[label style=black]{$\\bullet$} \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\qw \\gateinput[label style=black]{$\\bullet$} \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\qw \\gateinput[label style=black]{0} \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\meter[style={draw=black,fill=white!20}]{4}&\\qw &\\ctrl{2}&\\qw &\\qw &\\qw &\\qw &\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw & \\\\\n\\lstick{$q_4$}&\\qw \\gateinput[label style=black]{1} \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\qw \\gateinput[label style=black]{1}&\\qw \\gateinput[label style=black]{1}&\\qw &\\qw &\\qw &\\qw &\\qw &\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{0}}}&\\qw &\\qw &\\qw &\\qw &\\qw & \\\\\n\\lstick{$q_5$}&\\qw \\gateinput[label style=black]{2}&\\qw \\gateinput[label style=black]{2}&\\qw \\gateinput[label style=black]{2}&\\qw \\gateinput[label style=black]{0}&\\qw &\\qw &\\qw &\\gate[style={draw=black,fill=white!20},label style=black]{S}&\\qw &\\qw &\\qw &\\qw \\gateoutput[label style=black]{\\textcircled{\\raisebox{-0.2ex}{1}}}&\\qw &\\qw & \\\\\n\\end{quantikz}"

        assert code == expect

    def test_quantum_control_non_unitary(self):
        non_unitaries = [
            Measure(2),
            DropQubits(2),
            SetBits("s", 2),
            SetQubits("s", 2),
            SetDensityMatrix("d", 2),
        ]
        non_unitary = random.choice(non_unitaries)
        op = QuantumControl([0], non_unitary)
        with pytest.raises(
            TypeError,
            match="Non-unitary operations are not eligible targets for Quantum or ClassicalControl",
        ):
            seq = Sequence([0, 1, 2], [0, 1, 2], [(op, [0, 1, 2])])
            tolatex(seq)

    """def test_plot_latex_saves_file(self):
        test_file = "test_plot_output"
        try:
            plot_latex(seq, filename=test_file)
            assert os.path.exists(f"{test_file}.png")
        finally:
            if os.path.exists(f"{test_file}.png"):
                os.remove(f"{test_file}.png")"""
