Skip to content

QuantumCircuit

An extended class of QuantumCircuit from Qiskit.

This class extends the QuantumCircuit class from Qiskit to provide additional functionalities for converting basis and visualizing the quantum circuit in matrix form.

See Also

Qiskit QuantumCircuit documentation

Source code in QIRT/quantum_circuit.py
  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
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
class QuantumCircuit:
    """An extended class of QuantumCircuit from Qiskit.

    This class extends the QuantumCircuit class from Qiskit to provide additional
    functionalities for converting basis and visualizing the quantum circuit in
    matrix form.

    See Also:
        [Qiskit QuantumCircuit documentation](https://qiskit.org/documentation/stubs/qiskit.circuit.QuantumCircuit.html)
    """

    def __init__(self, *args, **kwargs):
        """Initialize the QuantumCircuit class."""
        self._qiskit_qc = QiskitQC(*args, **kwargs)

    def to_matrix(self) -> NDArray[np.complex128]:
        """Return matrix form of the quantum circuit as a numpy array.

        This method returns the matrix representation of the quantum circuit by
        reversing the order of qubits to match textbook notation.

        Returns:
            NDArray[np.complex128]: The matrix representation of the quantum circuit.
        """
        reverse_qc = self._qiskit_qc.reverse_bits()  # REVERSE the order of qubits to match textbook notation
        return np.asarray(quantum_info.Operator(reverse_qc).data, dtype=np.complex128)

    def draw(self, output: str | None = "mpl", source: bool = False, *args, **kwargs):
        r"""Draw the quantum circuit, or show its matrix form if output is 'matrix'.

        Args:
            output (str | None, optional): The output format for drawing the circuit.
                If 'text', generates ASCII art TextDrawing that can be printed in the console.
                If 'mpl', generates images with color rendered purely in Python using matplotlib.
                If 'latex', generates high-quality images compiled via latex.
                If 'matrix', shows the matrix form of the circuit. Defaults to "mpl".
            source (bool, optional): Whether to return the latex source code for the visualization. Defaults to False.
            *args: Additional positional arguments to pass to the draw method.
            **kwargs: Additional keyword arguments to pass to the draw method.

        Returns:
            The drawn circuit in the specified format.
        """
        match output:
            case "matrix":
                return latex_drawer.matrix_to_latex(self.to_matrix(), source=source)
            case "latex":
                if source:
                    return self._qiskit_qc.draw(output="latex_source", *args, **kwargs)
                return self._qiskit_qc.draw(output="latex", *args, **kwargs)
            case _:
                return self._qiskit_qc.draw(output=output, *args, **kwargs)

    def _xyz_convert_circ(self, target_basis: str, current_basis: str, qubit_index: int) -> QuantumCircuit:
        """Add the corresponding gate that converts different basis.

        This method adds the appropriate gates to the circuit to convert a qubit
        from the current basis to the target basis.

        Args:
            target_basis (str): The target basis to convert to.
            current_basis (str): The current basis of the qubit.
            qubit_index (int): The index of the qubit to be converted.
        """
        if current_basis == target_basis:
            return self
        current_basis += target_basis
        match current_basis:
            case "zx" | "xz":
                self._qiskit_qc.h(qubit_index)
            case "zy":
                self._qiskit_qc.sdg(qubit_index)
                self._qiskit_qc.h(qubit_index)
            case "yz":
                self._qiskit_qc.h(qubit_index)
                self._qiskit_qc.s(qubit_index)
            case "xy":
                self._qiskit_qc.h(qubit_index)
                self._qiskit_qc.sdg(qubit_index)
                self._qiskit_qc.h(qubit_index)
            case "yx":
                self._qiskit_qc.h(qubit_index)
                self._qiskit_qc.s(qubit_index)
                self._qiskit_qc.h(qubit_index)
        return self

    def unitary(
        self,
        matrix: NDArray[np.complex128] | list[list[int]],
        qubits: Sequence[QubitSpecifier],
        label: str | None = None,
    ) -> QuantumCircuit:
        """Apply a unitary matrix to specified qubits.

        This method applies a given unitary matrix to the specified qubits in the
        quantum circuit. The matrix is converted to match the qubit order of the
        quantum circuit by reversing the order of qubits.

        Args:
            matrix (NDArray[np.complex128] | list[list[int]]): The unitary matrix to apply.
            qubits (Sequence[QubitSpecifier]): The qubits to which the unitary matrix will be applied.
            label (str | None, optional): An optional label for the unitary gate. Defaults to None.

        Returns:
            QuantumCircuit: Quantum circuit with the applied unitary matrix.
        """
        matrix = np.asarray(matrix, dtype=np.complex128)
        matrix = inverse_tensor(matrix)  # REVERSE the order of qubits to match textbook notation
        self._qiskit_qc.unitary(matrix, qubits, label=label)
        return self

    # --------------------------------------------------------------------
    # The following methods are copied from Qiskit's QuantumCircuit class.
    # --------------------------------------------------------------------

    def barrier(self, *qargs: QubitSpecifier, label=None) -> QuantumCircuit:
        """Apply :class:`~.library.Barrier`.

        If ``qargs`` is empty, applies to all qubits
        in the circuit.

        Args:
            qargs (QubitSpecifier): Specification for one or more qubit arguments.
            label (str): The string label of the barrier.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.barrier(*qargs, label=label)
        return self

    def delay(
        self,
        duration: float | int | ParameterExpression,
        qarg: QubitSpecifier | None = None,
        unit: str = "dt",
    ) -> QuantumCircuit:
        """Apply :class:`~.circuit.Delay`.

        If qarg is ``None``, applies to all qubits.
        When applying to multiple qubits, delays with the same duration will be created.

        Args:
            duration (int or float or ParameterExpression): duration of the delay.
            qarg (Object): qubit argument to apply this delay.
            unit (str): unit of the duration. Supported units: ``'s'``, ``'ms'``, ``'us'``,
                ``'ns'``, ``'ps'``, and ``'dt'``. Default is ``'dt'``, i.e. integer time unit
                depending on the target backend.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.

        Raises:
            CircuitError: if arguments have bad format.
        """
        self._qiskit_qc.delay(duration, qarg=qarg, unit=unit)
        return self

    def h(self, qubit: QubitSpecifier) -> QuantumCircuit:
        """Apply :class:`~qiskit.circuit.library.HGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            qubit: The qubit(s) to apply the gate to.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.h(qubit)
        return self

    def ch(
        self,
        control_qubit: QubitSpecifier,
        target_qubit: QubitSpecifier,
        label: str | None = None,
        ctrl_state: str | int | None = None,
    ) -> QuantumCircuit:
        """Apply :class:`~qiskit.circuit.library.CHGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            control_qubit: The qubit(s) used as the control.
            target_qubit: The qubit(s) targeted by the gate.
            label: The string label of the gate in the circuit.
            ctrl_state:
                The control state in decimal, or as a bitstring (e.g. '1').  Defaults to controlling
                on the '1' state.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.ch(control_qubit, target_qubit, label=label, ctrl_state=ctrl_state)
        return self

    def id(self, qubit: QubitSpecifier) -> QuantumCircuit:
        """Apply :class:`~qiskit.circuit.library.IGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            qubit: The qubit(s) to apply the gate to.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.id(qubit)
        return self

    def ms(self, theta: ParameterExpression | float, qubits: Sequence[QubitSpecifier]) -> QuantumCircuit:
        """Apply :class:`~qiskit.circuit.library.MSGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            theta: The angle of the rotation.
            qubits: The qubits to apply the gate to.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.ms(theta, qubits)
        return self

    def p(self, theta: ParameterExpression | float, qubit: QubitSpecifier) -> QuantumCircuit:
        """Apply :class:`~qiskit.circuit.library.PhaseGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            theta: THe angle of the rotation.
            qubit: The qubit(s) to apply the gate to.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.p(theta, qubit)
        return self

    def cp(
        self,
        theta: ParameterExpression | float,
        control_qubit: QubitSpecifier,
        target_qubit: QubitSpecifier,
        label: str | None = None,
        ctrl_state: str | int | None = None,
    ) -> QuantumCircuit:
        """Apply :class:`~qiskit.circuit.library.CPhaseGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            theta: The angle of the rotation.
            control_qubit: The qubit(s) used as the control.
            target_qubit: The qubit(s) targeted by the gate.
            label: The string label of the gate in the circuit.
            ctrl_state:
                The control state in decimal, or as a bitstring (e.g. '1').  Defaults to controlling
                on the '1' state.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.cp(theta, control_qubit, target_qubit, label=label, ctrl_state=ctrl_state)
        return self

    def mcp(
        self,
        lam: ParameterExpression | float,
        control_qubits: Sequence[QubitSpecifier],
        target_qubit: QubitSpecifier,
        ctrl_state: str | int | None = None,
    ) -> QuantumCircuit:
        """Apply :class:`~qiskit.circuit.library.MCPhaseGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            lam: The angle of the rotation.
            control_qubits: The qubits used as the controls.
            target_qubit: The qubit(s) targeted by the gate.
            ctrl_state:
                The control state in decimal, or as a bitstring (e.g. '1').  Defaults to controlling
                on the '1' state.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.mcp(lam, control_qubits, target_qubit, ctrl_state=ctrl_state)
        return self

    def r(
        self, theta: ParameterExpression | float, phi: ParameterExpression | float, qubit: QubitSpecifier
    ) -> QuantumCircuit:
        """Apply :class:`~qiskit.circuit.library.RGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            theta: The angle of the rotation.
            phi: The angle of the axis of rotation in the x-y plane.
            qubit: The qubit(s) to apply the gate to.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.r(theta, phi, qubit)
        return self

    def rv(
        self,
        vx: ParameterExpression | float,
        vy: ParameterExpression | float,
        vz: ParameterExpression | float,
        qubit: QubitSpecifier,
    ) -> QuantumCircuit:
        """Apply :class:`~qiskit.circuit.library.RVGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Rotation around an arbitrary rotation axis :math:`v`, where :math:`|v|` is the angle of
        rotation in radians.

        Args:
            vx: x-component of the rotation axis.
            vy: y-component of the rotation axis.
            vz: z-component of the rotation axis.
            qubit: The qubit(s) to apply the gate to.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.rv(vx, vy, vz, qubit)
        return self

    def rccx(
        self,
        control_qubit1: QubitSpecifier,
        control_qubit2: QubitSpecifier,
        target_qubit: QubitSpecifier,
    ) -> QuantumCircuit:
        """Apply :class:`~qiskit.circuit.library.RCCXGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            control_qubit1: The qubit(s) used as the first control.
            control_qubit2: The qubit(s) used as the second control.
            target_qubit: The qubit(s) targeted by the gate.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.rccx(control_qubit1, control_qubit2, target_qubit)
        return self

    def rcccx(
        self,
        control_qubit1: QubitSpecifier,
        control_qubit2: QubitSpecifier,
        control_qubit3: QubitSpecifier,
        target_qubit: QubitSpecifier,
    ) -> QuantumCircuit:
        """Apply :class:`~qiskit.circuit.library.RC3XGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            control_qubit1: The qubit(s) used as the first control.
            control_qubit2: The qubit(s) used as the second control.
            control_qubit3: The qubit(s) used as the third control.
            target_qubit: The qubit(s) targeted by the gate.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.rcccx(control_qubit1, control_qubit2, control_qubit3, target_qubit)
        return self

    def rx(self, theta: ParameterExpression | float, qubit: QubitSpecifier, label: str | None = None) -> QuantumCircuit:
        """Apply :class:`~qiskit.circuit.library.RXGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            theta: The rotation angle of the gate.
            qubit: The qubit(s) to apply the gate to.
            label: The string label of the gate in the circuit.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.rx(theta, qubit, label=label)
        return self

    def crx(
        self,
        theta: ParameterExpression | float,
        control_qubit: QubitSpecifier,
        target_qubit: QubitSpecifier,
        label: str | None = None,
        ctrl_state: str | int | None = None,
    ) -> QuantumCircuit:
        """Apply :class:`~qiskit.circuit.library.CRXGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            theta: The angle of the rotation.
            control_qubit: The qubit(s) used as the control.
            target_qubit: The qubit(s) targeted by the gate.
            label: The string label of the gate in the circuit.
            ctrl_state:
                The control state in decimal, or as a bitstring (e.g. '1').  Defaults to controlling
                on the '1' state.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.crx(theta, control_qubit, target_qubit, label=label, ctrl_state=ctrl_state)
        return self

    def rxx(self, theta: ParameterExpression | float, qubit1: QubitSpecifier, qubit2: QubitSpecifier) -> QuantumCircuit:
        """Apply :class:`~qiskit.circuit.library.RXXGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            theta: The angle of the rotation.
            qubit1: The qubit(s) to apply the gate to.
            qubit2: The qubit(s) to apply the gate to.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.rxx(theta, qubit1, qubit2)
        return self

    def ry(self, theta: ParameterExpression | float, qubit: QubitSpecifier, label: str | None = None) -> QuantumCircuit:
        """Apply :class:`~qiskit.circuit.library.RYGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            theta: The rotation angle of the gate.
            qubit: The qubit(s) to apply the gate to.
            label: The string label of the gate in the circuit.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.ry(theta, qubit, label=label)
        return self

    def cry(
        self,
        theta: ParameterExpression | float,
        control_qubit: QubitSpecifier,
        target_qubit: QubitSpecifier,
        label: str | None = None,
        ctrl_state: str | int | None = None,
    ) -> QuantumCircuit:
        """Apply :class:`~qiskit.circuit.library.CRYGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            theta: The angle of the rotation.
            control_qubit: The qubit(s) used as the control.
            target_qubit: The qubit(s) targeted by the gate.
            label: The string label of the gate in the circuit.
            ctrl_state:
                The control state in decimal, or as a bitstring (e.g. '1').  Defaults to controlling
                on the '1' state.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.cry(theta, control_qubit, target_qubit, label=label, ctrl_state=ctrl_state)
        return self

    def ryy(self, theta: ParameterExpression | float, qubit1: QubitSpecifier, qubit2: QubitSpecifier) -> QuantumCircuit:
        """Apply :class:`~qiskit.circuit.library.RYYGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            theta: The rotation angle of the gate.
            qubit1: The qubit(s) to apply the gate to.
            qubit2: The qubit(s) to apply the gate to.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.ryy(theta, qubit1, qubit2)
        return self

    def rz(self, phi: ParameterExpression | float, qubit: QubitSpecifier) -> QuantumCircuit:
        """Apply :class:`~qiskit.circuit.library.RZGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            phi: The rotation angle of the gate.
            qubit: The qubit(s) to apply the gate to.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.rz(phi, qubit)
        return self

    def crz(
        self,
        theta: ParameterExpression | float,
        control_qubit: QubitSpecifier,
        target_qubit: QubitSpecifier,
        label: str | None = None,
        ctrl_state: str | int | None = None,
    ) -> QuantumCircuit:
        """Apply :class:`~qiskit.circuit.library.CRZGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            theta: The angle of the rotation.
            control_qubit: The qubit(s) used as the control.
            target_qubit: The qubit(s) targeted by the gate.
            label: The string label of the gate in the circuit.
            ctrl_state:
                The control state in decimal, or as a bitstring (e.g. '1').  Defaults to controlling
                on the '1' state.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.crz(theta, control_qubit, target_qubit, label=label, ctrl_state=ctrl_state)
        return self

    def rzx(self, theta: ParameterExpression | float, qubit1: QubitSpecifier, qubit2: QubitSpecifier) -> QuantumCircuit:
        """Apply :class:`~qiskit.circuit.library.RZXGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            theta: The rotation angle of the gate.
            qubit1: The qubit(s) to apply the gate to.
            qubit2: The qubit(s) to apply the gate to.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.rzx(theta, qubit1, qubit2)
        return self

    def rzz(self, theta: ParameterExpression | float, qubit1: QubitSpecifier, qubit2: QubitSpecifier) -> QuantumCircuit:
        """Apply :class:`~qiskit.circuit.library.RZZGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            theta: The rotation angle of the gate.
            qubit1: The qubit(s) to apply the gate to.
            qubit2: The qubit(s) to apply the gate to.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.rzz(theta, qubit1, qubit2)
        return self

    def ecr(self, qubit1: QubitSpecifier, qubit2: QubitSpecifier) -> QuantumCircuit:
        """Apply :class:`~qiskit.circuit.library.ECRGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            qubit1: The first qubit(s) to apply the gate to.
            qubit2: The second qubit(s) to apply the gate to.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.ecr(qubit1, qubit2)
        return self

    def s(self, qubit: QubitSpecifier) -> QuantumCircuit:
        """Apply :class:`~qiskit.circuit.library.SGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            qubit: The qubit(s) to apply the gate to.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.s(qubit)
        return self

    def sdg(self, qubit: QubitSpecifier) -> QuantumCircuit:
        """Apply :class:`~qiskit.circuit.library.SdgGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            qubit: The qubit(s) to apply the gate to.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.sdg(qubit)
        return self

    def cs(
        self,
        control_qubit: QubitSpecifier,
        target_qubit: QubitSpecifier,
        label: str | None = None,
        ctrl_state: str | int | None = None,
    ) -> QuantumCircuit:
        """Apply :class:`~qiskit.circuit.library.CSGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            control_qubit: The qubit(s) used as the control.
            target_qubit: The qubit(s) targeted by the gate.
            label: The string label of the gate in the circuit.
            ctrl_state:
                The control state in decimal, or as a bitstring (e.g. '1').  Defaults to controlling
                on the '1' state.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.cs(control_qubit, target_qubit, label=label, ctrl_state=ctrl_state)
        return self

    def csdg(
        self,
        control_qubit: QubitSpecifier,
        target_qubit: QubitSpecifier,
        label: str | None = None,
        ctrl_state: str | int | None = None,
    ) -> QuantumCircuit:
        """Apply :class:`~qiskit.circuit.library.CSdgGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            control_qubit: The qubit(s) used as the control.
            target_qubit: The qubit(s) targeted by the gate.
            label: The string label of the gate in the circuit.
            ctrl_state:
                The control state in decimal, or as a bitstring (e.g. '1').  Defaults to controlling
                on the '1' state.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.csdg(control_qubit, target_qubit, label=label, ctrl_state=ctrl_state)
        return self

    def swap(self, qubit1: QubitSpecifier, qubit2: QubitSpecifier) -> QuantumCircuit:
        """Apply :class:`~qiskit.circuit.library.SwapGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            qubit1: The first qubit to apply the gate to.
            qubit2: The second qubit to apply the gate to.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.swap(qubit1, qubit2)
        return self

    def iswap(self, qubit1: QubitSpecifier, qubit2: QubitSpecifier) -> QuantumCircuit:
        """Apply :class:`~qiskit.circuit.library.iSwapGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            qubit1: The first qubit to apply the gate to.
            qubit2: The second qubit to apply the gate to.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.iswap(qubit1, qubit2)
        return self

    def cswap(
        self,
        control_qubit: QubitSpecifier,
        target_qubit1: QubitSpecifier,
        target_qubit2: QubitSpecifier,
        label: str | None = None,
        ctrl_state: str | int | None = None,
    ) -> QuantumCircuit:
        """Apply :class:`~qiskit.circuit.library.CSwapGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            control_qubit: The qubit(s) used as the control.
            target_qubit1: The qubit(s) targeted by the gate.
            target_qubit2: The qubit(s) targeted by the gate.
            label: The string label of the gate in the circuit.
            ctrl_state:
                The control state in decimal, or as a bitstring (e.g. ``'1'``).  Defaults to controlling
                on the ``'1'`` state.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.cswap(control_qubit, target_qubit1, target_qubit2, label=label, ctrl_state=ctrl_state)
        return self

    def sx(self, qubit: QubitSpecifier) -> QuantumCircuit:
        """Apply :class:`~qiskit.circuit.library.SXGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            qubit: The qubit(s) to apply the gate to.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.sx(qubit)
        return self

    def sxdg(self, qubit: QubitSpecifier) -> QuantumCircuit:
        """Apply :class:`~qiskit.circuit.library.SXdgGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            qubit: The qubit(s) to apply the gate to.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.sxdg(qubit)
        return self

    def csx(
        self,
        control_qubit: QubitSpecifier,
        target_qubit: QubitSpecifier,
        label: str | None = None,
        ctrl_state: str | int | None = None,
    ) -> QuantumCircuit:
        """Apply :class:`~qiskit.circuit.library.CSXGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            control_qubit: The qubit(s) used as the control.
            target_qubit: The qubit(s) targeted by the gate.
            label: The string label of the gate in the circuit.
            ctrl_state:
                The control state in decimal, or as a bitstring (e.g. '1').  Defaults to controlling
                on the '1' state.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.csx(control_qubit, target_qubit, label=label, ctrl_state=ctrl_state)
        return self

    def t(self, qubit: QubitSpecifier) -> QuantumCircuit:
        """Apply :class:`~qiskit.circuit.library.TGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            qubit: The qubit(s) to apply the gate to.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.t(qubit)
        return self

    def tdg(self, qubit: QubitSpecifier) -> QuantumCircuit:
        """Apply :class:`~qiskit.circuit.library.TdgGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            qubit: The qubit(s) to apply the gate to.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.tdg(qubit)
        return self

    def u(
        self,
        theta: ParameterExpression | float,
        phi: ParameterExpression | float,
        lam: ParameterExpression | float,
        qubit: QubitSpecifier,
    ) -> QuantumCircuit:
        r"""Apply :class:`~qiskit.circuit.library.UGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            theta: The :math:`\theta` rotation angle of the gate.
            phi: The :math:`\phi` rotation angle of the gate.
            lam: The :math:`\lambda` rotation angle of the gate.
            qubit: The qubit(s) to apply the gate to.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.u(theta, phi, lam, qubit)
        return self

    def cu(
        self,
        theta: ParameterExpression | float,
        phi: ParameterExpression | float,
        lam: ParameterExpression | float,
        gamma: ParameterExpression | float,
        control_qubit: QubitSpecifier,
        target_qubit: QubitSpecifier,
        label: str | None = None,
        ctrl_state: str | int | None = None,
    ) -> QuantumCircuit:
        r"""Apply :class:`~qiskit.circuit.library.CUGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            theta: The :math:`\theta` rotation angle of the gate.
            phi: The :math:`\phi` rotation angle of the gate.
            lam: The :math:`\lambda` rotation angle of the gate.
            gamma: The global phase applied of the U gate, if applied.
            control_qubit: The qubit(s) used as the control.
            target_qubit: The qubit(s) targeted by the gate.
            label: The string label of the gate in the circuit.
            ctrl_state:
                The control state in decimal, or as a bitstring (e.g. '1').  Defaults to controlling
                on the '1' state.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.cu(theta, phi, lam, gamma, control_qubit, target_qubit, label=label, ctrl_state=ctrl_state)
        return self

    def x(self, qubit: QubitSpecifier, label: str | None = None) -> QuantumCircuit:
        r"""Apply :class:`~qiskit.circuit.library.XGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            qubit: The qubit(s) to apply the gate to.
            label: The string label of the gate in the circuit.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.x(qubit, label=label)
        return self

    def cx(
        self,
        control_qubit: QubitSpecifier,
        target_qubit: QubitSpecifier,
        label: str | None = None,
        ctrl_state: str | int | None = None,
    ) -> QuantumCircuit:
        r"""Apply :class:`~qiskit.circuit.library.CXGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            control_qubit: The qubit(s) used as the control.
            target_qubit: The qubit(s) targeted by the gate.
            label: The string label of the gate in the circuit.
            ctrl_state:
                The control state in decimal, or as a bitstring (e.g. '1').  Defaults to controlling
                on the '1' state.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.cx(control_qubit, target_qubit, label=label, ctrl_state=ctrl_state)
        return self

    def dcx(self, qubit1: QubitSpecifier, qubit2: QubitSpecifier) -> QuantumCircuit:
        r"""Apply :class:`~qiskit.circuit.library.DCXGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            qubit1: The qubit(s) to apply the gate to.
            qubit2: The qubit(s) to apply the gate to.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.dcx(qubit1, qubit2)
        return self

    def ccx(
        self,
        control_qubit1: QubitSpecifier,
        control_qubit2: QubitSpecifier,
        target_qubit: QubitSpecifier,
        ctrl_state: str | int | None = None,
    ) -> QuantumCircuit:
        r"""Apply :class:`~qiskit.circuit.library.CCXGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            control_qubit1: The qubit(s) used as the first control.
            control_qubit2: The qubit(s) used as the second control.
            target_qubit: The qubit(s) targeted by the gate.
            ctrl_state:
                The control state in decimal, or as a bitstring (e.g. '1').  Defaults to controlling
                on the '1' state.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.ccx(control_qubit1, control_qubit2, target_qubit, ctrl_state=ctrl_state)
        return self

    def mcx(
        self,
        control_qubits: Sequence[QubitSpecifier],
        target_qubit: QubitSpecifier,
        ancilla_qubits: QubitSpecifier | Sequence[QubitSpecifier] | None = None,
        mode: str = "noancilla",
        ctrl_state: str | int | None = None,
    ) -> QuantumCircuit:
        """Apply :class:`~qiskit.circuit.library.MCXGate`.

        The multi-cX gate can be implemented using different techniques, which use different numbers
        of ancilla qubits and have varying circuit depth. These modes are:

        - ``'noancilla'``: Requires 0 ancilla qubits.
        - ``'recursion'``: Requires 1 ancilla qubit if more than 4 controls are used, otherwise 0.
        - ``'v-chain'``: Requires 2 less ancillas than the number of control qubits.
        - ``'v-chain-dirty'``: Same as for the clean ancillas (but the circuit will be longer).

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            control_qubits: The qubits used as the controls.
            target_qubit: The qubit(s) targeted by the gate.
            ancilla_qubits: The qubits used as the ancillae, if the mode requires them.
            mode: The choice of mode, explained further above.
            ctrl_state:
                The control state in decimal, or as a bitstring (e.g. '1').  Defaults to controlling
                on the '1' state.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.

        Raises:
            ValueError: if the given mode is not known, or if too few ancilla qubits are passed.
            AttributeError: if no ancilla qubits are passed, but some are needed.
        """
        self._qiskit_qc.mcx(
            control_qubits, target_qubit, ancilla_qubits=ancilla_qubits, mode=mode, ctrl_state=ctrl_state
        )
        return self

    def y(self, qubit: QubitSpecifier) -> QuantumCircuit:
        r"""Apply :class:`~qiskit.circuit.library.YGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            qubit: The qubit(s) to apply the gate to.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.y(qubit)
        return self

    def cy(
        self,
        control_qubit: QubitSpecifier,
        target_qubit: QubitSpecifier,
        label: str | None = None,
        ctrl_state: str | int | None = None,
    ) -> QuantumCircuit:
        r"""Apply :class:`~qiskit.circuit.library.CYGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            control_qubit: The qubit(s) used as the controls.
            target_qubit: The qubit(s) targeted by the gate.
            label: The string label of the gate in the circuit.
            ctrl_state:
                The control state in decimal, or as a bitstring (e.g. '1').  Defaults to controlling
                on the '1' state.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.cy(control_qubit, target_qubit, label=label, ctrl_state=ctrl_state)
        return self

    def z(self, qubit: QubitSpecifier) -> QuantumCircuit:
        r"""Apply :class:`~qiskit.circuit.library.ZGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            qubit: The qubit(s) to apply the gate to.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.z(qubit)
        return self

    def cz(
        self,
        control_qubit: QubitSpecifier,
        target_qubit: QubitSpecifier,
        label: str | None = None,
        ctrl_state: str | int | None = None,
    ) -> QuantumCircuit:
        r"""Apply :class:`~qiskit.circuit.library.CZGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            control_qubit: The qubit(s) used as the controls.
            target_qubit: The qubit(s) targeted by the gate.
            label: The string label of the gate in the circuit.
            ctrl_state:
                The control state in decimal, or as a bitstring (e.g. '1').  Defaults to controlling
                on the '1' state.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.cz(control_qubit, target_qubit, label=label, ctrl_state=ctrl_state)
        return self

    def ccz(
        self,
        control_qubit1: QubitSpecifier,
        control_qubit2: QubitSpecifier,
        target_qubit: QubitSpecifier,
        label: str | None = None,
        ctrl_state: str | int | None = None,
    ) -> QuantumCircuit:
        r"""Apply :class:`~qiskit.circuit.library.CCZGate`.

        For the full matrix form of this gate, see the underlying gate documentation.

        Args:
            control_qubit1: The qubit(s) used as the first control.
            control_qubit2: The qubit(s) used as the second control.
            target_qubit: The qubit(s) targeted by the gate.
            label: The string label of the gate in the circuit.
            ctrl_state:
                The control state in decimal, or as a bitstring (e.g. '10').  Defaults to controlling
                on the '11' state.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.ccz(control_qubit1, control_qubit2, target_qubit, label=label, ctrl_state=ctrl_state)
        return self

    def pauli(
        self,
        pauli_string: str,
        qubits: Sequence[QubitSpecifier],
    ) -> QuantumCircuit:
        """Apply :class:`~qiskit.circuit.library.PauliGate`.

        Args:
            pauli_string: A string representing the Pauli operator to apply, e.g. 'XX'.
            qubits: The qubits to apply this gate to.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.
        """
        self._qiskit_qc.pauli(pauli_string, qubits)
        return self

    def prepare_state(
        self,
        state: QuantumState | Statevector | Sequence[complex] | str | int,
        qubits: Sequence[QubitSpecifier] | None = None,
        label: str | None = None,
        normalize: bool = False,
    ) -> QuantumCircuit:
        r"""Prepare qubits in a specific state.

        This class implements a state preparing unitary. Unlike
        :meth:`.initialize` it does not reset the qubits first.

        Args:
            state: The state to initialize to, can be either of the following.

                * Statevector or vector of complex amplitudes to initialize to.
                * Labels of basis states of the Pauli eigenstates Z, X, Y. See
                  :meth:`.Statevector.from_label`. Notice the order of the labels is reversed with
                  respect to the qubit index to be applied to. Example label '01' initializes the
                  qubit zero to :math:`|1\rangle` and the qubit one to :math:`|0\rangle`.
                * An integer that is used as a bitmap indicating which qubits to initialize to
                  :math:`|1\rangle`. Example: setting params to 5 would initialize qubit 0 and qubit
                  2 to :math:`|1\rangle` and qubit 1 to :math:`|0\rangle`.

            qubits: Qubits to initialize. If ``None`` the initialization is applied to all qubits in
                the circuit.
            label: An optional label for the gate
            normalize: Whether to normalize an input array to a unit vector.

        Returns:
            A handle to the instruction that was just initialized

        Examples:
            Prepare a qubit in the state :math:`(|0\rangle - |1\rangle) / \sqrt{2}`.

            .. code-block::

                import numpy as np
                from qiskit import QuantumCircuit

                circuit = QuantumCircuit(1)
                circuit.prepare_state([1/np.sqrt(2), -1/np.sqrt(2)], 0)
                circuit.draw()

            output:

            .. parsed-literal::

                     ┌─────────────────────────────────────┐
                q_0: ┤ State Preparation(0.70711,-0.70711) ├
                     └─────────────────────────────────────┘


            Prepare from a string two qubits in the state :math:`|10\rangle`.
            The order of the labels is reversed with respect to qubit index.
            More information about labels for basis states are in
            :meth:`.Statevector.from_label`.

            .. code-block::

                import numpy as np
                from qiskit import QuantumCircuit

                circuit = QuantumCircuit(2)
                circuit.prepare_state('01', circuit.qubits)
                circuit.draw()

            output:

            .. parsed-literal::

                     ┌─────────────────────────┐
                q_0: ┤0                        ├
                     │  State Preparation(0,1) │
                q_1: ┤1                        ├
                     └─────────────────────────┘


            Initialize two qubits from an array of complex amplitudes
            .. code-block::

                import numpy as np
                from qiskit import QuantumCircuit

                circuit = QuantumCircuit(2)
                circuit.prepare_state([0, 1/np.sqrt(2), -1.j/np.sqrt(2), 0], circuit.qubits)
                circuit.draw()

            output:

            .. parsed-literal::

                     ┌───────────────────────────────────────────┐
                q_0: ┤0                                          ├
                     │  State Preparation(0,0.70711,-0.70711j,0) │
                q_1: ┤1                                          ├
                     └───────────────────────────────────────────┘
        """
        if isinstance(state, QuantumState):
            state = state.state_vector
        self._qiskit_qc.prepare_state(state, qubits=qubits, label=label, normalize=normalize)
        return self

    def initialize(
        self,
        params: QuantumState | Statevector | Sequence[complex] | str | int,
        qubits: Sequence[QubitSpecifier] | None = None,
        normalize: bool = False,
    ):
        r"""Initialize qubits in a specific state.

        Qubit initialization is done by first resetting the qubits to :math:`|0\rangle`
        followed by calling :class:`~qiskit.circuit.library.StatePreparation`
        class to prepare the qubits in a specified state.
        Both these steps are included in the
        :class:`~qiskit.circuit.library.Initialize` instruction.

        Args:
            params: The state to initialize to, can be either of the following.

                * Statevector or vector of complex amplitudes to initialize to.
                * Labels of basis states of the Pauli eigenstates Z, X, Y. See
                  :meth:`.Statevector.from_label`. Notice the order of the labels is reversed with
                  respect to the qubit index to be applied to. Example label '01' initializes the
                  qubit zero to :math:`|1\rangle` and the qubit one to :math:`|0\rangle`.
                * An integer that is used as a bitmap indicating which qubits to initialize to
                  :math:`|1\rangle`. Example: setting params to 5 would initialize qubit 0 and qubit
                  2 to :math:`|1\rangle` and qubit 1 to :math:`|0\rangle`.

            qubits: Qubits to initialize. If ``None`` the initialization is applied to all qubits in
                the circuit.
            normalize: Whether to normalize an input array to a unit vector.

        Returns:
            QuantumCircuit: Quantum circuit with the applied gate.

        Examples:
            Prepare a qubit in the state :math:`(|0\rangle - |1\rangle) / \sqrt{2}`.

            .. code-block::

                import numpy as np
                from qiskit import QuantumCircuit

                circuit = QuantumCircuit(1)
                circuit.initialize([1/np.sqrt(2), -1/np.sqrt(2)], 0)
                circuit.draw()

            output:

            .. parsed-literal::

                     ┌──────────────────────────────┐
                q_0: ┤ Initialize(0.70711,-0.70711) ├
                     └──────────────────────────────┘


            Initialize from a string two qubits in the state :math:`|10\rangle`.
            The order of the labels is reversed with respect to qubit index.
            More information about labels for basis states are in
            :meth:`.Statevector.from_label`.

            .. code-block::

                import numpy as np
                from qiskit import QuantumCircuit

                circuit = QuantumCircuit(2)
                circuit.initialize('01', circuit.qubits)
                circuit.draw()

            output:

            .. parsed-literal::

                     ┌──────────────────┐
                q_0: ┤0                 ├
                     │  Initialize(0,1) │
                q_1: ┤1                 ├
                     └──────────────────┘

            Initialize two qubits from an array of complex amplitudes.

            .. code-block::

                import numpy as np
                from qiskit import QuantumCircuit

                circuit = QuantumCircuit(2)
                circuit.initialize([0, 1/np.sqrt(2), -1.j/np.sqrt(2), 0], circuit.qubits)
                circuit.draw()

            output:

            .. parsed-literal::

                     ┌────────────────────────────────────┐
                q_0: ┤0                                   ├
                     │  Initialize(0,0.70711,-0.70711j,0) │
                q_1: ┤1                                   ├
                     └────────────────────────────────────┘
        """
        if isinstance(params, QuantumState):
            params = params.state_vector
        self._qiskit_qc.initialize(params, qubits=qubits, normalize=normalize)
        return self

__init__(*args, **kwargs)

Initialize the QuantumCircuit class.

Source code in QIRT/quantum_circuit.py
51
52
53
def __init__(self, *args, **kwargs):
    """Initialize the QuantumCircuit class."""
    self._qiskit_qc = QiskitQC(*args, **kwargs)

barrier(*qargs, label=None)

Apply :class:~.library.Barrier.

If qargs is empty, applies to all qubits in the circuit.

Parameters:

Name Type Description Default
qargs QubitSpecifier

Specification for one or more qubit arguments.

()
label str

The string label of the barrier.

None

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
def barrier(self, *qargs: QubitSpecifier, label=None) -> QuantumCircuit:
    """Apply :class:`~.library.Barrier`.

    If ``qargs`` is empty, applies to all qubits
    in the circuit.

    Args:
        qargs (QubitSpecifier): Specification for one or more qubit arguments.
        label (str): The string label of the barrier.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.barrier(*qargs, label=label)
    return self

