quest-rs 0.2.8

Safe Rust wrapper around the Quantum Exact Simulation Toolkit (QuEST)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
<!-- HTML header for doxygen 1.8.8-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <!-- For Mobile Devices -->
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
        <meta name="generator" content="Doxygen 1.8.17"/>
        <script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
        <title>QuEST: Calculations</title>
        <!--<link href="tabs.css" rel="stylesheet" type="text/css"/>-->
        <script type="text/javascript" src="dynsections.js"></script>
        <link href="doxygen.css" rel="stylesheet" type="text/css" />
        <link href="style.css" rel="stylesheet" type="text/css"/>
        <link href='https://fonts.googleapis.com/css?family=Roboto+Slab' rel='stylesheet' type='text/css'>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
        <link href="jquery.smartmenus.bootstrap.css" rel="stylesheet">
        <script type="text/javascript" src="jquery.smartmenus.js"></script>
        <!-- SmartMenus jQuery Bootstrap Addon -->
        <script type="text/javascript" src="jquery.smartmenus.bootstrap.js"></script>
        <!-- SmartMenus jQuery plugin -->
    </head>
    <body>
        <nav class="navbar navbar-default" role="navigation">
            <div class="container">
                <div class="navbar-header">
                    <a class="navbar-brand"><img alt="Logo" src="logo.png"/></a>
                    <a class="navbar-brand"><b>QuEST</b> v3.1.0<br>The Quantum Exact Simulation Toolkit</a>
                </div>
            </div>
        </nav>
        <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
            <div class="content" id="content">
                <div class="container">
                    <div class="row">
                        <div class="col-sm-12 panel " style="padding-bottom: 15px;">
                            <div style="margin-bottom: 15px;">
<!-- end header part -->
<!-- Generated by Doxygen 1.8.17 -->
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',false,false,'search.php','Search');
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div class="header">
  <div class="summary">
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle">
<div class="title">Calculations</div>  </div>
</div><!--header-->
<div class="contents">

<p>Calculations and property-getters which do not modify the studied quantum state.  
<a href="#details">More...</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:ga658b3a5cab5e73a17a7fd76a83583a22"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__type.html#ga7740e349b4f8bae6451547680f0ce2d6">qreal</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__calc.html#ga658b3a5cab5e73a17a7fd76a83583a22">calcDensityInnerProduct</a> (<a class="el" href="structQureg.html">Qureg</a> rho1, <a class="el" href="structQureg.html">Qureg</a> rho2)</td></tr>
<tr class="memdesc:ga658b3a5cab5e73a17a7fd76a83583a22"><td class="mdescLeft">&#160;</td><td class="mdescRight">Computes the Hilbert-Schmidt scalar product (which is equivalent to the Frobenius inner product of matrices) of two density matrices <code>rho1</code> and <code>rho2</code> of equivalent size.  <a href="group__calc.html#ga658b3a5cab5e73a17a7fd76a83583a22">More...</a><br /></td></tr>
<tr class="separator:ga658b3a5cab5e73a17a7fd76a83583a22"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga15cfad3f3d26339128e3be32ae7deacd"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__type.html#ga7740e349b4f8bae6451547680f0ce2d6">qreal</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__calc.html#ga15cfad3f3d26339128e3be32ae7deacd">calcExpecPauliProd</a> (<a class="el" href="structQureg.html">Qureg</a> qureg, int *targetQubits, enum <a class="el" href="group__type.html#ga1c703cf89629e4e9c7023cd402d67028">pauliOpType</a> *pauliCodes, int numTargets, <a class="el" href="structQureg.html">Qureg</a> workspace)</td></tr>
<tr class="memdesc:ga15cfad3f3d26339128e3be32ae7deacd"><td class="mdescLeft">&#160;</td><td class="mdescRight">Computes the expected value of a product of Pauli operators.  <a href="group__calc.html#ga15cfad3f3d26339128e3be32ae7deacd">More...</a><br /></td></tr>
<tr class="separator:ga15cfad3f3d26339128e3be32ae7deacd"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga50ee589fd5ceab52fdd70d0082352b41"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__type.html#ga7740e349b4f8bae6451547680f0ce2d6">qreal</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__calc.html#ga50ee589fd5ceab52fdd70d0082352b41">calcExpecPauliSum</a> (<a class="el" href="structQureg.html">Qureg</a> qureg, enum <a class="el" href="group__type.html#ga1c703cf89629e4e9c7023cd402d67028">pauliOpType</a> *allPauliCodes, <a class="el" href="group__type.html#ga7740e349b4f8bae6451547680f0ce2d6">qreal</a> *termCoeffs, int numSumTerms, <a class="el" href="structQureg.html">Qureg</a> workspace)</td></tr>
<tr class="memdesc:ga50ee589fd5ceab52fdd70d0082352b41"><td class="mdescLeft">&#160;</td><td class="mdescRight">Computes the expected value of a sum of products of Pauli operators.  <a href="group__calc.html#ga50ee589fd5ceab52fdd70d0082352b41">More...</a><br /></td></tr>
<tr class="separator:ga50ee589fd5ceab52fdd70d0082352b41"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gaa266ed6c8ae5d0d0f49e1ac50819cffc"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__type.html#ga7740e349b4f8bae6451547680f0ce2d6">qreal</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__calc.html#gaa266ed6c8ae5d0d0f49e1ac50819cffc">calcFidelity</a> (<a class="el" href="structQureg.html">Qureg</a> qureg, <a class="el" href="structQureg.html">Qureg</a> pureState)</td></tr>
<tr class="memdesc:gaa266ed6c8ae5d0d0f49e1ac50819cffc"><td class="mdescLeft">&#160;</td><td class="mdescRight">Calculates the fidelity of <code>qureg</code> (a statevector or density matrix) against a reference pure state (necessarily a statevector).  <a href="group__calc.html#gaa266ed6c8ae5d0d0f49e1ac50819cffc">More...</a><br /></td></tr>
<tr class="separator:gaa266ed6c8ae5d0d0f49e1ac50819cffc"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga87ddbe5c8281543541ccd99e0dafd387"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__type.html#ga7740e349b4f8bae6451547680f0ce2d6">qreal</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__calc.html#ga87ddbe5c8281543541ccd99e0dafd387">calcHilbertSchmidtDistance</a> (<a class="el" href="structQureg.html">Qureg</a> a, <a class="el" href="structQureg.html">Qureg</a> b)</td></tr>
<tr class="memdesc:ga87ddbe5c8281543541ccd99e0dafd387"><td class="mdescLeft">&#160;</td><td class="mdescRight">Computes the Hilbert Schmidt distance between two density matrices <code>a</code> and <code>b</code>, defined as the Frobenius norm of the difference between them.  <a href="group__calc.html#ga87ddbe5c8281543541ccd99e0dafd387">More...</a><br /></td></tr>
<tr class="separator:ga87ddbe5c8281543541ccd99e0dafd387"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga374ad70804998394ae41ebfe106258a6"><td class="memItemLeft" align="right" valign="top"><a class="el" href="structComplex.html">Complex</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__calc.html#ga374ad70804998394ae41ebfe106258a6">calcInnerProduct</a> (<a class="el" href="structQureg.html">Qureg</a> bra, <a class="el" href="structQureg.html">Qureg</a> ket)</td></tr>
<tr class="memdesc:ga374ad70804998394ae41ebfe106258a6"><td class="mdescLeft">&#160;</td><td class="mdescRight">Computes the inner product <img class="formulaInl" alt="$ \langle \text{bra} | \text{ket} \rangle $" src="form_82.png"/> of two equal-size state vectors, given by.  <a href="group__calc.html#ga374ad70804998394ae41ebfe106258a6">More...</a><br /></td></tr>
<tr class="separator:ga374ad70804998394ae41ebfe106258a6"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga2a0fbd65f42d35dcd5ae966c48826920"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__type.html#ga7740e349b4f8bae6451547680f0ce2d6">qreal</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__calc.html#ga2a0fbd65f42d35dcd5ae966c48826920">calcProbOfOutcome</a> (<a class="el" href="structQureg.html">Qureg</a> qureg, const int measureQubit, int outcome)</td></tr>
<tr class="memdesc:ga2a0fbd65f42d35dcd5ae966c48826920"><td class="mdescLeft">&#160;</td><td class="mdescRight">Gives the probability of a specified qubit being measured in the given outcome (0 or 1).  <a href="group__calc.html#ga2a0fbd65f42d35dcd5ae966c48826920">More...</a><br /></td></tr>
<tr class="separator:ga2a0fbd65f42d35dcd5ae966c48826920"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga683779343fb2c6055f6b1d01079c2ede"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__type.html#ga7740e349b4f8bae6451547680f0ce2d6">qreal</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__calc.html#ga683779343fb2c6055f6b1d01079c2ede">calcPurity</a> (<a class="el" href="structQureg.html">Qureg</a> qureg)</td></tr>
<tr class="memdesc:ga683779343fb2c6055f6b1d01079c2ede"><td class="mdescLeft">&#160;</td><td class="mdescRight">Calculates the purity of a density matrix, by the trace of the density matrix squared.  <a href="group__calc.html#ga683779343fb2c6055f6b1d01079c2ede">More...</a><br /></td></tr>
<tr class="separator:ga683779343fb2c6055f6b1d01079c2ede"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gab082910d33473ec29e1d5852943de468"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__type.html#ga7740e349b4f8bae6451547680f0ce2d6">qreal</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__calc.html#gab082910d33473ec29e1d5852943de468">calcTotalProb</a> (<a class="el" href="structQureg.html">Qureg</a> qureg)</td></tr>
<tr class="memdesc:gab082910d33473ec29e1d5852943de468"><td class="mdescLeft">&#160;</td><td class="mdescRight">A debugging function which calculates the probability of the qubits in <code>qureg</code> being in any state, which should always be 1 for correctly normalised states (hence returning a real number).  <a href="group__calc.html#gab082910d33473ec29e1d5852943de468">More...</a><br /></td></tr>
<tr class="separator:gab082910d33473ec29e1d5852943de468"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga30d6f8b7c766c9c9914b2c61a2fc0def"><td class="memItemLeft" align="right" valign="top"><a class="el" href="structComplex.html">Complex</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__calc.html#ga30d6f8b7c766c9c9914b2c61a2fc0def">getAmp</a> (<a class="el" href="structQureg.html">Qureg</a> qureg, long long int index)</td></tr>
<tr class="memdesc:ga30d6f8b7c766c9c9914b2c61a2fc0def"><td class="mdescLeft">&#160;</td><td class="mdescRight">Get the complex amplitude at a given index in the state vector.  <a href="group__calc.html#ga30d6f8b7c766c9c9914b2c61a2fc0def">More...</a><br /></td></tr>
<tr class="separator:ga30d6f8b7c766c9c9914b2c61a2fc0def"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gadca286c4ad5cde6124d4e80a7ab95a68"><td class="memItemLeft" align="right" valign="top"><a class="el" href="structComplex.html">Complex</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__calc.html#gadca286c4ad5cde6124d4e80a7ab95a68">getDensityAmp</a> (<a class="el" href="structQureg.html">Qureg</a> qureg, long long int row, long long int col)</td></tr>
<tr class="memdesc:gadca286c4ad5cde6124d4e80a7ab95a68"><td class="mdescLeft">&#160;</td><td class="mdescRight">Get an amplitude from a density matrix at a given row and column.  <a href="group__calc.html#gadca286c4ad5cde6124d4e80a7ab95a68">More...</a><br /></td></tr>
<tr class="separator:gadca286c4ad5cde6124d4e80a7ab95a68"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gad575782de461d9ab0975b38cc7850f1a"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__type.html#ga7740e349b4f8bae6451547680f0ce2d6">qreal</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__calc.html#gad575782de461d9ab0975b38cc7850f1a">getImagAmp</a> (<a class="el" href="structQureg.html">Qureg</a> qureg, long long int index)</td></tr>
<tr class="memdesc:gad575782de461d9ab0975b38cc7850f1a"><td class="mdescLeft">&#160;</td><td class="mdescRight">Get the imaginary component of the complex probability amplitude at an index in the state vector.  <a href="group__calc.html#gad575782de461d9ab0975b38cc7850f1a">More...</a><br /></td></tr>
<tr class="separator:gad575782de461d9ab0975b38cc7850f1a"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga8cbe422d4981bf06847d229a4c6aa3df"><td class="memItemLeft" align="right" valign="top">long long int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__calc.html#ga8cbe422d4981bf06847d229a4c6aa3df">getNumAmps</a> (<a class="el" href="structQureg.html">Qureg</a> qureg)</td></tr>
<tr class="memdesc:ga8cbe422d4981bf06847d229a4c6aa3df"><td class="mdescLeft">&#160;</td><td class="mdescRight">Get the number of probability amplitudes in a qureg object, given by 2^numQubits.  <a href="group__calc.html#ga8cbe422d4981bf06847d229a4c6aa3df">More...</a><br /></td></tr>
<tr class="separator:ga8cbe422d4981bf06847d229a4c6aa3df"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga73036c778d800703585ab3d8796a915f"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__calc.html#ga73036c778d800703585ab3d8796a915f">getNumQubits</a> (<a class="el" href="structQureg.html">Qureg</a> qureg)</td></tr>
<tr class="memdesc:ga73036c778d800703585ab3d8796a915f"><td class="mdescLeft">&#160;</td><td class="mdescRight">Get the number of qubits in a qureg object.  <a href="group__calc.html#ga73036c778d800703585ab3d8796a915f">More...</a><br /></td></tr>
<tr class="separator:ga73036c778d800703585ab3d8796a915f"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga4a14d22379d399760b0cfc5c8053589b"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__type.html#ga7740e349b4f8bae6451547680f0ce2d6">qreal</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__calc.html#ga4a14d22379d399760b0cfc5c8053589b">getProbAmp</a> (<a class="el" href="structQureg.html">Qureg</a> qureg, long long int index)</td></tr>
<tr class="memdesc:ga4a14d22379d399760b0cfc5c8053589b"><td class="mdescLeft">&#160;</td><td class="mdescRight">Get the probability of a state-vector at an index in the full state vector.  <a href="group__calc.html#ga4a14d22379d399760b0cfc5c8053589b">More...</a><br /></td></tr>
<tr class="separator:ga4a14d22379d399760b0cfc5c8053589b"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga1416145280c62c5dd5ec9bed89b4cd05"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__type.html#ga7740e349b4f8bae6451547680f0ce2d6">qreal</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__calc.html#ga1416145280c62c5dd5ec9bed89b4cd05">getRealAmp</a> (<a class="el" href="structQureg.html">Qureg</a> qureg, long long int index)</td></tr>
<tr class="memdesc:ga1416145280c62c5dd5ec9bed89b4cd05"><td class="mdescLeft">&#160;</td><td class="mdescRight">Get the real component of the complex probability amplitude at an index in the state vector.  <a href="group__calc.html#ga1416145280c62c5dd5ec9bed89b4cd05">More...</a><br /></td></tr>
<tr class="separator:ga1416145280c62c5dd5ec9bed89b4cd05"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<p>Calculations and property-getters which do not modify the studied quantum state. </p>
<h2 class="groupheader">Function Documentation</h2>
<a id="ga658b3a5cab5e73a17a7fd76a83583a22"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga658b3a5cab5e73a17a7fd76a83583a22">&#9670;&nbsp;</a></span>calcDensityInnerProduct()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="group__type.html#ga7740e349b4f8bae6451547680f0ce2d6">qreal</a> calcDensityInnerProduct </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structQureg.html">Qureg</a>&#160;</td>
          <td class="paramname"><em>rho1</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="structQureg.html">Qureg</a>&#160;</td>
          <td class="paramname"><em>rho2</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Computes the Hilbert-Schmidt scalar product (which is equivalent to the Frobenius inner product of matrices) of two density matrices <code>rho1</code> and <code>rho2</code> of equivalent size. </p>
