Skip to content

Commit

Permalink
Address #25: Now provide styles for selective addressing
Browse files Browse the repository at this point in the history
...and also take into account controls when calculating the extent of a gate
  • Loading branch information
projekter committed Feb 19, 2023
1 parent 4a2384a commit d80c50b
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 5 deletions.
Binary file modified doc/latex/yquant/yquant-doc.pdf
Binary file not shown.
38 changes: 35 additions & 3 deletions doc/latex/yquant/yquant-doc.tex
Original file line number Diff line number Diff line change
Expand Up @@ -898,11 +898,13 @@
\end{option}

\begin{option}{this operator}!!
This style is appended to the current style installed for an operator; it should be used only locally to overwrite any global configuration effect.
This style is appended to the current style installed for an operator; it should be used only locally to overwrite any global configuration effect. \\
\compat{New in 0.7.3}Consider using \style{/tikz/only at} and \style{/tikz/not at} \emph{within this style} if you want to selectively address certain operators when there are multiple.
\end{option}

\begin{option}{this control}!!
This style is appended to the current style installed for a control; it should be used only locally to overwrite any global configuration effect.
This style is appended to the current style installed for a control; it should be used only locally to overwrite any global configuration effect. \\
\compat{New in 0.7.3}Consider using \style{/tikz/only at} and \style{/tikz/not at} \emph{within this style} if you want to selectively address certain controls when there are multiple.
\end{option}

