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
// Copyright © 2021-2023 HQS Quantum Simulations GmbH. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
// in compliance with the License. You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the License for the specific language governing permissions and
// limitations under the License.

use num_complex::Complex64;
use numpy::{PyArray2, ToPyArray};
use pyo3::exceptions::{PyRuntimeError, PyValueError};
use pyo3::prelude::*;
use pyo3::types::PySet;
use qoqo_calculator::CalculatorFloat;
use qoqo_calculator_pyo3::{convert_into_calculator_float, CalculatorFloatWrapper};
use qoqo_macros::*;
use roqoqo::operations::*;
#[cfg(feature = "json_schema")]
use roqoqo::ROQOQO_VERSION;
use std::collections::HashMap;

#[allow(clippy::upper_case_acronyms)]
#[wrap(Operate, OperateTwoQubit, OperateGate, OperateTwoQubitGate, JsonSchema)]
#[derive(Eq)]
/// The controlled NOT quantum operation.
///
/// .. math::
///     U = \begin{pmatrix}
///         1 & 0 & 0 & 0 \\\\
///         0 & 1 & 0 & 0 \\\\
///         0 & 0 & 0 & 1 \\\\
///         0 & 0 & 1 & 0
///         \end{pmatrix}
///
/// Args:
///     control (int): The index of the most significant qubit in the unitary representation. Here, the qubit that controls the application of NOT on the target qubit.
///     target (int): The index of the least significant qubit in the unitary representation. Here, the qubit NOT is applied to.
///
pub struct CNOT {
    control: usize,
    target: usize,
}

#[allow(clippy::upper_case_acronyms)]
#[wrap(Operate, OperateTwoQubit, OperateGate, OperateTwoQubitGate, JsonSchema)]
#[derive(Eq)]
/// The controlled SWAP quantum operation.
///
/// .. math::
///     U = \begin{pmatrix}
///         1 & 0 & 0 & 0 \\\\
///         0 & 0 & 1 & 0 \\\\
///         0 & 1 & 0 & 0 \\\\
///         0 & 0 & 0 & 1
///         \end{pmatrix}
///
/// Args:
///     control (int): The index of the most significant qubit in the unitary representation.
///     target (int): The index of the least significant qubit in the unitary representation.
///
pub struct SWAP {
    control: usize,
    target: usize,
}

#[allow(clippy::upper_case_acronyms)]
#[wrap(Operate, OperateTwoQubit, OperateGate, OperateTwoQubitGate, JsonSchema)]
#[derive(Eq)]
/// The controlled ISwap quantum operation.
///
/// .. math::
///     U = \begin{pmatrix}
///         1 & 0 & 0 & 0 \\\\
///         0 & 0 & i & 0 \\\\
///         0 & i & 0 & 0 \\\\
///         0 & 0 & 0 & 1
///         \end{pmatrix}
///
/// Args:
///     control (int): The index of the most significant qubit in the unitary representation.
///     target (int): The index of the least significant qubit in the unitary representation.
///
pub struct ISwap {
    control: usize,
    target: usize,
}

#[allow(clippy::upper_case_acronyms)]
#[wrap(Operate, OperateTwoQubit, OperateGate, OperateTwoQubitGate, JsonSchema)]
#[derive(Eq)]
/// The controlled square root ISwap quantum operation.
///
/// .. math::
///     U = \begin{pmatrix}
///         1 & 0 & 0 & 0 \\\\
///         0 & \frac{1}{\sqrt{2}} & \frac{i}{\sqrt{2}} & 0 \\\\
///         0 & \frac{i}{\sqrt{2}} & \frac{1}{\sqrt{2}} & 0 \\\\
///         0 & 0 & 0 & 1
///         \end{pmatrix}
///
/// Args:
///     control (int): The index of the most significant qubit in the unitary representation.
///     target (int): The index of the least significant qubit in the unitary representation.
///
pub struct SqrtISwap {
    control: usize,
    target: usize,
}