<p>That is, we define the Hilbert-Schmidt scalar product </p><p class="formulaDsp">
<img class="formulaDsp" alt="\[ ((\rho_1, \rho_2))_{HS} := \text{Tr}[ \rho_1^\dagger \rho_2 ], \]" src="form_84.png"/>
</p>
<p> which is equivalent to the sum of products of matrix elemets, i.e., </p><p class="formulaDsp">
<img class="formulaDsp" alt="\[ ((\rho_1, \rho_2))_{HS} = \sum\limits_i \sum\limits_j (\rho_1)_{ij}^* (\rho_2)_{ij} \]" src="form_85.png"/>
</p>
<p> Assuming that both density matrices are Hermitian, the resulting scalar product is real and invariant under reordering its arguments as </p><p class="formulaDsp">
<img class="formulaDsp" alt="\[ ((\rho_1, \rho_2))_{HS} = ((\rho_2, \rho_1))_{HS} = \text{Tr}[\rho_1 \rho_2] \]" src="form_86.png"/>
</p>
<p> If both <code>rho1</code> and <code>rho2</code> are density matrices of pure states <code>bra</code> and <code>ket</code>, then the equality holds </p><p class="formulaDsp">
<img class="formulaDsp" alt="\[ ((\rho_1, \rho_2))_{HS} = |\langle \text{bra} | \text{ket} \rangle|^2. \]" src="form_87.png"/>
</p>
<p> If either or both of <code>rho1</code> and <code>rho2</code> are non Hermitian (i.e. invalid density matrices), then this function returns the real component of the scalar product, and discards the imaginary component. That is, it returns </p><p class="formulaDsp">
<img class="formulaDsp" alt="\[ \text{Re}\{ \text{Tr}[ \rho_1^\dagger \rho_2 ] \} = \text{Re}\{ \text{Tr}[ \rho_2^\dagger \rho_1 ] \}. \]" src="form_88.png"/>
</p>
<p> This is still sometimes useful, e.g. in calculating the inner product with an anti-commutator, e.g. (for Hermitian <img class="formulaInl" alt="$ \sigma $" src="form_89.png"/>, <img class="formulaInl" alt="$ \rho $" src="form_39.png"/>, <img class="formulaInl" alt="$ H $" src="form_90.png"/>) </p><p class="formulaDsp">
<img class="formulaDsp" alt="\[ ((\sigma, H \rho + \rho H))_{HS} = 2 \; \text{Re} \{ ((\sigma, H \rho))_{HS} \} \]" src="form_91.png"/>
</p>
<p> where <img class="formulaInl" alt="$ H \rho $" src="form_92.png"/> could be a weighted sum of Pauli products applied to <img class="formulaInl" alt="$ \rho $" src="form_39.png"/> through <a class="el" href="group__operator.html#ga6fc26cf857db070e12959e59ecfed8a6" title="Modifies outQureg to be the result of applying the weighted sum of Pauli products (a Hermitian but no...">applyPauliSum()</a>.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in]</td><td class="paramname">rho1</td><td>qureg as a density matrix (to have its values conjugate transposed) </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">rho2</td><td>qureg as a density matrix </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>the real Hilbert-Schmidt scalar product of density matrices <code>rho1</code> and <code>rho2</code> (assuming Hermiticity) </dd></dl>
<dl class="exception"><dt>Exceptions</dt><dd>
  <table class="exception">
    <tr><td class="paramname">exitWithError</td><td>if <code>rho1</code> and <code>rho2</code> are not density matrices or have mismatching dimensions. </td></tr>
  </table>
  </dd>
</dl>
<dl class="section author"><dt>Author</dt><dd>Balint Koczor (CPU) </dd>
<dd>
Tyson Jones (GPU) </dd></dl>

<p class="definition">Definition at line <a class="el" href="QuEST_8c_source.html#l00837">837</a> of file <a class="el" href="QuEST_8c_source.html">QuEST.c</a>.</p>
<div class="fragment"><div class="line"><a name="l00837"></a><span class="lineno">  837</span>&#160;                                                      {</div>
<div class="line"><a name="l00838"></a><span class="lineno">  838</span>&#160;    <a class="code" href="QuEST__validation_8c.html#af22919f5190ca1b3b6b52b8f2fb8213b">validateDensityMatrQureg</a>(rho1, __func__);</div>
<div class="line"><a name="l00839"></a><span class="lineno">  839</span>&#160;    <a class="code" href="QuEST__validation_8c.html#af22919f5190ca1b3b6b52b8f2fb8213b">validateDensityMatrQureg</a>(rho2, __func__);</div>
<div class="line"><a name="l00840"></a><span class="lineno">  840</span>&#160;    <a class="code" href="QuEST__validation_8c.html#a87d22240ccfd81827a2a34b8d569d347">validateMatchingQuregDims</a>(rho1, rho2, __func__);</div>
<div class="line"><a name="l00841"></a><span class="lineno">  841</span>&#160;    </div>
<div class="line"><a name="l00842"></a><span class="lineno">  842</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="QuEST__internal_8h.html#a6ff3dc624b5fafe8edae4fe327c255a0">densmatr_calcInnerProduct</a>(rho1, rho2);</div>
<div class="line"><a name="l00843"></a><span class="lineno">  843</span>&#160;}</div>
</div><!-- fragment -->
<p class="reference">References <a class="el" href="QuEST__cpu__distributed_8c_source.html#l00441">densmatr_calcInnerProduct()</a>, <a class="el" href="QuEST__validation_8c_source.html#l00422">validateDensityMatrQureg()</a>, and <a class="el" href="QuEST__validation_8c_source.html#l00434">validateMatchingQuregDims()</a>.</p>

<p class="reference">Referenced by <a class="el" href="test__calculations_8cpp_source.html#l00015">TEST_CASE()</a>.</p>

</div>
</div>
<a id="ga15cfad3f3d26339128e3be32ae7deacd"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga15cfad3f3d26339128e3be32ae7deacd">&#9670;&nbsp;</a></span>calcExpecPauliProd()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="group__type.html#ga7740e349b4f8bae6451547680f0ce2d6">qreal</a> calcExpecPauliProd </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structQureg.html">Qureg</a>&#160;</td>
          <td class="paramname"><em>qureg</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int *&#160;</td>
          <td class="paramname"><em>targetQubits</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">enum <a class="el" href="group__type.html#ga1c703cf89629e4e9c7023cd402d67028">pauliOpType</a> *&#160;</td>
          <td class="paramname"><em>pauliCodes</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>numTargets</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="structQureg.html">Qureg</a>&#160;</td>
          <td class="paramname"><em>workspace</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Computes the expected value of a product of Pauli operators. </p>
<p>Letting <img class="formulaInl" alt="$ \sigma = \otimes_j \hat{\sigma}_j $" src="form_126.png"/> be the operators indicated by <code>pauliCodes</code> and acting on qubits <code>targetQubits</code>, this function computes <img class="formulaInl" alt="$ \langle \psi | \sigma | \psi \rangle $" src="form_127.png"/> if <code>qureg</code> = <img class="formulaInl" alt="$ \psi $" src="form_37.png"/> is a statevector, and computes <img class="formulaInl" alt="$ \text{Trace}(\sigma \rho) $" src="form_128.png"/> if <code>qureg</code> = <img class="formulaInl" alt="$ \rho $" src="form_39.png"/> is a density matrix.</p>
<p><code>pauliCodes</code> is an array of length <code>numTargets</code> which specifies which Pauli operators to enact on the corresponding qubits in <code>targetQubits</code>, where 0 = <code>PAULI_I</code>, 1 = <code>PAULI_X</code>, 2 = <code>PAULI_Y</code>, 3 = <code>PAULI_Z</code>. The target qubits must be unique, and at most <code>qureg.numQubitsRepresented</code> may be specified. For example, on a 7-qubit statevector, </p><pre class="fragment">calcExpecPauliProd(qureg, {4,5,6}, {PAULI_X, PAULI_I, PAULI_Z}, 3, workspace);
</pre><p>will compute <img class="formulaInl" alt="$ \langle \psi | I I I I X I Z | \psi \rangle $" src="form_129.png"/> (where in this notation, the left-most operator applies to the least-significant qubit, i.e. that with index 0).</p>
<p><code>workspace</code> must be a register with the same type (statevector vs density matrix) and dimensions (number of represented qubits) as <code>qureg</code>, and is used as working space. When this function returns, <code>qureg</code> will be unchanged and <code>workspace</code> will be set to <img class="formulaInl" alt="$ \sigma | \psi \rangle $" src="form_130.png"/> (if <code>qureg</code> is a statevector) or <img class="formulaInl" alt="$ \sigma \rho $" src="form_131.png"/> (if <code>qureg</code> is a density matrix). NOTE that this last quantity is NOT the result of applying the paulis as unitaries, <img class="formulaInl" alt="$ \sigma^\dagger \rho \sigma $" src="form_132.png"/>, but is instead the result of their direct multiplication with the density matrix. It is therefore itself not a valid density matrix.</p>
<p>This function works by cloning the <code>qureg</code> state into <code>workspace</code>, applying the specified Pauli operators to <code>workspace</code> then computing its inner product with <code>qureg</code> (for statevectors) or its trace (for density matrices). It therefore should scale linearly in time with the number of specified non-identity Pauli operators, which is bounded by the number of represented qubits.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in]</td><td class="paramname">qureg</td><td>the register of which to find the expected value, which is unchanged by this function </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">targetQubits</td><td>a list of the indices of the target qubits </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">pauliCodes</td><td>a list of the Pauli codes (0=PAULI_I, 1=PAULI_X, 2=PAULI_Y, 3=PAULI_Z) to apply to the corresponding qubits in <code>targetQubits</code> </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">numTargets</td><td>number of target qubits, i.e. the length of <code>targetQubits</code> and <code>pauliCodes</code> </td></tr>
    <tr><td class="paramdir">[in,out]</td><td class="paramname">workspace</td><td>a working-space qureg with the same dimensions as <code>qureg</code>, which is modified to be the result of multiplying the state with the pauli operators </td></tr>
  </table>
  </dd>