\begin{option}{operator style}!/yquant/this operator/.append style={#1}!
Expand All @@ -917,6 +919,33 @@
This is a shorthand that modifies the appearance of both the current operator and any controls or control lines.
\end{option}

\begin{option*}[New in 0.7.3]{tikz}{only at}!!
This is a style which is available within \style{/yquant/this operator} and \style{/yquant/this control}.
It allows to selectively apply its contents only to a certain part of a multi\hyp partite operator.
The style expects an even number of parameters.
The first (third, ...) parameter contains the index of the operator/control where the style should apply.
This index corresponds to the values that \tex!\idx! can take; i.e., it will be zero for the topmost operator/control (leftmost for vertical circuits) and then increment by one.
The indices of operators, positive, and negative controls are all independent.
You may not only give a single index, but instead also a comma\hyp separated list, and you may also use index ranges (where both the first and second part of the range can be omitted, which then means ``from the first'' or ``to the last'').
The second (fourth, ...) parameter then contains all the styles that should actually be applied.

\begin{codeexample}
\begin{tikzpicture}
\begin{yquant}
qubit q[7];
[operator style={only at={1, 3-}{fill=yellow}
{0}{ultra thick}},
control style={only at={0}{fill=orange}}]
h q[-2, 4, 5] | q[3, 6];
\end{yquant}
\end{tikzpicture}
\end{codeexample}
\end{option*}

\begin{option*}[New in 0.7.3]{tikz}{not at}!!
See \style{/tikz/not at}; this style does the same, but instead only acts if the current register is \emph{not} the one given in the odd arguments.
\end{option*}

\begin{option}[Changed in 0.7.1\\New in 0.1.2]{operator/multi as single}!/yquant/every multi line/.style=/yquant/every control line!
This style is automatically set for certain gates such as the \gate{swap} or the \gate{zz} gate.
For those gates, neighboring registers will be treated as discontiguous; and this style will enforce their connecting line to have the style used by control lines.
Expand Down Expand Up @@ -5357,6 +5386,9 @@

\subsection*{2023-01-21: Version 0.7.3}
Fix \href{https://github.com/projekter/yquant/issues/24}{\#24}: Clipping in subcircuits can under very special circumstances fail. Change all clipping paths to a most conservative huge rectangle---before, we tried to be economical.
Also use a more meticulous way of subcircuit position alignment (which will probably consume more resources during compilation, but multiple subcircuits may cancel each other in height and depth calculation if we don't do it).
Also use a more meticulous way of subcircuit position alignment (which will probably consume more resources during compilation, but multiple subcircuits may cancel each other in height and depth calculation if we don't do it). \\
Address \href{https://github.com/projekter/yquant/issues/25}{\#25}: We now provide the styles \style{/tikz/only at} and \style{/tikz/not at} that allow to easily use styles on an multi\hyp register operator that just affect some parts of their register representation. \\
Now the size of controls is taken into account when calculating the size of an operation---so extremely large controls will appropriate enlarge the height/depth or horizontal increment.
This is more useful when putting labels to controls.
%END_FOLD
\end{document}
76 changes: 76 additions & 0 deletions tex/latex/yquant/yquant-config.tex
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,78 @@
},%
every post measurement control/direct/.code={%
\let\yquant@lang@attr@directcontrol=\relax%
},%
}
\def\yquant@config@only@multi#1#2#3#4\yquant@sep{%
\yquant@config@only{#1}{#2}{#3}%
\ifstrempty{#4}\relax{%
\yquant@config@only@multi{#1}#4\yquant@sep%
}%
}
\protected\def\yquant@config@only#1#2#3{%
\begingroup%
\let\yquant@config@onlyloop@idxs=\empty%
\forcsvlist\yquant@config@onlyloop{#2}%
\let\ifdoit=\iffalse%
\ifdefined\yquant@config@onlyloop@allupto%
\unless\ifnum\idx>\yquant@config@onlyloop@allupto\space%
\csletcs{ifdoit}{iftrue}%
\fi%
\fi%
\ifdefined\yquant@config@onlyloop@allfrom%
\unless\ifnum\idx<\yquant@config@onlyloop@allfrom\space%
\csletcs{ifdoit}{iftrue}%
\fi%
\fi%
\unless\ifdoit%
\xifinlist\idx\yquant@config@onlyloop@idxs{%
\csletcs{ifdoit}{iftrue}%
}\relax%
\fi%
\expandafter%
\endgroup%
#1\ifdoit
\pgfkeysalso{#3}%
\fi%
}
\protected\def\yquant@config@onlyloop#1{%
\yquant@config@onlyloop@checkrange#1-\yquant@sep%
}
\protected\def\yquant@config@onlyloop@checkrange#1-#2\yquant@sep{%
\ifstrempty{#2}{%
\listeadd\yquant@config@onlyloop@idxs{#1}%
}{%
\yquant@config@onlyloop@range#1-#2\yquant@sep%
}%
}
\protected\def\yquant@config@onlyloop@range#1-#2-\yquant@sep{%
\ifblank{#1}{%
\ifblank{#2}{%
% pretty meaningless, but let's allow for it
\def\yquant@config@onlyloop@allfrom{0}%
}{%
\ifdefined\yquant@config@onlyloop@allupto%
\ifnum#2>\yquant@config@onlyloop@allupto\space%
\numdef\yquant@config@onlyloop@allupto{#2}%
\fi%
\else%
\numdef\yquant@config@onlyloop@allupto{#2}%
\fi%
}
}{%
\ifblank{#2}{%
\ifdefined\yquant@config@onlyloop@allfrom%
\ifnum#1<\yquant@config@onlyloop@allfrom\space%
\numdef\yquant@config@onlyloop@allfrom{#1}%
\fi%
\else%
\numdef\yquant@config@onlyloop@allfrom{#1}%
\fi%
}{%
\yquant@for \i := #1 to #2 {%
\listeadd\yquant@config@onlyloop@idxs\i%
}%
}%
}%
}
% END_FOLD
Expand Down Expand Up @@ -412,6 +484,10 @@
{\yquant@config@circuitsetupfalse},%
internal/autorotate init/.style={},%
internal/autorotate output/.style={},%
internal/before styles/.style={%
/tikz/only at/.code=\yquant@config@only@multi{}##1\yquant@sep,
/tikz/not at/.code=\yquant@config@only@multi\unless##1\yquant@sep
},
}
\ifnum\yquant@compat<2 %
\pgfqkeys{/yquant}{%
Expand Down
1 change: 1 addition & 0 deletions tex/latex/yquant/yquant-draw.tex
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
\tikz@enable@node@quotes%
\yquant@config@operator@position@rightalignfalse%
\yquant@config@operator@position@advancetrue%
\pgfkeys{/yquant/internal/before styles}%
\yquant@set{#3}%
% if the operator is right-aligned, we will not advance, as we must assume that the x position is already chosen appropriately
\ifyquant@config@operator@position@rightalign%
Expand Down
26 changes: 25 additions & 1 deletion tex/latex/yquant/yquant-prepare.tex
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
\else%
\let\yquant@prepare@list=\empty%
\fi%
\pgfkeys{/yquant/internal/before styles}%
% BEGIN_FOLD register
\def\do##1{%
\ifx\yquant@lang@attr@name\empty%
Expand Down Expand Up @@ -237,10 +238,33 @@
{#2}% register index
{\nodename}%
}%
\numdef\idx{\idx+1}%
\unless\ifdefined\yquant@prepare@controltype%
\edef\yquant@prepare@controltype{#2}%
\fi%
\pgfinterruptboundingbox%
\yquant@config@operator@multifalse%
\yquant@env@virtualize@path%
\ifx#1p
\path%
(0pt, 0pt)%
node[/yquant/every control, /yquant/every positive control, /yquant/this control,%
name prefix=, name suffix=, name=] {};%
\else%
\path%
(0pt, 0pt)%
node[/yquant/every control, /yquant/every negative control, /yquant/this control,%
name prefix=, name suffix=, name=] {};%
\fi
\yquant@register@update@height{#2}{\the\yquant@pgf@picmaxy}%
\yquant@register@update@depth{#2}{\the\dimexpr-\yquant@pgf@picminy\relax}%
\expandafter%
\endpgfinterruptboundingbox%
\expandafter\dimen\expandafter0\expandafter=%
\the\dimexpr\yquant@pgf@picmaxx-\yquant@pgf@picminx\relax\relax%
\ifdim\dimen0>\dimen2 %
\dimen2=\dimen0 %
\fi%
\numdef\idx{\idx+1}%
\fi%
}

Expand Down
2 changes: 1 addition & 1 deletion tex/latex/yquant/yquant.sty
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
%
% The Current Maintainer of this work is Benjamin Desef.
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{yquant}[2023/01/21 v0.7.3 Yet another quantum circuit library for LaTeX]
\ProvidesPackage{yquant}[2023/02/19 v0.7.3 Yet another quantum circuit library for LaTeX]

\RequirePackage{etoolbox}[2018/02/11]
\RequirePackage{tikz}[2015/08/29]
Expand Down

0 comments on commit d80c50b

Please sign in to comment.