#[allow(clippy::upper_case_acronyms)]
#[wrap(Operate, OperateTwoQubit, OperateGate, OperateTwoQubitGate, JsonSchema)]
#[derive(Eq)]
/// The controlled inverse square root ISwap quantum operation.
///
/// .. math::
///     U = \begin{pmatrix}
///         1 & 0 & 0 & 0 \\\\
///         0 & \frac{1}{\sqrt{2}} & \frac{-i}{\sqrt{2}} & 0 \\\\
///         0 & \frac{-i}{\sqrt{2}} & \frac{1}{\sqrt{2}} & 0 \\\\
///         0 & 0 & 0 & 1
///         \end{pmatrix}
///
/// Args:
///     control (int): The index of the most significant qubit in the unitary representation.
///     target (int): The index of the least significant qubit in the unitary representation.
///
pub struct InvSqrtISwap {
    control: usize,
    target: usize,
}

#[allow(clippy::upper_case_acronyms)]
#[wrap(Operate, OperateTwoQubit, OperateGate, OperateTwoQubitGate, JsonSchema)]
#[derive(Eq)]
/// The controlled fermionic SWAP gate.
///
/// .. math::
///     U = \begin{pmatrix}
///         1 & 0 & 0 & 0 \\\\
///         0 & 0 & 1 & 0 \\\\
///         0 & 1 & 0 & 0 \\\\
///         0 & 0 & 0 & -1
///         \end{pmatrix}
///
/// Args:
///     control (int): The index of the most significant qubit in the unitary representation.
///     target (int): The index of the least significant qubit in the unitary representation.
///
pub struct FSwap {
    control: usize,
    target: usize,
}

#[allow(clippy::upper_case_acronyms)]
#[wrap(Operate, OperateTwoQubit, OperateGate, OperateTwoQubitGate, JsonSchema)]
#[derive(Eq)]
/// The fixed phase MolmerSorensen XX gate. <http://arxiv.org/abs/1705.02771>
///
/// .. math::
///     U = \frac{1}{\sqrt{2}} \begin{pmatrix}
///         1 & 0 & 0 & -i \\\\
///         0 & 1 & -i & 0 \\\\
///         0 & -i & 1 & 0 \\\\
///         -i & 0 & 0 & 1
///         \end{pmatrix}
///
/// Args:
///     control (int): The index of the most significant qubit in the unitary representation. The gate is symmetric under the exchange of qubits.
///     target (int): The index of the least significant qubit in the unitary representation. The gate is symmetric under the exchange of qubits.
///
pub struct MolmerSorensenXX {
    control: usize,
    target: usize,
}

#[allow(clippy::upper_case_acronyms)]
#[wrap(
    Operate,
    OperateTwoQubit,
    Rotate,
    OperateGate,
    OperateTwoQubitGate,
    JsonSchema
)]
/// The variable-angle MolmerSorensen XX gate.
///
/// .. math::
///     U = \begin{pmatrix}
///         \cos(\theta/2) & 0 & 0 & -i \sin(\theta/2) \\\\
///         0 & \cos(\theta/2) & -i \sin(\theta/2) & 0 \\\\
///         0 & -i \sin(\theta/2) & \cos(\theta/2) & 0 \\\\
///         -i \sin(\theta/2) & 0 & 0 & \cos(\theta/2)
///         \end{pmatrix}
///
/// Args:
///     control (int): The index of the most significant qubit in the unitary representation. The gate is symmetric under the exchange of qubits.
///     target (int): The index of the least significant qubit in the unitary representation. The gate is symmetric under the exchange of qubits.
///     theta (CalculatorFloat): The rotation angle :math:`\theta`.
///
pub struct VariableMSXX {
    control: usize,
    target: usize,
    theta: CalculatorFloat,
}