ccx(control_qubit1, control_qubit2, target_qubit, ctrl_state=None)

Apply :class:~qiskit.circuit.library.CCXGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
control_qubit1 QubitSpecifier

The qubit(s) used as the first control.

required
control_qubit2 QubitSpecifier

The qubit(s) used as the second control.

required
target_qubit QubitSpecifier

The qubit(s) targeted by the gate.

required
ctrl_state str | int | None

The control state in decimal, or as a bitstring (e.g. '1'). Defaults to controlling on the '1' state.

None

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
def ccx(
    self,
    control_qubit1: QubitSpecifier,
    control_qubit2: QubitSpecifier,
    target_qubit: QubitSpecifier,
    ctrl_state: str | int | None = None,
) -> QuantumCircuit:
    r"""Apply :class:`~qiskit.circuit.library.CCXGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        control_qubit1: The qubit(s) used as the first control.
        control_qubit2: The qubit(s) used as the second control.
        target_qubit: The qubit(s) targeted by the gate.
        ctrl_state:
            The control state in decimal, or as a bitstring (e.g. '1').  Defaults to controlling
            on the '1' state.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.ccx(control_qubit1, control_qubit2, target_qubit, ctrl_state=ctrl_state)
    return self

ccz(control_qubit1, control_qubit2, target_qubit, label=None, ctrl_state=None)

Apply :class:~qiskit.circuit.library.CCZGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
control_qubit1 QubitSpecifier

The qubit(s) used as the first control.

required
control_qubit2 QubitSpecifier

The qubit(s) used as the second control.

required
target_qubit QubitSpecifier

The qubit(s) targeted by the gate.

required
label str | None

The string label of the gate in the circuit.

None
ctrl_state str | int | None

The control state in decimal, or as a bitstring (e.g. '10'). Defaults to controlling on the '11' state.

None

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
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
def ccz(
    self,
    control_qubit1: QubitSpecifier,
    control_qubit2: QubitSpecifier,
    target_qubit: QubitSpecifier,
    label: str | None = None,
    ctrl_state: str | int | None = None,
) -> QuantumCircuit:
    r"""Apply :class:`~qiskit.circuit.library.CCZGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        control_qubit1: The qubit(s) used as the first control.
        control_qubit2: The qubit(s) used as the second control.
        target_qubit: The qubit(s) targeted by the gate.
        label: The string label of the gate in the circuit.
        ctrl_state:
            The control state in decimal, or as a bitstring (e.g. '10').  Defaults to controlling
            on the '11' state.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.ccz(control_qubit1, control_qubit2, target_qubit, label=label, ctrl_state=ctrl_state)
    return self

ch(control_qubit, target_qubit, label=None, ctrl_state=None)

Apply :class:~qiskit.circuit.library.CHGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
control_qubit QubitSpecifier

The qubit(s) used as the control.

required
target_qubit QubitSpecifier

The qubit(s) targeted by the gate.

required
label str | None

The string label of the gate in the circuit.

None
ctrl_state str | int | None

The control state in decimal, or as a bitstring (e.g. '1'). Defaults to controlling on the '1' state.

None

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
def ch(
    self,
    control_qubit: QubitSpecifier,
    target_qubit: QubitSpecifier,
    label: str | None = None,
    ctrl_state: str | int | None = None,
) -> QuantumCircuit:
    """Apply :class:`~qiskit.circuit.library.CHGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        control_qubit: The qubit(s) used as the control.
        target_qubit: The qubit(s) targeted by the gate.
        label: The string label of the gate in the circuit.
        ctrl_state:
            The control state in decimal, or as a bitstring (e.g. '1').  Defaults to controlling
            on the '1' state.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.ch(control_qubit, target_qubit, label=label, ctrl_state=ctrl_state)
    return self