</dl>
<dl class="exception"><dt>Exceptions</dt><dd>
  <table class="exception">
    <tr><td class="paramname">exitWithError</td><td>if <code>numTargets</code> is outside [1, <code>qureg.numQubitsRepresented</code>]), or if any qubit in <code>targetQubits</code> is outside [0, <code>qureg.numQubitsRepresented</code>)) or if any qubit in <code>targetQubits</code> is repeated, or if any code in <code>pauliCodes</code> is not in {0,1,2,3}, or if <code>workspace</code> is not of the same type and dimensions as <code>qureg</code> </td></tr>
  </table>
  </dd>
</dl>
<dl class="section author"><dt>Author</dt><dd>Tyson Jones </dd></dl>

<p class="definition">Definition at line <a class="el" href="QuEST_8c_source.html#l00871">871</a> of file <a class="el" href="QuEST_8c_source.html">QuEST.c</a>.</p>
<div class="fragment"><div class="line"><a name="l00871"></a><span class="lineno">  871</span>&#160;                                                                                                                        {</div>
<div class="line"><a name="l00872"></a><span class="lineno">  872</span>&#160;    <a class="code" href="QuEST__validation_8c.html#a17409defd561446f561279caa9c443f4">validateMultiTargets</a>(qureg, targetQubits, numTargets, __func__);</div>
<div class="line"><a name="l00873"></a><span class="lineno">  873</span>&#160;    <a class="code" href="QuEST__validation_8c.html#aa194ba5f5c6e19c6caa4c715b3dbefcc">validatePauliCodes</a>(pauliCodes, numTargets, __func__);</div>
<div class="line"><a name="l00874"></a><span class="lineno">  874</span>&#160;    <a class="code" href="QuEST__validation_8c.html#a031812e1cf2c98d72d795cea7bbe73a5">validateMatchingQuregTypes</a>(qureg, workspace, __func__);</div>
<div class="line"><a name="l00875"></a><span class="lineno">  875</span>&#160;    <a class="code" href="QuEST__validation_8c.html#a87d22240ccfd81827a2a34b8d569d347">validateMatchingQuregDims</a>(qureg, workspace, __func__);</div>
<div class="line"><a name="l00876"></a><span class="lineno">  876</span>&#160;    </div>
<div class="line"><a name="l00877"></a><span class="lineno">  877</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="QuEST__common_8c.html#aef380928d1b0003411d6159ca6594cd5">statevec_calcExpecPauliProd</a>(qureg, targetQubits, pauliCodes, numTargets, workspace);</div>
<div class="line"><a name="l00878"></a><span class="lineno">  878</span>&#160;}</div>
</div><!-- fragment -->
<p class="reference">References <a class="el" href="QuEST__common_8c_source.html#l00464">statevec_calcExpecPauliProd()</a>, <a class="el" href="QuEST__validation_8c_source.html#l00434">validateMatchingQuregDims()</a>, <a class="el" href="QuEST__validation_8c_source.html#l00438">validateMatchingQuregTypes()</a>, <a class="el" href="QuEST__validation_8c_source.html#l00335">validateMultiTargets()</a>, and <a class="el" href="QuEST__validation_8c_source.html#l00498">validatePauliCodes()</a>.</p>

<p class="reference">Referenced by <a class="el" href="test__calculations_8cpp_source.html#l00111">TEST_CASE()</a>.</p>

</div>
</div>
<a id="ga50ee589fd5ceab52fdd70d0082352b41"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga50ee589fd5ceab52fdd70d0082352b41">&#9670;&nbsp;</a></span>calcExpecPauliSum()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="group__type.html#ga7740e349b4f8bae6451547680f0ce2d6">qreal</a> calcExpecPauliSum </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structQureg.html">Qureg</a>&#160;</td>
          <td class="paramname"><em>qureg</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">enum <a class="el" href="group__type.html#ga1c703cf89629e4e9c7023cd402d67028">pauliOpType</a> *&#160;</td>
          <td class="paramname"><em>allPauliCodes</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="group__type.html#ga7740e349b4f8bae6451547680f0ce2d6">qreal</a> *&#160;</td>
          <td class="paramname"><em>termCoeffs</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>numSumTerms</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="structQureg.html">Qureg</a>&#160;</td>
          <td class="paramname"><em>workspace</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Computes the expected value of a sum of products of Pauli operators. </p>
<p>Let <img class="formulaInl" alt="$ H = \sum_i c_i \otimes_j^{N} \hat{\sigma}_{i,j} $" src="form_133.png"/> be the operators indicated by <code>allPauliCodes</code> (where <img class="formulaInl" alt="$ c_i \in $" src="form_134.png"/> <code>termCoeffs</code> and <img class="formulaInl" alt="$ N = $" src="form_135.png"/> <code>qureg.numQubitsRepresented</code>). This function computes <img class="formulaInl" alt="$ \langle \psi | H | \psi \rangle $" src="form_136.png"/> if <code>qureg</code> = <img class="formulaInl" alt="$ \psi $" src="form_37.png"/> is a statevector, and computes <img class="formulaInl" alt="$ \text{Trace}(H \rho) =\text{Trace}(\rho H) $" src="form_137.png"/> if <code>qureg</code> = <img class="formulaInl" alt="$ \rho $" src="form_39.png"/> is a density matrix.</p>
<p><code>allPauliCodes</code> is an array of length <code>numSumTerms*<code>qureg.numQubitsRepresented</code> which</code> specifies which Pauli operators to apply, where 0 = <code>PAULI_I</code>, 1 = <code>PAULI_X</code>, 2 = <code>PAULI_Y</code>, 3 = <code>PAULI_Z</code>. For each sum term, a Pauli operator must be specified for EVERY qubit in <code>qureg</code>; each set of <code>numSumTerms</code> operators will be grouped into a product. <code>termCoeffs</code> is an arrray of length <code>numSumTerms</code> containing the term coefficients. For example, on a 3-qubit statevector, </p><pre class="fragment">int paulis[6] = {PAULI_X, PAULI_I, PAULI_I,  PAULI_X, PAULI_Y, PAULI_Z};
qreal coeffs[2] = {1.5, -3.6};
calcExpecPauliSum(qureg, paulis, coeffs, 2, workspace);
</pre><p>will compute <img class="formulaInl" alt="$ \langle \psi | (1.5 X I I - 3.6 X Y Z) | \psi \rangle $" src="form_138.png"/> (where in this notation, the left-most operator applies to the least-significant qubit, i.e. that with index 0).</p>
<p><code>workspace</code> must be a register with the same type (statevector vs density matrix) and dimensions (number of represented qubits) as <code>qureg</code>, and is used as working space. When this function returns, <code>qureg</code> will be unchanged and <code>workspace</code> will be set to <code>qureg</code> pre-multiplied with the final Pauli product. NOTE that if <code>qureg</code> is a density matrix, <code>workspace</code> will become <img class="formulaInl" alt="$ \hat{\sigma} \rho $" src="form_139.png"/> which is itself not a density matrix (it is distinct from <img class="formulaInl" alt="$ \hat{\sigma}^\dagger \rho \hat{\sigma} $" src="form_140.png"/>).</p>
<p>This function works by cloning the <code>qureg</code> state into <code>workspace</code>, applying each of the specified Pauli products to <code>workspace</code> (one Pauli operation at a time), then computing its inner product with <code>qureg</code> (for statevectors) or its trace (for density matrices) multiplied with the corresponding coefficient, and summing these contributions. It therefore should scale linearly in time with the total number of non-identity specified Pauli operators.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in]</td><td class="paramname">qureg</td><td>the register of which to find the expected value, which is unchanged by this function </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">allPauliCodes</td><td>a list of the Pauli codes (0=PAULI_I, 1=PAULI_X, 2=PAULI_Y, 3=PAULI_Z) of all Paulis involved in the products of terms. A Pauli must be specified for each qubit in the register, in every term of the sum. </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">termCoeffs</td><td>The coefficients of each term in the sum of Pauli products </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">numSumTerms</td><td>The total number of Pauli products specified </td></tr>
    <tr><td class="paramdir">[in,out]</td><td class="paramname">workspace</td><td>a working-space qureg with the same dimensions as <code>qureg</code>, which is modified to be the result of multiplying the state with the final specified Pauli product </td></tr>
  </table>
  </dd>
</dl>
<dl class="exception"><dt>Exceptions</dt><dd>
  <table class="exception">
    <tr><td class="paramname">exitWithError</td><td>if any code in <code>allPauliCodes</code> is not in {0,1,2,3}, or if numSumTerms &lt;= 0, or if <code>workspace</code> is not of the same type and dimensions as <code>qureg</code> </td></tr>
  </table>
  </dd>
</dl>
<dl class="section author"><dt>Author</dt><dd>Tyson Jones </dd></dl>

<p class="definition">Definition at line <a class="el" href="QuEST_8c_source.html#l00880">880</a> of file <a class="el" href="QuEST_8c_source.html">QuEST.c</a>.</p>
<div class="fragment"><div class="line"><a name="l00880"></a><span class="lineno">  880</span>&#160;                                                                                                                           {</div>
<div class="line"><a name="l00881"></a><span class="lineno">  881</span>&#160;    <a class="code" href="QuEST__validation_8c.html#a5be128290a7bba9a7f12d32cabe2276b">validateNumPauliSumTerms</a>(numSumTerms, __func__);</div>
<div class="line"><a name="l00882"></a><span class="lineno">  882</span>&#160;    <a class="code" href="QuEST__validation_8c.html#aa194ba5f5c6e19c6caa4c715b3dbefcc">validatePauliCodes</a>(allPauliCodes, numSumTerms*qureg.<a class="code" href="structQureg.html#ad08dff5316b8937f4b2a1417591543dc">numQubitsRepresented</a>, __func__);</div>
<div class="line"><a name="l00883"></a><span class="lineno">  883</span>&#160;    <a class="code" href="QuEST__validation_8c.html#a031812e1cf2c98d72d795cea7bbe73a5">validateMatchingQuregTypes</a>(qureg, workspace, __func__);</div>
<div class="line"><a name="l00884"></a><span class="lineno">  884</span>&#160;    <a class="code" href="QuEST__validation_8c.html#a87d22240ccfd81827a2a34b8d569d347">validateMatchingQuregDims</a>(qureg, workspace, __func__);</div>
<div class="line"><a name="l00885"></a><span class="lineno">  885</span>&#160;    </div>
<div class="line"><a name="l00886"></a><span class="lineno">  886</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="QuEST__common_8c.html#ae0cfea24091c8336146aa84c2253992e">statevec_calcExpecPauliSum</a>(qureg, allPauliCodes, termCoeffs, numSumTerms, workspace);</div>
<div class="line"><a name="l00887"></a><span class="lineno">  887</span>&#160;}</div>
</div><!-- fragment -->
<p class="reference">References <a class="el" href="QuEST_8h_source.html#l00165">Qureg::numQubitsRepresented</a>, <a class="el" href="QuEST__common_8c_source.html#l00479">statevec_calcExpecPauliSum()</a>, <a class="el" href="QuEST__validation_8c_source.html#l00434">validateMatchingQuregDims()</a>, <a class="el" href="QuEST__validation_8c_source.html#l00438">validateMatchingQuregTypes()</a>, <a class="el" href="QuEST__validation_8c_source.html#l00507">validateNumPauliSumTerms()</a>, and <a class="el" href="QuEST__validation_8c_source.html#l00498">validatePauliCodes()</a>.</p>