#[allow(clippy::upper_case_acronyms)]
#[wrap(
    Operate,
    OperateTwoQubit,
    Rotate,
    OperateGate,
    OperateTwoQubitGate,
    JsonSchema
)]
/// The Givens rotation interaction gate in big endian notation: :math:`e^{-\mathrm{i} \theta (X_c Y_t - Y_c X_t)}`.
///
/// Where :math:`X_c` is the Pauli matrix :math:`\sigma^x` acting on the control qubit
/// and :math:`Y_t` is the Pauli matrix :math:`\sigma^y` acting on the target qubit.
///
/// .. math::
///     U = \begin{pmatrix}
///         1 & 0 & 0 & 0 \\\\
///         0 & \cos(\theta) \cdot e^{i \phi} & \sin(\theta) & 0 \\\\
///         0 & -\sin(\theta) \cdot e^{i \phi} & \cos(\theta) & 0 \\\\
///         0 & 0 & 0 & e^{i \phi}
///         \end{pmatrix}
///
/// Args:
///     control (int): The index of the most significant qubit in the unitary representation.
///     target (int): The index of the least significant qubit in the unitary representation.
///     theta (CalculatorFloat): The rotation angle :math:`\theta`.
///     phase (CalculatorFloat): The phase :math:`\phi` of the rotation.
///
pub struct GivensRotation {
    control: usize,
    target: usize,
    theta: CalculatorFloat,
    phi: CalculatorFloat,
}

#[allow(clippy::upper_case_acronyms)]
#[wrap(
    Operate,
    OperateTwoQubit,
    Rotate,
    OperateGate,
    OperateTwoQubitGate,
    JsonSchema
)]
/// The Givens rotation interaction gate in little endian notation: :math:`e^{-\mathrm{i} \theta (X_c Y_t - Y_c X_t)}`.
///
/// Where :math:`X_c` is the Pauli matrix :math:`\sigma^x` acting on the control qubit
/// and :math:`Y_t` is the Pauli matrix :math:`\sigma^y` acting on the target qubit.
///
/// .. math::
///     U = \begin{pmatrix}
///         1 & 0 & 0 & 0 \\\\
///         0 & \cos(\theta) & \sin(\theta) & 0 \\\\
///         0 & -\sin(\theta) \cdot e^{i \phi} & \cos(\theta) \cdot e^{i \phi} & 0 \\\\
///         0 & 0 & 0 & e^{i \phi}
///         \end{pmatrix}
///
/// Args:
///     control (int): The index of the most significant qubit in the unitary representation.
///     target (int): The index of the least significant qubit in the unitary representation.
///     theta (CalculatorFloat): The rotation angle :math:`\theta`.
///     phase (CalculatorFloat): The phase :math:`\phi` of the rotation.
///
pub struct GivensRotationLittleEndian {
    control: usize,
    target: usize,
    theta: CalculatorFloat,
    phi: CalculatorFloat,
}

#[allow(clippy::upper_case_acronyms)]
#[wrap(
    Operate,
    OperateTwoQubit,
    Rotate,
    OperateGate,
    OperateTwoQubitGate,
    JsonSchema
)]
/// The controlled XY quantum operation
///
/// .. math::
///     U = \begin{pmatrix}
///         1 & 0 & 0 & 0 \\\
///         0 & \cos(\theta/2) & i \sin(\theta/2) & 0 \\\
///         0 & i \sin(\theta/2) & \cos(\theta/2) & 0 \\\
///         0 & 0 & 0 & 1
///         \end{pmatrix}
///
/// Args:
///     control (int): The index of the most significant qubit in the unitary representation.
///     target (int): The index of the least significant qubit in the unitary representation.
///     theta (CalculatorFloat): The rotation angle :math:`\theta`.
///
pub struct XY {
    control: usize,
    target: usize,
    theta: CalculatorFloat,
}

#[allow(clippy::upper_case_acronyms)]
#[wrap(
    Operate,
    OperateTwoQubit,
    Rotate,
    OperateGate,
    OperateTwoQubitGate,
    JsonSchema
)]
/// The controlled-PhaseShift quantum operation.
///
/// .. math::
///     U = \begin{pmatrix}
///         1 & 0 & 0 & 0 \\\\
///         0 & 1 & 0 & 0 \\\\
///         0 & 0 & 1 & 0 \\\\
///         0 & 0 & 0 & e^{i \theta}
///         \end{pmatrix}
///
/// Args:
///     control (int): The index of the most significant qubit in the unitary representation. Here, the qubit that controls the application of the phase-shift on the target qubit.
///     target (int): The index of the least significant qubit in the unitary representation. Here, the qubit phase-shift is applied to.
///     theta (CalculatorFloat): The rotation angle :math:`\theta`.
///
pub struct ControlledPhaseShift {
    control: usize,
    target: usize,
    theta: CalculatorFloat,
}