cp(theta, control_qubit, target_qubit, label=None, ctrl_state=None)

Apply :class:~qiskit.circuit.library.CPhaseGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
theta ParameterExpression | float

The angle of the rotation.

required
control_qubit QubitSpecifier

The qubit(s) used as the control.

required
target_qubit QubitSpecifier

The qubit(s) targeted by the gate.

required
label str | None

The string label of the gate in the circuit.

None
ctrl_state str | int | None

The control state in decimal, or as a bitstring (e.g. '1'). Defaults to controlling on the '1' state.

None

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
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
def cp(
    self,
    theta: ParameterExpression | float,
    control_qubit: QubitSpecifier,
    target_qubit: QubitSpecifier,
    label: str | None = None,
    ctrl_state: str | int | None = None,
) -> QuantumCircuit:
    """Apply :class:`~qiskit.circuit.library.CPhaseGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        theta: The angle of the rotation.
        control_qubit: The qubit(s) used as the control.
        target_qubit: The qubit(s) targeted by the gate.
        label: The string label of the gate in the circuit.
        ctrl_state:
            The control state in decimal, or as a bitstring (e.g. '1').  Defaults to controlling
            on the '1' state.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.cp(theta, control_qubit, target_qubit, label=label, ctrl_state=ctrl_state)
    return self

crx(theta, control_qubit, target_qubit, label=None, ctrl_state=None)

Apply :class:~qiskit.circuit.library.CRXGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
theta ParameterExpression | float

The angle of the rotation.

required
control_qubit QubitSpecifier

The qubit(s) used as the control.

required
target_qubit QubitSpecifier

The qubit(s) targeted by the gate.

required
label str | None

The string label of the gate in the circuit.

None
ctrl_state str | int | None

The control state in decimal, or as a bitstring (e.g. '1'). Defaults to controlling on the '1' state.

None

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
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
def crx(
    self,
    theta: ParameterExpression | float,
    control_qubit: QubitSpecifier,
    target_qubit: QubitSpecifier,
    label: str | None = None,
    ctrl_state: str | int | None = None,
) -> QuantumCircuit:
    """Apply :class:`~qiskit.circuit.library.CRXGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        theta: The angle of the rotation.
        control_qubit: The qubit(s) used as the control.
        target_qubit: The qubit(s) targeted by the gate.
        label: The string label of the gate in the circuit.
        ctrl_state:
            The control state in decimal, or as a bitstring (e.g. '1').  Defaults to controlling
            on the '1' state.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.crx(theta, control_qubit, target_qubit, label=label, ctrl_state=ctrl_state)
    return self

cry(theta, control_qubit, target_qubit, label=None, ctrl_state=None)

Apply :class:~qiskit.circuit.library.CRYGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
theta ParameterExpression | float

The angle of the rotation.

required
control_qubit QubitSpecifier

The qubit(s) used as the control.

required
target_qubit QubitSpecifier

The qubit(s) targeted by the gate.

required
label str | None

The string label of the gate in the circuit.

None
ctrl_state str | int | None

The control state in decimal, or as a bitstring (e.g. '1'). Defaults to controlling on the '1' state.

None

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
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
def cry(
    self,
    theta: ParameterExpression | float,
    control_qubit: QubitSpecifier,
    target_qubit: QubitSpecifier,
    label: str | None = None,
    ctrl_state: str | int | None = None,
) -> QuantumCircuit:
    """Apply :class:`~qiskit.circuit.library.CRYGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        theta: The angle of the rotation.
        control_qubit: The qubit(s) used as the control.
        target_qubit: The qubit(s) targeted by the gate.
        label: The string label of the gate in the circuit.
        ctrl_state:
            The control state in decimal, or as a bitstring (e.g. '1').  Defaults to controlling
            on the '1' state.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.cry(theta, control_qubit, target_qubit, label=label, ctrl_state=ctrl_state)
    return self