<p class="reference">Referenced by <a class="el" href="test__calculations_8cpp_source.html#l00253">TEST_CASE()</a>.</p>

</div>
</div>
<a id="gaa266ed6c8ae5d0d0f49e1ac50819cffc"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gaa266ed6c8ae5d0d0f49e1ac50819cffc">&#9670;&nbsp;</a></span>calcFidelity()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="group__type.html#ga7740e349b4f8bae6451547680f0ce2d6">qreal</a> calcFidelity </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structQureg.html">Qureg</a>&#160;</td>
          <td class="paramname"><em>qureg</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="structQureg.html">Qureg</a>&#160;</td>
          <td class="paramname"><em>pureState</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Calculates the fidelity of <code>qureg</code> (a statevector or density matrix) against a reference pure state (necessarily a statevector). </p>
<p>If <code>qureg</code> is a state-vector, this function computes </p><p class="formulaDsp">
<img class="formulaDsp" alt="\[ |\langle \text{qureg} | \text{pureState} \rangle|^2 \]" src="form_111.png"/>
</p>
<p> If <code>qureg</code> is a density matrix, this function computes </p><p class="formulaDsp">
<img class="formulaDsp" alt="\[ \langle \text{pureState} | \text{qureg} | \text{pureState} \rangle \]" src="form_112.png"/>
</p>
<p> In either case, the returned fidelity lies in [0, 1] (assuming both input states have valid normalisation). If any of the input <code>Quregs</code> are not normalised, this function will return the real component of the correct linear algebra calculation.</p>
<p>The number of qubits represented in <code>qureg</code> and <code>pureState</code> must match.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in]</td><td class="paramname">qureg</td><td>a density matrix or state vector </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">pureState</td><td>a state vector </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>the fidelity between the input registers </dd></dl>
<dl class="exception"><dt>Exceptions</dt><dd>
  <table class="exception">
    <tr><td class="paramname">exitWithError</td><td>if the second argument (<code>pureState</code>) is not a statevector, or if the number of qubits in <code>qureg</code> and <code>pureState</code> do not match </td></tr>
  </table>
  </dd>
</dl>
<dl class="section author"><dt>Author</dt><dd>Tyson Jones </dd></dl>

<p class="definition">Definition at line <a class="el" href="QuEST_8c_source.html#l00861">861</a> of file <a class="el" href="QuEST_8c_source.html">QuEST.c</a>.</p>
<div class="fragment"><div class="line"><a name="l00861"></a><span class="lineno">  861</span>&#160;                                                 {</div>
<div class="line"><a name="l00862"></a><span class="lineno">  862</span>&#160;    <a class="code" href="QuEST__validation_8c.html#a7adc86571f1154558676d95daf0cbd1f">validateSecondQuregStateVec</a>(pureState, __func__);</div>
<div class="line"><a name="l00863"></a><span class="lineno">  863</span>&#160;    <a class="code" href="QuEST__validation_8c.html#a87d22240ccfd81827a2a34b8d569d347">validateMatchingQuregDims</a>(qureg, pureState, __func__);</div>
<div class="line"><a name="l00864"></a><span class="lineno">  864</span>&#160;    </div>
<div class="line"><a name="l00865"></a><span class="lineno">  865</span>&#160;    <span class="keywordflow">if</span> (qureg.<a class="code" href="structQureg.html#acf78445e9435d09f44f0cc832c6aee79">isDensityMatrix</a>)</div>
<div class="line"><a name="l00866"></a><span class="lineno">  866</span>&#160;        <span class="keywordflow">return</span> <a class="code" href="QuEST__internal_8h.html#aa6c3f86010ad398f42b0577ea3bb5bcf">densmatr_calcFidelity</a>(qureg, pureState);</div>
<div class="line"><a name="l00867"></a><span class="lineno">  867</span>&#160;    <span class="keywordflow">else</span></div>
<div class="line"><a name="l00868"></a><span class="lineno">  868</span>&#160;        <span class="keywordflow">return</span> <a class="code" href="QuEST__common_8c.html#aeeec9fe1501e25930adf6c38763a158e">statevec_calcFidelity</a>(qureg, pureState);</div>
<div class="line"><a name="l00869"></a><span class="lineno">  869</span>&#160;}</div>
</div><!-- fragment -->
<p class="reference">References <a class="el" href="QuEST__cpu__distributed_8c_source.html#l00415">densmatr_calcFidelity()</a>, <a class="el" href="QuEST_8h_source.html#l00163">Qureg::isDensityMatrix</a>, <a class="el" href="QuEST__common_8c_source.html#l00376">statevec_calcFidelity()</a>, <a class="el" href="QuEST__validation_8c_source.html#l00434">validateMatchingQuregDims()</a>, and <a class="el" href="QuEST__validation_8c_source.html#l00442">validateSecondQuregStateVec()</a>.</p>

<p class="reference">Referenced by <a class="el" href="test__calculations_8cpp_source.html#l00393">TEST_CASE()</a>.</p>

</div>
</div>
<a id="ga87ddbe5c8281543541ccd99e0dafd387"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga87ddbe5c8281543541ccd99e0dafd387">&#9670;&nbsp;</a></span>calcHilbertSchmidtDistance()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="group__type.html#ga7740e349b4f8bae6451547680f0ce2d6">qreal</a> calcHilbertSchmidtDistance </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structQureg.html">Qureg</a>&#160;</td>
          <td class="paramname"><em>a</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="structQureg.html">Qureg</a>&#160;</td>
          <td class="paramname"><em>b</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Computes the Hilbert Schmidt distance between two density matrices <code>a</code> and <code>b</code>, defined as the Frobenius norm of the difference between them. </p>
<p>That is, we define the Hilbert Schmidt distance </p><p class="formulaDsp">
<img class="formulaDsp" alt="\[ D(a, b) = \| a - b \|_F = \sqrt{ \text{Tr}[ (a-b)(a-b)^\dagger ] } \]" src="form_159.png"/>
</p>
<p> This is equivalent to the square-root of the sum of the absolute value squared of the element-differences of the matrices, i.e. </p><p class="formulaDsp">
<img class="formulaDsp" alt="\[ D(a, b) = \sqrt{ \sum\limits_i \sum\limits_j | a_{ij} - b_{ij} |^2 } \]" src="form_160.png"/>
</p>
<p> We caution this may differ by some definitions of the Hilbert Schmidt distance by a square-root.</p>
<p>This function correctly returns the result of the above formulations even when <code>a</code> and <code>b</code> are incorrectly normalised (i.e. are general matrices).</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in]</td><td class="paramname">a</td><td>a density matrix </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">b</td><td>an equally-sized density matrix </td></tr>
  </table>
  </dd>
</dl>
<dl class="exception"><dt>Exceptions</dt><dd>
  <table class="exception">
    <tr><td class="paramname">exitWithError</td><td>if either <code>a</code> or <code>b</code> are not density matrices, or if <code>a</code> and <code>have</code> mismatching dimensions. </td></tr>
  </table>
  </dd>
</dl>
<dl class="section author"><dt>Author</dt><dd>Balint Koczor </dd>
<dd>
Tyson Jones (refactored, doc) </dd></dl>

<p class="definition">Definition at line <a class="el" href="QuEST_8c_source.html#l00889">889</a> of file <a class="el" href="QuEST_8c_source.html">QuEST.c</a>.</p>
<div class="fragment"><div class="line"><a name="l00889"></a><span class="lineno">  889</span>&#160;                                                   {</div>
<div class="line"><a name="l00890"></a><span class="lineno">  890</span>&#160;    <a class="code" href="QuEST__validation_8c.html#af22919f5190ca1b3b6b52b8f2fb8213b">validateDensityMatrQureg</a>(a, __func__);</div>
<div class="line"><a name="l00891"></a><span class="lineno">  891</span>&#160;    <a class="code" href="QuEST__validation_8c.html#af22919f5190ca1b3b6b52b8f2fb8213b">validateDensityMatrQureg</a>(b, __func__);</div>
<div class="line"><a name="l00892"></a><span class="lineno">  892</span>&#160;    <a class="code" href="QuEST__validation_8c.html#a87d22240ccfd81827a2a34b8d569d347">validateMatchingQuregDims</a>(a, b, __func__);</div>
<div class="line"><a name="l00893"></a><span class="lineno">  893</span>&#160;    </div>
<div class="line"><a name="l00894"></a><span class="lineno">  894</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="QuEST__internal_8h.html#a8c9da88f734b0862f4cce7d819e6d3b5">densmatr_calcHilbertSchmidtDistance</a>(a, b);</div>
<div class="line"><a name="l00895"></a><span class="lineno">  895</span>&#160;}</div>
</div><!-- fragment -->
<p class="reference">References <a class="el" href="QuEST__cpu__distributed_8c_source.html#l00430">densmatr_calcHilbertSchmidtDistance()</a>, <a class="el" href="QuEST__validation_8c_source.html#l00422">validateDensityMatrQureg()</a>, and <a class="el" href="QuEST__validation_8c_source.html#l00434">validateMatchingQuregDims()</a>.</p>

<p class="reference">Referenced by <a class="el" href="test__calculations_8cpp_source.html#l00545">TEST_CASE()</a>.</p>

</div>
</div>
<a id="ga374ad70804998394ae41ebfe106258a6"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga374ad70804998394ae41ebfe106258a6">&#9670;&nbsp;</a></span>calcInnerProduct()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="structComplex.html">Complex</a> calcInnerProduct </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structQureg.html">Qureg</a>&#160;</td>
          <td class="paramname"><em>bra</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="structQureg.html">Qureg</a>&#160;</td>
          <td class="paramname"><em>ket</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Computes the inner product <img class="formulaInl" alt="$ \langle \text{bra} | \text{ket} \rangle $" src="form_82.png"/> of two equal-size state vectors, given by. </p>
<p class="formulaDsp">
<img class="formulaDsp" alt="\[ \langle \text{bra} | \text{ket} \rangle = \sum_i {\text{bra}_i}^* \; \times \; \text{ket}_i \]" src="form_83.png"/>
</p>
<p> The same <code>qureg</code> may be passed as both <code>bra</code> and <code>ket</code>, though we recommend users check state-vector normalisation with <code>calcTotalProb</code> which employs Kahan summation for greater accuracy. Neither state-vector is modified.</p>
<p>This function returns the correct inner product even if <code>bra</code> and <code>ket</code> are not correctly normalised states.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in]</td><td class="paramname">bra</td><td>qureg to be the 'bra' (i.e. have its values conjugate transposed) in the inner product </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">ket</td><td>qureg to be the 'ket' in the inner product </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>the complex inner product of <code>bra</code> and <code>ket</code> </dd></dl>
<dl class="exception"><dt>Exceptions</dt><dd>
  <table class="exception">
    <tr><td class="paramname">exitWithError</td><td>if either <code>bra</code> or <code>ket</code> are not state-vectors, or if <code>bra</code> and <code>ket</code> do not have equal dimensions. </td></tr>
  </table>
  </dd>
</dl>
<dl class="section author"><dt>Author</dt><dd>Tyson Jones </dd></dl>

