forked from stewdio/q.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Q-Circuit.html
1179 lines (1056 loc) · 46.2 KB
/
Q-Circuit.html
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
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<title>Q ⟩ Circuit</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<meta name="description" content="Quantum computing in your browser.">
<meta name="copyright" content="Stewart Smith 2019–2020">
<meta name="keywords" content="
Q, Q.js, Q-js, Qjs, quantum JavaScript,
quantum, quantum physics, quantum mechanics, superposition,
quantum computer, quantum computer programming, quantum computing, QC,
quantum simulator, quantum computer simulator,
qubit, qbit, gate, Hadamard, Bloch, Bloch Sphere,
Web, Web site, website, Web browser, browser, HTML, HTML5, JavaScript, ES6, CSS,
Chrome, Firefox, Safari, Opera, Brave, Edge, WebKit, Blink, Gecko, Mozilla,
Stewart Smith, Stewart, Stew, Stuart, Steven, Steve, Stewdio, stewartsmith, stew_rtsmith, @stew_rtsmith,
Moar, Moar Technologies Corp, MTC,
Google, IBM, Microsoft, Amazon, NASA, DWave, D-Wave,
Quil, OpenQASM,
ProjectQ, Qiskit,
Quantum Development Kit, Cirq, Strawberry Fields, t|ket>,
QCL, Quantum pseudocode, Q#, Q|SI>, Q language, qGCL, QFC, QML, LIQUi|>, Quipper,
Stanford CS 269 Q: Quantum Computer Programming">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="@stew_rtsmith">
<meta name="twitter:creator" content="@stew_rtsmith">
<meta name="twitter:title" content="Q ⟩ Circuit">
<meta name="twitter:description" content="Quantum computing in your browser.">
<meta name="twitter:image" content="https://quantumjavascript.app/assets/Q-website-preview.jpg">
<meta property="og:type" content="website">
<meta property="og:title" content="Q ⟩ Circuit">
<meta property="og:description" content="Quantum computing in your browser.">
<meta property="og:image" content="https://quantumjavascript.app/assets/Q-website-preview.jpg">
<meta property="og:url" content="https://quantumjavascript.app/Circuit.html">
<link rel="canonical" href="https://quantumjavascript.app/Circuit.html">
<link href="assets/Q-favicon-064.png" rel="icon" type="image/png">
<link href="assets/Q-favicon-144.png" rel="apple-touch-icon">
<link rel="stylesheet" href="Q/Q.css">
<link rel="stylesheet" href="Q/Q-Circuit-Editor.css">
<link rel="stylesheet" href="assets/documentation.css">
<script src="https://www.googletagmanager.com/gtag/js" async></script>
<script src="assets/ga.js"></script>
<script src="Q/Q.js"></script>
<script src="Q/Q-ComplexNumber.js"></script>
<script src="Q/Q-Matrix.js"></script>
<script src="Q/Q-Qubit.js"></script>
<script src="Q/Q-Gate.js"></script>
<script src="Q/Q-History.js"></script>
<script src="Q/Q-Circuit.js"></script>
<script src="Q/Q-Circuit-Editor.js"></script>
<script src="assets/navigation.js"></script>
</head>
<body>
<main class="api">
<p>
Source code:
<a href="https://github.com/stewdio/q.js/blob/master/source/Q-Circuit.js?ts=4" target="_blank">
<code>Q-Circuit.js</code>
</a>
</p>
<hr>
<h3 id="The_sounds_of_circuitry">The sounds of circuitry</h3>
<!-- <p>
A quantum computer is just a collection of
<a href="Q-Qubit.html">qubits</a>.
These qubits hold values like
<code>1</code>, <code>0</code>, or some value inbetween.
A quantum computer
is able calculate things
by changing the value of its qubits.
We tell the computer exactly how it should change
the value of a qubit
by instructing it to apply
<a href="https://en.wikipedia.org/wiki/Quantum_logic_gate" target="_blank">quantum gates</a>
to the qubit
in a particular sequence.
We can think of this as choreographing a dance;
the qubit dances through a sequence of gates
and as it dances through each gate
it will change the style in which it dances.
</p> -->
<p>
Quantum circuits are represented by diagrams similar to
<a href="https://en.wikipedia.org/wiki/Staff_(music)" target="_blank">musical staves</a>.
When a musician reads a line of music
she begins at moment zero on the left edge
and proceeds forward in time by reading to the right.
In this example we can see
from the ornate figure on the left
that the pitch of the notes will be described by a
<a href="https://en.wikipedia.org/wiki/Clef" target="_blank">C clef</a>
and that each measure will span three beats
thanks to the 3/4
<a href="https://en.wikipedia.org/wiki/Time_signature" target="_blank">time signature</a> notation.
</p>
<br>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 600 140" style="enable-background:new 0 0 600 140;" xml:space="preserve">
<g class="clef">
<rect x="90" y="20" class="st0" width="420" height="1" />
<rect x="90" y="40" class="st0" width="420" height="1" />
<rect x="90" y="60" class="st0" width="420" height="1" />
<rect x="90" y="80" class="st0" width="420" height="1" />
<rect x="90" y="100" class="st0" width="420" height="1" />
<rect x="504" y="20" class="st0" width="6" height="81"/>
<rect x="498" y="20" class="st0" width="2" height="81"/>
<rect x="90" y="20" class="st0" width="2" height="81"/>
<path class="st0" d="M186.1,62c0,0,0.2-1.4,0.8-1.7c0.6-0.2,0.9-0.2,0.9-0.2l10.8-0.2c0,0-3.7,7.5-20.6,26h14.6l0.2-3.5
c0,0,0-1.1-1.5-2.1l10.6-12.4l0.3,18.1h4.8v2h-4.9v5.4c0,0,0.3,4,4.9,3.6v2.9l-18.8,0.1v-2.3c0,0,5-0.8,4.7-4.1v-2.1
c0,0,0.3-3.2-3.5-3.3l-14.1,0.2c0,0-0.6-0.8,0-1.7C178.3,82.1,185.5,73.9,186.1,62z"/>
<path class="st0" d="M122.2,101h-12.1c0,0-0.1,0-0.1-0.1V20.1c0,0,0-0.1,0.1-0.1h12.1c0,0,0.1,0,0.1,0.1L122.2,101
C122.3,101,122.2,101,122.2,101z"/>
<path class="st0" d="M130.9,101h-3.3c0,0-0.1,0-0.1-0.1V20.1c0,0,0-0.1,0.1-0.1h3.3c0,0,0.1,0,0.1,0.1L130.9,101
C130.9,101,130.9,101,130.9,101z"/>
<path class="st0" d="M156.6,65.1c-3.8-3.1-9.4-4-13.6-1.4c-0.9,0.6-2,1.5-3,0.5c-0.5-0.5-0.7-1.1-1-1.7c-0.5-2.2,0-3.8,0-3.8
c0.2-0.6,0.5-1.3,1-1.7c1-1,2-0.1,3,0.5c4.2,2.5,9.9,1.6,13.6-1.4c8.7-7,8.3-21.7,1.5-30.1c-2.7-3.4-6.4-5.6-10.8-5.6
c-4.1,0.1-8.9,1.8-12.4,7.7c0,0-1.9,3.4-0.3,7.5c0.9,2.6,3.2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2,4.3-1.1,5.2-3.1c1-2.2,0.7-4.7-1-5.2
c-3.6-1.1-3.3-4.4,4.4-4.2c2.9,0.1,5.2,3.4,5.1,7.1c-0.1,3.4-2.5,7.7-7.4,7.7h-3.7l-0.2,2.9c0,0,2.7,0,4.5,0c3.3,0,6.8,3,6.8,7.8
c0,4-3,7.7-6.3,7.6c-1.7,0-4.4-0.9-4.4-2.6c0-1.3,1.9-1.8,1.9-4.5c0-3.7-2.8-4.9-5.4-4.9c-2.7,0-5.1,2.5-5,6.6
C179.2,57.3,183.1,61,192.5,61z"/>
</g>
<g class="beat doh">
<path d="M258,24.5L258,24.5v65c0,0.3,0.2,0.5,0.5,0.5h1.2c0.3,0,0.5-0.2,0.5-0.5V29.8c3.3,1.7,9.4,1.4,14.2-1.2
c6.6-3.6,10.2-10.1,7.9-14.6c-2.3-4.5-9.5-5.3-16.1-1.7C260.7,15.2,258,20.3,258,24.5z"/>
</g>
<g class="beat ray">
<path d="M338,64.5L338,64.5v65c0,0.3,0.2,0.5,0.5,0.5h1.2c0.3,0,0.5-0.2,0.5-0.5V69.8c3.3,1.7,9.4,1.4,14.2-1.2
c6.6-3.6,10.2-10.1,7.9-14.6c-2.3-4.5-9.5-5.3-16.1-1.7C340.7,55.2,338,60.3,338,64.5z"/>
<path d="M338,24.5L338,24.5v65c0,0.3,0.2,0.5,0.5,0.5h1.2c0.3,0,0.5-0.2,0.5-0.5V29.8c3.3,1.7,9.4,1.4,14.2-1.2
c6.6-3.6,10.2-10.1,7.9-14.6c-2.3-4.5-9.5-5.3-16.1-1.7C340.7,15.2,338,20.3,338,24.5z"/>
<polygon points="351,86.8 327,99 327,93.2 351,81"/>
<polygon points="351,96.8 327,109 327,103.2 351,91"/>
<polygon points="351,106.8 327,119 327,113.2 351,101"/>
</g>
<g class="beat egon">
<path d="M418,64.5L418,64.5v65c0,0.3,0.2,0.5,0.5,0.5h1.2c0.3,0,0.5-0.2,0.5-0.5V69.8c3.3,1.7,9.4,1.4,14.2-1.2
c6.6-3.6,10.2-10.1,7.9-14.6c-2.3-4.5-9.5-5.3-16.1-1.7C420.7,55.2,418,60.3,418,64.5z"/>
<path d="M418,24.5L418,24.5v65c0,0.3,0.2,0.5,0.5,0.5h1.2c0.3,0,0.5-0.2,0.5-0.5V29.8c3.3,1.7,9.4,1.4,14.2-1.2
c6.6-3.6,10.2-10.1,7.9-14.6c-2.3-4.5-9.5-5.3-16.1-1.7C420.7,15.2,418,20.3,418,24.5z"/>
</g>
</svg>
<br>
<p>
Similarly, quantum circuit diagrams are a series of moments in time,
beginning at moment zero on the left edge
and proceeding forward in time by reading to the right.
Here we have a quantum circuit that is 3 moments long
and operates on just 2 quantum bits:
</p>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="70 0 480 180" style="enable-background:new 0 0 600 180;" xml:space="preserve">
<g class="clef">
<path d="M398.6,29l0.9,0c0.3,0,0.6,0,0.9-0.1c0.3-0.1,0.5-0.2,0.7-0.4s0.4-0.4,0.5-0.6c0.1-0.2,0.2-0.5,0.3-0.8
c0-0.3,0-0.5,0-0.7s-0.1-0.4-0.3-0.6c-0.1-0.2-0.3-0.3-0.5-0.4c-0.2-0.1-0.4-0.1-0.7-0.2c-0.3,0-0.6,0-0.8,0.1s-0.5,0.2-0.6,0.4
c-0.2,0.2-0.3,0.4-0.5,0.6c-0.1,0.2-0.2,0.5-0.3,0.8l-1.3,0c0-0.5,0.2-0.9,0.4-1.2c0.2-0.4,0.5-0.7,0.8-0.9
c0.3-0.3,0.7-0.5,1.1-0.6c0.4-0.1,0.8-0.2,1.3-0.2c0.4,0,0.8,0.1,1.2,0.2c0.4,0.1,0.7,0.3,0.9,0.6c0.2,0.3,0.4,0.6,0.5,0.9
c0.1,0.4,0.2,0.8,0.1,1.2c0,0.3-0.1,0.6-0.2,0.8s-0.3,0.5-0.5,0.7c-0.2,0.2-0.4,0.4-0.6,0.5s-0.5,0.3-0.7,0.4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1.4,7.9h-1.3L150.8,134.2z"/>
<path d="M161.1,131.1c-0.1,0.8-0.3,1.5-0.7,2.2s-0.8,1.1-1.3,1.4s-1,0.5-1.6,0.4c-1,0-1.7-0.4-2.1-1.1l-0.3,0.9h-1.2
l2-11.2h1.3l-0.8,4.2c0.6-0.7,1.4-1,2.3-1c0.8,0,1.4,0.3,1.8,0.8s0.6,1.3,0.7,2.2c0,0.3,0,0.6,0,0.9L161.1,131.1z M159.8,130.3
c0-0.7-0.1-1.3-0.4-1.6s-0.6-0.6-1.2-0.6c-0.8,0-1.5,0.4-2.1,1.2l-0.6,3.4c0.3,0.8,0.8,1.2,1.6,1.2c0.5,0,1-0.1,1.4-0.5
c0.4-0.3,0.7-0.8,0.9-1.4C159.7,131.6,159.8,131,159.8,130.3z"/>
<path d="M163.5,135h-1.3l1.4-7.9h1.3L163.5,135z M164.6,124.2c0.2,0,0.4,0.1,0.6,0.2c0.1,0.1,0.2,0.3,0.2,0.6
c0,0.2-0.1,0.4-0.2,0.6c-0.1,0.1-0.3,0.2-0.6,0.2s-0.4-0.1-0.6-0.2s-0.2-0.3-0.2-0.6s0.1-0.4,0.2-0.6S164.4,124.2,164.6,124.2z"/>
<path d="M169.2,125.2l-0.3,1.9h1.4l-0.2,1h-1.4l-0.8,4.9c0,0.1,0,0.2,0,0.4c0,0.4,0.2,0.6,0.6,0.6
c0.2,0,0.4,0,0.6-0.1L169,135c-0.3,0.1-0.6,0.1-1,0.1c-0.5,0-0.9-0.2-1.2-0.6c-0.3-0.4-0.4-0.9-0.3-1.5l0.8-4.9H166l0.2-1h1.4
l0.3-1.9H169.2z"/>
<path d="M179.1,135h-2l1.4-8.1l-2.8,1l0.3-1.8l4.7-1.6h0.1L179.1,135z"/>
<polygon points="229.9,80.5 228.1,79.5 233.9,69.9 230.1,60.4 231.9,59.6 236.1,70.1 "/>
<polygon points="229.9,140.5 228.1,139.5 233.9,129.9 230.1,120.4 231.9,119.6 236.1,130.1 "/>
<circle cx="280" cy="130" r="5"/>
</g>
<g class="beat doh">
<rect x="260" y="50" width="40" height="40"/>
</g>
<g class="beat ray">
<circle cx="340" cy="70" r="5"/>
<circle cx="340" cy="130" r="15"/>
<rect x="339" y="70" width="2" height="60"/>
</g>
<g class="beat egon">
<rect x="380" y="110" width="40" height="40"/>
<rect x="380" y="50" width="40" height="40"/>
</g>
<g class="clef label">
<path d="M284.7,77h-3.3l1-5.9h-4.9l-1,5.9h-3.3l2.5-14.2h3.3l-1,5.6h4.9l1-5.6h3.3L284.7,77z"/>
<path d="M400.4,127.5l3-4.7h4l-5.1,7.2l2.8,7h-3.7l-1.6-4.8l-3.1,4.8h-4l5.2-7.3l-2.7-6.9h3.7L400.4,127.5z"/>
<path d="M400.4,67.5l3-4.7h4l-5.1,7.2l2.8,7h-3.7l-1.6-4.8l-3.1,4.8h-4l5.2-7.3l-2.7-6.9h3.7L400.4,67.5z"/>
<rect x="339" y="123" width="2" height="14"/>
<rect x="333" y="129" width="14" height="2"/>
</g>
</svg>
<br>
<p>
Let’s read it from left to right,
observing what happens at each passing moment.
We begin at moment zero (<code>t0</code>) with our initial qubit values.
Both qubit #0 and qubit #1 begin with a value of <span class="complex-vector beta">0</span>.
This is a <a href="Q-Qubit.html#.HORIZONTAL">“horizontal” qubit state</a>.
In normal quantum circuit design these initial values will always be <span class="complex-vector beta">0</span>.
Q, however, allows us to manually change these input values
to any possible qubit state
so that you may simulate a snippet of a complete circuit.
We’ll come back to this later, but for now let’s read on.
</p>
<p>
During our first moment of true operation (<code>t1</code>)
we apply a <a href="Q-Gate.html#.HADAMARD">Hadamard</a> gate to qubit #0,
putting it in to a <a href="https://en.wikipedia.org/wiki/Quantum_superposition" target="_blank">superposition state</a>.
(This is represented by the “H” within a square on qubit #0’s circuit wire.)
We leave qubit #1 as-is by
applying an
<a href="Q-Gate.html#.IDENTITY">Identity</a> gate; a
<code>null</code> operator or “do nothing” gate.
This is represented by the small circle on qubit #1’s circuit wire.
</p>
<p>
In our next moment (<code>t2</code>) we operate on both qubits at once
by applying a <a href="Q-Gate.html#.CONTROLLED_NOT">Controlled-Not</a> gate.
This operation will flip the value of qubit #1 if, and only if,
the value of qubit #0 collapses to <span class="complex-vector beta">1</span>.
This action
<a href="https://en.wikipedia.org/wiki/Qubit#Quantum_entanglement" target="_blank">entangles the two qubits</a>;
their states are now dependent on one another.
At this point it is impossible to compute the values of either
qubit #0 or qubit #1 independently.
From here onward the state of the circuit
can only be computed as a whole.
</p>
<p>
In our circuit’s final moment (<code>t3</code>)
we apply a
<a href="Q-Gate.html#.PAULI_X">Pauli X</a> gate
to each qubit,
flipping the value of both.
</p>
<h3 id="Writing_quantum_circuits">Writing quantum circuits</h3>
<p>
To create the above circuit we can take advantage of several Q shortcuts.
To beging with, the <a href="Q.html"><code>Q</code> object</a> itself is a function
that internally passes its arguments to the
<code>Circuit.<a href="Q-Circuit.html#.fromText">fromText()</a></code>
static method.
This function can accept text as an argument,
but also accepts
<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals" target="_blank">Template literals</a>,
which use backticks rather than single or double quotes,
and <em>do not require parentheses to invoke a function call.</em>
Note the backticks and lack of parentheses in this example.
We’ll call our example circuit “fox”:
</p>
<pre><code>
var fox = <a href="Q.html">Q</a>`<strong>
H-X#0-X
I-X#1-X</strong>
`
</code></pre>
<p>
Q is rather flexible when it comes to parsing text into circuits.
New lines indicate a new qubit to operate on.
Within a line, any non-alphanumeric character between alphanumerics
is interpreted as a moment seperator.
Therefore, the following (less sensible) input creates a circuit identical to the one above.
</p>
<pre><code>
var fox = <a href="Q.html">Q</a>`<strong>H X#0--X
I X#1 X</strong>`
</code></pre>
<p>
Internally, <code><a href="Q-Circuit.html#.fromText">fromText</a></code>
is making the following calls to create the circuit.
Note the extreme difference between
the very little we must type (above) to create the circuit
and the large amount of construction happening under the hood (below).
</p>
<pre><code>
<span class="comment">// Create a circuit
// that operates on 2 qubits
// and lasts for 3 moments.</span>
var fox = new <a href="Q.html">Q</a>.Circuit( 2, 3 )
<span class="comment">// At moment #1 (the first moment we can operate),
// we’ll use a Hadamard gate
// to set the value of the qubit
// on register #1 in to superposition.</span>
.<a href="#.prototype.set$">set$</a>( <a href="Q.html">Q</a>.<a href="Q-Gate.html">Gate</a>.<a href="Q-Gate.html#.HADAMARD">HADAMARD</a>, 1, 1 )
<span class="comment">// Then at moment #2
// we’ll use a Controlled-Not gate
// to invert the value on register #2
// if the value of register #1 is 1.
// Note this is actually created from a
// Pauli X gate with two inputs!</span>
.<a href="#.prototype.set$">set$</a>( <a href="Q.html">Q</a>.<a href="Q-Gate.html">Gate</a>.<a href="Q-Gate.html#.PAULI_X">PAULI_X</a>, 2, [ 1, 2 ])
<span class="comment">// Finally, at moment #3
// we’ll use a Pauli X gate
// to flip the value of register #1,
// and do the same for register #2.</span>
.<a href="#.prototype.set$">set$</a>( <a href="Q.html">Q</a>.<a href="Q-Gate.html">Gate</a>.<a href="Q-Gate.html#.PAULI_X">PAULI_X</a>, 3, 1 )
.<a href="#.prototype.set$">set$</a>( <a href="Q.html">Q</a>.<a href="Q-Gate.html">Gate</a>.<a href="Q-Gate.html#.PAULI_X">PAULI_X</a>, 3, 2 )
</code></pre>
<p>
I think you’ll agree the shorter <code>Q`…`</code> syntax is preferable.
</p>
<h3 id="Inspecting_quantum_circuits">Inspecting quantum circuits</h3>
<p>
Let’s create that fox circuit again using our compressed Q syntax.
(This illustrates yet another small variation on the whitespace and gate separator used
in the input <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals">Template literal</a>.)
</p>
<pre><code>
var fox = <a href="Q.html">Q</a>`<strong>
H X#0 X
I X#1 X</strong>
`
</code></pre>
<p>
We can fully inspect our circuit as an object in the JavaScript console, of course.
But we can also get a summary overview with the following command.
</p>
<pre><code>
fox.<a href="#.prototype.toText">toText</a>()
</code></pre>
<p>
This returns the following string.
</p>
<pre><samp>
H-X#0-X
I-X#1-X
</samp></pre>
<p>
Does that look familiar?
It’s very nearly the text we used to construct our circuit in the first place.
In fact, because we can both construct and ouput circuits using text
we can clone and test for equality between circuits like so.
</p>
<pre><code>
var dog = <a href="Q.html">Q</a>( fox.<a href="#.prototype.toText">toText</a>() )
fox === dog<span class="comment">// false.</span>
fox.<a href="#.prototype.toText">toText</a>() === dog.<a href="#.prototype.toText">toText</a>()<span class="comment">// true.</span>
</code></pre>
<p>
Though in practice you’re far more likely to clone a circuit
by using its own method for doing so.
</p>
<pre><code>
var dog = <strong>fox.<a href="#.prototype.clone">clone</a>()</strong>
dog === fox<span class="comment">// false.</span>
fox.<a href="#.prototype.toText">toText</a>() === dog.<a href="#.prototype.toText">toText</a>()<span class="comment">// true.</span>
</code></pre>
<h4 id="ASCII_circuit_diagrams">ASCII circuit diagrams</h4>
<p>
While outputting a circuit as simple text can be useful,
we humans often need a little more visual hand-holding
in order to quickly make sense of things.
With this in mind, Q offers full-on ASCII circuit diagrams.
</p>
<pre><code>
fox.<a href="#.prototype.toDiagram">toDiagram</a>()
</code></pre>
<p>
The above command yields the following,
with time labeled from <code>t0</code> (the moment of input)
progressing onward,
and qubits labeled likewise.
</p>
<pre><samp>
m1 m2 m3
┌───┐╭─────╮┌───┐
r1 |0⟩─┤ H ├┤ X#0 ├┤ X │
└───┘╰──┬──╯└───┘
╭──┴──╮┌───┐
r2 |0⟩───○──┤ X#1 ├┤ X │
╰─────╯└───┘
</samp></pre>
<h4>Interactive circuit diagrams</h4>
<p>
But this is a <a href="https://en.wikipedia.org/wiki/Web_browser" target="_blank">Web browser</a>—we ought to make use of its
<a href="https://en.wikipedia.org/wiki/Document_Object_Model" target="_blank">document object model</a> for interactivity, no?!
The <code><a href="#.prototype.toDom">toDom</a>()</code> method
returns a document fragment, complete with event handlers,
that can be attached to your live document.
</p>
<div class="coming-soon">
Note that this feature is still in its early stages
and is not yet fully functional.
Check back in May 2020 for updates.
Better yet, <a href="https://github.com/stewdio/q.js" target="_blank">contribute to Q!</a>
</div>
<pre><code>
document.body.appendChild( fox.<a href="#.prototype.toDom">toDom</a>() )
</code></pre>
<p>
This yields the following:
</p>
<div class="fox-dom"></div>
<h3 id="Executing_quantum_circuits">Executing quantum circuits</h3>
<p>
Once a circuit is created it must be evaluated with
<code><a href="#.prototype.evaluate$">evaluate$</a>()</code>.
This resolve’s the circuit’s state <code><a href="#this.matrix">matrix</a></code>
and also notes the state names (binary digits)
and their corresponding propabilities in
the instance’s <code><a href="#this.outcomes">outcomes</a></code> property.
And that’s good.
But what’s even better is seeing those results!
A circuit’s <code><a href="#.prototype.report">report$</a>()</code> method
will internally call
<code><a href="#.prototype.evaluate$">evaluate$</a>()</code> if need be,
then log out the possible outcomes,
including bar graphs of the probabilities.
</p>
<pre><code>
fox.<a href="#.prototype.report">report$</a>()
<samp>
1 |00⟩ ██████████░░░░░░░░░░ 50% chance
2 |01⟩ ░░░░░░░░░░░░░░░░░░░░ 0% chance
3 |10⟩ ░░░░░░░░░░░░░░░░░░░░ 0% chance
4 |11⟩ ██████████░░░░░░░░░░ 50% chance
</samp>
</code></pre>
<p>
For fun we can also use
<code><a href="#.prototype.try$">try$</a>()</code>
to randomly pick an outcome based on
the outcome probabilities.
Similar to
<code><a href="#.prototype.report">report$</a>()</code>,
the <code><a href="#.prototype.try$">try$</a>()</code> method
will internally call
<code><a href="#.prototype.evaluate$">evaluate$</a>()</code>
if need be.
</p>
<pre><code>
fox.<a href="#.prototype.try$">try$</a>()
<samp>|00⟩</samp>
fox.<a href="#.prototype.try$">try$</a>()
<samp>|11⟩</samp>
</code></pre>
<h3 id="Overlapping_multi-qubit_gates">Overlapping multi-qubit gates</h3>
<p>
Some physical architectures allow for interactions between qubits that don’t resolve in to the simplest diagrams.
Take this circuit, for example, which contains two C-not gates at moment 2:
</p>
<pre><code>
var cat = <a href="Q.html">Q</a>`<strong>
H X.0#0
I X.1#0
I X.0#1
I X.1#1
X I</strong>
`
</code></pre>
<p>
We can see that they overlap. The first C-not [0] operates on qubit 0 and qubit 2, while the second C-not [1] operates on qubit 1 and qubit 3.
We can see this slightly more clearly as a diagram
with the <code>cat.<a href="#.prototype.toDiagram">toDiagram</a>()</code> command:
</p>
<pre><samp>
m1 m2
┌───┐╭───────╮
r1 |0⟩─┤ H ├┤ X.0#0 │
└───┘╰──┬────╯
╭───────╮
r2 |0⟩───○──┤ X.1#0 │
╰────┬──╯
╭──┴────╮
r3 |0⟩───○──┤ X.0#1 │
╰───────╯
╭────┴──╮
r4 |0⟩───○──┤ X.1#1 │
╰───────╯
┌───┐
r5 |0⟩─┤ X ├────○──
└───┘
</samp></pre>
<h3 id="Editing_quantum_circuits">Editing quantum circuits</h3>
<h4 id="Copy,_cut,_paste">Copy, cut, paste</h4>
<p>
Let’s start with the <code>cat</code> circuit above,
and copy a section of it.
In this case we’re copying all of its moments
and all of its qubits
so it is effectively equal to
<code>cat.<a href="#.prototype.clone">clone</a>()</code>:
</p>
<pre><code>
var gup = cat.<a href="#.prototype.copy">copy</a>({
qubitFirstIndex: 0,
qubitRange: cat.<a href="#this.bandwidth">bandwidth</a>,
momentFirstIndex: 0,
momentRange: cat.<a href="#this.timewidth">timewidth</a>
})
</code></pre>
<p>
Both <code><a href="#.prototype.copy">copy</a></code>
and <code><a href="#.prototype.cut$">cut$</a></code>
are very flexible with the parameter object.
Supplying no parameters is effectively equal to selecting the entire circuit.
(So the above example is a bit superfluous, but socratic.)
</p>
<p>
Cutting replaces the “cut” operations with Identity gates
and returns the cut portion.
</p>
<pre><code>
var hen = gup.<a href="#.prototype.cut$">cut$</a>()
</code></pre>
<p>
Cutting <em>all</em> of the operations as above
will yield a blank circuit as seen below.
(And <code>hen</code> will now contain those cut operations.)
</p>
<pre><samp>
m0 m1 m2 m3
r0 |0⟩───○────○────○
r1 |0⟩───○────○────○
r2 |0⟩───○────○────○
r3 |0⟩───○────○────○
r4 |0⟩───○────○────○
</samp></pre>
<p>
Pasting in to a circuit can cause that circuit to expand
in both time and qubits.
For example, both our <code>cat</code>
and <code>gup</code> circuits are 4 moments long (0, 1, 2, 3)
and 5 qubits in bandwidth (0, 1, 2, 3, 4).
What if we paste our <code>cat</code> circuit
in to our empty <code>gup</code> circuit
but do so by pushing it one moment further and one qubit further?
</p>
<pre><code>
gup.<a href="#.prototype.paste$">paste$</a>( cat, 1, 1 )
</code></pre>
<p>
Notice how <code>gup</code> has now expanded.
The first qubit registers are still empty.
The first moment of qubits also remains empty.
But the entirety of <code>cat</code>
is now pasted in there.
</p>
<pre><samp>
m0 m1 m2 m3 m4
r0 |0⟩───○────○──────○──────○
┌───┐┌───────┐┌───┐
r1 |0⟩───○──┤ H ├┤ X.0#0 ├┤ M │
└───┘└─┬─────┘└───┘
┌───────┐┌───┐
r2 |0⟩───○────○──┤ X.1#0 ├┤ M │
└───┬───┘└───┘
┌─┴─────┐┌───┐
r3 |0⟩───○────○──┤ X.0#1 ├┤ M │
└───────┘└───┘
┌───┴───┐┌───┐
r4 |0⟩───○────○──┤ X.1#1 ├┤ M │
└───────┘└───┘
┌───┐ ┌───┐
r5 |0⟩───○──┤ X ├────○────┤ M │
└───┘ └───┘
</samp></pre>
<p class="coming-soon">
More to come! More examples! Revised examples!
Check back in May 2020.
</p>
<hr>
<h3>Constructor</h3>
<p>
<span class="constructor">Circuit</span>
<code class="value-type">Function([ bandwidth: Number [, timewidth: Number ]]) => <a href="Q.html">Q</a>.Circuit</code>
<br>
Description TK.
</p>
<ul class="properties">
<li>
<dt id="this.index">index</dt>
<dd>
<code class="value-type">Number</code>
Description TK.
</dd>
</li>
<li>
<dt id="this.bandwidth">bandwidth</dt>
<dd>
<code class="value-type">Number</code>
Description TK.
</dd>
</li>
<li>
<dt id="this.timewidth">timewidth</dt>
<dd>
<code class="value-type">Number</code>
Description TK.
</dd>
</li>
<li>
<dt id="this.matrix">needsEvaluation</dt>
<dd>
<code class="value-type">Boolean</code>
Description TK.
</dd>
</li>
<li>
<dt id="this.matrix">matrix</dt>
<dd>
<code class="value-type">null or Q.Matrix</code>
Description TK.
</dd>
</li>
</ul>
<h3>Static properties</h3>
<ul class="properties">
<li>
<dt id=".index">index</dt>
<dd>
<code class="value-type">Number</code>
Description TK.
</dd>
</li>
<li>
<dt id=".help">help</dt>
<dd>
<code class="value-type">Function</code>
Description TK.
</dd>
</li>
<li>
<dt id=".constants">constants</dt>
<dd>
<code class="value-type">Object</code>
Description TK.
</dd>
</li>
<li>
<dt id=".createConstant">createConstant</dt>
<dd>
<code class="value-type">Function</code>
Description TK.
</dd>
</li>
<li>
<dt id=".createConstants">createConstants</dt>
<dd>
<code class="value-type">Function</code>
Description TK.
</dd>
</li>
<li>
<dt id=".controlled">controlled</dt>
<dd>
<code class="value-type">Function</code>
Description TK.
</dd>
</li>
<li>
<dt id=".expandMatrix">expandMatrix</dt>
<dd>
<code class="value-type">Function</code>
Description TK.
</dd>
</li>
<li>
<dt id=".evaluate">evaluate</dt>
<dd>
<code class="value-type">Function</code>
Description TK.
</dd>
</li>
<li>
<dt id=".fromText">fromText</dt>
<dd>
<code class="value-type">Function</code>
Description TK.
</dd>
</li>
</ul>
<h3 id="Prototype_properties">Prototype properties</h3>
<h4>Non-destructive methods</h4>
<ul class="properties">
<li>
<dt id=".prototype.clone">clone</dt>
<dd>
<code class="value-type">Function</code>
Description TK.
</dd>
</li>
<li>
<dt id=".prototype.toTable">toTable</dt>
<dd>
<code class="value-type">Function</code>
Description TK.
</dd>
</li>
<li>
<dt id=".prototype.toText">toText</dt>
<dd>
<code class="value-type">Function</code>
Description TK.
</dd>
</li>
<li>
<dt id=".prototype.toDiagram">toDiagram</dt>
<dd>
<code class="value-type">Function</code>
Description TK.
</dd>
</li>
<li>
<dt id=".prototype.toDom">toDom</dt>
<dd>
<code class="value-type">Function</code>
Description TK.
</dd>
</li>
<li>
<dt id=".prototype.determineRanges">determineRanges</dt>
<dd>
<code class="value-type">Function</code>
Description TK.
</dd>
</li>
<li>
<dt id=".prototype.copy">copy</dt>
<dd>
<code class="value-type">Function</code>
Description TK.
</dd>
</li>
</ul>
<h4>Destructive methods</h4>
<ul class="properties">
<li>
<dt id=".prototype.ensureMomentsAreReady$">ensureMomentsAreReady$</dt>
<dd>
<code class="value-type">Function</code>
Description TK.
</dd>
</li>
<li>
<dt id=".prototype.fillEmptyOperations$">fillEmptyOperations$</dt>
<dd>
<code class="value-type">Function</code>
Description TK.
</dd>
</li>
<li>
<dt id=".prototype.removeHangingOperations$">removeHangingOperations$</dt>
<dd>
<code class="value-type">Function</code>
Description TK.
</dd>
</li>
<li>
<dt id=".prototype.clearThisInput$">clearThisInput$</dt>
<dd>
<code class="value-type">Function</code>
Description TK.
</dd>
</li>
<li>
<dt id=".prototype.set$">set$</dt>
<dd>
<code class="value-type">Function</code>
Description TK.
</dd>
</li>
<li>
<dt id=".prototype.cut$">cut$</dt>
<dd>
<code class="value-type">Function</code>
Description TK.
</dd>
</li>
<li>
<dt id=".prototype.spliceCut$">spliceCut$</dt>
<dd>
<code class="value-type">Function</code>
Description TK.
</dd>
</li>
<li>
<dt id=".prototype.paste$">paste$</dt>
<dd>
<code class="value-type">Function</code>
Description TK.
</dd>
</li>
<li>
<dt id=".prototype.splicePaste$">splicePaste$</dt>
<dd>
<code class="value-type">Function</code>
Description TK.
</dd>
</li>
<li>
<dt id=".prototype.pasteInsert$">pasteInsert$</dt>
<dd>
<code class="value-type">Function</code>
Description TK.
</dd>
</li>
<li>
<dt id=".prototype.expand$">expand$</dt>
<dd>
<code class="value-type">Function</code>
Description TK.
</dd>
</li>
<li>
<dt id=".prototype.trim$">trim$</dt>
<dd>
<code class="value-type">Function</code>
Description TK.
</dd>
</li>
<li>
<dt id=".prototype.evaluate$">evaluate$</dt>
<dd>
<code class="value-type">Function</code>
Description TK.
</dd>
</li>
<li>
<dt id=".prototype.report$">report$</dt>
<dd>
<code class="value-type">Function</code>
Description TK.
</dd>
</li>
<li>
<dt id=".prototype.try$">try$</dt>
<dd>
<code class="value-type">Function</code>
Description TK.
</dd>
</li>
</ul>
</main>
<svg style="display: none" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 60 60" style="enable-background:new 0 0 60 60;" xml:space="preserve">
<g id="qjs-circuit-wire">
<rect y="30" width="60" height="1"/>
</g>
</svg>
<svg style="display: none"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
x="0px" y="0px"
viewBox="0 30 60 60">
<symbol id="qjs-circuit-control-straight">
<line x1="30" y1="0" x2="30" y2="60"/>
</symbol>
<symbol id="qjs-circuit-control-curved" viewBox="0 0 60 60" preserveAspectRatio="none">
<path d="M30,0c13.8,0,25,13.4,25,30S43.8,60,30,60"/>
</symbol>
</svg>