crz(theta, control_qubit, target_qubit, label=None, ctrl_state=None)

Apply :class:~qiskit.circuit.library.CRZGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
theta ParameterExpression | float

The angle of the rotation.

required
control_qubit QubitSpecifier

The qubit(s) used as the control.

required
target_qubit QubitSpecifier

The qubit(s) targeted by the gate.

required
label str | None

The string label of the gate in the circuit.

None
ctrl_state str | int | None

The control state in decimal, or as a bitstring (e.g. '1'). Defaults to controlling on the '1' state.

None

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
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
def crz(
    self,
    theta: ParameterExpression | float,
    control_qubit: QubitSpecifier,
    target_qubit: QubitSpecifier,
    label: str | None = None,
    ctrl_state: str | int | None = None,
) -> QuantumCircuit:
    """Apply :class:`~qiskit.circuit.library.CRZGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        theta: The angle of the rotation.
        control_qubit: The qubit(s) used as the control.
        target_qubit: The qubit(s) targeted by the gate.
        label: The string label of the gate in the circuit.
        ctrl_state:
            The control state in decimal, or as a bitstring (e.g. '1').  Defaults to controlling
            on the '1' state.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.crz(theta, control_qubit, target_qubit, label=label, ctrl_state=ctrl_state)
    return self

cs(control_qubit, target_qubit, label=None, ctrl_state=None)

Apply :class:~qiskit.circuit.library.CSGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
control_qubit QubitSpecifier

The qubit(s) used as the control.

required
target_qubit QubitSpecifier

The qubit(s) targeted by the gate.

required
label str | None

The string label of the gate in the circuit.

None
ctrl_state str | int | None

The control state in decimal, or as a bitstring (e.g. '1'). Defaults to controlling on the '1' state.

None

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
def cs(
    self,
    control_qubit: QubitSpecifier,
    target_qubit: QubitSpecifier,
    label: str | None = None,
    ctrl_state: str | int | None = None,
) -> QuantumCircuit:
    """Apply :class:`~qiskit.circuit.library.CSGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        control_qubit: The qubit(s) used as the control.
        target_qubit: The qubit(s) targeted by the gate.
        label: The string label of the gate in the circuit.
        ctrl_state:
            The control state in decimal, or as a bitstring (e.g. '1').  Defaults to controlling
            on the '1' state.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.cs(control_qubit, target_qubit, label=label, ctrl_state=ctrl_state)
    return self

csdg(control_qubit, target_qubit, label=None, ctrl_state=None)

Apply :class:~qiskit.circuit.library.CSdgGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
control_qubit QubitSpecifier

The qubit(s) used as the control.

required
target_qubit QubitSpecifier

The qubit(s) targeted by the gate.

required
label str | None

The string label of the gate in the circuit.

None
ctrl_state str | int | None

The control state in decimal, or as a bitstring (e.g. '1'). Defaults to controlling on the '1' state.

None

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
def csdg(
    self,
    control_qubit: QubitSpecifier,
    target_qubit: QubitSpecifier,
    label: str | None = None,
    ctrl_state: str | int | None = None,
) -> QuantumCircuit:
    """Apply :class:`~qiskit.circuit.library.CSdgGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        control_qubit: The qubit(s) used as the control.
        target_qubit: The qubit(s) targeted by the gate.
        label: The string label of the gate in the circuit.
        ctrl_state:
            The control state in decimal, or as a bitstring (e.g. '1').  Defaults to controlling
            on the '1' state.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.csdg(control_qubit, target_qubit, label=label, ctrl_state=ctrl_state)
    return self

cswap(control_qubit, target_qubit1, target_qubit2, label=None, ctrl_state=None)

Apply :class:~qiskit.circuit.library.CSwapGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
control_qubit QubitSpecifier

The qubit(s) used as the control.

required
target_qubit1 QubitSpecifier

The qubit(s) targeted by the gate.

required
target_qubit2 QubitSpecifier

The qubit(s) targeted by the gate.

required
label str | None

The string label of the gate in the circuit.

None
ctrl_state str | int | None

The control state in decimal, or as a bitstring (e.g. '1'). Defaults to controlling on the '1' state.