<p class="definition">Definition at line <a class="el" href="QuEST_8c_source.html#l00829">829</a> of file <a class="el" href="QuEST_8c_source.html">QuEST.c</a>.</p>
<div class="fragment"><div class="line"><a name="l00829"></a><span class="lineno">  829</span>&#160;                                               {</div>
<div class="line"><a name="l00830"></a><span class="lineno">  830</span>&#160;    <a class="code" href="QuEST__validation_8c.html#a72feec2aaa05f98aed7f3c3fee141251">validateStateVecQureg</a>(bra, __func__);</div>
<div class="line"><a name="l00831"></a><span class="lineno">  831</span>&#160;    <a class="code" href="QuEST__validation_8c.html#a72feec2aaa05f98aed7f3c3fee141251">validateStateVecQureg</a>(ket, __func__);</div>
<div class="line"><a name="l00832"></a><span class="lineno">  832</span>&#160;    <a class="code" href="QuEST__validation_8c.html#a87d22240ccfd81827a2a34b8d569d347">validateMatchingQuregDims</a>(bra, ket,  __func__);</div>
<div class="line"><a name="l00833"></a><span class="lineno">  833</span>&#160;    </div>
<div class="line"><a name="l00834"></a><span class="lineno">  834</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="QuEST__internal_8h.html#a7ebd3198a198f4cd20840f64fd8b84d0">statevec_calcInnerProduct</a>(bra, ket);</div>
<div class="line"><a name="l00835"></a><span class="lineno">  835</span>&#160;}</div>
</div><!-- fragment -->
<p class="reference">References <a class="el" href="QuEST__cpu__distributed_8c_source.html#l00035">statevec_calcInnerProduct()</a>, <a class="el" href="QuEST__validation_8c_source.html#l00434">validateMatchingQuregDims()</a>, and <a class="el" href="QuEST__validation_8c_source.html#l00418">validateStateVecQureg()</a>.</p>

<p class="reference">Referenced by <a class="el" href="test__calculations_8cpp_source.html#l00641">TEST_CASE()</a>.</p>

</div>
</div>
<a id="ga2a0fbd65f42d35dcd5ae966c48826920"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga2a0fbd65f42d35dcd5ae966c48826920">&#9670;&nbsp;</a></span>calcProbOfOutcome()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="group__type.html#ga7740e349b4f8bae6451547680f0ce2d6">qreal</a> calcProbOfOutcome </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structQureg.html">Qureg</a>&#160;</td>
          <td class="paramname"><em>qureg</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const int&#160;</td>
          <td class="paramname"><em>measureQubit</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>outcome</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Gives the probability of a specified qubit being measured in the given outcome (0 or 1). </p>
<p>This performs no actual measurement and does not change the state of the qubits.</p>
<p>For state-vectors, this function works by summing the absolute-value-squared of every amplitude in the state-vector for which <code>measureQubit</code> <code>=</code> <code>0</code>. If <code>outcome</code> <code>=</code> <code>1</code>, it returns <code>1</code> minus this value. Hence for unnormalised state-vectors, this result will differ from the absolute-value-squared of every amplitude where <code>measureQubit</code> <code>=</code> <code>outcome</code>.</p>
<p>For density matrices, this function sums the diagonal values (should be real) corresponding to <code>measureQubit</code> <code>=</code> <code>0</code> (returning 1 minus this if <code>outcome</code> <code>=</code> <code>1</code>).</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in]</td><td class="paramname">qureg</td><td>object representing the set of all qubits </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">measureQubit</td><td>qubit to study </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">outcome</td><td>for which to find the probability of the qubit being measured in </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>probability of qubit measureQubit being measured in the given outcome </dd></dl>
<dl class="exception"><dt>Exceptions</dt><dd>
  <table class="exception">
    <tr><td class="paramname">exitWithError</td><td>if <code>measureQubit</code> is outside [0, <code>qureg.numQubitsRepresented</code>), or if <code>outcome</code> is not in {0, 1}. </td></tr>
  </table>
  </dd>
</dl>
<dl class="section author"><dt>Author</dt><dd>Ania Brown (state-vector) </dd>
<dd>
Tyson Jones (density matrix) </dd></dl>

<p class="definition">Definition at line <a class="el" href="QuEST_8c_source.html#l00845">845</a> of file <a class="el" href="QuEST_8c_source.html">QuEST.c</a>.</p>
<div class="fragment"><div class="line"><a name="l00845"></a><span class="lineno">  845</span>&#160;                                                                          {</div>
<div class="line"><a name="l00846"></a><span class="lineno">  846</span>&#160;    <a class="code" href="QuEST__validation_8c.html#ac31c45c5a31c523be0eb26abba6cf598">validateTarget</a>(qureg, measureQubit, __func__);</div>
<div class="line"><a name="l00847"></a><span class="lineno">  847</span>&#160;    <a class="code" href="QuEST__validation_8c.html#ad613c75ff252a88e54f911053bd2032c">validateOutcome</a>(outcome, __func__);</div>
<div class="line"><a name="l00848"></a><span class="lineno">  848</span>&#160;    </div>
<div class="line"><a name="l00849"></a><span class="lineno">  849</span>&#160;    <span class="keywordflow">if</span> (qureg.<a class="code" href="structQureg.html#acf78445e9435d09f44f0cc832c6aee79">isDensityMatrix</a>)</div>
<div class="line"><a name="l00850"></a><span class="lineno">  850</span>&#160;        <span class="keywordflow">return</span> <a class="code" href="QuEST__internal_8h.html#ad405e3fac20997043e0236b751e44270">densmatr_calcProbOfOutcome</a>(qureg, measureQubit, outcome);</div>
<div class="line"><a name="l00851"></a><span class="lineno">  851</span>&#160;    <span class="keywordflow">else</span></div>
<div class="line"><a name="l00852"></a><span class="lineno">  852</span>&#160;        <span class="keywordflow">return</span> <a class="code" href="QuEST__internal_8h.html#ab33cdf01831c4545e51299178acf7f27">statevec_calcProbOfOutcome</a>(qureg, measureQubit, outcome);</div>
<div class="line"><a name="l00853"></a><span class="lineno">  853</span>&#160;}</div>
</div><!-- fragment -->
<p class="reference">References <a class="el" href="QuEST__cpu__distributed_8c_source.html#l01279">densmatr_calcProbOfOutcome()</a>, <a class="el" href="QuEST_8h_source.html#l00163">Qureg::isDensityMatrix</a>, <a class="el" href="QuEST__cpu__distributed_8c_source.html#l01263">statevec_calcProbOfOutcome()</a>, <a class="el" href="QuEST__validation_8c_source.html#l00426">validateOutcome()</a>, and <a class="el" href="QuEST__validation_8c_source.html#l00307">validateTarget()</a>.</p>

<p class="reference">Referenced by <a class="el" href="test__calculations_8cpp_source.html#l00716">TEST_CASE()</a>.</p>

</div>
</div>
<a id="ga683779343fb2c6055f6b1d01079c2ede"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga683779343fb2c6055f6b1d01079c2ede">&#9670;&nbsp;</a></span>calcPurity()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="group__type.html#ga7740e349b4f8bae6451547680f0ce2d6">qreal</a> calcPurity </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structQureg.html">Qureg</a>&#160;</td>
          <td class="paramname"><em>qureg</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Calculates the purity of a density matrix, by the trace of the density matrix squared. </p>
<p>Returns <img class="formulaInl" alt="$\text{Tr}(\rho^2)$" src="form_109.png"/>. For a pure state, this =1. For a mixed state, the purity is less than 1 and is lower bounded by 1/2^n, where n is the number of qubits. The minimum purity is achieved for the maximally mixed state identity/2^n.</p>
<p>This function does not accept state-vectors, which clearly have purity 1.</p>
<p>Note this function will give incorrect results for non-Hermitian Quregs (i.e. invalid density matrices), which will disagree with <img class="formulaInl" alt="$\text{Tr}(\rho^2)$" src="form_109.png"/>. Instead, this function returns <img class="formulaInl" alt="$\sum_{ij} |\rho_{ij}|^2 $" src="form_110.png"/>.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in]</td><td class="paramname">qureg</td><td>a density matrix of which to measure the purity </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>the purity </dd></dl>
<dl class="exception"><dt>Exceptions</dt><dd>
  <table class="exception">
    <tr><td class="paramname">exitWithError</td><td>if either <code>combineQureg</code> or <code>otherQureg</code> are not density matrices, or if the dimensions of <code>combineQureg</code> and <code>otherQureg</code> do not match, or if <code>prob</code> is not in [0, 1] </td></tr>
  </table>
  </dd>
</dl>
<dl class="section author"><dt>Author</dt><dd>Tyson Jones </dd></dl>

<p class="definition">Definition at line <a class="el" href="QuEST_8c_source.html#l00855">855</a> of file <a class="el" href="QuEST_8c_source.html">QuEST.c</a>.</p>
<div class="fragment"><div class="line"><a name="l00855"></a><span class="lineno">  855</span>&#160;                              {</div>
<div class="line"><a name="l00856"></a><span class="lineno">  856</span>&#160;    <a class="code" href="QuEST__validation_8c.html#af22919f5190ca1b3b6b52b8f2fb8213b">validateDensityMatrQureg</a>(qureg, __func__);</div>
<div class="line"><a name="l00857"></a><span class="lineno">  857</span>&#160;    </div>
<div class="line"><a name="l00858"></a><span class="lineno">  858</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="QuEST__internal_8h.html#ae45eefa65f4ecd37bab84fade7cf7f1f">densmatr_calcPurity</a>(qureg);</div>
<div class="line"><a name="l00859"></a><span class="lineno">  859</span>&#160;}</div>
</div><!-- fragment -->
<p class="reference">References <a class="el" href="QuEST__cpu__distributed_8c_source.html#l01291">densmatr_calcPurity()</a>, and <a class="el" href="QuEST__validation_8c_source.html#l00422">validateDensityMatrQureg()</a>.</p>

<p class="reference">Referenced by <a class="el" href="test__calculations_8cpp_source.html#l00839">TEST_CASE()</a>.</p>

</div>
</div>
<a id="gab082910d33473ec29e1d5852943de468"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gab082910d33473ec29e1d5852943de468">&#9670;&nbsp;</a></span>calcTotalProb()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="group__type.html#ga7740e349b4f8bae6451547680f0ce2d6">qreal</a> calcTotalProb </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structQureg.html">Qureg</a>&#160;</td>
          <td class="paramname"><em>qureg</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>A debugging function which calculates the probability of the qubits in <code>qureg</code> being in any state, which should always be 1 for correctly normalised states (hence returning a real number). </p>
<p>For state-vectors <img class="formulaInl" alt="$ \psi $" src="form_37.png"/>, this is the norm of the entire state-vector (the sum of the absolute-value-squared of every amplitude): </p><p class="formulaDsp">
<img class="formulaDsp" alt="\[ \sum\limits_i |\psi_i|^2 \]" src="form_38.png"/>
</p>
<p> and for density matrices <img class="formulaInl" alt="$ \rho $" src="form_39.png"/>, it is the trace: </p><p class="formulaDsp">
<img class="formulaDsp" alt="\[ \text{Trace}(\rho) = \sum\limits_i \rho_{i,i} \; \]" src="form_40.png"/>
</p>
<p>For un-normalised density matrices (those directly modified or initialised by the user), this function returns the real component of the trace.</p>
<p>Note this calculation utilises Kahan summation for greater accuracy, and hence is not parallelised and so will be slower than other functions.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in]</td><td class="paramname">qureg</td><td>object representing a set of qubits </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>the total probability of the qubits in <code>qureg</code> being in any state </dd></dl>
<dl class="section author"><dt>Author</dt><dd>Ania Brown (state-vector) </dd>
<dd>
Tyson Jones (density matrix, doc) </dd></dl>

<p class="definition">Definition at line <a class="el" href="QuEST_8c_source.html#l00822">822</a> of file <a class="el" href="QuEST_8c_source.html">QuEST.c</a>.</p>
<div class="fragment"><div class="line"><a name="l00822"></a><span class="lineno">  822</span>&#160;                                 {</div>
<div class="line"><a name="l00823"></a><span class="lineno">  823</span>&#160;    <span class="keywordflow">if</span> (qureg.<a class="code" href="structQureg.html#acf78445e9435d09f44f0cc832c6aee79">isDensityMatrix</a>)  </div>
<div class="line"><a name="l00824"></a><span class="lineno">  824</span>&#160;            <span class="keywordflow">return</span> <a class="code" href="QuEST__internal_8h.html#a6153547f245c05874161a105e9a2f02c">densmatr_calcTotalProb</a>(qureg);</div>
<div class="line"><a name="l00825"></a><span class="lineno">  825</span>&#160;        <span class="keywordflow">else</span></div>
<div class="line"><a name="l00826"></a><span class="lineno">  826</span>&#160;            <span class="keywordflow">return</span> <a class="code" href="QuEST__internal_8h.html#ad65ad1b5ea6f30b0c6b4ffda96e1a8e6">statevec_calcTotalProb</a>(qureg);</div>
<div class="line"><a name="l00827"></a><span class="lineno">  827</span>&#160;}</div>
</div><!-- fragment -->
<p class="reference">References <a class="el" href="QuEST__cpu__distributed_8c_source.html#l00053">densmatr_calcTotalProb()</a>, <a class="el" href="QuEST_8h_source.html#l00163">Qureg::isDensityMatrix</a>, and <a class="el" href="QuEST__cpu__distributed_8c_source.html#l00088">statevec_calcTotalProb()</a>.</p>

