@@ -76,10 +76,9 @@ using Matrix1q = std::array<std::array<std::complex<fp_type>, 2>, 2>;
76
76
template <typename fp_type>
77
77
using Matrix2q = std::array<std::array<std::complex<fp_type>, 4 >, 4 >;
78
78
79
- constexpr double h = 0.5 ;
80
- constexpr double pi = M_PI;
81
- constexpr double inv_pi = 1.0 / pi ;
82
- constexpr double is2 = 0.7071067811865475 ;
79
+ constexpr double h_double = 0.5 ;
80
+ constexpr double pi_double = M_PI;
81
+ constexpr double is2_double = 0.7071067811865475 ;
83
82
84
83
// Gates from cirq/ops/identity.py:
85
84
@@ -124,6 +123,8 @@ struct XPowGate {
124
123
static constexpr char name[] = " XPowGate" ;
125
124
static constexpr unsigned num_qubits = 1 ;
126
125
126
+ static constexpr fp_type pi = static_cast <fp_type>(pi_double);
127
+
127
128
static GateCirq<fp_type> Create (unsigned time, unsigned q0,
128
129
fp_type exponent, fp_type global_shift = 0 ) {
129
130
fp_type c = std::cos (pi * exponent * 0.5 );
@@ -143,6 +144,8 @@ struct YPowGate {
143
144
static constexpr char name[] = " YPowGate" ;
144
145
static constexpr unsigned num_qubits = 1 ;
145
146
147
+ static constexpr fp_type pi = static_cast <fp_type>(pi_double);
148
+
146
149
static GateCirq<fp_type> Create (unsigned time, unsigned q0,
147
150
fp_type exponent, fp_type global_shift = 0 ) {
148
151
fp_type c = std::cos (pi * exponent * 0.5 );
@@ -162,6 +165,8 @@ struct ZPowGate {
162
165
static constexpr char name[] = " ZPowGate" ;
163
166
static constexpr unsigned num_qubits = 1 ;
164
167
168
+ static constexpr fp_type pi = static_cast <fp_type>(pi_double);
169
+
165
170
static GateCirq<fp_type> Create (unsigned time, unsigned q0,
166
171
fp_type exponent, fp_type global_shift = 0 ) {
167
172
fp_type c = std::cos (pi * exponent);
@@ -181,6 +186,9 @@ struct HPowGate {
181
186
static constexpr char name[] = " HPowGate" ;
182
187
static constexpr unsigned num_qubits = 1 ;
183
188
189
+ static constexpr fp_type pi = static_cast <fp_type>(pi_double);
190
+ static constexpr fp_type is2 = static_cast <fp_type>(is2_double);
191
+
184
192
static GateCirq<fp_type> Create (unsigned time, unsigned q0,
185
193
fp_type exponent, fp_type global_shift = 0 ) {
186
194
fp_type c = std::cos (pi * exponent * 0.5 );
@@ -203,6 +211,8 @@ struct CZPowGate {
203
211
static constexpr char name[] = " CZPowGate" ;
204
212
static constexpr unsigned num_qubits = 2 ;
205
213
214
+ static constexpr fp_type pi = static_cast <fp_type>(pi_double);
215
+
206
216
static GateCirq<fp_type> Create (unsigned time, unsigned q0, unsigned q1,
207
217
fp_type exponent, fp_type global_shift = 0 ) {
208
218
fp_type gc = std::cos (pi * exponent * global_shift);
@@ -237,6 +247,8 @@ struct CXPowGate {
237
247
static constexpr char name[] = " CXPowGate" ;
238
248
static constexpr unsigned num_qubits = 2 ;
239
249
250
+ static constexpr fp_type pi = static_cast <fp_type>(pi_double);
251
+
240
252
static GateCirq<fp_type> Create (unsigned time, unsigned q0, unsigned q1,
241
253
fp_type exponent, fp_type global_shift = 0 ) {
242
254
fp_type c = std::cos (pi * exponent * 0.5 );
@@ -330,6 +342,8 @@ struct H {
330
342
static constexpr char name[] = " H" ;
331
343
static constexpr unsigned num_qubits = 1 ;
332
344
345
+ static constexpr fp_type is2 = static_cast <fp_type>(is2_double);
346
+
333
347
static GateCirq<fp_type> Create (unsigned time, unsigned q0) {
334
348
return CreateGate<GateCirq<fp_type>, H>(
335
349
time , q0, {is2, 0 , is2, 0 , is2, 0 , -is2, 0 });
@@ -356,6 +370,8 @@ struct T {
356
370
static constexpr char name[] = " T" ;
357
371
static constexpr unsigned num_qubits = 1 ;
358
372
373
+ static constexpr fp_type is2 = static_cast <fp_type>(is2_double);
374
+
359
375
static GateCirq<fp_type> Create (unsigned time, unsigned q0) {
360
376
return CreateGate<GateCirq<fp_type>, T>(
361
377
time , q0, {1 , 0 , 0 , 0 , 0 , 0 , is2, is2});
@@ -464,6 +480,8 @@ struct PhasedXPowGate {
464
480
static constexpr char name[] = " PhasedXPowGate" ;
465
481
static constexpr unsigned num_qubits = 1 ;
466
482
483
+ static constexpr fp_type pi = static_cast <fp_type>(pi_double);
484
+
467
485
static GateCirq<fp_type> Create (unsigned time, unsigned q0,
468
486
fp_type phase_exponent, fp_type exponent = 1 ,
469
487
fp_type global_shift = 0 ) {
@@ -494,6 +512,8 @@ struct PhasedXZGate {
494
512
static constexpr char name[] = " PhasedXZGate" ;
495
513
static constexpr unsigned num_qubits = 1 ;
496
514
515
+ static constexpr fp_type pi = static_cast <fp_type>(pi_double);
516
+
497
517
static GateCirq<fp_type> Create (unsigned time, unsigned q0,
498
518
fp_type x_exponent, fp_type z_exponent,
499
519
fp_type axis_phase_exponent) {
@@ -527,6 +547,8 @@ struct XXPowGate {
527
547
static constexpr char name[] = " XXPowGate" ;
528
548
static constexpr unsigned num_qubits = 2 ;
529
549
550
+ static constexpr fp_type pi = static_cast <fp_type>(pi_double);
551
+
530
552
static GateCirq<fp_type> Create (unsigned time, unsigned q0, unsigned q1,
531
553
fp_type exponent, fp_type global_shift = 0 ) {
532
554
fp_type gc = std::cos (pi * exponent * global_shift);
@@ -569,6 +591,8 @@ struct YYPowGate {
569
591
static constexpr char name[] = " YYPowGate" ;
570
592
static constexpr unsigned num_qubits = 2 ;
571
593
594
+ static constexpr fp_type pi = static_cast <fp_type>(pi_double);
595
+
572
596
static GateCirq<fp_type> Create (unsigned time, unsigned q0, unsigned q1,
573
597
fp_type exponent, fp_type global_shift = 0 ) {
574
598
fp_type gc = std::cos (pi * exponent * global_shift);
@@ -611,6 +635,8 @@ struct ZZPowGate {
611
635
static constexpr char name[] = " ZZPowGate" ;
612
636
static constexpr unsigned num_qubits = 2 ;
613
637
638
+ static constexpr fp_type pi = static_cast <fp_type>(pi_double);
639
+
614
640
static GateCirq<fp_type> Create (unsigned time, unsigned q0, unsigned q1,
615
641
fp_type exponent, fp_type global_shift = 0 ) {
616
642
fp_type gc = std::cos (pi * exponent * global_shift);
@@ -717,6 +743,9 @@ struct SwapPowGate {
717
743
static constexpr char name[] = " SwapPowGate" ;
718
744
static constexpr unsigned num_qubits = 2 ;
719
745
746
+ static constexpr fp_type pi = static_cast <fp_type>(pi_double);
747
+ static constexpr fp_type h = static_cast <fp_type>(h_double);
748
+
720
749
static GateCirq<fp_type> Create (unsigned time, unsigned q0, unsigned q1,
721
750
fp_type exponent, fp_type global_shift = 0 ) {
722
751
fp_type gc = std::cos (pi * exponent * global_shift);
@@ -761,6 +790,9 @@ struct ISwapPowGate {
761
790
static constexpr char name[] = " ISwapPowGate" ;
762
791
static constexpr unsigned num_qubits = 2 ;
763
792
793
+ static constexpr fp_type pi = static_cast <fp_type>(pi_double);
794
+ static constexpr fp_type h = static_cast <fp_type>(h_double);
795
+
764
796
static GateCirq<fp_type> Create (unsigned time, unsigned q0, unsigned q1,
765
797
fp_type exponent, fp_type global_shift = 0 ) {
766
798
fp_type gc = std::cos (pi * exponent * global_shift);
@@ -803,6 +835,9 @@ struct riswap {
803
835
static constexpr char name[] = " riswap" ;
804
836
static constexpr unsigned num_qubits = 2 ;
805
837
838
+ static constexpr fp_type pi = static_cast <fp_type>(pi_double);
839
+ static constexpr fp_type h = static_cast <fp_type>(h_double);
840
+
806
841
static GateCirq<fp_type> Create (unsigned time, unsigned q0, unsigned q1,
807
842
fp_type phi) {
808
843
fp_type c = std::cos (phi);
@@ -835,6 +870,8 @@ struct SWAP {
835
870
static constexpr char name[] = " SWAP" ;
836
871
static constexpr unsigned num_qubits = 2 ;
837
872
873
+ static constexpr fp_type is2 = static_cast <fp_type>(is2_double);
874
+
838
875
static GateCirq<fp_type> Create (unsigned time, unsigned q0, unsigned q1) {
839
876
return CreateGate<GateCirq<fp_type>, SWAP>(
840
877
time , q0, q1, {1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
@@ -860,6 +897,9 @@ struct ISWAP {
860
897
static constexpr char name[] = " ISWAP" ;
861
898
static constexpr unsigned num_qubits = 2 ;
862
899
900
+ static constexpr fp_type h = static_cast <fp_type>(h_double);
901
+ static constexpr fp_type is2 = static_cast <fp_type>(is2_double);
902
+
863
903
static GateCirq<fp_type> Create (unsigned time, unsigned q0, unsigned q1) {
864
904
return CreateGate<GateCirq<fp_type>, ISWAP>(
865
905
time , q0, q1, {1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
@@ -886,6 +926,9 @@ struct PhasedISwapPowGate {
886
926
static constexpr char name[] = " PhasedISwapPowGate" ;
887
927
static constexpr unsigned num_qubits = 2 ;
888
928
929
+ static constexpr fp_type pi = static_cast <fp_type>(pi_double);
930
+ static constexpr fp_type h = static_cast <fp_type>(h_double);
931
+
889
932
static GateCirq<fp_type> Create (unsigned time, unsigned q0, unsigned q1,
890
933
fp_type phase_exponent = 0.25 ,
891
934
fp_type exponent = 1.0 ) {
@@ -927,6 +970,9 @@ struct givens {
927
970
static constexpr char name[] = " givens" ;
928
971
static constexpr unsigned num_qubits = 2 ;
929
972
973
+ static constexpr fp_type pi = static_cast <fp_type>(pi_double);
974
+ static constexpr fp_type h = static_cast <fp_type>(h_double);
975
+
930
976
static GateCirq<fp_type> Create (unsigned time, unsigned q0, unsigned q1,
931
977
fp_type phi) {
932
978
fp_type c = std::cos (phi);
@@ -961,6 +1007,8 @@ struct FSimGate {
961
1007
static constexpr char name[] = " FSimGate" ;
962
1008
static constexpr unsigned num_qubits = 2 ;
963
1009
1010
+ static constexpr fp_type is2 = static_cast <fp_type>(is2_double);
1011
+
964
1012
static GateCirq<fp_type> Create (
965
1013
unsigned time, unsigned q0, unsigned q1, fp_type theta, fp_type phi) {
966
1014
if (phi < 0 ) {
0 commit comments