None

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
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
def cswap(
    self,
    control_qubit: QubitSpecifier,
    target_qubit1: QubitSpecifier,
    target_qubit2: QubitSpecifier,
    label: str | None = None,
    ctrl_state: str | int | None = None,
) -> QuantumCircuit:
    """Apply :class:`~qiskit.circuit.library.CSwapGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        control_qubit: The qubit(s) used as the control.
        target_qubit1: The qubit(s) targeted by the gate.
        target_qubit2: The qubit(s) targeted by the gate.
        label: The string label of the gate in the circuit.
        ctrl_state:
            The control state in decimal, or as a bitstring (e.g. ``'1'``).  Defaults to controlling
            on the ``'1'`` state.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.cswap(control_qubit, target_qubit1, target_qubit2, label=label, ctrl_state=ctrl_state)
    return self

csx(control_qubit, target_qubit, label=None, ctrl_state=None)

Apply :class:~qiskit.circuit.library.CSXGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
control_qubit QubitSpecifier

The qubit(s) used as the control.

required
target_qubit QubitSpecifier

The qubit(s) targeted by the gate.

required
label str | None

The string label of the gate in the circuit.

None
ctrl_state str | int | None

The control state in decimal, or as a bitstring (e.g. '1'). Defaults to controlling on the '1' state.

None

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
def csx(
    self,
    control_qubit: QubitSpecifier,
    target_qubit: QubitSpecifier,
    label: str | None = None,
    ctrl_state: str | int | None = None,
) -> QuantumCircuit:
    """Apply :class:`~qiskit.circuit.library.CSXGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        control_qubit: The qubit(s) used as the control.
        target_qubit: The qubit(s) targeted by the gate.
        label: The string label of the gate in the circuit.
        ctrl_state:
            The control state in decimal, or as a bitstring (e.g. '1').  Defaults to controlling
            on the '1' state.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.csx(control_qubit, target_qubit, label=label, ctrl_state=ctrl_state)
    return self

cu(theta, phi, lam, gamma, control_qubit, target_qubit, label=None, ctrl_state=None)

Apply :class:~qiskit.circuit.library.CUGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
theta ParameterExpression | float

The :math:\theta rotation angle of the gate.

required
phi ParameterExpression | float

The :math:\phi rotation angle of the gate.

required
lam ParameterExpression | float

The :math:\lambda rotation angle of the gate.

required
gamma ParameterExpression | float

The global phase applied of the U gate, if applied.

required
control_qubit QubitSpecifier

The qubit(s) used as the control.

required
target_qubit QubitSpecifier

The qubit(s) targeted by the gate.

required
label str | None

The string label of the gate in the circuit.

None
ctrl_state str | int | None

The control state in decimal, or as a bitstring (e.g. '1'). Defaults to controlling on the '1' state.

None

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
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
def cu(
    self,
    theta: ParameterExpression | float,
    phi: ParameterExpression | float,
    lam: ParameterExpression | float,
    gamma: ParameterExpression | float,
    control_qubit: QubitSpecifier,
    target_qubit: QubitSpecifier,
    label: str | None = None,
    ctrl_state: str | int | None = None,
) -> QuantumCircuit:
    r"""Apply :class:`~qiskit.circuit.library.CUGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        theta: The :math:`\theta` rotation angle of the gate.
        phi: The :math:`\phi` rotation angle of the gate.
        lam: The :math:`\lambda` rotation angle of the gate.
        gamma: The global phase applied of the U gate, if applied.
        control_qubit: The qubit(s) used as the control.
        target_qubit: The qubit(s) targeted by the gate.
        label: The string label of the gate in the circuit.
        ctrl_state:
            The control state in decimal, or as a bitstring (e.g. '1').  Defaults to controlling
            on the '1' state.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.cu(theta, phi, lam, gamma, control_qubit, target_qubit, label=label, ctrl_state=ctrl_state)
    return self

cx(control_qubit, target_qubit, label=None, ctrl_state=None)

Apply :class:~qiskit.circuit.library.CXGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
control_qubit QubitSpecifier

The qubit(s) used as the control.

required
target_qubit QubitSpecifier

The qubit(s) targeted by the gate.

required
label str | None

The string label of the gate in the circuit.

None
ctrl_state str | int | None

The control state in decimal, or as a bitstring (e.g. '1'). Defaults to controlling on the '1' state.

None

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
def cx(
    self,
    control_qubit: QubitSpecifier,
    target_qubit: QubitSpecifier,
    label: str | None = None,
    ctrl_state: str | int | None = None,
) -> QuantumCircuit:
    r"""Apply :class:`~qiskit.circuit.library.CXGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        control_qubit: The qubit(s) used as the control.
        target_qubit: The qubit(s) targeted by the gate.
        label: The string label of the gate in the circuit.
        ctrl_state:
            The control state in decimal, or as a bitstring (e.g. '1').  Defaults to controlling
            on the '1' state.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.cx(control_qubit, target_qubit, label=label, ctrl_state=ctrl_state)
    return self

cy(control_qubit, target_qubit, label=None, ctrl_state=None)

Apply :class:~qiskit.circuit.library.CYGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
control_qubit QubitSpecifier

The qubit(s) used as the controls.

required
target_qubit QubitSpecifier

The qubit(s) targeted by the gate.

required
label str | None

The string label of the gate in the circuit.

None
ctrl_state str | int | None

The control state in decimal, or as a bitstring (e.g. '1'). Defaults to controlling on the '1' state.

None

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
def cy(
    self,
    control_qubit: QubitSpecifier,
    target_qubit: QubitSpecifier,
    label: str | None = None,
    ctrl_state: str | int | None = None,
) -> QuantumCircuit:
    r"""Apply :class:`~qiskit.circuit.library.CYGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        control_qubit: The qubit(s) used as the controls.
        target_qubit: The qubit(s) targeted by the gate.
        label: The string label of the gate in the circuit.
        ctrl_state:
            The control state in decimal, or as a bitstring (e.g. '1').  Defaults to controlling
            on the '1' state.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.cy(control_qubit, target_qubit, label=label, ctrl_state=ctrl_state)
    return self

cz(control_qubit, target_qubit, label=None, ctrl_state=None)

Apply :class:~qiskit.circuit.library.CZGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
control_qubit QubitSpecifier

The qubit(s) used as the controls.

required
target_qubit QubitSpecifier

The qubit(s) targeted by the gate.

required
label str | None

The string label of the gate in the circuit.

None
ctrl_state str | int | None

The control state in decimal, or as a bitstring (e.g. '1'). Defaults to controlling on the '1' state.

None

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
def cz(
    self,
    control_qubit: QubitSpecifier,
    target_qubit: QubitSpecifier,
    label: str | None = None,
    ctrl_state: str | int | None = None,
) -> QuantumCircuit:
    r"""Apply :class:`~qiskit.circuit.library.CZGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        control_qubit: The qubit(s) used as the controls.
        target_qubit: The qubit(s) targeted by the gate.
        label: The string label of the gate in the circuit.
        ctrl_state:
            The control state in decimal, or as a bitstring (e.g. '1').  Defaults to controlling
            on the '1' state.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.cz(control_qubit, target_qubit, label=label, ctrl_state=ctrl_state)
    return self

dcx(qubit1, qubit2)

Apply :class:~qiskit.circuit.library.DCXGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
qubit1 QubitSpecifier

The qubit(s) to apply the gate to.

required
qubit2 QubitSpecifier

The qubit(s) to apply the gate to.

required

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
940
941
942
943
944
945
946
947
948
949
950
951
952
953
def dcx(self, qubit1: QubitSpecifier, qubit2: QubitSpecifier) -> QuantumCircuit:
    r"""Apply :class:`~qiskit.circuit.library.DCXGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        qubit1: The qubit(s) to apply the gate to.
        qubit2: The qubit(s) to apply the gate to.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.dcx(qubit1, qubit2)
    return self

delay(duration, qarg=None, unit='dt')

Apply :class:~.circuit.Delay.

If qarg is None, applies to all qubits. When applying to multiple qubits, delays with the same duration will be created.

Parameters:

Name Type Description Default
duration int or float or ParameterExpression

duration of the delay.

required
qarg Object

qubit argument to apply this delay.

None
unit str

unit of the duration. Supported units: 's', 'ms', 'us', 'ns', 'ps', and 'dt'. Default is 'dt', i.e. integer time unit depending on the target backend.

'dt'

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Raises:

Type Description
CircuitError

if arguments have bad format.

Source code in QIRT/quantum_circuit.py
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
def delay(
    self,
    duration: float | int | ParameterExpression,
    qarg: QubitSpecifier | None = None,
    unit: str = "dt",
) -> QuantumCircuit:
    """Apply :class:`~.circuit.Delay`.

    If qarg is ``None``, applies to all qubits.
    When applying to multiple qubits, delays with the same duration will be created.

    Args:
        duration (int or float or ParameterExpression): duration of the delay.
        qarg (Object): qubit argument to apply this delay.
        unit (str): unit of the duration. Supported units: ``'s'``, ``'ms'``, ``'us'``,
            ``'ns'``, ``'ps'``, and ``'dt'``. Default is ``'dt'``, i.e. integer time unit
            depending on the target backend.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.

    Raises:
        CircuitError: if arguments have bad format.
    """
    self._qiskit_qc.delay(duration, qarg=qarg, unit=unit)
    return self

draw(output='mpl', source=False, *args, **kwargs)

Draw the quantum circuit, or show its matrix form if output is 'matrix'.

Parameters:

Name Type Description Default
output str | None

The output format for drawing the circuit. If 'text', generates ASCII art TextDrawing that can be printed in the console. If 'mpl', generates images with color rendered purely in Python using matplotlib. If 'latex', generates high-quality images compiled via latex. If 'matrix', shows the matrix form of the circuit. Defaults to "mpl".

'mpl'
source bool

Whether to return the latex source code for the visualization. Defaults to False.

False
*args

Additional positional arguments to pass to the draw method.

()
**kwargs

Additional keyword arguments to pass to the draw method.

{}

Returns:

Type Description

The drawn circuit in the specified format.

Source code in QIRT/quantum_circuit.py
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
def draw(self, output: str | None = "mpl", source: bool = False, *args, **kwargs):
    r"""Draw the quantum circuit, or show its matrix form if output is 'matrix'.

    Args:
        output (str | None, optional): The output format for drawing the circuit.
            If 'text', generates ASCII art TextDrawing that can be printed in the console.
            If 'mpl', generates images with color rendered purely in Python using matplotlib.
            If 'latex', generates high-quality images compiled via latex.
            If 'matrix', shows the matrix form of the circuit. Defaults to "mpl".
        source (bool, optional): Whether to return the latex source code for the visualization. Defaults to False.
        *args: Additional positional arguments to pass to the draw method.
        **kwargs: Additional keyword arguments to pass to the draw method.

    Returns:
        The drawn circuit in the specified format.
    """
    match output:
        case "matrix":
            return latex_drawer.matrix_to_latex(self.to_matrix(), source=source)
        case "latex":
            if source:
                return self._qiskit_qc.draw(output="latex_source", *args, **kwargs)
            return self._qiskit_qc.draw(output="latex", *args, **kwargs)
        case _:
            return self._qiskit_qc.draw(output=output, *args, **kwargs)

ecr(qubit1, qubit2)

Apply :class:~qiskit.circuit.library.ECRGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
qubit1 QubitSpecifier

The first qubit(s) to apply the gate to.

required
qubit2 QubitSpecifier

The second qubit(s) to apply the gate to.

required

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
613
614
615
616
617
618
619
620
621
622
623
624
625
626
def ecr(self, qubit1: QubitSpecifier, qubit2: QubitSpecifier) -> QuantumCircuit:
    """Apply :class:`~qiskit.circuit.library.ECRGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        qubit1: The first qubit(s) to apply the gate to.
        qubit2: The second qubit(s) to apply the gate to.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.ecr(qubit1, qubit2)
    return self

h(qubit)

Apply :class:~qiskit.circuit.library.HGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
qubit QubitSpecifier

The qubit(s) to apply the gate to.

required

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
198
199
200
201
202
203
204
205
206
207
208
209
210
def h(self, qubit: QubitSpecifier) -> QuantumCircuit:
    """Apply :class:`~qiskit.circuit.library.HGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        qubit: The qubit(s) to apply the gate to.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.h(qubit)
    return self