<p class="reference">Referenced by <a class="el" href="test__calculations_8cpp_source.html#l00911">TEST_CASE()</a>.</p>

</div>
</div>
<a id="ga30d6f8b7c766c9c9914b2c61a2fc0def"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga30d6f8b7c766c9c9914b2c61a2fc0def">&#9670;&nbsp;</a></span>getAmp()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="structComplex.html">Complex</a> getAmp </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structQureg.html">Qureg</a>&#160;</td>
          <td class="paramname"><em>qureg</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">long long int&#160;</td>
          <td class="paramname"><em>index</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Get the complex amplitude at a given index in the state vector. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in]</td><td class="paramname">qureg</td><td>object representing a set of qubits </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">index</td><td>index in state vector of probability amplitudes </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>amplitude at index, returned as a <a class="el" href="structComplex.html" title="Represents one complex number.">Complex</a> struct (with .real and .imag attributes) </dd></dl>
<dl class="exception"><dt>Exceptions</dt><dd>
  <table class="exception">
    <tr><td class="paramname">exitWithError</td><td>if <code>qureg</code> is a density matrix, or if <code>index</code> is outside [0, <img class="formulaInl" alt="$2^{N}$" src="form_35.png"/>) where <img class="formulaInl" alt="$N = $" src="form_36.png"/> <code>qureg.numQubitsRepresented</code> </td></tr>
  </table>
  </dd>
</dl>
<dl class="section author"><dt>Author</dt><dd>Tyson Jones </dd></dl>

<p class="definition">Definition at line <a class="el" href="QuEST_8c_source.html#l00697">697</a> of file <a class="el" href="QuEST_8c_source.html">QuEST.c</a>.</p>
<div class="fragment"><div class="line"><a name="l00697"></a><span class="lineno">  697</span>&#160;                                                 {</div>
<div class="line"><a name="l00698"></a><span class="lineno">  698</span>&#160;    <a class="code" href="QuEST__validation_8c.html#a72feec2aaa05f98aed7f3c3fee141251">validateStateVecQureg</a>(qureg, __func__);</div>
<div class="line"><a name="l00699"></a><span class="lineno">  699</span>&#160;    <a class="code" href="QuEST__validation_8c.html#a5f87419b253a97f6caadb72b507b9853">validateAmpIndex</a>(qureg, index, __func__);</div>
<div class="line"><a name="l00700"></a><span class="lineno">  700</span>&#160;    </div>
<div class="line"><a name="l00701"></a><span class="lineno">  701</span>&#160;    <a class="code" href="structComplex.html">Complex</a> amp;</div>
<div class="line"><a name="l00702"></a><span class="lineno">  702</span>&#160;    amp.<a class="code" href="structComplex.html#ab5b2e2eca02131fc74b289a83636cbe3">real</a> = <a class="code" href="QuEST__internal_8h.html#abc9a9ef4344c7faaaf28ac25c76649b9">statevec_getRealAmp</a>(qureg, index);</div>
<div class="line"><a name="l00703"></a><span class="lineno">  703</span>&#160;    amp.<a class="code" href="structComplex.html#a84f5439aad0ef495efdd3b4c1c02d27e">imag</a> = <a class="code" href="QuEST__internal_8h.html#abd509244d57657e148e4084c5ab5d28f">statevec_getImagAmp</a>(qureg, index);</div>
<div class="line"><a name="l00704"></a><span class="lineno">  704</span>&#160;    <span class="keywordflow">return</span> amp;</div>
<div class="line"><a name="l00705"></a><span class="lineno">  705</span>&#160;}</div>
</div><!-- fragment -->
<p class="reference">References <a class="el" href="QuEST_8h_source.html#l00106">Complex::imag</a>, <a class="el" href="QuEST_8h_source.html#l00105">Complex::real</a>, <a class="el" href="QuEST__cpu__distributed_8c_source.html#l00208">statevec_getImagAmp()</a>, <a class="el" href="QuEST__cpu__distributed_8c_source.html#l00198">statevec_getRealAmp()</a>, <a class="el" href="QuEST__validation_8c_source.html#l00296">validateAmpIndex()</a>, and <a class="el" href="QuEST__validation_8c_source.html#l00418">validateStateVecQureg()</a>.</p>

<p class="reference">Referenced by <a class="el" href="test__calculations_8cpp_source.html#l00978">TEST_CASE()</a>.</p>

</div>
</div>
<a id="gadca286c4ad5cde6124d4e80a7ab95a68"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gadca286c4ad5cde6124d4e80a7ab95a68">&#9670;&nbsp;</a></span>getDensityAmp()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="structComplex.html">Complex</a> getDensityAmp </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structQureg.html">Qureg</a>&#160;</td>
          <td class="paramname"><em>qureg</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">long long int&#160;</td>
          <td class="paramname"><em>row</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">long long int&#160;</td>
          <td class="paramname"><em>col</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Get an amplitude from a density matrix at a given row and column. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in]</td><td class="paramname">qureg</td><td>object representing a density matrix </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">row</td><td>row of the desired amplitude in the density matrix </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">col</td><td>column of the desired amplitude in the density matrix </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>a <a class="el" href="structComplex.html" title="Represents one complex number.">Complex</a> scalar representing the desired amplitude </dd></dl>
<dl class="exception"><dt>Exceptions</dt><dd>
  <table class="exception">
    <tr><td class="paramname">exitWithError</td><td>if <code>qureg</code> is a statevector, or if <code>row</code> or <code>col</code> are outside [0, <img class="formulaInl" alt="$2^{N}$" src="form_35.png"/>) where <img class="formulaInl" alt="$N = $" src="form_36.png"/> <code>qureg.numQubitsRepresented</code> </td></tr>
  </table>
  </dd>
</dl>
<dl class="section author"><dt>Author</dt><dd>Tyson Jones </dd></dl>

<p class="definition">Definition at line <a class="el" href="QuEST_8c_source.html#l00707">707</a> of file <a class="el" href="QuEST_8c_source.html">QuEST.c</a>.</p>
<div class="fragment"><div class="line"><a name="l00707"></a><span class="lineno">  707</span>&#160;                                                                         {</div>
<div class="line"><a name="l00708"></a><span class="lineno">  708</span>&#160;    <a class="code" href="QuEST__validation_8c.html#af22919f5190ca1b3b6b52b8f2fb8213b">validateDensityMatrQureg</a>(qureg, __func__);</div>
<div class="line"><a name="l00709"></a><span class="lineno">  709</span>&#160;    <a class="code" href="QuEST__validation_8c.html#a5f87419b253a97f6caadb72b507b9853">validateAmpIndex</a>(qureg, row, __func__);</div>
<div class="line"><a name="l00710"></a><span class="lineno">  710</span>&#160;    <a class="code" href="QuEST__validation_8c.html#a5f87419b253a97f6caadb72b507b9853">validateAmpIndex</a>(qureg, col, __func__);</div>
<div class="line"><a name="l00711"></a><span class="lineno">  711</span>&#160;    </div>
<div class="line"><a name="l00712"></a><span class="lineno">  712</span>&#160;    <span class="keywordtype">long</span> <span class="keywordtype">long</span> ind = row + col*(1LL &lt;&lt; qureg.<a class="code" href="structQureg.html#ad08dff5316b8937f4b2a1417591543dc">numQubitsRepresented</a>);</div>
<div class="line"><a name="l00713"></a><span class="lineno">  713</span>&#160;    <a class="code" href="structComplex.html">Complex</a> amp;</div>
<div class="line"><a name="l00714"></a><span class="lineno">  714</span>&#160;    amp.<a class="code" href="structComplex.html#ab5b2e2eca02131fc74b289a83636cbe3">real</a> = <a class="code" href="QuEST__internal_8h.html#abc9a9ef4344c7faaaf28ac25c76649b9">statevec_getRealAmp</a>(qureg, ind);</div>
<div class="line"><a name="l00715"></a><span class="lineno">  715</span>&#160;    amp.imag = <a class="code" href="QuEST__internal_8h.html#abd509244d57657e148e4084c5ab5d28f">statevec_getImagAmp</a>(qureg, ind);</div>
<div class="line"><a name="l00716"></a><span class="lineno">  716</span>&#160;    <span class="keywordflow">return</span> amp;</div>
<div class="line"><a name="l00717"></a><span class="lineno">  717</span>&#160;}</div>
</div><!-- fragment -->
<p class="reference">References <a class="el" href="QuEST_8h_source.html#l00165">Qureg::numQubitsRepresented</a>, <a class="el" href="QuEST_8h_source.html#l00105">Complex::real</a>, <a class="el" href="QuEST__cpu__distributed_8c_source.html#l00208">statevec_getImagAmp()</a>, <a class="el" href="QuEST__cpu__distributed_8c_source.html#l00198">statevec_getRealAmp()</a>, <a class="el" href="QuEST__validation_8c_source.html#l00296">validateAmpIndex()</a>, and <a class="el" href="QuEST__validation_8c_source.html#l00422">validateDensityMatrQureg()</a>.</p>

<p class="reference">Referenced by <a class="el" href="test__calculations_8cpp_source.html#l01017">TEST_CASE()</a>.</p>

</div>
</div>
<a id="gad575782de461d9ab0975b38cc7850f1a"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gad575782de461d9ab0975b38cc7850f1a">&#9670;&nbsp;</a></span>getImagAmp()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="group__type.html#ga7740e349b4f8bae6451547680f0ce2d6">qreal</a> getImagAmp </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structQureg.html">Qureg</a>&#160;</td>
          <td class="paramname"><em>qureg</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">long long int&#160;</td>
          <td class="paramname"><em>index</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Get the imaginary component of the complex probability amplitude at an index in the state vector. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in]</td><td class="paramname">qureg</td><td>object representing a set of qubits </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">index</td><td>index in state vector of probability amplitudes </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>imaginary component at that index </dd></dl>
<dl class="exception"><dt>Exceptions</dt><dd>
  <table class="exception">
    <tr><td class="paramname">exitWithError</td><td>if <code>qureg</code> is a density matrix, or if <code>index</code> is outside [0, <img class="formulaInl" alt="$2^{N}$" src="form_35.png"/>) where <img class="formulaInl" alt="$N = $" src="form_36.png"/> <code>qureg.numQubitsRepresented</code> </td></tr>
  </table>
  </dd>
</dl>
<dl class="section author"><dt>Author</dt><dd>Ania Brown </dd></dl>

<p class="definition">Definition at line <a class="el" href="QuEST_8c_source.html#l00683">683</a> of file <a class="el" href="QuEST_8c_source.html">QuEST.c</a>.</p>
<div class="fragment"><div class="line"><a name="l00683"></a><span class="lineno">  683</span>&#160;                                                   {</div>
<div class="line"><a name="l00684"></a><span class="lineno">  684</span>&#160;    <a class="code" href="QuEST__validation_8c.html#a72feec2aaa05f98aed7f3c3fee141251">validateStateVecQureg</a>(qureg, __func__);</div>
<div class="line"><a name="l00685"></a><span class="lineno">  685</span>&#160;    <a class="code" href="QuEST__validation_8c.html#a5f87419b253a97f6caadb72b507b9853">validateAmpIndex</a>(qureg, index, __func__);</div>
<div class="line"><a name="l00686"></a><span class="lineno">  686</span>&#160;    </div>
<div class="line"><a name="l00687"></a><span class="lineno">  687</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="QuEST__internal_8h.html#abd509244d57657e148e4084c5ab5d28f">statevec_getImagAmp</a>(qureg, index);</div>
<div class="line"><a name="l00688"></a><span class="lineno">  688</span>&#160;}</div>
</div><!-- fragment -->
<p class="reference">References <a class="el" href="QuEST__cpu__distributed_8c_source.html#l00208">statevec_getImagAmp()</a>, <a class="el" href="QuEST__validation_8c_source.html#l00296">validateAmpIndex()</a>, and <a class="el" href="QuEST__validation_8c_source.html#l00418">validateStateVecQureg()</a>.</p>

<p class="reference">Referenced by <a class="el" href="test__calculations_8cpp_source.html#l01060">TEST_CASE()</a>.</p>