#[allow(clippy::upper_case_acronyms)]
#[wrap(Operate, OperateTwoQubit, OperateGate, OperateTwoQubitGate, JsonSchema)]
#[derive(Eq)]
/// The controlled PauliY quantum operation
///
/// .. math::
///     U = \begin{pmatrix}
///         1 & 0 & 0 & 0 \\\\
///         0 & 1 & 0 & 0 \\\\
///         0 & 0 & 0 & -i \\\\
///         0 & 0 & i & 0
///         \end{pmatrix}
///
/// Args:
///     control (int): The index of the most significant qubit in the unitary representation. Here, the qubit that controls the application of PauliY gate on the target qubit.
///     target (int): The index of the least significant qubit in the unitary representation. Here, the qubit PauliY is applied to.
///
pub struct ControlledPauliY {
    control: usize,
    target: usize,
}

#[allow(clippy::upper_case_acronyms)]
#[wrap(Operate, OperateTwoQubit, OperateGate, OperateTwoQubitGate, JsonSchema)]
#[derive(Eq)]
/// The controlled PauliZ quantum operation
///
/// .. math::
///     U = \begin{pmatrix}
///         1 & 0 & 0 & 0 \\\\
///         0 & 1 & 0 & 0 \\\\
///         0 & 0 & 1 & 0 \\\\
///         0 & 0 & 0 & -1
///         \end{pmatrix}
///
/// Args:
///     control (int): The index of the most significant qubit in the unitary representation. Here, the qubit that controls the application of PauliZ gate on the target qubit.
///     target (int): The index of the least significant qubit in the unitary representation. Here, the qubit PauliZ is applied to.
///
pub struct ControlledPauliZ {
    control: usize,
    target: usize,
}

#[allow(clippy::upper_case_acronyms)]
#[wrap(Operate, OperateTwoQubit, OperateGate, OperateTwoQubitGate, JsonSchema)]
/// The qubit simulation (Qsim) gate.
///
/// .. math::
///     U = \begin{pmatrix}
///         \cos(x-y) \cdot e^{-i z} & 0 & 0 & -i\sin(x-y)\cdot e^{-i z} \\\\
///         0 & -i \sin(x+y)\cdot e^{i z} & \cos(x+y)\cdot e^{i z} & 0 \\\\
///         0 & \cos(x+y)\cdot e^{i z}& -i \sin(x+y)\cdot e^{i z} & 0 \\\\
///         -\sin(x-y)\cdot e^{-i z} & 0 & 0 & \cos(x-y)\cdot e^{-i z}
///         \end{pmatrix}
///
/// Args:
///     control (int): The index of the most significant qubit in the unitary representation.
///     target (int):: The index of the least significant qubit in the unitary representation.
///     x (CalculatorFloat): The prefactor of the XX interaction.
///     y (CalculatorFloat): The prefactor of the YY interaction.
///     z (CalculatorFloat): The prefactor of the ZZ interaction.
///
pub struct Qsim {
    control: usize,
    target: usize,
    x: CalculatorFloat,
    y: CalculatorFloat,
    z: CalculatorFloat,
}