id(qubit)

Apply :class:~qiskit.circuit.library.IGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
qubit QubitSpecifier

The qubit(s) to apply the gate to.

required

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
237
238
239
240
241
242
243
244
245
246
247
248
249
def id(self, qubit: QubitSpecifier) -> QuantumCircuit:
    """Apply :class:`~qiskit.circuit.library.IGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        qubit: The qubit(s) to apply the gate to.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.id(qubit)
    return self

initialize(params, qubits=None, normalize=False)

Initialize qubits in a specific state.

Qubit initialization is done by first resetting the qubits to :math:|0\rangle followed by calling :class:~qiskit.circuit.library.StatePreparation class to prepare the qubits in a specified state. Both these steps are included in the :class:~qiskit.circuit.library.Initialize instruction.

Parameters:

Name Type Description Default
params QuantumState | Statevector | Sequence[complex] | str | int

The state to initialize to, can be either of the following.

  • Statevector or vector of complex amplitudes to initialize to.
  • Labels of basis states of the Pauli eigenstates Z, X, Y. See :meth:.Statevector.from_label. Notice the order of the labels is reversed with respect to the qubit index to be applied to. Example label '01' initializes the qubit zero to :math:|1\rangle and the qubit one to :math:|0\rangle.
  • An integer that is used as a bitmap indicating which qubits to initialize to :math:|1\rangle. Example: setting params to 5 would initialize qubit 0 and qubit 2 to :math:|1\rangle and qubit 1 to :math:|0\rangle.
required
qubits Sequence[QubitSpecifier] | None

Qubits to initialize. If None the initialization is applied to all qubits in the circuit.

None
normalize bool

Whether to normalize an input array to a unit vector.

False

Returns:

Name Type Description
QuantumCircuit

Quantum circuit with the applied gate.

Examples:

Prepare a qubit in the state :math:(|0\rangle - |1\rangle) / \sqrt{2}.

.. code-block::

import numpy as np
from qiskit import QuantumCircuit

circuit = QuantumCircuit(1)
circuit.initialize([1/np.sqrt(2), -1/np.sqrt(2)], 0)
circuit.draw()

output:

.. parsed-literal::

     ┌──────────────────────────────┐
q_0: ┤ Initialize(0.70711,-0.70711) ├
     └──────────────────────────────┘

Initialize from a string two qubits in the state :math:|10\rangle. The order of the labels is reversed with respect to qubit index. More information about labels for basis states are in :meth:.Statevector.from_label.

.. code-block::

import numpy as np
from qiskit import QuantumCircuit

circuit = QuantumCircuit(2)
circuit.initialize('01', circuit.qubits)
circuit.draw()

output:

.. parsed-literal::

     ┌──────────────────┐
q_0: ┤0                 ├
     │  Initialize(0,1) │
q_1: ┤1                 ├
     └──────────────────┘

Initialize two qubits from an array of complex amplitudes.

.. code-block::

import numpy as np
from qiskit import QuantumCircuit

circuit = QuantumCircuit(2)
circuit.initialize([0, 1/np.sqrt(2), -1.j/np.sqrt(2), 0], circuit.qubits)
circuit.draw()

output:

.. parsed-literal::

     ┌────────────────────────────────────┐
q_0: ┤0                                   ├
     │  Initialize(0,0.70711,-0.70711j,0) │
q_1: ┤1                                   ├
     └────────────────────────────────────┘
Source code in QIRT/quantum_circuit.py
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
def initialize(
    self,
    params: QuantumState | Statevector | Sequence[complex] | str | int,
    qubits: Sequence[QubitSpecifier] | None = None,
    normalize: bool = False,
):
    r"""Initialize qubits in a specific state.

    Qubit initialization is done by first resetting the qubits to :math:`|0\rangle`
    followed by calling :class:`~qiskit.circuit.library.StatePreparation`
    class to prepare the qubits in a specified state.
    Both these steps are included in the
    :class:`~qiskit.circuit.library.Initialize` instruction.

    Args:
        params: The state to initialize to, can be either of the following.

            * Statevector or vector of complex amplitudes to initialize to.
            * Labels of basis states of the Pauli eigenstates Z, X, Y. See
              :meth:`.Statevector.from_label`. Notice the order of the labels is reversed with
              respect to the qubit index to be applied to. Example label '01' initializes the
              qubit zero to :math:`|1\rangle` and the qubit one to :math:`|0\rangle`.
            * An integer that is used as a bitmap indicating which qubits to initialize to
              :math:`|1\rangle`. Example: setting params to 5 would initialize qubit 0 and qubit
              2 to :math:`|1\rangle` and qubit 1 to :math:`|0\rangle`.

        qubits: Qubits to initialize. If ``None`` the initialization is applied to all qubits in
            the circuit.
        normalize: Whether to normalize an input array to a unit vector.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.

    Examples:
        Prepare a qubit in the state :math:`(|0\rangle - |1\rangle) / \sqrt{2}`.

        .. code-block::

            import numpy as np
            from qiskit import QuantumCircuit

            circuit = QuantumCircuit(1)
            circuit.initialize([1/np.sqrt(2), -1/np.sqrt(2)], 0)
            circuit.draw()

        output:

        .. parsed-literal::

                 ┌──────────────────────────────┐
            q_0: ┤ Initialize(0.70711,-0.70711) ├
                 └──────────────────────────────┘


        Initialize from a string two qubits in the state :math:`|10\rangle`.
        The order of the labels is reversed with respect to qubit index.
        More information about labels for basis states are in
        :meth:`.Statevector.from_label`.

        .. code-block::

            import numpy as np
            from qiskit import QuantumCircuit

            circuit = QuantumCircuit(2)
            circuit.initialize('01', circuit.qubits)
            circuit.draw()

        output:

        .. parsed-literal::

                 ┌──────────────────┐
            q_0: ┤0                 ├
                 │  Initialize(0,1) │
            q_1: ┤1                 ├
                 └──────────────────┘

        Initialize two qubits from an array of complex amplitudes.

        .. code-block::

            import numpy as np
            from qiskit import QuantumCircuit

            circuit = QuantumCircuit(2)
            circuit.initialize([0, 1/np.sqrt(2), -1.j/np.sqrt(2), 0], circuit.qubits)
            circuit.draw()

        output:

        .. parsed-literal::

                 ┌────────────────────────────────────┐
            q_0: ┤0                                   ├
                 │  Initialize(0,0.70711,-0.70711j,0) │
            q_1: ┤1                                   ├
                 └────────────────────────────────────┘
    """
    if isinstance(params, QuantumState):
        params = params.state_vector
    self._qiskit_qc.initialize(params, qubits=qubits, normalize=normalize)
    return self

iswap(qubit1, qubit2)

Apply :class:~qiskit.circuit.library.iSwapGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
qubit1 QubitSpecifier

The first qubit to apply the gate to.

required
qubit2 QubitSpecifier

The second qubit to apply the gate to.

required

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
721
722
723
724
725
726
727
728
729
730
731
732
733
734
def iswap(self, qubit1: QubitSpecifier, qubit2: QubitSpecifier) -> QuantumCircuit:
    """Apply :class:`~qiskit.circuit.library.iSwapGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        qubit1: The first qubit to apply the gate to.
        qubit2: The second qubit to apply the gate to.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.iswap(qubit1, qubit2)
    return self

mcp(lam, control_qubits, target_qubit, ctrl_state=None)

Apply :class:~qiskit.circuit.library.MCPhaseGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
lam ParameterExpression | float

The angle of the rotation.

required
control_qubits Sequence[QubitSpecifier]

The qubits used as the controls.

required
target_qubit QubitSpecifier

The qubit(s) targeted by the gate.

required
ctrl_state str | int | None

The control state in decimal, or as a bitstring (e.g. '1'). Defaults to controlling on the '1' state.

None

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
def mcp(
    self,
    lam: ParameterExpression | float,
    control_qubits: Sequence[QubitSpecifier],
    target_qubit: QubitSpecifier,
    ctrl_state: str | int | None = None,
) -> QuantumCircuit:
    """Apply :class:`~qiskit.circuit.library.MCPhaseGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        lam: The angle of the rotation.
        control_qubits: The qubits used as the controls.
        target_qubit: The qubit(s) targeted by the gate.
        ctrl_state:
            The control state in decimal, or as a bitstring (e.g. '1').  Defaults to controlling
            on the '1' state.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.mcp(lam, control_qubits, target_qubit, ctrl_state=ctrl_state)
    return self

mcx(control_qubits, target_qubit, ancilla_qubits=None, mode='noancilla', ctrl_state=None)

Apply :class:~qiskit.circuit.library.MCXGate.

The multi-cX gate can be implemented using different techniques, which use different numbers of ancilla qubits and have varying circuit depth. These modes are:

  • 'noancilla': Requires 0 ancilla qubits.
  • 'recursion': Requires 1 ancilla qubit if more than 4 controls are used, otherwise 0.
  • 'v-chain': Requires 2 less ancillas than the number of control qubits.
  • 'v-chain-dirty': Same as for the clean ancillas (but the circuit will be longer).

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
control_qubits Sequence[QubitSpecifier]

The qubits used as the controls.

required
target_qubit QubitSpecifier

The qubit(s) targeted by the gate.

required
ancilla_qubits QubitSpecifier | Sequence[QubitSpecifier] | None

The qubits used as the ancillae, if the mode requires them.

None
mode str

The choice of mode, explained further above.

'noancilla'
ctrl_state str | int | None

The control state in decimal, or as a bitstring (e.g. '1'). Defaults to controlling on the '1' state.

None

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Raises:

Type Description
ValueError

if the given mode is not known, or if too few ancilla qubits are passed.

AttributeError

if no ancilla qubits are passed, but some are needed.

Source code in QIRT/quantum_circuit.py
 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
def mcx(
    self,
    control_qubits: Sequence[QubitSpecifier],
    target_qubit: QubitSpecifier,
    ancilla_qubits: QubitSpecifier | Sequence[QubitSpecifier] | None = None,
    mode: str = "noancilla",
    ctrl_state: str | int | None = None,
) -> QuantumCircuit:
    """Apply :class:`~qiskit.circuit.library.MCXGate`.

    The multi-cX gate can be implemented using different techniques, which use different numbers
    of ancilla qubits and have varying circuit depth. These modes are:

    - ``'noancilla'``: Requires 0 ancilla qubits.
    - ``'recursion'``: Requires 1 ancilla qubit if more than 4 controls are used, otherwise 0.
    - ``'v-chain'``: Requires 2 less ancillas than the number of control qubits.
    - ``'v-chain-dirty'``: Same as for the clean ancillas (but the circuit will be longer).

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        control_qubits: The qubits used as the controls.
        target_qubit: The qubit(s) targeted by the gate.
        ancilla_qubits: The qubits used as the ancillae, if the mode requires them.
        mode: The choice of mode, explained further above.
        ctrl_state:
            The control state in decimal, or as a bitstring (e.g. '1').  Defaults to controlling
            on the '1' state.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.

    Raises:
        ValueError: if the given mode is not known, or if too few ancilla qubits are passed.
        AttributeError: if no ancilla qubits are passed, but some are needed.
    """
    self._qiskit_qc.mcx(
        control_qubits, target_qubit, ancilla_qubits=ancilla_qubits, mode=mode, ctrl_state=ctrl_state
    )
    return self

ms(theta, qubits)

Apply :class:~qiskit.circuit.library.MSGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
theta ParameterExpression | float

The angle of the rotation.

required
qubits Sequence[QubitSpecifier]

The qubits to apply the gate to.