</div>
</div>
<a id="ga8cbe422d4981bf06847d229a4c6aa3df"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga8cbe422d4981bf06847d229a4c6aa3df">&#9670;&nbsp;</a></span>getNumAmps()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">long long int getNumAmps </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structQureg.html">Qureg</a>&#160;</td>
          <td class="paramname"><em>qureg</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Get the number of probability amplitudes in a qureg object, given by 2^numQubits. </p>
<dl class="section author"><dt>Author</dt><dd>Tyson Jones </dd></dl>

<p class="definition">Definition at line <a class="el" href="QuEST_8c_source.html#l00670">670</a> of file <a class="el" href="QuEST_8c_source.html">QuEST.c</a>.</p>
<div class="fragment"><div class="line"><a name="l00670"></a><span class="lineno">  670</span>&#160;                                      {</div>
<div class="line"><a name="l00671"></a><span class="lineno">  671</span>&#160;    <a class="code" href="QuEST__validation_8c.html#a72feec2aaa05f98aed7f3c3fee141251">validateStateVecQureg</a>(qureg, __func__);</div>
<div class="line"><a name="l00672"></a><span class="lineno">  672</span>&#160;    </div>
<div class="line"><a name="l00673"></a><span class="lineno">  673</span>&#160;    <span class="keywordflow">return</span> qureg.<a class="code" href="structQureg.html#adef4935cac95763c29164cf99b144ed4">numAmpsTotal</a>;</div>
<div class="line"><a name="l00674"></a><span class="lineno">  674</span>&#160;}</div>
</div><!-- fragment -->
<p class="reference">References <a class="el" href="QuEST_8h_source.html#l00172">Qureg::numAmpsTotal</a>, and <a class="el" href="QuEST__validation_8c_source.html#l00418">validateStateVecQureg()</a>.</p>

<p class="reference">Referenced by <a class="el" href="test__calculations_8cpp_source.html#l01098">TEST_CASE()</a>.</p>

</div>
</div>
<a id="ga73036c778d800703585ab3d8796a915f"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga73036c778d800703585ab3d8796a915f">&#9670;&nbsp;</a></span>getNumQubits()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int getNumQubits </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structQureg.html">Qureg</a>&#160;</td>
          <td class="paramname"><em>qureg</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Get the number of qubits in a qureg object. </p>
<dl class="section author"><dt>Author</dt><dd>Tyson Jones </dd></dl>

<p class="definition">Definition at line <a class="el" href="QuEST_8c_source.html#l00666">666</a> of file <a class="el" href="QuEST_8c_source.html">QuEST.c</a>.</p>
<div class="fragment"><div class="line"><a name="l00666"></a><span class="lineno">  666</span>&#160;                              {</div>
<div class="line"><a name="l00667"></a><span class="lineno">  667</span>&#160;    <span class="keywordflow">return</span> qureg.<a class="code" href="structQureg.html#ad08dff5316b8937f4b2a1417591543dc">numQubitsRepresented</a>;</div>
<div class="line"><a name="l00668"></a><span class="lineno">  668</span>&#160;}</div>
</div><!-- fragment -->
<p class="reference">References <a class="el" href="QuEST_8h_source.html#l00165">Qureg::numQubitsRepresented</a>.</p>

<p class="reference">Referenced by <a class="el" href="test__calculations_8cpp_source.html#l01128">TEST_CASE()</a>.</p>

</div>
</div>
<a id="ga4a14d22379d399760b0cfc5c8053589b"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga4a14d22379d399760b0cfc5c8053589b">&#9670;&nbsp;</a></span>getProbAmp()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="group__type.html#ga7740e349b4f8bae6451547680f0ce2d6">qreal</a> getProbAmp </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structQureg.html">Qureg</a>&#160;</td>
          <td class="paramname"><em>qureg</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">long long int&#160;</td>
          <td class="paramname"><em>index</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Get the probability of a state-vector at an index in the full state vector. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in]</td><td class="paramname">qureg</td><td>object representing a set of qubits </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">index</td><td>index in state vector of probability amplitudes </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>realEl*realEl + imagEl*imagEl </dd></dl>
<dl class="exception"><dt>Exceptions</dt><dd>
  <table class="exception">
    <tr><td class="paramname">exitWithError</td><td>if <code>qureg</code> is a density matrix, or if <code>index</code> is outside [0, <img class="formulaInl" alt="$2^{N}$" src="form_35.png"/>) where <img class="formulaInl" alt="$N = $" src="form_36.png"/> <code>qureg.numQubitsRepresented</code> </td></tr>
  </table>
  </dd>
</dl>
<dl class="section author"><dt>Author</dt><dd>Ania Brown </dd></dl>

<p class="definition">Definition at line <a class="el" href="QuEST_8c_source.html#l00690">690</a> of file <a class="el" href="QuEST_8c_source.html">QuEST.c</a>.</p>
<div class="fragment"><div class="line"><a name="l00690"></a><span class="lineno">  690</span>&#160;                                                   {</div>
<div class="line"><a name="l00691"></a><span class="lineno">  691</span>&#160;    <a class="code" href="QuEST__validation_8c.html#a72feec2aaa05f98aed7f3c3fee141251">validateStateVecQureg</a>(qureg, __func__);</div>
<div class="line"><a name="l00692"></a><span class="lineno">  692</span>&#160;    <a class="code" href="QuEST__validation_8c.html#a5f87419b253a97f6caadb72b507b9853">validateAmpIndex</a>(qureg, index, __func__);</div>
<div class="line"><a name="l00693"></a><span class="lineno">  693</span>&#160;    </div>
<div class="line"><a name="l00694"></a><span class="lineno">  694</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="QuEST__common_8c.html#a3afe58e49dce5536bc4c1b7caddf44a6">statevec_getProbAmp</a>(qureg, index);</div>
<div class="line"><a name="l00695"></a><span class="lineno">  695</span>&#160;}</div>
</div><!-- fragment -->
<p class="reference">References <a class="el" href="QuEST__common_8c_source.html#l00244">statevec_getProbAmp()</a>, <a class="el" href="QuEST__validation_8c_source.html#l00296">validateAmpIndex()</a>, and <a class="el" href="QuEST__validation_8c_source.html#l00418">validateStateVecQureg()</a>.</p>

<p class="reference">Referenced by <a class="el" href="test__calculations_8cpp_source.html#l01161">TEST_CASE()</a>.</p>

</div>
</div>
<a id="ga1416145280c62c5dd5ec9bed89b4cd05"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga1416145280c62c5dd5ec9bed89b4cd05">&#9670;&nbsp;</a></span>getRealAmp()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="group__type.html#ga7740e349b4f8bae6451547680f0ce2d6">qreal</a> getRealAmp </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structQureg.html">Qureg</a>&#160;</td>
          <td class="paramname"><em>qureg</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">long long int&#160;</td>
          <td class="paramname"><em>index</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Get the real component of the complex probability amplitude at an index in the state vector. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in]</td><td class="paramname">qureg</td><td>object representing a set of qubits </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">index</td><td>index in state vector of probability amplitudes </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>real component at that index </dd></dl>
<dl class="exception"><dt>Exceptions</dt><dd>
  <table class="exception">
    <tr><td class="paramname">exitWithError</td><td>if <code>qureg</code> is a density matrix, or if <code>index</code> is outside [0, <img class="formulaInl" alt="$2^{N}$" src="form_35.png"/>) where <img class="formulaInl" alt="$N = $" src="form_36.png"/> <code>qureg.numQubitsRepresented</code> </td></tr>
  </table>
  </dd>
</dl>
<dl class="section author"><dt>Author</dt><dd>Ania Brown </dd></dl>

<p class="definition">Definition at line <a class="el" href="QuEST_8c_source.html#l00676">676</a> of file <a class="el" href="QuEST_8c_source.html">QuEST.c</a>.</p>
<div class="fragment"><div class="line"><a name="l00676"></a><span class="lineno">  676</span>&#160;                                                   {</div>
<div class="line"><a name="l00677"></a><span class="lineno">  677</span>&#160;    <a class="code" href="QuEST__validation_8c.html#a72feec2aaa05f98aed7f3c3fee141251">validateStateVecQureg</a>(qureg, __func__);</div>
<div class="line"><a name="l00678"></a><span class="lineno">  678</span>&#160;    <a class="code" href="QuEST__validation_8c.html#a5f87419b253a97f6caadb72b507b9853">validateAmpIndex</a>(qureg, index, __func__);</div>
<div class="line"><a name="l00679"></a><span class="lineno">  679</span>&#160;    </div>
<div class="line"><a name="l00680"></a><span class="lineno">  680</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="QuEST__internal_8h.html#abc9a9ef4344c7faaaf28ac25c76649b9">statevec_getRealAmp</a>(qureg, index);</div>
<div class="line"><a name="l00681"></a><span class="lineno">  681</span>&#160;}</div>
</div><!-- fragment -->
<p class="reference">References <a class="el" href="QuEST__cpu__distributed_8c_source.html#l00198">statevec_getRealAmp()</a>, <a class="el" href="QuEST__validation_8c_source.html#l00296">validateAmpIndex()</a>, and <a class="el" href="QuEST__validation_8c_source.html#l00418">validateStateVecQureg()</a>.</p>

<p class="reference">Referenced by <a class="el" href="test__calculations_8cpp_source.html#l01200">TEST_CASE()</a>.</p>