#[allow(clippy::upper_case_acronyms)]
#[wrap(Operate, OperateTwoQubit, OperateGate, OperateTwoQubitGate, JsonSchema)]
/// The fermionic qubit simulation (Fsim) gate.
///
/// .. math::
///     U = \begin{pmatrix}
///         \cos(\Delta) & 0 & 0 & i \sin(\Delta) \\\\
///         0 & -i \sin(t) & \cos(t) & 0 \\\\
///         0 & \cos(t) & -i \sin(t) & 0 \\\\
///         -\sin(\Delta) \cdot e^{-i U} & 0 & 0 & -\cos(\Delta) \cdot e^{-i U}
///         \end{pmatrix}
///
/// Args:
///     control (int): The index of the most significant qubit in the unitary representation.
///     target (int):: The index of the least significant qubit in the unitary representation.
///     t (CalculatorFloat): The hopping strength.
///     u (CalculatorFloat): The interaction strength.
///     delta (CalculatorFloat): The Bogoliubov interaction strength :math:`\Delta`.
///
/// Note:
/// The qubits have to be adjacent, i.e., :math:`|i-j|=1` has to hold. This is the only case
/// in which the gate is valid as a two-qubit gate (due to the Jordan-Wigner transformation).
///
pub struct Fsim {
    control: usize,
    target: usize,
    t: CalculatorFloat,
    u: CalculatorFloat,
    delta: CalculatorFloat,
}

#[allow(clippy::upper_case_acronyms)]
#[wrap(Operate, OperateTwoQubit, OperateGate, OperateTwoQubitGate, JsonSchema)]
/// The generalized, anisotropic XYZ Heisenberg interaction between spins.
///
/// :math:`e^{-\mathrm{i} (x \cdot X_c X_t + y \cdot Y_c Y_t + z \cdot Z_c Z_t)}`
///
/// Where x, y, z are prefactors of the :math:`X_c X_t`, :math:`Y_c Y_t`, :math:`Z_c Z_t` Pauliproducts acting on control and target qubit,
/// with :math:`XX \equiv \sigma_x \sigma_x`, :math:`YY \equiv \sigma_y \sigma_y` and :math:`ZZ \equiv \sigma_z \sigma_z`.
///
/// Args:
///     control (int): The index of the most significant qubit in the unitary representation.
///     target (int):: The index of the least significant qubit in the unitary representation.
///     x (CalculatorFloat): The prefactor of the XX interaction.
///     y (CalculatorFloat): The prefactor of the YY interaction.
///     z (CalculatorFloat): The prefactor of the ZZ interaction.
///
pub struct SpinInteraction {
    control: usize,
    target: usize,
    x: CalculatorFloat,
    y: CalculatorFloat,
    z: CalculatorFloat,
}

#[allow(clippy::upper_case_acronyms)]
#[wrap(Operate, OperateTwoQubit, OperateGate, OperateTwoQubitGate, JsonSchema)]
/// The Bogoliubov DeGennes interaction gate.
///
/// :math:`e^{-\mathrm{i} Re(\Delta) (X_c X_t - Y_c Y_t)/2 + Im(\Delta) (X_c Y_t+Y_c X_t)/2}`
///
/// Where :math:`X_c` is the Pauli matrix :math:`\sigma^x` acting on the control qubit
/// and :math:`Y_t` is the Pauli matrix :math:`\sigma^y` acting on the target qubit.
///
/// The unitary matrix representation is:
///
/// .. math::
///     U = \begin{pmatrix}
///         \cos(|\Delta|) & 0 & 0 & \mathrm{i} \sin(|\Delta|) e^{\mathrm{i} \cdot \mathrm{angle}(\Delta)} \\\\
///         0 & 1 & 0 & 0 \\\\
///         0 & 0 & 1 & 0 \\\\
///         \mathrm{i} \sin(|\Delta|) e^{-\mathrm{i} \cdot \mathrm{angle}(\Delta)} & 0 & 0 & \cos(|\Delta|)
///         \end{pmatrix}
///
/// Args:
///     control (int): The index of the most significant qubit in the unitary representation.
///     target (int):: The index of the least significant qubit in the unitary representation.
///     delta_real (CalculatorFloat): The real part of the complex Bogoliubov interaction strength :math:`Re(\Delta)`.
///     delta_imag (CalculatorFloat): The imaginary part of the complex Bogoliubov interaction strength :math:`Im(\Delta)`.
///
pub struct Bogoliubov {
    control: usize,
    target: usize,
    delta_real: CalculatorFloat,
    delta_imag: CalculatorFloat,
}