required

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
251
252
253
254
255
256
257
258
259
260
261
262
263
264
def ms(self, theta: ParameterExpression | float, qubits: Sequence[QubitSpecifier]) -> QuantumCircuit:
    """Apply :class:`~qiskit.circuit.library.MSGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        theta: The angle of the rotation.
        qubits: The qubits to apply the gate to.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.ms(theta, qubits)
    return self

p(theta, qubit)

Apply :class:~qiskit.circuit.library.PhaseGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
theta ParameterExpression | float

THe angle of the rotation.

required
qubit QubitSpecifier

The qubit(s) to apply the gate to.

required

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
266
267
268
269
270
271
272
273
274
275
276
277
278
279
def p(self, theta: ParameterExpression | float, qubit: QubitSpecifier) -> QuantumCircuit:
    """Apply :class:`~qiskit.circuit.library.PhaseGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        theta: THe angle of the rotation.
        qubit: The qubit(s) to apply the gate to.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.p(theta, qubit)
    return self

pauli(pauli_string, qubits)

Apply :class:~qiskit.circuit.library.PauliGate.

Parameters:

Name Type Description Default
pauli_string str

A string representing the Pauli operator to apply, e.g. 'XX'.

required
qubits Sequence[QubitSpecifier]

The qubits to apply this gate to.

required

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
def pauli(
    self,
    pauli_string: str,
    qubits: Sequence[QubitSpecifier],
) -> QuantumCircuit:
    """Apply :class:`~qiskit.circuit.library.PauliGate`.

    Args:
        pauli_string: A string representing the Pauli operator to apply, e.g. 'XX'.
        qubits: The qubits to apply this gate to.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.pauli(pauli_string, qubits)
    return self

prepare_state(state, qubits=None, label=None, normalize=False)

Prepare qubits in a specific state.

This class implements a state preparing unitary. Unlike :meth:.initialize it does not reset the qubits first.

Parameters:

Name Type Description Default
state QuantumState | Statevector | Sequence[complex] | str | int

The state to initialize to, can be either of the following.

  • Statevector or vector of complex amplitudes to initialize to.
  • Labels of basis states of the Pauli eigenstates Z, X, Y. See :meth:.Statevector.from_label. Notice the order of the labels is reversed with respect to the qubit index to be applied to. Example label '01' initializes the qubit zero to :math:|1\rangle and the qubit one to :math:|0\rangle.
  • An integer that is used as a bitmap indicating which qubits to initialize to :math:|1\rangle. Example: setting params to 5 would initialize qubit 0 and qubit 2 to :math:|1\rangle and qubit 1 to :math:|0\rangle.
required
qubits Sequence[QubitSpecifier] | None

Qubits to initialize. If None the initialization is applied to all qubits in the circuit.

None
label str | None

An optional label for the gate

None
normalize bool

Whether to normalize an input array to a unit vector.

False

Returns:

Type Description
QuantumCircuit

A handle to the instruction that was just initialized

Examples:

Prepare a qubit in the state :math:(|0\rangle - |1\rangle) / \sqrt{2}.

.. code-block::

import numpy as np
from qiskit import QuantumCircuit

circuit = QuantumCircuit(1)
circuit.prepare_state([1/np.sqrt(2), -1/np.sqrt(2)], 0)
circuit.draw()

output:

.. parsed-literal::

     ┌─────────────────────────────────────┐
q_0: ┤ State Preparation(0.70711,-0.70711) ├
     └─────────────────────────────────────┘

Prepare from a string two qubits in the state :math:|10\rangle. The order of the labels is reversed with respect to qubit index. More information about labels for basis states are in :meth:.Statevector.from_label.

.. code-block::

import numpy as np
from qiskit import QuantumCircuit

circuit = QuantumCircuit(2)
circuit.prepare_state('01', circuit.qubits)
circuit.draw()

output:

.. parsed-literal::

     ┌─────────────────────────┐
q_0: ┤0                        ├
     │  State Preparation(0,1) │
q_1: ┤1                        ├
     └─────────────────────────┘

Initialize two qubits from an array of complex amplitudes .. code-block::

import numpy as np
from qiskit import QuantumCircuit

circuit = QuantumCircuit(2)
circuit.prepare_state([0, 1/np.sqrt(2), -1.j/np.sqrt(2), 0], circuit.qubits)
circuit.draw()

output:

.. parsed-literal::

     ┌───────────────────────────────────────────┐
q_0: ┤0                                          ├
     │  State Preparation(0,0.70711,-0.70711j,0) │
q_1: ┤1                                          ├
     └───────────────────────────────────────────┘
Source code in QIRT/quantum_circuit.py
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
def prepare_state(
    self,
    state: QuantumState | Statevector | Sequence[complex] | str | int,
    qubits: Sequence[QubitSpecifier] | None = None,
    label: str | None = None,
    normalize: bool = False,
) -> QuantumCircuit:
    r"""Prepare qubits in a specific state.

    This class implements a state preparing unitary. Unlike
    :meth:`.initialize` it does not reset the qubits first.

    Args:
        state: The state to initialize to, can be either of the following.

            * Statevector or vector of complex amplitudes to initialize to.
            * Labels of basis states of the Pauli eigenstates Z, X, Y. See
              :meth:`.Statevector.from_label`. Notice the order of the labels is reversed with
              respect to the qubit index to be applied to. Example label '01' initializes the
              qubit zero to :math:`|1\rangle` and the qubit one to :math:`|0\rangle`.
            * An integer that is used as a bitmap indicating which qubits to initialize to
              :math:`|1\rangle`. Example: setting params to 5 would initialize qubit 0 and qubit
              2 to :math:`|1\rangle` and qubit 1 to :math:`|0\rangle`.

        qubits: Qubits to initialize. If ``None`` the initialization is applied to all qubits in
            the circuit.
        label: An optional label for the gate
        normalize: Whether to normalize an input array to a unit vector.

    Returns:
        A handle to the instruction that was just initialized

    Examples:
        Prepare a qubit in the state :math:`(|0\rangle - |1\rangle) / \sqrt{2}`.

        .. code-block::

            import numpy as np
            from qiskit import QuantumCircuit

            circuit = QuantumCircuit(1)
            circuit.prepare_state([1/np.sqrt(2), -1/np.sqrt(2)], 0)
            circuit.draw()

        output:

        .. parsed-literal::

                 ┌─────────────────────────────────────┐
            q_0: ┤ State Preparation(0.70711,-0.70711) ├
                 └─────────────────────────────────────┘


        Prepare from a string two qubits in the state :math:`|10\rangle`.
        The order of the labels is reversed with respect to qubit index.
        More information about labels for basis states are in
        :meth:`.Statevector.from_label`.

        .. code-block::

            import numpy as np
            from qiskit import QuantumCircuit

            circuit = QuantumCircuit(2)
            circuit.prepare_state('01', circuit.qubits)
            circuit.draw()

        output:

        .. parsed-literal::

                 ┌─────────────────────────┐
            q_0: ┤0                        ├
                 │  State Preparation(0,1) │
            q_1: ┤1                        ├
                 └─────────────────────────┘


        Initialize two qubits from an array of complex amplitudes
        .. code-block::

            import numpy as np
            from qiskit import QuantumCircuit

            circuit = QuantumCircuit(2)
            circuit.prepare_state([0, 1/np.sqrt(2), -1.j/np.sqrt(2), 0], circuit.qubits)
            circuit.draw()

        output:

        .. parsed-literal::

                 ┌───────────────────────────────────────────┐
            q_0: ┤0                                          ├
                 │  State Preparation(0,0.70711,-0.70711j,0) │
            q_1: ┤1                                          ├
                 └───────────────────────────────────────────┘
    """
    if isinstance(state, QuantumState):
        state = state.state_vector
    self._qiskit_qc.prepare_state(state, qubits=qubits, label=label, normalize=normalize)
    return self

r(theta, phi, qubit)

Apply :class:~qiskit.circuit.library.RGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
theta ParameterExpression | float

The angle of the rotation.

required
phi ParameterExpression | float

The angle of the axis of rotation in the x-y plane.

required
qubit QubitSpecifier

The qubit(s) to apply the gate to.

required

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
def r(
    self, theta: ParameterExpression | float, phi: ParameterExpression | float, qubit: QubitSpecifier
) -> QuantumCircuit:
    """Apply :class:`~qiskit.circuit.library.RGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        theta: The angle of the rotation.
        phi: The angle of the axis of rotation in the x-y plane.
        qubit: The qubit(s) to apply the gate to.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.r(theta, phi, qubit)
    return self

rcccx(control_qubit1, control_qubit2, control_qubit3, target_qubit)

Apply :class:~qiskit.circuit.library.RC3XGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
control_qubit1 QubitSpecifier

The qubit(s) used as the first control.

required
control_qubit2 QubitSpecifier

The qubit(s) used as the second control.

required
control_qubit3 QubitSpecifier

The qubit(s) used as the third control.

required
target_qubit QubitSpecifier

The qubit(s) targeted by the gate.

required

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
def rcccx(
    self,
    control_qubit1: QubitSpecifier,
    control_qubit2: QubitSpecifier,
    control_qubit3: QubitSpecifier,
    target_qubit: QubitSpecifier,
) -> QuantumCircuit:
    """Apply :class:`~qiskit.circuit.library.RC3XGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        control_qubit1: The qubit(s) used as the first control.
        control_qubit2: The qubit(s) used as the second control.
        control_qubit3: The qubit(s) used as the third control.
        target_qubit: The qubit(s) targeted by the gate.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.rcccx(control_qubit1, control_qubit2, control_qubit3, target_qubit)
    return self

rccx(control_qubit1, control_qubit2, target_qubit)

Apply :class:~qiskit.circuit.library.RCCXGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
control_qubit1 QubitSpecifier

The qubit(s) used as the first control.

required
control_qubit2 QubitSpecifier

The qubit(s) used as the second control.

required
target_qubit QubitSpecifier

The qubit(s) targeted by the gate.

required

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
def rccx(
    self,
    control_qubit1: QubitSpecifier,
    control_qubit2: QubitSpecifier,
    target_qubit: QubitSpecifier,
) -> QuantumCircuit:
    """Apply :class:`~qiskit.circuit.library.RCCXGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        control_qubit1: The qubit(s) used as the first control.
        control_qubit2: The qubit(s) used as the second control.
        target_qubit: The qubit(s) targeted by the gate.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.rccx(control_qubit1, control_qubit2, target_qubit)
    return self

rv(vx, vy, vz, qubit)

Apply :class:~qiskit.circuit.library.RVGate.

For the full matrix form of this gate, see the underlying gate documentation.

Rotation around an arbitrary rotation axis :math:v, where :math:|v| is the angle of rotation in radians.

Parameters:

Name Type Description Default
vx ParameterExpression | float

x-component of the rotation axis.

required
vy ParameterExpression | float

y-component of the rotation axis.

required
vz ParameterExpression | float

z-component of the rotation axis.

required
qubit QubitSpecifier

The qubit(s) to apply the gate to.

required

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
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
def rv(
    self,
    vx: ParameterExpression | float,
    vy: ParameterExpression | float,
    vz: ParameterExpression | float,
    qubit: QubitSpecifier,
) -> QuantumCircuit:
    """Apply :class:`~qiskit.circuit.library.RVGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Rotation around an arbitrary rotation axis :math:`v`, where :math:`|v|` is the angle of
    rotation in radians.

    Args:
        vx: x-component of the rotation axis.
        vy: y-component of the rotation axis.
        vz: z-component of the rotation axis.
        qubit: The qubit(s) to apply the gate to.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.rv(vx, vy, vz, qubit)
    return self

rx(theta, qubit, label=None)

Apply :class:~qiskit.circuit.library.RXGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
theta ParameterExpression | float

The rotation angle of the gate.

required
qubit QubitSpecifier

The qubit(s) to apply the gate to.

required
label str | None

The string label of the gate in the circuit.

None

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
def rx(self, theta: ParameterExpression | float, qubit: QubitSpecifier, label: str | None = None) -> QuantumCircuit:
    """Apply :class:`~qiskit.circuit.library.RXGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        theta: The rotation angle of the gate.
        qubit: The qubit(s) to apply the gate to.
        label: The string label of the gate in the circuit.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.rx(theta, qubit, label=label)
    return self

rxx(theta, qubit1, qubit2)

Apply :class:~qiskit.circuit.library.RXXGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
theta ParameterExpression | float

The angle of the rotation.

required
qubit1 QubitSpecifier

The qubit(s) to apply the gate to.

required
qubit2 QubitSpecifier

The qubit(s) to apply the gate to.

required

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
def rxx(self, theta: ParameterExpression | float, qubit1: QubitSpecifier, qubit2: QubitSpecifier) -> QuantumCircuit:
    """Apply :class:`~qiskit.circuit.library.RXXGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        theta: The angle of the rotation.
        qubit1: The qubit(s) to apply the gate to.
        qubit2: The qubit(s) to apply the gate to.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.rxx(theta, qubit1, qubit2)
    return self

ry(theta, qubit, label=None)

Apply :class:~qiskit.circuit.library.RYGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
theta ParameterExpression | float

The rotation angle of the gate.

required
qubit QubitSpecifier

The qubit(s) to apply the gate to.

required
label str | None

The string label of the gate in the circuit.

None

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
def ry(self, theta: ParameterExpression | float, qubit: QubitSpecifier, label: str | None = None) -> QuantumCircuit:
    """Apply :class:`~qiskit.circuit.library.RYGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        theta: The rotation angle of the gate.
        qubit: The qubit(s) to apply the gate to.
        label: The string label of the gate in the circuit.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.ry(theta, qubit, label=label)
    return self