</div>
</div>
</div><!-- contents -->
<div class="ttc" id="aQuEST__validation_8c_html_af22919f5190ca1b3b6b52b8f2fb8213b"><div class="ttname"><a href="QuEST__validation_8c.html#af22919f5190ca1b3b6b52b8f2fb8213b">validateDensityMatrQureg</a></div><div class="ttdeci">void validateDensityMatrQureg(Qureg qureg, const char *caller)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__validation_8c_source.html#l00422">QuEST_validation.c:422</a></div></div>
<div class="ttc" id="aQuEST__validation_8c_html_ac31c45c5a31c523be0eb26abba6cf598"><div class="ttname"><a href="QuEST__validation_8c.html#ac31c45c5a31c523be0eb26abba6cf598">validateTarget</a></div><div class="ttdeci">void validateTarget(Qureg qureg, int targetQubit, const char *caller)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__validation_8c_source.html#l00307">QuEST_validation.c:307</a></div></div>
<div class="ttc" id="aQuEST__validation_8c_html_ad613c75ff252a88e54f911053bd2032c"><div class="ttname"><a href="QuEST__validation_8c.html#ad613c75ff252a88e54f911053bd2032c">validateOutcome</a></div><div class="ttdeci">void validateOutcome(int outcome, const char *caller)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__validation_8c_source.html#l00426">QuEST_validation.c:426</a></div></div>
<div class="ttc" id="aQuEST__internal_8h_html_a6ff3dc624b5fafe8edae4fe327c255a0"><div class="ttname"><a href="QuEST__internal_8h.html#a6ff3dc624b5fafe8edae4fe327c255a0">densmatr_calcInnerProduct</a></div><div class="ttdeci">qreal densmatr_calcInnerProduct(Qureg a, Qureg b)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__cpu__distributed_8c_source.html#l00441">QuEST_cpu_distributed.c:441</a></div></div>
<div class="ttc" id="aQuEST__common_8c_html_aef380928d1b0003411d6159ca6594cd5"><div class="ttname"><a href="QuEST__common_8c.html#aef380928d1b0003411d6159ca6594cd5">statevec_calcExpecPauliProd</a></div><div class="ttdeci">qreal statevec_calcExpecPauliProd(Qureg qureg, int *targetQubits, enum pauliOpType *pauliCodes, int numTargets, Qureg workspace)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__common_8c_source.html#l00464">QuEST_common.c:464</a></div></div>
<div class="ttc" id="aQuEST__validation_8c_html_a72feec2aaa05f98aed7f3c3fee141251"><div class="ttname"><a href="QuEST__validation_8c.html#a72feec2aaa05f98aed7f3c3fee141251">validateStateVecQureg</a></div><div class="ttdeci">void validateStateVecQureg(Qureg qureg, const char *caller)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__validation_8c_source.html#l00418">QuEST_validation.c:418</a></div></div>
<div class="ttc" id="aQuEST__common_8c_html_ae0cfea24091c8336146aa84c2253992e"><div class="ttname"><a href="QuEST__common_8c.html#ae0cfea24091c8336146aa84c2253992e">statevec_calcExpecPauliSum</a></div><div class="ttdeci">qreal statevec_calcExpecPauliSum(Qureg qureg, enum pauliOpType *allCodes, qreal *termCoeffs, int numSumTerms, Qureg workspace)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__common_8c_source.html#l00479">QuEST_common.c:479</a></div></div>
<div class="ttc" id="aQuEST__internal_8h_html_ae45eefa65f4ecd37bab84fade7cf7f1f"><div class="ttname"><a href="QuEST__internal_8h.html#ae45eefa65f4ecd37bab84fade7cf7f1f">densmatr_calcPurity</a></div><div class="ttdeci">qreal densmatr_calcPurity(Qureg qureg)</div><div class="ttdoc">Computes the trace of the density matrix squared.</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__cpu__distributed_8c_source.html#l01291">QuEST_cpu_distributed.c:1291</a></div></div>
<div class="ttc" id="aQuEST__validation_8c_html_a17409defd561446f561279caa9c443f4"><div class="ttname"><a href="QuEST__validation_8c.html#a17409defd561446f561279caa9c443f4">validateMultiTargets</a></div><div class="ttdeci">void validateMultiTargets(Qureg qureg, int *targetQubits, const int numTargetQubits, const char *caller)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__validation_8c_source.html#l00335">QuEST_validation.c:335</a></div></div>
<div class="ttc" id="aQuEST__validation_8c_html_a5be128290a7bba9a7f12d32cabe2276b"><div class="ttname"><a href="QuEST__validation_8c.html#a5be128290a7bba9a7f12d32cabe2276b">validateNumPauliSumTerms</a></div><div class="ttdeci">void validateNumPauliSumTerms(int numTerms, const char *caller)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__validation_8c_source.html#l00507">QuEST_validation.c:507</a></div></div>
<div class="ttc" id="aQuEST__common_8c_html_aeeec9fe1501e25930adf6c38763a158e"><div class="ttname"><a href="QuEST__common_8c.html#aeeec9fe1501e25930adf6c38763a158e">statevec_calcFidelity</a></div><div class="ttdeci">qreal statevec_calcFidelity(Qureg qureg, Qureg pureState)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__common_8c_source.html#l00376">QuEST_common.c:376</a></div></div>
<div class="ttc" id="aQuEST__common_8c_html_a3afe58e49dce5536bc4c1b7caddf44a6"><div class="ttname"><a href="QuEST__common_8c.html#a3afe58e49dce5536bc4c1b7caddf44a6">statevec_getProbAmp</a></div><div class="ttdeci">qreal statevec_getProbAmp(Qureg qureg, long long int index)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__common_8c_source.html#l00244">QuEST_common.c:244</a></div></div>
<div class="ttc" id="aQuEST__internal_8h_html_a6153547f245c05874161a105e9a2f02c"><div class="ttname"><a href="QuEST__internal_8h.html#a6153547f245c05874161a105e9a2f02c">densmatr_calcTotalProb</a></div><div class="ttdeci">qreal densmatr_calcTotalProb(Qureg qureg)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__cpu__distributed_8c_source.html#l00053">QuEST_cpu_distributed.c:53</a></div></div>
<div class="ttc" id="aQuEST__validation_8c_html_a87d22240ccfd81827a2a34b8d569d347"><div class="ttname"><a href="QuEST__validation_8c.html#a87d22240ccfd81827a2a34b8d569d347">validateMatchingQuregDims</a></div><div class="ttdeci">void validateMatchingQuregDims(Qureg qureg1, Qureg qureg2, const char *caller)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__validation_8c_source.html#l00434">QuEST_validation.c:434</a></div></div>
<div class="ttc" id="aQuEST__internal_8h_html_a7ebd3198a198f4cd20840f64fd8b84d0"><div class="ttname"><a href="QuEST__internal_8h.html#a7ebd3198a198f4cd20840f64fd8b84d0">statevec_calcInnerProduct</a></div><div class="ttdeci">Complex statevec_calcInnerProduct(Qureg bra, Qureg ket)</div><div class="ttdoc">Terrible code which unnecessarily individually computes and sums the real and imaginary components of...</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__cpu__distributed_8c_source.html#l00035">QuEST_cpu_distributed.c:35</a></div></div>
<div class="ttc" id="aQuEST__internal_8h_html_ab33cdf01831c4545e51299178acf7f27"><div class="ttname"><a href="QuEST__internal_8h.html#ab33cdf01831c4545e51299178acf7f27">statevec_calcProbOfOutcome</a></div><div class="ttdeci">qreal statevec_calcProbOfOutcome(Qureg qureg, const int measureQubit, int outcome)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__cpu__distributed_8c_source.html#l01263">QuEST_cpu_distributed.c:1263</a></div></div>
<div class="ttc" id="aQuEST__internal_8h_html_abd509244d57657e148e4084c5ab5d28f"><div class="ttname"><a href="QuEST__internal_8h.html#abd509244d57657e148e4084c5ab5d28f">statevec_getImagAmp</a></div><div class="ttdeci">qreal statevec_getImagAmp(Qureg qureg, long long int index)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__cpu__distributed_8c_source.html#l00208">QuEST_cpu_distributed.c:208</a></div></div>
<div class="ttc" id="aQuEST__internal_8h_html_ad405e3fac20997043e0236b751e44270"><div class="ttname"><a href="QuEST__internal_8h.html#ad405e3fac20997043e0236b751e44270">densmatr_calcProbOfOutcome</a></div><div class="ttdeci">qreal densmatr_calcProbOfOutcome(Qureg qureg, const int measureQubit, int outcome)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__cpu__distributed_8c_source.html#l01279">QuEST_cpu_distributed.c:1279</a></div></div>
<div class="ttc" id="aQuEST__internal_8h_html_aa6c3f86010ad398f42b0577ea3bb5bcf"><div class="ttname"><a href="QuEST__internal_8h.html#aa6c3f86010ad398f42b0577ea3bb5bcf">densmatr_calcFidelity</a></div><div class="ttdeci">qreal densmatr_calcFidelity(Qureg qureg, Qureg pureState)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__cpu__distributed_8c_source.html#l00415">QuEST_cpu_distributed.c:415</a></div></div>
<div class="ttc" id="astructQureg_html_acf78445e9435d09f44f0cc832c6aee79"><div class="ttname"><a href="structQureg.html#acf78445e9435d09f44f0cc832c6aee79">Qureg::isDensityMatrix</a></div><div class="ttdeci">int isDensityMatrix</div><div class="ttdoc">Whether this instance is a density-state representation.</div><div class="ttdef"><b>Definition:</b> <a href="QuEST_8h_source.html#l00163">QuEST.h:163</a></div></div>
<div class="ttc" id="aQuEST__validation_8c_html_a031812e1cf2c98d72d795cea7bbe73a5"><div class="ttname"><a href="QuEST__validation_8c.html#a031812e1cf2c98d72d795cea7bbe73a5">validateMatchingQuregTypes</a></div><div class="ttdeci">void validateMatchingQuregTypes(Qureg qureg1, Qureg qureg2, const char *caller)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__validation_8c_source.html#l00438">QuEST_validation.c:438</a></div></div>
<div class="ttc" id="aQuEST__validation_8c_html_a5f87419b253a97f6caadb72b507b9853"><div class="ttname"><a href="QuEST__validation_8c.html#a5f87419b253a97f6caadb72b507b9853">validateAmpIndex</a></div><div class="ttdeci">void validateAmpIndex(Qureg qureg, long long int ampInd, const char *caller)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__validation_8c_source.html#l00296">QuEST_validation.c:296</a></div></div>
<div class="ttc" id="aQuEST__validation_8c_html_a7adc86571f1154558676d95daf0cbd1f"><div class="ttname"><a href="QuEST__validation_8c.html#a7adc86571f1154558676d95daf0cbd1f">validateSecondQuregStateVec</a></div><div class="ttdeci">void validateSecondQuregStateVec(Qureg qureg2, const char *caller)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__validation_8c_source.html#l00442">QuEST_validation.c:442</a></div></div>
<div class="ttc" id="astructQureg_html_ad08dff5316b8937f4b2a1417591543dc"><div class="ttname"><a href="structQureg.html#ad08dff5316b8937f4b2a1417591543dc">Qureg::numQubitsRepresented</a></div><div class="ttdeci">int numQubitsRepresented</div><div class="ttdoc">The number of qubits represented in either the state-vector or density matrix.</div><div class="ttdef"><b>Definition:</b> <a href="QuEST_8h_source.html#l00165">QuEST.h:165</a></div></div>
<div class="ttc" id="astructQureg_html_adef4935cac95763c29164cf99b144ed4"><div class="ttname"><a href="structQureg.html#adef4935cac95763c29164cf99b144ed4">Qureg::numAmpsTotal</a></div><div class="ttdeci">long long int numAmpsTotal</div><div class="ttdoc">Total number of amplitudes, which are possibly distributed among machines.</div><div class="ttdef"><b>Definition:</b> <a href="QuEST_8h_source.html#l00172">QuEST.h:172</a></div></div>
<div class="ttc" id="astructComplex_html_ab5b2e2eca02131fc74b289a83636cbe3"><div class="ttname"><a href="structComplex.html#ab5b2e2eca02131fc74b289a83636cbe3">Complex::real</a></div><div class="ttdeci">qreal real</div><div class="ttdef"><b>Definition:</b> <a href="QuEST_8h_source.html#l00105">QuEST.h:105</a></div></div>
<div class="ttc" id="astructComplex_html_a84f5439aad0ef495efdd3b4c1c02d27e"><div class="ttname"><a href="structComplex.html#a84f5439aad0ef495efdd3b4c1c02d27e">Complex::imag</a></div><div class="ttdeci">qreal imag</div><div class="ttdef"><b>Definition:</b> <a href="QuEST_8h_source.html#l00106">QuEST.h:106</a></div></div>
<div class="ttc" id="aQuEST__internal_8h_html_a8c9da88f734b0862f4cce7d819e6d3b5"><div class="ttname"><a href="QuEST__internal_8h.html#a8c9da88f734b0862f4cce7d819e6d3b5">densmatr_calcHilbertSchmidtDistance</a></div><div class="ttdeci">qreal densmatr_calcHilbertSchmidtDistance(Qureg a, Qureg b)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__cpu__distributed_8c_source.html#l00430">QuEST_cpu_distributed.c:430</a></div></div>
<div class="ttc" id="astructComplex_html"><div class="ttname"><a href="structComplex.html">Complex</a></div><div class="ttdoc">Represents one complex number.</div><div class="ttdef"><b>Definition:</b> <a href="QuEST_8h_source.html#l00103">QuEST.h:103</a></div></div>
<div class="ttc" id="aQuEST__validation_8c_html_aa194ba5f5c6e19c6caa4c715b3dbefcc"><div class="ttname"><a href="QuEST__validation_8c.html#aa194ba5f5c6e19c6caa4c715b3dbefcc">validatePauliCodes</a></div><div class="ttdeci">void validatePauliCodes(enum pauliOpType *pauliCodes, int numPauliCodes, const char *caller)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__validation_8c_source.html#l00498">QuEST_validation.c:498</a></div></div>
<div class="ttc" id="aQuEST__internal_8h_html_abc9a9ef4344c7faaaf28ac25c76649b9"><div class="ttname"><a href="QuEST__internal_8h.html#abc9a9ef4344c7faaaf28ac25c76649b9">statevec_getRealAmp</a></div><div class="ttdeci">qreal statevec_getRealAmp(Qureg qureg, long long int index)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__cpu__distributed_8c_source.html#l00198">QuEST_cpu_distributed.c:198</a></div></div>
<div class="ttc" id="aQuEST__internal_8h_html_ad65ad1b5ea6f30b0c6b4ffda96e1a8e6"><div class="ttname"><a href="QuEST__internal_8h.html#ad65ad1b5ea6f30b0c6b4ffda96e1a8e6">statevec_calcTotalProb</a></div><div class="ttdeci">qreal statevec_calcTotalProb(Qureg qureg)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__cpu__distributed_8c_source.html#l00088">QuEST_cpu_distributed.c:88</a></div></div>
<!-- HTML footer for doxygen 1.8.8-->
<!-- start footer part -->
</div>
</div>
</div>
</div>
</div>
</body>
        <script type="text/javascript" src="boot.js"></script>
</html>