#[allow(clippy::upper_case_acronyms)]
#[wrap(Operate, OperateTwoQubit, OperateGate, OperateTwoQubitGate, JsonSchema)]
/// The transversal interaction gate.
///
/// :math:`e^{-\mathrm{i} \theta (X_c X_t + Y_c Y_t)} = e^{-\mathrm{i} \theta (\sigma^+_c \sigma^-_t + \sigma^-_c \sigma^+_t)}`
///
/// Where :math:`X_c` is the Pauli matrix :math:`\sigma^x` acting on the control qubit
/// and :math:`Y_t` is the Pauli matrix :math:`\sigma^y` acting on the target qubit.
///
/// Args:
///     control (int): The index of the most significant qubit in the unitary representation.
///     target (int):: The index of the least significant qubit in the unitary representation.
///     t (CalculatorFloat): The strength of the rotation :math:`\theta`.
///
pub struct PMInteraction {
    control: usize,
    target: usize,
    t: CalculatorFloat,
}

#[allow(clippy::upper_case_acronyms)]
#[wrap(Operate, OperateTwoQubit, OperateGate, OperateTwoQubitGate, JsonSchema)]
/// The complex hopping gate.
///
/// :math:`e^{-\mathrm{i} \left[ Re(\theta) \cdot (X_c X_t + Y_c Y_t) - Im(\theta) \cdot (X_c Y_t - Y_c X_t) \right] }`
///
/// Where :math:`X_c` is the Pauli matrix :math:`\sigma^x` acting on the control qubit
/// and :math:`Y_t` is the Pauli matrix :math:`\sigma^y` acting on the target qubit.
///
/// Args:
///     control (int): The index of the most significant qubit in the unitary representation.
///     target (int):: The index of the least significant qubit in the unitary representation.
///     t_real (CalculatorFloat): The real part of the strength of the rotation :math:`Re(\theta)`.
///     t_imag (CalculatorFloat): The imaginary part of the strength of the rotation :math:`Im(\theta)`.
///
pub struct ComplexPMInteraction {
    control: usize,
    target: usize,
    t_real: CalculatorFloat,
    t_imag: CalculatorFloat,
}

#[allow(clippy::upper_case_acronyms)]
#[wrap(Operate, OperateTwoQubit, OperateGate, OperateTwoQubitGate, JsonSchema)]
/// The phased-shifted controlled-Z gate.
///
/// Modified, i.e. phase-shifted ControlledPauliZ two-qubit gate. <https://arxiv.org/pdf/1908.06101.pdf eq.(1)>
///
/// The unitary matrix representation is:
///
/// .. math::
///     U = \begin{pmatrix}
///         1 & 0 & 0 & 0 \\\\
///         0 & e^{i \phi} & 0 & 0 \\\\
///         0 & 0 & e^{i \phi} & 0 \\\\
///         0 & 0 & 0 & e^{i (2\cdot\phi + \pi)}
///         \end{pmatrix}
///
/// Args:
///     control (int): The index of the most significant qubit in the unitary representation. Here, the qubit that controls the application of the phase-shift on the target qubit.
///     target (int):: The index of the least significant qubit in the unitary representation. Here, the qubit phase-shift is applied to.
///     phi (CalculatorFloat): The single qubit phase $\phi$.
///
pub struct PhaseShiftedControlledZ {
    control: usize,
    target: usize,
    phi: CalculatorFloat,
}

#[allow(clippy::upper_case_acronyms)]
#[wrap(
    Operate,
    OperateTwoQubit,
    Rotate,
    OperateGate,
    OperateTwoQubitGate,
    JsonSchema
)]
/// Implements the phase-shifted controlled PhaseShift gate.
///
/// The unitary matrix representation is:
///
/// .. math::
///     U = \begin{pmatrix}
///         1 & 0 & 0 & 0 \\\\
///         0 & e^{i \phi} & 0 & 0 \\\\
///         0 & 0 & e^{i \phi} & 0 \\\\
///         0 & 0 & 0 & e^{i(2\cdot\phi + \theta)}
///         \end{pmatrix}
///
/// Args:
///     control (int): The index of the most significant qubit in the unitary representation. Here, the qubit that controls the application of the phase-shift on the target qubit.
///     target (int):: The index of the least significant qubit in the unitary representation. Here, the qubit phase-shift is applied to.
///     theta (CalculatorFloat): The phase rotation $\theta$.
///     phi (CalculatorFloat): The single qubit phase $\phi$.
///
pub struct PhaseShiftedControlledPhase {
    control: usize,
    target: usize,
    theta: CalculatorFloat,
    phi: CalculatorFloat,
}

