summaryrefslogtreecommitdiff
path: root/graphics/pgf/contrib/yquant/tex/yquant-lang.tex
blob: 8658d3af9fa4a89ff40dc51a2d90d286c38203e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
% BEGIN_FOLD Attributes
\yquant@langhelper@declare@attr{%
   value/.store in=\yquant@lang@attr@value,%
   after/.code={%
      \yquant@register@get@ids{#1}%
      \let\yquant@lang@attr@after=\yquant@register@get@ids@list%
   },%
   type/.store in=\yquant@lang@attr@type,%
   ancilla/.code={%
      \undef\yquant@lang@attr@input%
      \undef\yquant@lang@attr@output%
   },%
   in/.code={%
      \let\yquant@lang@attr@input=\relax%
      \undef\yquant@lang@attr@output%
   },%
   out/.code={%
      \undef\yquant@lang@attr@input%
      \let\yquant@lang@attr@output=\relax%
   },%
   inout/.code={%
      \let\yquant@lang@attr@input=\relax%
      \let\yquant@lang@attr@output=\relax%
   },%
   frameless/.code={%
      \pgfkeysalso{/yquant/operators/subcircuit/frameless}%
      \appto\yquant@attrs@remaining{,/yquant/operators/subcircuit/frameless}%
   },%
   seamless/.code={%
      \pgfkeysalso{/yquant/operators/subcircuit/seamless}%
      \appto\yquant@attrs@remaining{,/yquant/operators/subcircuit/seamless}%
   },%
   direct control/.code={%
      \let\yquant@lang@attr@directcontrol=\relax%
   },%
   indirect control/.code={%
      \undef\yquant@lang@attr@directcontrol%
   },%
   name mangling/.code={%
      \pgfkeysalso{/yquant/operators/subcircuit/name mangling={#1}}%
      \appto\yquant@attrs@remaining{,/yquant/operators/subcircuit/name mangling={#1}}%
   }%
}
\yquant@langhelper@declare@attr@global{%
   name/.store in=\yquant@lang@attr@name,%
   overlay/.code={%
      \ifstrequal{#1}{true}{%
         \yquant@lang@attr@overlay@multitrue%
         \yquant@lang@attr@overlay@heighttrue%
         \yquant@lang@attr@overlay@depthtrue%
      }{%
         \ifstrequal{#1}{false}{%
            % Why??? This is the default and should always be reset automatically!
            \yquant@lang@attr@overlay@multifalse%
            \yquant@lang@attr@overlay@heightfalse%
            \yquant@lang@attr@overlay@depthfalse%
         }{%
            \pgfqkeys{/yquant/global attrs/overlay}{#1}%
         }%
      }%
   },%
   overlay/.default=true,%
   overlay/multi/.is if=yquant@lang@attr@overlay@multi,%
   overlay/m/.forward to=/yquant/global attrs/overlay/multi,%
   overlay/height/.is if=yquant@lang@attr@overlay@height,%
   overlay/ht/.forward to=/yquant/global attrs/overlay/height,%
   overlay/h/.forward to=/yquant/global attrs/overlay/height,%
   overlay/depth/.is if=yquant@lang@attr@overlay@depth,%
   overlay/dp/.forward to=/yquant/global attrs/overlay/depth,%
   overlay/d/.forward to=/yquant/global attrs/overlay/depth,%
   overlay/single/.code={\pgfkeysalso{%
      /yquant/global attrs/overlay/height={#1},%
      /yquant/global attrs/overlay/depth={#1}%
   }},%
   overlay/single/.default=true,%
   overlay/s/.forward to=/yquant/global attrs/overlay/single,%
}
\newif\ifyquant@lang@attr@overlay@multi%
\newif\ifyquant@lang@attr@overlay@height%
\newif\ifyquant@lang@attr@overlay@depth%

\protected\def\yquant@lang@reset@attrs{%
   \undef\yquant@lang@attr@value%
   \undef\yquant@lang@attr@after%
   \undef\yquant@lang@attr@type%
   \yquant@lang@reset@attrs@inputoutput%
   \let\yquant@lang@attr@name=\empty%
   \yquant@lang@attr@overlay@multifalse%
   \yquant@lang@attr@overlay@heightfalse%
   \yquant@lang@attr@overlay@depthfalse%
}

\protected\def\yquant@lang@reset@attrs@inputoutput{%
   \undef\yquant@lang@attr@input%
   \undef\yquant@lang@attr@output%
}

\protected\def\yquant@lang@reset@attrs@inputoutput@subcircuit{%
   \let\yquant@lang@attr@input=\relax%
   \let\yquant@lang@attr@output=\relax%
}
% END_FOLD

% BEGIN_FOLD Declaration of registers
\yquant@langhelper@declare@command@create{nobit}\yquant@lang@@nobit
\yquant@langhelper@setup@attrs{nobit}{}{ancilla,out}
\def\yquant@lang@@nobit#1{%
   \let\yquant@lang@create@type=\yquant@register@type@none%
   \def\yquant@lang@create@style{initial}% there is no separate style, just duplicate
   \ifdefined\yquant@lang@attr@value%
      \PackageError{yquant.sty}{Placeholder initialization must not have value}%
                   {You must not provide a description for an invisible register.}
   \else%
      \let\yquant@lang@attr@value=\empty%
   \fi%
   \yquant@lang@create@parse@name#1[;%
}

\yquant@langhelper@declare@command@create{qubit}\yquant@lang@@qubit
\yquant@langhelper@setup@attrs{qubit}{}{after,value,ancilla,in,out,inout}
\def\yquant@lang@@qubit#1{%
   \let\yquant@lang@create@type=\yquant@register@type@q%
   \def\yquant@lang@create@style{qubit}%
   \unless\ifdefined\yquant@lang@attr@value%
      \let\yquant@lang@attr@value=\yquant@config@register@default@name%
   \fi%
   \yquant@lang@create@parse@name#1[;%
}

\yquant@langhelper@declare@command@create{cbit}\yquant@lang@@cbit
\yquant@langhelper@setup@attrs{cbit}{}{after,value,ancilla,in,out,inout}
\def\yquant@lang@@cbit#1{%
   \let\yquant@lang@create@type=\yquant@register@type@c%
   \def\yquant@lang@create@style{cbit}%
   \unless\ifdefined\yquant@lang@attr@value%
      \let\yquant@lang@attr@value=\yquant@config@register@default@name%
   \fi%
   \yquant@lang@create@parse@name#1[;%
}

\yquant@langhelper@declare@command@create{qubits}\yquant@lang@@qubits
\yquant@langhelper@setup@attrs{qubits}{}{after,value,ancilla,in,out,inout}
\def\yquant@lang@@qubits#1{%
   \let\yquant@lang@create@type=\yquant@register@type@qs%
   \def\yquant@lang@create@style{qubits}%
   \unless\ifdefined\yquant@lang@attr@value%
      \let\yquant@lang@attr@value=\yquant@config@register@default@name%
   \fi%
   \yquant@lang@create@parse@name#1[;%
}

\def\yquant@lang@create@parse@name#1[#2;{%
   \ifstrempty{#2}{%
      \yquant@lang@create@do#1[1][;%
   }{%
      \yquant@lang@create@do#1[#2;%
   }%
}

\protected\def\yquant@lang@create@do#1[#2]#3[;{%
   % parse length
   \ifstrempty{#3}{%
      \yquant@langhelper@validate\len\count{#2}%
      \ifnum\len<1 %
         \PackageError{yquant.sty}{Invalid register length}%
                      {Valid register lengths are integers greater or equal to one.}%
      \fi%
   }{%
      \PackageError{yquant.sty}{Invalid register name}%
         {Register names must not contain `[' apart from register length indication.}%
   }%
   \edef\reg{\trim@spaces{#1}}%
   % we allow for scattering, so check whether the register already exists
   \ifcsname\yquant@prefix registerhigh@\reg\endcsname%
      \ifyquant@firsttoken+{#2}{%
         \numdef\idx{\csname\yquant@prefix registerhigh@\reg\endcsname+1}%
         \numdef\len{\len+\idx}%
      }{%
         \PackageError{yquant.sty}{Duplicate registers}%
            {Register `\reg' was already defined. Use `\reg[+#2]' with explicit plus symbol to indicate that you want to enlarge the register on purpose.}%
      }%
   \else%
      \def\idx{0}%
   \fi%
   % define text macros
   \ifnum\len=1 %
      \let\regidx=\reg%
   \else%
      \def\regidx{\reg[\idx]}%
   \fi%
   \numdef\yquant@circuit@operator@mintarget{\csname\yquant@prefix registers\endcsname+1}%
   % create the registers
   \begingroup%
      % if we have the after attribute, we start with a discarded wire
      \ifdefined\yquant@lang@attr@after%
         \ifdefined\yquant@lang@attr@input%
            \PackageError{yquant.sty}{An input register cannot be created with `after` attribute}{}%
         \fi%
         \let\yquant@lang@create@type=\yquant@register@type@none%
      \fi%
      \yquant@for \idx := \idx to \numexpr \len -1\relax {%
         \yquant@prepare@create\reg\idx\yquant@lang@create@type%
      }%
   \endgroup%
   % gather details about the created registers
   \letcs\yquant@circuit@operator@maxtarget{\yquant@prefix registers}%
   \numdef\yquant@circuit@operator@numtarget{\yquant@circuit@operator@maxtarget-\yquant@circuit@operator@mintarget+1}%
   \edef\yquant@circuit@operator@targets{%
      \yquant@list@range%
         \yquant@circuit@operator@mintarget%
         \yquant@circuit@operator@maxtarget%
   }%
   \let\yquant@circuit@operator@pctrls=\empty%
   \def\yquant@circuit@operator@minpctrl{2147483647}%
   \def\yquant@circuit@operator@maxpctrl{0}%
   \let\yquant@circuit@operator@numpctrl=\yquant@circuit@operator@maxpctrl%
   \let\yquant@circuit@operator@nctrls=\empty%
   \let\yquant@circuit@operator@minnctrl=\yquant@circuit@operator@minpctrl%
   \let\yquant@circuit@operator@maxnctrl=\yquant@circuit@operator@maxpctrl%
   \let\yquant@circuit@operator@numnctrl=\yquant@circuit@operator@numpctrl%
   \let\yquant@circuit@operator@minctrl=\yquant@circuit@operator@mintarget%
   \let\yquant@circuit@operator@maxctrl=\yquant@circuit@operator@maxtarget%
   % if we have the after attribute, we fake an align gate
   \ifdefined\yquant@lang@attr@after%
      \edef\jointindices{\yquant@circuit@operator@targets\yquant@lang@attr@after}%
      \yquant@circuit@align\jointindices%
      % and we also need to change the wire after the alignment
      \let\yquant@circuit@settype@to=\yquant@lang@create@type%
      \let\yquant@prepare@callback@prepare=\yquant@circuit@settype@prepare%
      \let\yquant@prepare@callback@draw=\yquant@circuit@settype%
      \expandafter\@thirdofthree%
   \else%
      \expandafter\@firstofone%
   \fi%
   % unless there is no name, no text and no after attribute, we now need an init gate
   {%
      \ifx\yquant@lang@attr@value\empty%
         \expandafter\@firstofone%
      \else%
         \expandafter\@secondoftwo%
      \fi%
   }%
   {%
      \ifx\yquant@lang@attr@name\empty%
         \expandafter\@gobble%
      \else%
         \expandafter\@firstofone%
      \fi%
   }%
   {%
      % there are no multi inits in this context
      \preto\yquant@attrs@remaining{internal/move label,}%
      \def\yquant@config@operator@minimum@width{0pt}%
      \unless\ifx\yquant@lang@attr@value\empty%
         % make sure to immediately remove the "clear" marker again if we have a text
         \yquant@for \i := \yquant@circuit@operator@mintarget to \yquant@circuit@operator@maxtarget {%
            \yquant@register@execclear@lastgate{\i}{init}%
         }%
      \fi%
      \expandafter\yquant@prepare%
         \expandafter{\yquant@lang@attr@value}%
         {/yquant/every label, /yquant/every initial label,%
          /yquant/every \yquant@lang@create@style\space label,%
          \ifnum\yquant@compat<2 \ifdefined\yquant@lang@attr@input /yquant/every input label\fi\fi}%
      \unless\ifx\yquant@lang@attr@name\empty%
         \ifnum\len=1 %
            \csxappto{\yquant@prefix draw}%
                     {\yquant@draw@alias{\yquant@lang@attr@name}}%
         \fi%
      \fi%
   }%
}
% END_FOLD

% BEGIN_FOLD Define own gates
\def\yquantdefinegate#1{%
   \ifcsname yquant@lang@#1\endcsname%
      \PackageError{yquant.sty}{Gate redefined}%
                   {The gate `#1' already exists. Use \string\yquantredefinegate\space if you really want to redefine it.}%
   \fi%
   \@ifnextchar[{\yquantdefinegate@i{#1}}%
                {\yquantdefinegate@i{#1}[/yquant/operators/every custom gate]}%
}

% while this command is provided to redefine gates, we do not clear the attributes that were once assigned to the previous one, so gate redefinition is discouraged!
\def\yquantredefinegate#1{%
   \unless\ifcsname yquant@lang@#1\endcsname%
      \PackageError{yquant.sty}{Unknown gate redefined}%
                   {The gate `#1' is unknown and cannot be redefined. Use \string\yquantdefinegate\space to define it.}%
   \fi%
   \@ifnextchar[{\yquantdefinegate@i{#1}}%
                {\yquantdefinegate@i{#1}[/yquant/operators/every custom gate]}%
}

\protected\long\def\yquantdefinegate@i#1[#2]#3{%
   \begingroup%
      \yquant@prepare@ifs@set%
      % usually, we will not be in a tikzpicture here, so all the commands that abbreviate some path operation are undefined!
      \tikz@installcommands%
      % While we want the content to be expanded, protect the most likely TikZ commands - the same ones that we usually substitute in \yquant@env@substikz.
      \protected\def\path{}%
      \let\scoped=\path%
      \let\scope=\path%
      \let\endscope=\path%
      \let\stopscope=\path%
      \protected@edef\yquantdefinegate@do{%
         \endgroup%
         \noexpand\pgfkeys{/yquant/operators/every #1/.code={%
            \yquant@config@operator@subcircuit@mangling@set{%
               \yquant@config@operator@subcircuit@mangling%
            }%
            \noexpand\pgfkeysalso{\unexpanded{#2}}%
         }}%
         \yquant@langhelper@declare@command%
            {#1}%
            \yquant@register@get@multiaslist%
            {%
               \let\noexpand\yquant@lang@attr@value=\expandafter\noexpand\csname yquant@lang@@#1\endcsname%
               \yquant@prepare@subcircuit{/yquant/operators/every #1}%
            }%
         % This does not clear the attributes for redefines, but makes at least sure nothing is marked as required that should not be.
         \yquant@langhelper@setup@attrs{#1}{}{}%
         % Now define the gate's content as a macro
         \def\expandafter\noexpand\csname yquant@lang@@#1\endcsname{%
            #3%
         }%
      }%
   \yquantdefinegate@do%
}

\def\yquantdefinebox#1{%
   \ifcsname yquant@lang@#1\endcsname%
      \PackageError{yquant.sty}{Gate redefined}%
                   {The gate `#1' already exists. Use \string\yquantredefinebox\space if you really want to redefine it.}%
   \fi%
   \yquantdefinebox@{#1}{}%
}

\def\yquantdefinemultibox#1{%
   \ifcsname yquant@lang@#1\endcsname%
      \PackageError{yquant.sty}{Gate redefined}%
                   {The gate `#1' already exists. Use \string\yquantredefinemultibox\space if you really want to redefine it.}%
   \fi%
   \yquantdefinebox@{#1}\yquant@register@get@allowmultitrue%
}

\def\yquantredefinebox#1{%
   \unless\ifcsname yquant@lang@#1\endcsname%
      \PackageError{yquant.sty}{Unknown gate redefined}%
                   {The gate `#1' is unknown and cannot be redefined. Use \string\yquantdefinebox\space to define it.}%
   \fi%
   \yquantdefinebox@{#1}{}%
}

\def\yquantredefinemultibox#1{%
   \unless\ifcsname yquant@lang@#1\endcsname%
      \PackageError{yquant.sty}{Unknown gate redefined}%
                   {The gate `#1' is unknown and cannot be redefined. Use \string\yquantdefinemultibox\space to define it.}%
   \fi%
   \yquantdefinebox@{#1}\yquant@register@get@allowmultitrue%
}

\def\yquantdefinebox@#1#2{%
   \@ifnextchar[{\yquantdefinebox@i{#1}{#2}}%
                {\yquantdefinebox@i{#1}{#2}[/yquant/operators/every box]}%
}

\protected\long\def\yquantdefinebox@i#1#2[#3]#4{%
   \pgfkeys{/yquant/operators/every #1/.style={#3}}%
   \begingroup%
      \yquant@prepare@ifs@set%
      \protected@edef\yquantdefinebox@do{%
         \endgroup%
         \yquant@langhelper@declare@command%
            {#1}%
            {\unexpanded{#2}}%
            {\yquant@prepare{#4}{/yquant/operators/every #1}}%
      }%
      \yquantdefinebox@do%
   \yquant@langhelper@setup@attrs{#1}{}{}%
}
% END_FOLD

% BEGIN_FOLD Box registers
% all-purpose box with arbitrary text
\yquant@langhelper@declare@command%
   {box}%
   \yquant@register@get@allowmultitrue%
   {%
      \expandafter\yquant@prepare%
         \expandafter{\yquant@lang@attr@value}%
         {/yquant/operators/every box}%
   }
\yquant@langhelper@setup@attrs{box}{value}{}

% Hadamard
\yquantdefinebox{h}{$H$}

% Pauli X (or NOT)
\yquantdefinebox{x}[/yquant/operators/every pauli]{$X$}

% Pauli Y
\yquantdefinebox{y}[/yquant/operators/every pauli]{$Y$}

% Pauli Z
\yquantdefinebox{z}[/yquant/operators/every pauli]{$Z$}

% sub-circuit: This is a nested circuit.
\yquant@langhelper@declare@command%
   {subcircuit}%
   \yquant@register@get@multiaslist%
   {%
      \yquant@prepare@subcircuit{/yquant/operators/every subcircuit}%
   }
\yquant@langhelper@setup@attrs{subcircuit}{value}{frameless,seamless,name mangling}
% END_FOLD

% BEGIN_FOLD other geometric shapes
% phase
\yquant@langhelper@declare@command%
   {phase}%
   {}%
   {%
      \edef\cmd{%
         \yquant@prepare%
            {}%
            {/yquant/operators/every phase, label={\unexpanded\expandafter{\yquant@lang@attr@value}}}%
      }%
      \cmd%
   }
\yquant@langhelper@setup@attrs{phase}{value}{}%

% two-qubit controlled x (symmetric notation)
\yquant@langhelper@declare@command%
   {xx}%
   \yquant@register@get@multiassingle%
   {%
      \yquant@prepare%
         {}%
         {/yquant/operators/every xx}%
   }
\yquant@langhelper@setup@attrs{xx}{}{}

% two-qubit controlled phase (symmetric notation)
\yquant@langhelper@declare@command@uncontrolled%
   {zz}%
   \yquant@register@get@multiassingle%
   {%
      \yquant@prepare%
         {}%
         {/yquant/operators/every zz}%
   }
\yquant@langhelper@setup@attrs{zz}{}{}

% slash (pseudo-operator, alternative indication for a bundle)
\yquant@langhelper@declare@command@uncontrolled%
   {slash}%
   {}%
   {%
      % temporarily squeeze most into the separation
      \pgfkeys{%
         /yquant/operator/minimum width=0pt,%
      }%
      \preto\yquant@attrs@remaining{internal/squeeze slash,}%
      \yquant@prepare%
         {}%
         {/yquant/operators/every slash}%
   }
\yquant@langhelper@setup@attrs{slash}{}{}

% swap
\yquant@langhelper@declare@command%
   {swap}%
   \yquant@register@get@multiassingle
   {%
      \yquant@prepare%
         {}%
         {/yquant/operators/every swap}%
   }
\yquant@langhelper@setup@attrs{swap}{}{}

% not
\yquant@langhelper@declare@command%
   {not}%
   {}%
   {%
      \yquant@prepare%
         {}%
         {/yquant/operators/every not}%
   }
\yquant@langhelper@setup@attrs{not}{}{}
% alias to cnot
\yquant@langhelper@declare@command@alias{cnot}{not}
\yquant@langhelper@setup@attrs{cnot}{}{}

% measure
\yquant@langhelper@declare@command@uncontrolled%
   {measure}%
   \yquant@register@get@allowmultitrue%
   {%
      \ifdefined\yquant@lang@attr@type%
         \yquant@register@type@fromstring\yquant@lang@attr@type\yquant@circuit@settype@to%
      \else%
         \let\yquant@circuit@settype@to=\yquant@register@type@c%
      \fi%
      \let\yquant@prepare@callback@prepare=\yquant@circuit@settype@prepare%
      \let\yquant@prepare@callback@draw=\yquant@circuit@settype%
      \unless\ifcsname yquant@lang@attr@value\endcsname%
         \let\yquant@lang@attr@value=\empty%
      \fi%
      \ifdefined\yquant@lang@attr@directcontrol%
         % direct control means that we must defer this operator until the next that has this/these targets as positive controls.
         \expandafter\yquant@prepare@injection%
            \expandafter{\yquant@lang@attr@value}%
            {/yquant/operators/every measure}%
      \else%
         \expandafter\yquant@prepare%
            \expandafter{\yquant@lang@attr@value}%
            {/yquant/operators/every measure}%
      \fi%
   }
\yquant@langhelper@setup@attrs{measure}{}{value,type,direct control,indirect control}

% measure (dmeter)
\yquant@langhelper@declare@command@uncontrolled%
   {dmeter}%
   \yquant@register@get@allowmultitrue%
   {%
      \ifdefined\yquant@lang@attr@type%
         \yquant@register@type@fromstring\yquant@lang@attr@type\yquant@circuit@settype@to%
      \else%
         \let\yquant@circuit@settype@to=\yquant@register@type@c%
      \fi%
      \let\yquant@prepare@callback@prepare=\yquant@circuit@settype@prepare%
      \let\yquant@prepare@callback@draw=\yquant@circuit@settype%
      \unless\ifcsname yquant@lang@attr@value\endcsname%
         \let\yquant@lang@attr@value=\empty%
      \fi%
      \expandafter\yquant@prepare%
         \expandafter{\yquant@lang@attr@value}%
         {/yquant/operators/every dmeter}%
   }
\yquant@langhelper@setup@attrs{dmeter}{}{value,type}
% END_FOLD

% BEGIN_FOLD miscellaneous
\yquant@langhelper@declare@command@uncontrolled%
   {barrier}%
   \yquant@register@get@allowmultitrue%
   {%
      \yquant@prepare%
         {}%
         {/yquant/operators/every barrier}%
   }%
\yquant@langhelper@setup@attrs{barrier}{}{}

\yquant@langhelper@declare@command@uncontrolled%
   {correlate}%
   {%
      % do not call \yquant@register@get@multiassingle, we do not want to install a different multi line style!
      \yquant@register@get@allowmultitrue%
      \let\yquant@register@multi@splitparts=\yquant@register@multi@splitparts@sepall%
   }{%
      \yquant@prepare%
         {}%
         {/yquant/operators/every wave}%
   }
\yquant@langhelper@setup@attrs{correlate}{}{}

\yquant@langhelper@declare@command@uncontrolled%
   {align}%
   {}%
   {%
      \yquant@circuit@align\yquant@circuit@operator@targets%
   }
\yquant@langhelper@setup@attrs{align}{}{}

\yquant@langhelper@declare@command@uncontrolled%
   {hspace}%
   {%
      \yquant@langhelper@validate\amount\dimen\yquant@lang@attr@value%
   }{%
      \yquant@circuit@hspace\yquant@circuit@operator@targets\amount%
   }
\yquant@langhelper@setup@attrs{hspace}{value}{}

\yquant@langhelper@declare@command@uncontrolled%
   {discard}%
   {}%
   {%
      \let\yquant@circuit@settype@to=\yquant@register@type@none%
      \yquant@circuit@actonwires%
         \yquant@circuit@settype@prepare%
         \yquant@circuit@settype%
         \yquant@circuit@operator@targets%
         {}%
   }
\yquant@langhelper@setup@attrs{discard}{}{}

\yquant@langhelper@declare@command@uncontrolled%
   {init}%
   {%
      \yquant@register@get@allowmultitrue%
      % we will count how many registers contain the "clean" flag, and only if this is equal to the number of targets, we apply the shift.
      \count8=0 %
   }%
   {%
      \ifdefined\yquant@lang@attr@type%
         \yquant@register@type@fromstring\yquant@lang@attr@type\yquant@circuit@settype@to%
      \else%
         % We don't know which type is desired. Scan all target registers and use the first wire that is available as a type.
         \let\yquant@circuit@settype@to=\yquant@register@type@none%
         \forlistloop\yquant@lang@@init@loop\yquant@circuit@operator@targets%
         \ifx\yquant@circuit@settype@to\yquant@register@type@none%
            % now we don't have a clue; assume it's a qubit
            \let\yquant@circuit@settype@to=\yquant@register@type@q%
         \fi%
         \edef\yquant@lang@attr@type{%
            \yquant@register@type@tostring\yquant@circuit@settype@to%
         }%
      \fi%
      \let\yquant@prepare@callback@prepare=\yquant@circuit@settype@prepare%
      \let\yquant@prepare@callback@draw=\yquant@circuit@settype%
      \let\yquant@prepare@multi=\yquant@prepare@multiinit%
      \ifnum\count8=\numexpr\yquant@circuit@operator@maxctrl-\yquant@circuit@operator@minctrl+1\relax%
         \def\yquant@config@operator@minimum@width{0pt}%
         \preto\yquant@attrs@remaining{internal/move label,}%
         \edef\cmd{%
            \yquant@prepare%
               {\unexpanded\expandafter{\yquant@lang@attr@value}}%
               {/yquant/every label, /yquant/every initial label,%
                /yquant/every \yquant@lang@attr@type\space label}%
         }%
      \else%
         \edef\cmd{%
            \yquant@prepare%
               {\unexpanded\expandafter{\yquant@lang@attr@value}}%
               {/yquant/every label, /yquant/every \yquant@lang@attr@type\space label}%
         }%
      \fi%
      \cmd%
   }
\yquant@langhelper@setup@attrs{init}{value}{type}

\protected\def\yquant@lang@@init@loop#1{%
   \ifyquant@firsttoken\yquant@register@multi{#1}{%
      \let\yquant@register@multi@contiguous=\yquant@lang@@init@multi@@extract%
      \@fifthoffive#1%
      % we should reset multi@contiguous to the original command; but this is really just a placeholder. As long as it is \protected, everything is fine.
   }{%
      \edef\yquant@circuit@settype@to{\yquant@register@get@type{#1}}%
   }%
   \unless\ifx\yquant@circuit@settype@to\yquant@register@type@none%
      \expandafter\listbreak%
   \fi%
}

\protected\def\yquant@lang@@init@multi@@extract#1#2#3{%
   \yquant@for \yquant@i := #1 to #2 {%
      \edef\yquant@circuit@settype@to{\yquant@register@get@type\yquant@i}%
      \unless\ifx\yquant@circuit@settype@to\yquant@register@type@none%
         \expandafter\yquant@for@break%
      \fi%
   }%
}

\yquant@langhelper@declare@command@uncontrolled%
   {output}%
   \yquant@register@get@allowmultitrue%
   \yquant@circuit@output%
\yquant@langhelper@setup@attrs{output}{value}{}

\yquant@langhelper@declare@command@uncontrolled%
   {inspect}%
   \yquant@register@get@allowmultitrue%
   {%
      \expandafter\yquant@prepare%
         \expandafter{\yquant@lang@attr@value}%
         {/yquant/operators/every inspect}%
   }
\yquant@langhelper@setup@attrs{inspect}{value}{}

\yquant@langhelper@declare@command@uncontrolled%
   {settype}%
   {}%
   {%
      \yquant@register@type@fromstring\yquant@lang@attr@value\yquant@circuit@settype@to%
      \yquant@circuit@actonwires%
         \yquant@circuit@settype@prepare%
         \yquant@circuit@settype%
         \yquant@circuit@operator@targets%
         {}%
   }
\yquant@langhelper@setup@attrs{settype}{value}{}

\ifnum\yquant@compat<2 %
   \def\yquant@lang@setwire{%
      \PackageWarning{yquant.sty}{`setwire' gate is deprecated as of yquant 0.1.2. Use `settype' instead.}%
      \yquant@lang@settype%
   }
   \yquant@langhelper@setup@attrs{setwire}{value}{}
\fi

\yquant@langhelper@declare@command@uncontrolled%
   {setstyle}%
   {}%
   {%
      \yquant@circuit@actonwires%
         \@gobbletwo%
         \yquant@circuit@setstyle%
         \yquant@circuit@operator@targets%
         {{\yquant@lang@attr@value}}%
   }
\yquant@langhelper@setup@attrs{setstyle}{value}{}

\yquant@langhelper@declare@command@uncontrolled%
   {addstyle}%
   {}%
   {%
      \yquant@circuit@actonwires%
         \@gobbletwo%
         \yquant@circuit@addstyle%
         \yquant@circuit@operator@targets%
         {{\yquant@lang@attr@value}}%
   }
\yquant@langhelper@setup@attrs{addstyle}{value}{}
% END_FOLD