diff --git a/qiskit/visualization/latex.py b/qiskit/visualization/latex.py index 654b472d617f..9da818c5b3bf 100644 --- a/qiskit/visualization/latex.py +++ b/qiskit/visualization/latex.py @@ -320,7 +320,7 @@ def _get_image_depth(self): # which take 4 columns base_type = None if not hasattr(op, "base_gate") else op.base_gate if isinstance(op, RZZGate) or isinstance(base_type, (U1Gate, PhaseGate, RZZGate)): - column_width = 4 + column_width = 5 max_column_widths.append(current_max) columns += column_width @@ -520,8 +520,13 @@ def _build_symmetric_gate(self, op, gate_text, wire_list, col): ) self._latex[wire_last][col] = "\\control \\qw" # Put side text to the right between bottom wire in wire_list and the one above it - self._latex[wire_max - 1][col + 1] = "\\dstick{\\hspace{2.0em}%s} \\qw" % gate_text - return 4 # num_cols for side text gates + self._latex[wire_max][ + col + ] += " \\cds{-1}{\\hspace{0.5em}\\hphantom{\\ensuremath{%s}}" "\\ensuremath{%s}}" % ( + gate_text, + gate_text, + ) + return 5 # num_cols for side text gates def _build_measure(self, node, col): """Build a meter and the lines to the creg""" diff --git a/test/python/visualization/references/test_latex_cswap_rzz.tex b/test/python/visualization/references/test_latex_cswap_rzz.tex index 2ab50b9d5f15..3c967045a943 100644 --- a/test/python/visualization/references/test_latex_cswap_rzz.tex +++ b/test/python/visualization/references/test_latex_cswap_rzz.tex @@ -6,10 +6,10 @@ \begin{document} \scalebox{1.0}{ \Qcircuit @C=1.0em @R=0.2em @!R { \\ - \nghost{{q}_{0} : } & \lstick{{q}_{0} : } & \gate{\mathrm{X}} & \ctrl{1} & \control \qw & \qw & \qw & \qw & \qw & \qw\\ - \nghost{{q}_{1} : } & \lstick{{q}_{1} : } & \gate{\mathrm{X}} & \qswap & \ctrl{-1} & \qw & \qw & \qw & \qw & \qw\\ - \nghost{{q}_{2} : } & \lstick{{q}_{2} : } & \qw & \qswap \qwx[-1] & \ctrlo{-1} & \qw & \qw & \qw & \qw & \qw\\ - \nghost{{q}_{3} : } & \lstick{{q}_{3} : } & \qw & \qw & \ctrl{-3} & \dstick{\hspace{2.0em}\mathrm{ZZ}\,(\mathrm{\frac{3\pi}{4}})} \qw & \qw & \qw & \qw & \qw\\ - \nghost{{q}_{4} : } & \lstick{{q}_{4} : } & \qw & \qw & \ctrlo{-1} & \qw & \qw & \qw & \qw & \qw\\ + \nghost{{q}_{0} : } & \lstick{{q}_{0} : } & \gate{\mathrm{X}} & \ctrl{1} & \control \qw & \qw & \qw & \qw & \qw & \qw & \qw\\ + \nghost{{q}_{1} : } & \lstick{{q}_{1} : } & \gate{\mathrm{X}} & \qswap & \ctrl{-1} & \qw & \qw & \qw & \qw & \qw & \qw\\ + \nghost{{q}_{2} : } & \lstick{{q}_{2} : } & \qw & \qswap \qwx[-1] & \ctrlo{-1} & \qw & \qw & \qw & \qw & \qw & \qw\\ + \nghost{{q}_{3} : } & \lstick{{q}_{3} : } & \qw & \qw & \ctrl{-3} & \qw & \qw & \qw & \qw & \qw & \qw\\ + \nghost{{q}_{4} : } & \lstick{{q}_{4} : } & \qw & \qw & \ctrlo{-1} \cds{-1}{\hspace{0.5em}\hphantom{\ensuremath{\mathrm{ZZ}\,(\mathrm{\frac{3\pi}{4}})}}\ensuremath{\mathrm{ZZ}\,(\mathrm{\frac{3\pi}{4}})}} & \qw & \qw & \qw & \qw & \qw & \qw\\ \\ }} \end{document} \ No newline at end of file diff --git a/test/python/visualization/references/test_latex_iqx.tex b/test/python/visualization/references/test_latex_iqx.tex index 6dd70d09a005..98a674836d23 100644 --- a/test/python/visualization/references/test_latex_iqx.tex +++ b/test/python/visualization/references/test_latex_iqx.tex @@ -6,12 +6,12 @@ \begin{document} \scalebox{1.0}{ \Qcircuit @C=1.0em @R=0.2em @!R { \\ - \nghost{{q}_{0} : } & \lstick{{q}_{0} : } & \gate{\mathrm{H}} & \gate{\mathrm{X}} & \qw & \qw & \qw & \ctrl{1} & \ctrl{1} & \qswap & \ctrl{1} & \ctrl{1} & \multigate{1}{\mathrm{Dcx}}_<<<{0} & \ctrl{1} & \ctrl{1} & \qw & \qw\\ - \nghost{{q}_{1} : } & \lstick{{q}_{1} : } & \qw & \qw & \qw & \qw & \qw & \targ & \ctrl{1} & \qswap \qwx[-1] & \qswap & \ctrl{1} & \ghost{\mathrm{Dcx}}_<<<{1} & \multigate{1}{\mathrm{Dcx}}_<<<{0} & \ctrl{1} & \qw & \qw\\ - \nghost{{q}_{2} : } & \lstick{{q}_{2} : } & \qw & \qw & \qw & \qw & \qw & \qw & \targ & \qw & \qswap \qwx[-1] & \qswap & \qw & \ghost{\mathrm{Dcx}}_<<<{1} & \multigate{1}{\mathrm{Dcx}}_<<<{0} & \qw & \qw\\ - \nghost{{q}_{3} : } & \lstick{{q}_{3} : } & \qw & \qw & \qw & \qw & \qw & \qw & \qw & \qw & \qw & \qswap \qwx[-1] & \qw & \qw & \ghost{\mathrm{Dcx}}_<<<{1} & \qw & \qw\\ - \nghost{{q}_{4} : } & \lstick{{q}_{4} : } & \gate{\mathrm{Z}} & \gate{\mathrm{S}} & \qw & \qw & \qw & \gate{\mathrm{S^\dagger}} & \gate{\mathrm{T}} & \gate{\mathrm{T^\dagger}} & \gate{\mathrm{P}\,(\mathrm{\frac{\pi}{2}})} & \gate{\mathrm{P}\,(\mathrm{\frac{\pi}{2}})} & \qw & \qw & \qw & \qw & \qw\\ - \nghost{{q}_{5} : } & \lstick{{q}_{5} : } & \ctrl{1} & \ctrl{1} & \dstick{\hspace{2.0em}\mathrm{P}\,(\mathrm{\frac{\pi}{2}})} \qw & \qw & \qw & \gate{\mathrm{Y}} & \gate{\mathrm{R_X}\,(\mathrm{\frac{\pi}{3}})} & \multigate{1}{\mathrm{R_{ZX}}\,(\mathrm{\frac{\pi}{2}})}_<<<{0} & \gate{\mathrm{U}\,(\mathrm{\frac{\pi}{2},\frac{\pi}{2},\frac{\pi}{2}})} \barrier[0em]{1} & \qw & \gate{\mathrm{\left|0\right\rangle}} & \qw & \qw & \qw & \qw\\ - \nghost{{q}_{6} : } & \lstick{{q}_{6} : } & \control\qw & \control \qw & \qw & \qw & \qw & \qw & \qw & \ghost{\mathrm{R_{ZX}}\,(\mathrm{\frac{\pi}{2}})}_<<<{1} & \qw & \qw & \qw & \qw & \qw & \qw & \qw\\ + \nghost{{q}_{0} : } & \lstick{{q}_{0} : } & \gate{\mathrm{H}} & \gate{\mathrm{X}} & \qw & \qw & \qw & \qw & \ctrl{1} & \ctrl{1} & \qswap & \ctrl{1} & \ctrl{1} & \multigate{1}{\mathrm{Dcx}}_<<<{0} & \ctrl{1} & \ctrl{1} & \qw & \qw\\ + \nghost{{q}_{1} : } & \lstick{{q}_{1} : } & \qw & \qw & \qw & \qw & \qw & \qw & \targ & \ctrl{1} & \qswap \qwx[-1] & \qswap & \ctrl{1} & \ghost{\mathrm{Dcx}}_<<<{1} & \multigate{1}{\mathrm{Dcx}}_<<<{0} & \ctrl{1} & \qw & \qw\\ + \nghost{{q}_{2} : } & \lstick{{q}_{2} : } & \qw & \qw & \qw & \qw & \qw & \qw & \qw & \targ & \qw & \qswap \qwx[-1] & \qswap & \qw & \ghost{\mathrm{Dcx}}_<<<{1} & \multigate{1}{\mathrm{Dcx}}_<<<{0} & \qw & \qw\\ + \nghost{{q}_{3} : } & \lstick{{q}_{3} : } & \qw & \qw & \qw & \qw & \qw & \qw & \qw & \qw & \qw & \qw & \qswap \qwx[-1] & \qw & \qw & \ghost{\mathrm{Dcx}}_<<<{1} & \qw & \qw\\ + \nghost{{q}_{4} : } & \lstick{{q}_{4} : } & \gate{\mathrm{Z}} & \gate{\mathrm{S}} & \qw & \qw & \qw & \qw & \gate{\mathrm{S^\dagger}} & \gate{\mathrm{T}} & \gate{\mathrm{T^\dagger}} & \gate{\mathrm{P}\,(\mathrm{\frac{\pi}{2}})} & \gate{\mathrm{P}\,(\mathrm{\frac{\pi}{2}})} & \qw & \qw & \qw & \qw & \qw\\ + \nghost{{q}_{5} : } & \lstick{{q}_{5} : } & \ctrl{1} & \ctrl{1} & \qw & \qw & \qw & \qw & \gate{\mathrm{Y}} & \gate{\mathrm{R_X}\,(\mathrm{\frac{\pi}{3}})} & \multigate{1}{\mathrm{R_{ZX}}\,(\mathrm{\frac{\pi}{2}})}_<<<{0} & \gate{\mathrm{U}\,(\mathrm{\frac{\pi}{2},\frac{\pi}{2},\frac{\pi}{2}})} \barrier[0em]{1} & \qw & \gate{\mathrm{\left|0\right\rangle}} & \qw & \qw & \qw & \qw\\ + \nghost{{q}_{6} : } & \lstick{{q}_{6} : } & \control\qw & \control \qw \cds{-1}{\hspace{0.5em}\hphantom{\ensuremath{\mathrm{P}\,(\mathrm{\frac{\pi}{2}})}}\ensuremath{\mathrm{P}\,(\mathrm{\frac{\pi}{2}})}} & \qw & \qw & \qw & \qw & \qw & \qw & \ghost{\mathrm{R_{ZX}}\,(\mathrm{\frac{\pi}{2}})}_<<<{1} & \qw & \qw & \qw & \qw & \qw & \qw & \qw\\ \\ }} \end{document} \ No newline at end of file diff --git a/test/python/visualization/references/test_latex_r_gates.tex b/test/python/visualization/references/test_latex_r_gates.tex index aa50c0cb1764..fe817fe77c07 100644 --- a/test/python/visualization/references/test_latex_r_gates.tex +++ b/test/python/visualization/references/test_latex_r_gates.tex @@ -6,9 +6,9 @@ \begin{document} \scalebox{1.0}{ \Qcircuit @C=1.0em @R=0.2em @!R { \\ - \nghost{{q}_{0} : } & \lstick{{q}_{0} : } & \gate{\mathrm{R}\,(\mathrm{\frac{3\pi}{4},\frac{3\pi}{8}})} & \multigate{1}{\mathrm{R_{XX}}\,(\mathrm{\frac{\pi}{2}})}_<<<{0} & \multigate{1}{\mathrm{R_{ZX}}\,(\mathrm{\frac{-\pi}{2}})}_<<<{0} & \qw & \qw & \qw & \qw & \qw\\ - \nghost{{q}_{1} : } & \lstick{{q}_{1} : } & \gate{\mathrm{R_X}\,(\mathrm{\frac{\pi}{2}})} & \ghost{\mathrm{R_{XX}}\,(\mathrm{\frac{\pi}{2}})}_<<<{1} & \ghost{\mathrm{R_{ZX}}\,(\mathrm{\frac{-\pi}{2}})}_<<<{1} & \qw & \qw & \qw & \qw & \qw\\ - \nghost{{q}_{2} : } & \lstick{{q}_{2} : } & \gate{\mathrm{R_Y}\,(\mathrm{\frac{-\pi}{2}})} & \multigate{1}{\mathrm{R_{YY}}\,(\mathrm{\frac{3\pi}{4}})}_<<<{0} & \ctrl{1} & \dstick{\hspace{2.0em}\mathrm{ZZ}\,(\mathrm{\frac{\pi}{2}})} \qw & \qw & \qw & \qw & \qw\\ - \nghost{{q}_{3} : } & \lstick{{q}_{3} : } & \gate{\mathrm{R_Z}\,(\mathrm{\frac{3\pi}{4}})} & \ghost{\mathrm{R_{YY}}\,(\mathrm{\frac{3\pi}{4}})}_<<<{1} & \control \qw & \qw & \qw & \qw & \qw & \qw\\ + \nghost{{q}_{0} : } & \lstick{{q}_{0} : } & \gate{\mathrm{R}\,(\mathrm{\frac{3\pi}{4},\frac{3\pi}{8}})} & \multigate{1}{\mathrm{R_{XX}}\,(\mathrm{\frac{\pi}{2}})}_<<<{0} & \multigate{1}{\mathrm{R_{ZX}}\,(\mathrm{\frac{-\pi}{2}})}_<<<{0} & \qw & \qw & \qw & \qw & \qw & \qw\\ + \nghost{{q}_{1} : } & \lstick{{q}_{1} : } & \gate{\mathrm{R_X}\,(\mathrm{\frac{\pi}{2}})} & \ghost{\mathrm{R_{XX}}\,(\mathrm{\frac{\pi}{2}})}_<<<{1} & \ghost{\mathrm{R_{ZX}}\,(\mathrm{\frac{-\pi}{2}})}_<<<{1} & \qw & \qw & \qw & \qw & \qw & \qw\\ + \nghost{{q}_{2} : } & \lstick{{q}_{2} : } & \gate{\mathrm{R_Y}\,(\mathrm{\frac{-\pi}{2}})} & \multigate{1}{\mathrm{R_{YY}}\,(\mathrm{\frac{3\pi}{4}})}_<<<{0} & \ctrl{1} & \qw & \qw & \qw & \qw & \qw & \qw\\ + \nghost{{q}_{3} : } & \lstick{{q}_{3} : } & \gate{\mathrm{R_Z}\,(\mathrm{\frac{3\pi}{4}})} & \ghost{\mathrm{R_{YY}}\,(\mathrm{\frac{3\pi}{4}})}_<<<{1} & \control \qw \cds{-1}{\hspace{0.5em}\hphantom{\ensuremath{\mathrm{ZZ}\,(\mathrm{\frac{\pi}{2}})}}\ensuremath{\mathrm{ZZ}\,(\mathrm{\frac{\pi}{2}})}} & \qw & \qw & \qw & \qw & \qw & \qw\\ \\ }} \end{document} \ No newline at end of file diff --git a/test/python/visualization/references/test_latex_u_gates.tex b/test/python/visualization/references/test_latex_u_gates.tex index 91017cd2d891..95034ada2a58 100644 --- a/test/python/visualization/references/test_latex_u_gates.tex +++ b/test/python/visualization/references/test_latex_u_gates.tex @@ -6,9 +6,9 @@ \begin{document} \scalebox{1.0}{ \Qcircuit @C=1.0em @R=0.2em @!R { \\ - \nghost{{q}_{0} : } & \lstick{{q}_{0} : } & \gate{\mathrm{U_1}\,(\mathrm{\frac{3\pi}{2}})} & \ctrl{1} & \dstick{\hspace{2.0em}\mathrm{U_1}\,(\mathrm{\frac{\pi}{4}})} \qw & \qw & \qw & \ctrl{1} & \qw & \qw\\ - \nghost{{q}_{1} : } & \lstick{{q}_{1} : } & \gate{\mathrm{U_2}\,(\mathrm{\frac{3\pi}{2},\frac{2\pi}{3}})} & \control \qw & \qw & \qw & \qw & \gate{\mathrm{U_3}\,(\mathrm{\frac{3\pi}{2},\frac{-3\pi}{4},\frac{-\pi}{2}})} & \qw & \qw\\ - \nghost{{q}_{2} : } & \lstick{{q}_{2} : } & \gate{\mathrm{U_3}\,(\mathrm{\frac{3\pi}{2},4.5,\frac{\pi}{4}})} & \ctrl{1} & \qw & \qw & \qw & \qw & \qw & \qw\\ - \nghost{{q}_{3} : } & \lstick{{q}_{3} : } & \qw & \gate{\mathrm{U_2}\,(\mathrm{\frac{\pi}{2},\frac{3\pi}{2}})} & \qw & \qw & \qw & \qw & \qw & \qw\\ + \nghost{{q}_{0} : } & \lstick{{q}_{0} : } & \gate{\mathrm{U_1}\,(\mathrm{\frac{3\pi}{2}})} & \ctrl{1} & \qw & \qw & \qw & \qw & \ctrl{1} & \qw & \qw\\ + \nghost{{q}_{1} : } & \lstick{{q}_{1} : } & \gate{\mathrm{U_2}\,(\mathrm{\frac{3\pi}{2},\frac{2\pi}{3}})} & \control \qw \cds{-1}{\hspace{0.5em}\hphantom{\ensuremath{\mathrm{U_1}\,(\mathrm{\frac{\pi}{4}})}}\ensuremath{\mathrm{U_1}\,(\mathrm{\frac{\pi}{4}})}} & \qw & \qw & \qw & \qw & \gate{\mathrm{U_3}\,(\mathrm{\frac{3\pi}{2},\frac{-3\pi}{4},\frac{-\pi}{2}})} & \qw & \qw\\ + \nghost{{q}_{2} : } & \lstick{{q}_{2} : } & \gate{\mathrm{U_3}\,(\mathrm{\frac{3\pi}{2},4.5,\frac{\pi}{4}})} & \ctrl{1} & \qw & \qw & \qw & \qw & \qw & \qw & \qw\\ + \nghost{{q}_{3} : } & \lstick{{q}_{3} : } & \qw & \gate{\mathrm{U_2}\,(\mathrm{\frac{\pi}{2},\frac{3\pi}{2}})} & \qw & \qw & \qw & \qw & \qw & \qw & \qw\\ \\ }} \end{document} \ No newline at end of file