#[allow(clippy::upper_case_acronyms)]
#[wrap(
    Operate,
    OperateTwoQubit,
    Rotate,
    OperateGate,
    OperateTwoQubitGate,
    JsonSchema
)]
/// Implements the controlled RotateX operation.
///
/// The unitary matrix representation is:
///
/// .. math::
///     U = \begin{pmatrix}
///         1 & 0 & 0 & 0 \\\\
///         0 & 1 & 0 & 0 \\\\
///         0 & 0 & \cos(\frac{\theta}{2}) & -i \sin(\frac{\theta}{2}) \\\\
///         0 & 0 & -i \sin(\frac{\theta}{2}) & \cos(\frac{\theta}{2})
///         \end{pmatrix}
///
/// Args:
///     control (int): The index of the most significant qubit in the unitary representation. Here, the qubit that controls the application of the Rotatex Operation on the target qubit.
///     target (int):: The index of the least significant qubit in the unitary representation. Here, the qubit RotateX Operation is applied to.
///     theta (CalculatorFloat): The angle $\theta$ of the rotation.
pub struct ControlledRotateX {
    control: usize,
    target: usize,
    theta: CalculatorFloat,
}

#[allow(clippy::upper_case_acronyms)]
#[wrap(
    Operate,
    OperateTwoQubit,
    Rotate,
    OperateGate,
    OperateTwoQubitGate,
    JsonSchema
)]
/// Implements the controlled RotateXY operation.
///
/// The unitary matrix representation is:
///
/// .. math::
///     U = \begin{pmatrix}
///         1 & 0 & 0 & 0 \\\\
///         0 & 1 & 0 & 0 \\\\
///         0 & 0 & \cos(\frac{\theta}{2}) & -i e^{-i \phi} \sin(\frac{\theta}{2}) \\\\
///         0 & 0 & -i e^{-i \phi} \sin(\frac{\theta}{2}) & \cos(\frac{\theta}{2})
///         \end{pmatrix}
///
/// Args:
///     control (int): The index of the most significant qubit in the unitary representation. Here, the qubit that controls the application of the Rotatex Operation on the target qubit.
///     target (int):: The index of the least significant qubit in the unitary representation. Here, the qubit RotateX Operation is applied to.
///     theta (CalculatorFloat): The angle $\theta$ of the rotation.
///     phi (CalculatorFloat): The rotation axis, in spherical coordinates :math:`\phi_{sph}`  gives the angle in the x-y plane.
pub struct ControlledRotateXY {
    control: usize,
    target: usize,
    theta: CalculatorFloat,
    phi: CalculatorFloat,
}

#[allow(clippy::upper_case_acronyms)]
#[wrap(Operate, OperateTwoQubit, OperateGate, OperateTwoQubitGate, JsonSchema)]
/// Implements the controlled RotateXY operation.
///
/// The unitary matrix representation is:
///
/// .. math::
///     U = \frac{1}{\sqrt{2}} \begin{pmatrix}
///         0 & 1 & 0 & i \\\\
///         1 & 0 & -i & 0 \\\\
///         0 & i & 0 & 1 \\\\
///         -i & 0 & 1 & 0
///         \end{pmatrix}
///
/// Args:
///     control (int): The index of the most significant qubit in the unitary representation. Here, the qubit that controls the application of the Rotatex Operation on the target qubit.
///     target (int):: The index of the least significant qubit in the unitary representation. Here, the qubit RotateX Operation is applied to.
///     theta (CalculatorFloat): The angle $\theta$ of the rotation.
///     phi (CalculatorFloat): The rotation axis, in spherical coordinates :math:`\phi_{sph}`  gives the angle in the x-y plane.
pub struct EchoCrossResonance {
    control: usize,
    target: usize,
}