ryy(theta, qubit1, qubit2)

Apply :class:~qiskit.circuit.library.RYYGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
theta ParameterExpression | float

The rotation angle of the gate.

required
qubit1 QubitSpecifier

The qubit(s) to apply the gate to.

required
qubit2 QubitSpecifier

The qubit(s) to apply the gate to.

required

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
def ryy(self, theta: ParameterExpression | float, qubit1: QubitSpecifier, qubit2: QubitSpecifier) -> QuantumCircuit:
    """Apply :class:`~qiskit.circuit.library.RYYGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        theta: The rotation angle of the gate.
        qubit1: The qubit(s) to apply the gate to.
        qubit2: The qubit(s) to apply the gate to.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.ryy(theta, qubit1, qubit2)
    return self

rz(phi, qubit)

Apply :class:~qiskit.circuit.library.RZGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
phi ParameterExpression | float

The rotation angle of the gate.

required
qubit QubitSpecifier

The qubit(s) to apply the gate to.

required

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
539
540
541
542
543
544
545
546
547
548
549
550
551
552
def rz(self, phi: ParameterExpression | float, qubit: QubitSpecifier) -> QuantumCircuit:
    """Apply :class:`~qiskit.circuit.library.RZGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        phi: The rotation angle of the gate.
        qubit: The qubit(s) to apply the gate to.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.rz(phi, qubit)
    return self

rzx(theta, qubit1, qubit2)

Apply :class:~qiskit.circuit.library.RZXGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
theta ParameterExpression | float

The rotation angle of the gate.

required
qubit1 QubitSpecifier

The qubit(s) to apply the gate to.

required
qubit2 QubitSpecifier

The qubit(s) to apply the gate to.

required

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
def rzx(self, theta: ParameterExpression | float, qubit1: QubitSpecifier, qubit2: QubitSpecifier) -> QuantumCircuit:
    """Apply :class:`~qiskit.circuit.library.RZXGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        theta: The rotation angle of the gate.
        qubit1: The qubit(s) to apply the gate to.
        qubit2: The qubit(s) to apply the gate to.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.rzx(theta, qubit1, qubit2)
    return self

rzz(theta, qubit1, qubit2)

Apply :class:~qiskit.circuit.library.RZZGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
theta ParameterExpression | float

The rotation angle of the gate.

required
qubit1 QubitSpecifier

The qubit(s) to apply the gate to.

required
qubit2 QubitSpecifier

The qubit(s) to apply the gate to.

required

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
def rzz(self, theta: ParameterExpression | float, qubit1: QubitSpecifier, qubit2: QubitSpecifier) -> QuantumCircuit:
    """Apply :class:`~qiskit.circuit.library.RZZGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        theta: The rotation angle of the gate.
        qubit1: The qubit(s) to apply the gate to.
        qubit2: The qubit(s) to apply the gate to.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.rzz(theta, qubit1, qubit2)
    return self

s(qubit)

Apply :class:~qiskit.circuit.library.SGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
qubit QubitSpecifier

The qubit(s) to apply the gate to.

required

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
628
629
630
631
632
633
634
635
636
637
638
639
640
def s(self, qubit: QubitSpecifier) -> QuantumCircuit:
    """Apply :class:`~qiskit.circuit.library.SGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        qubit: The qubit(s) to apply the gate to.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.s(qubit)
    return self

sdg(qubit)

Apply :class:~qiskit.circuit.library.SdgGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
qubit QubitSpecifier

The qubit(s) to apply the gate to.

required

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
642
643
644
645
646
647
648
649
650
651
652
653
654
def sdg(self, qubit: QubitSpecifier) -> QuantumCircuit:
    """Apply :class:`~qiskit.circuit.library.SdgGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        qubit: The qubit(s) to apply the gate to.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.sdg(qubit)
    return self

swap(qubit1, qubit2)

Apply :class:~qiskit.circuit.library.SwapGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
qubit1 QubitSpecifier

The first qubit to apply the gate to.

required
qubit2 QubitSpecifier

The second qubit to apply the gate to.

required

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
706
707
708
709
710
711
712
713
714
715
716
717
718
719
def swap(self, qubit1: QubitSpecifier, qubit2: QubitSpecifier) -> QuantumCircuit:
    """Apply :class:`~qiskit.circuit.library.SwapGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        qubit1: The first qubit to apply the gate to.
        qubit2: The second qubit to apply the gate to.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.swap(qubit1, qubit2)
    return self

sx(qubit)

Apply :class:~qiskit.circuit.library.SXGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
qubit QubitSpecifier

The qubit(s) to apply the gate to.

required

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
763
764
765
766
767
768
769
770
771
772
773
774
775
def sx(self, qubit: QubitSpecifier) -> QuantumCircuit:
    """Apply :class:`~qiskit.circuit.library.SXGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        qubit: The qubit(s) to apply the gate to.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.sx(qubit)
    return self

sxdg(qubit)

Apply :class:~qiskit.circuit.library.SXdgGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
qubit QubitSpecifier

The qubit(s) to apply the gate to.

required

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
777
778
779
780
781
782
783
784
785
786
787
788
789
def sxdg(self, qubit: QubitSpecifier) -> QuantumCircuit:
    """Apply :class:`~qiskit.circuit.library.SXdgGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        qubit: The qubit(s) to apply the gate to.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.sxdg(qubit)
    return self

t(qubit)

Apply :class:~qiskit.circuit.library.TGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
qubit QubitSpecifier

The qubit(s) to apply the gate to.

required

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
816
817
818
819
820
821
822
823
824
825
826
827
828
def t(self, qubit: QubitSpecifier) -> QuantumCircuit:
    """Apply :class:`~qiskit.circuit.library.TGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        qubit: The qubit(s) to apply the gate to.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.t(qubit)
    return self

tdg(qubit)

Apply :class:~qiskit.circuit.library.TdgGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
qubit QubitSpecifier

The qubit(s) to apply the gate to.

required

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
830
831
832
833
834
835
836
837
838
839
840
841
842
def tdg(self, qubit: QubitSpecifier) -> QuantumCircuit:
    """Apply :class:`~qiskit.circuit.library.TdgGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        qubit: The qubit(s) to apply the gate to.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.tdg(qubit)
    return self

to_matrix()

Return matrix form of the quantum circuit as a numpy array.

This method returns the matrix representation of the quantum circuit by reversing the order of qubits to match textbook notation.

Returns:

Type Description
NDArray[complex128]

NDArray[np.complex128]: The matrix representation of the quantum circuit.

Source code in QIRT/quantum_circuit.py
55
56
57
58
59
60
61
62
63
64
65
def to_matrix(self) -> NDArray[np.complex128]:
    """Return matrix form of the quantum circuit as a numpy array.

    This method returns the matrix representation of the quantum circuit by
    reversing the order of qubits to match textbook notation.

    Returns:
        NDArray[np.complex128]: The matrix representation of the quantum circuit.
    """
    reverse_qc = self._qiskit_qc.reverse_bits()  # REVERSE the order of qubits to match textbook notation
    return np.asarray(quantum_info.Operator(reverse_qc).data, dtype=np.complex128)

u(theta, phi, lam, qubit)

Apply :class:~qiskit.circuit.library.UGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
theta ParameterExpression | float

The :math:\theta rotation angle of the gate.

required
phi ParameterExpression | float

The :math:\phi rotation angle of the gate.

required
lam ParameterExpression | float

The :math:\lambda rotation angle of the gate.

required
qubit QubitSpecifier

The qubit(s) to apply the gate to.

required

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
def u(
    self,
    theta: ParameterExpression | float,
    phi: ParameterExpression | float,
    lam: ParameterExpression | float,
    qubit: QubitSpecifier,
) -> QuantumCircuit:
    r"""Apply :class:`~qiskit.circuit.library.UGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        theta: The :math:`\theta` rotation angle of the gate.
        phi: The :math:`\phi` rotation angle of the gate.
        lam: The :math:`\lambda` rotation angle of the gate.
        qubit: The qubit(s) to apply the gate to.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.u(theta, phi, lam, qubit)
    return self

unitary(matrix, qubits, label=None)

Apply a unitary matrix to specified qubits.

This method applies a given unitary matrix to the specified qubits in the quantum circuit. The matrix is converted to match the qubit order of the quantum circuit by reversing the order of qubits.

Parameters:

Name Type Description Default
matrix NDArray[complex128] | list[list[int]]

The unitary matrix to apply.

required
qubits Sequence[QubitSpecifier]

The qubits to which the unitary matrix will be applied.

required
label str | None

An optional label for the unitary gate. Defaults to None.

None

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied unitary matrix.

Source code in QIRT/quantum_circuit.py
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
def unitary(
    self,
    matrix: NDArray[np.complex128] | list[list[int]],
    qubits: Sequence[QubitSpecifier],
    label: str | None = None,
) -> QuantumCircuit:
    """Apply a unitary matrix to specified qubits.

    This method applies a given unitary matrix to the specified qubits in the
    quantum circuit. The matrix is converted to match the qubit order of the
    quantum circuit by reversing the order of qubits.

    Args:
        matrix (NDArray[np.complex128] | list[list[int]]): The unitary matrix to apply.
        qubits (Sequence[QubitSpecifier]): The qubits to which the unitary matrix will be applied.
        label (str | None, optional): An optional label for the unitary gate. Defaults to None.

    Returns:
        QuantumCircuit: Quantum circuit with the applied unitary matrix.
    """
    matrix = np.asarray(matrix, dtype=np.complex128)
    matrix = inverse_tensor(matrix)  # REVERSE the order of qubits to match textbook notation
    self._qiskit_qc.unitary(matrix, qubits, label=label)
    return self

x(qubit, label=None)

Apply :class:~qiskit.circuit.library.XGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
qubit QubitSpecifier

The qubit(s) to apply the gate to.

required
label str | None

The string label of the gate in the circuit.

None

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
900
901
902
903
904
905
906
907
908
909
910
911
912
913
def x(self, qubit: QubitSpecifier, label: str | None = None) -> QuantumCircuit:
    r"""Apply :class:`~qiskit.circuit.library.XGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        qubit: The qubit(s) to apply the gate to.
        label: The string label of the gate in the circuit.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.x(qubit, label=label)
    return self

y(qubit)

Apply :class:~qiskit.circuit.library.YGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
qubit QubitSpecifier

The qubit(s) to apply the gate to.

required

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
def y(self, qubit: QubitSpecifier) -> QuantumCircuit:
    r"""Apply :class:`~qiskit.circuit.library.YGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        qubit: The qubit(s) to apply the gate to.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.y(qubit)
    return self

z(qubit)

Apply :class:~qiskit.circuit.library.ZGate.

For the full matrix form of this gate, see the underlying gate documentation.

Parameters:

Name Type Description Default
qubit QubitSpecifier

The qubit(s) to apply the gate to.

required

Returns:

Name Type Description
QuantumCircuit QuantumCircuit

Quantum circuit with the applied gate.

Source code in QIRT/quantum_circuit.py
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
def z(self, qubit: QubitSpecifier) -> QuantumCircuit:
    r"""Apply :class:`~qiskit.circuit.library.ZGate`.

    For the full matrix form of this gate, see the underlying gate documentation.

    Args:
        qubit: The qubit(s) to apply the gate to.

    Returns:
        QuantumCircuit: Quantum circuit with the applied gate.
    """
    self._qiskit_qc.z(qubit)
    return self