Skip to content

Warning

This page is under construction. The content may be incomplete or incorrect. Submit an issue on GitHub if you need help or want to contribute.

QASM2 and its extensions

Bloqade provides a set of dialects (missing link) for QASM2 and our custom extensions to model parallel gates in neutral atom architectures. The basic QASM2 functionality can be enabled via

pip install bloqade[qasm2]

Quick Example

When programming with QASM2, the most common usage is via the qasm2.extended decorator, e.g the following Quantum Fourier Transform (QFT) circuit:

import math
from bloqade import qasm2

@qasm2.extended
def qft(qreg: qasm2.QReg, n: int):
    if n == 0:
        return qreg

    qasm2.h(qreg[0])
    for i in range(1, n):
        qasm2.cu1(qreg[i], qreg[0], 2 * math.pi / 2**i)
    qft(qreg, n - 1)
    return qreg

While the syntax is similar to Python, the qasm2.extended decorator actually compiles the qft function into lower-level intermediate representation (IR) code that can be later executed on a simulator (available via PyQrack) or a quantum computer.

You can inspect the initial IR code by calling the pretty printer:

qft.print()

QFT IR

Running simulations

The program can be executed via a simulator backend, e.g. PyQrack, you can install it via

pip install bloqade[pyqrack]
# or if you want to use the CPU only version
pip install bloqade[pyqrack-cpu]
@qasm2.extended
def main():
    return qft(qasm2.qreg(3), 3)

device = PyQrack()
qreg = device.run(main)
print(qreg)

Emitting QASM2 code

You can also emit QASM2 code from the IR code:

from bloqade.qasm2.emit import QASM2 # the QASM2 target
from bloqade.qasm2.parse import pprint # the QASM2 pretty printer

target = QASM2()
ast = target.emit(main)
pprint(ast)

QFT QASM2

Understanding the compilation process

The compilation process is divided into several stages:

  1. Lowering: the decorator qasm2.extended takes Python Abstract Syntax Tree (AST) and lowers it into Kirin IR in the Static Single Assignment (SSA) form.
  2. Interpretation: when invoking the PyQrack backend, the IR code is interpreted via Kirin's IR interpreter (missing link) with the PyQrack runtime backend.
  3. Target code generation: when emitting QASM2 code:
  4. The IR code gets aggressively inlined and all constant expressions are evaluated.
  5. All loops and control flow are unrolled.
  6. All compatible Python expressions (e.g sin, arithmetics) are translated into QASM2 expression.
  7. The QASM2 code is emitted as QASM2 AST for pretty printing.

In fact, the decorator qasm2.extended is a group of smaller dialects:

extended = structural_no_opt.union(
     [
         inline,
         uop,
         glob,
         noise,
         parallel,
         core,
     ]
 )

where structural_no_opt is the base dialect group that provides the basic control flow, common Python expressions (but not all), then:

  • core provides the core QASM2 operations such as register allocation, measurement and reset.
  • uop provides the unary operations, such as standard Pauli gates, rotation gates, etc.

The following dialects are specific to neutral atom quantum computing as an extension:

  • glob provides the global gates (Rydberg specific)
  • noise provides the noise channels
  • parallel provides the parallel gate support (Rydberg specific).
  • inline dialect provides the inline QASM string

Strict QASM2 mode

While the qasm2.extended decorator provides a lot of high-level features as an extension of QASM2, you may want to program in strict QASM2 mode for compatibility reasons. You can do this by using the qasm2.main and qasm2.gate decorators:

@qasm2.main
def main():
    qasm2.h(0)
    qasm2.cx(0, 1)
    qasm2.measure(0)
    qasm2.measure(1)
    return qasm2.qreg(2)

which corresponding to the following QASM2 code:

OPENQASM 2.0;
include "qelib1.inc";

qreg q[2];
creg c[2];

h q[0];
cx q[0], q[1];
measure q[0] -> c[0];
measure q[1] -> c[1];

Note that the return values are all ignore due to lack of equivalent in QASM2.

API Reference

barrier

barrier(qargs: tuple[Qubit, ...]) -> None

Barrier instruction.

Parameters:

Name Type Description Default
qargs tuple[Qubit, ...]

The qubits to apply the barrier to.

required
Source code in src/bloqade/qasm2/_wrappers.py
121
122
123
124
125
126
127
128
129
130
@wraps(uop.Barrier)
def barrier(qargs: tuple[Qubit, ...]) -> None:
    """
    Barrier instruction.

    Args:
        qargs: The qubits to apply the barrier to.
    """

    ...

ccx

ccx(ctrl1: Qubit, ctrl2: Qubit, qarg: Qubit) -> None

Toffoli gate.

Parameters:

Name Type Description Default
ctrl1 Qubit

The first control qubit.

required
ctrl2 Qubit

The second control qubit.

required
qarg Qubit

The target qubit.

required
Source code in src/bloqade/qasm2/_wrappers.py
400
401
402
403
404
405
406
407
408
409
410
@wraps(uop.CCX)
def ccx(ctrl1: Qubit, ctrl2: Qubit, qarg: Qubit) -> None:
    """
    Toffoli gate.

    Args:
        ctrl1: The first control qubit.
        ctrl2: The second control qubit.
        qarg: The target qubit.
    """
    ...

ch

ch(ctrl: Qubit, qarg: Qubit) -> None

Controlled-Hadamard gate.

Parameters:

Name Type Description Default
ctrl Qubit

The control qubit.

required
qarg Qubit

The target qubit

required
Source code in src/bloqade/qasm2/_wrappers.py
386
387
388
389
390
391
392
393
394
395
396
397
@wraps(uop.CH)
def ch(ctrl: Qubit, qarg: Qubit) -> None:
    """
    Controlled-Hadamard gate.

    Args:
        ctrl: The control qubit.
        qarg: The target qubit

    """

    ...

cos

cos(value: float) -> float

Cosine math function.

Parameters:

Name Type Description Default
value float

The value to take the cosine of.

required

Returns:

Type Description
float

The cosine of value.

Source code in src/bloqade/qasm2/_wrappers.py
587
588
589
590
591
592
593
594
595
596
597
598
599
600
@wraps(expr.Cos)
def cos(value: float) -> float:
    """
    Cosine math function.

    Args:
        value: The value to take the cosine of.

    Returns:
        The cosine of `value`.

    """

    ...

cp

cp(ctrl: Qubit, qarg: Qubit, lam: float) -> None

Controlled phase rotation gate. Same as cu1

Parameters:

Name Type Description Default
ctrl Qubit

The control qubit.

required
qarg Qubit

The target qubit.

required
lam float

The angle of rotation.

required
Source code in src/bloqade/qasm2/_wrappers.py
484
485
486
487
488
489
490
491
492
493
494
495
@wraps(uop.CU1)
def cp(ctrl: Qubit, qarg: Qubit, lam: float) -> None:
    """
    Controlled phase rotation gate. Same as cu1

    Args:
        ctrl: The control qubit.
        qarg: The target qubit.
        lam: The angle of rotation.
    """

    ...

creg

creg(n_bits: int) -> CReg

Create a new classical register with n_bits bits.

Parameters:

Name Type Description Default
n_bits int

The number of bits in the register.

required

Returns:

Type Description
CReg

The newly created classical register.

Source code in src/bloqade/qasm2/_wrappers.py
33
34
35
36
37
38
39
40
41
42
43
44
45
@wraps(core.CRegNew)
def creg(n_bits: int) -> CReg:
    """
    Create a new classical register with `n_bits` bits.

    Args:
        n_bits: The number of bits in the register.

    Returns:
        The newly created classical register.

    """
    ...

crx

crx(ctrl: Qubit, qarg: Qubit, lam: float) -> None

Controlled Rx rotation gate.

Parameters:

Name Type Description Default
ctrl Qubit

The control qubit.

required
qarg Qubit

The target qubit.

required
lam float

The angle of rotation.

required
Source code in src/bloqade/qasm2/_wrappers.py
426
427
428
429
430
431
432
433
434
435
436
437
438
@wraps(uop.CRX)
def crx(ctrl: Qubit, qarg: Qubit, lam: float) -> None:
    """
    Controlled Rx rotation gate.

    Args:
        ctrl: The control qubit.
        qarg: The target qubit.
        lam: The angle of rotation.

    """

    ...

cry

cry(ctrl: Qubit, qarg: Qubit, lam: float) -> None

Controlled Ry rotation gate.

Parameters:

Name Type Description Default
ctrl Qubit

The control qubit.

required
qarg Qubit

The target qubit.

required
lam float

The angle of rotation.

required
Source code in src/bloqade/qasm2/_wrappers.py
441
442
443
444
445
446
447
448
449
450
451
452
453
@wraps(uop.CRY)
def cry(ctrl: Qubit, qarg: Qubit, lam: float) -> None:
    """
    Controlled Ry rotation gate.

    Args:
        ctrl: The control qubit.
        qarg: The target qubit.
        lam: The angle of rotation.

    """

    ...

crz

crz(ctrl: Qubit, qarg: Qubit, lam: float) -> None

Controlled Rz rotation gate.

Parameters:

Name Type Description Default
ctrl Qubit

The control qubit.

required
qarg Qubit

The target qubit.

required
lam float

The angle of rotation.

required
Source code in src/bloqade/qasm2/_wrappers.py
456
457
458
459
460
461
462
463
464
465
466
467
@wraps(uop.CRZ)
def crz(ctrl: Qubit, qarg: Qubit, lam: float) -> None:
    """
    Controlled Rz rotation gate.

    Args:
        ctrl: The control qubit.
        qarg: The target qubit.
        lam: The angle of rotation.

    """
    ...

cswap

cswap(ctrl: Qubit, qarg1: Qubit, qarg2: Qubit) -> None

Controlled Swap gate (Fredkin gate).

Parameters:

Name Type Description Default
ctrl Qubit

The control qubit.

required
qarg1 Qubit

The first target qubit.

required
qarg2 Qubit

The second target qubit.

required
Source code in src/bloqade/qasm2/_wrappers.py
413
414
415
416
417
418
419
420
421
422
423
@wraps(uop.CSwap)
def cswap(ctrl: Qubit, qarg1: Qubit, qarg2: Qubit) -> None:
    """
    Controlled Swap gate (Fredkin gate).

    Args:
        ctrl: The control qubit.
        qarg1: The first target qubit.
        qarg2: The second target qubit.
    """
    ...

csx

csx(ctrl: Qubit, qarg: Qubit) -> None

Controlled-Sqrt(X) gate.

Parameters:

Name Type Description Default
ctrl Qubit

The control qubit.

required
qarg Qubit

The target qubit

required
Source code in src/bloqade/qasm2/_wrappers.py
361
362
363
364
365
366
367
368
369
370
@wraps(uop.CSX)
def csx(ctrl: Qubit, qarg: Qubit) -> None:
    """
    Controlled-Sqrt(X) gate.

    Args:
        ctrl: The control qubit.
        qarg: The target qubit
    """
    ...

cu

cu(
    ctrl: Qubit,
    qarg: Qubit,
    theta: float,
    phi: float,
    lam: float,
    gamma: float,
) -> None

Controlled 4-parameter unitary gate.

This is equal to:

gate cu(theta,phi,lambda,gamma) c, t{ p(gamma) c; p((lambda+phi)/2) c; p((lambda-phi)/2) t; cx c,t; u(-theta/2,0,-(phi+lambda)/2) t; cx c,t; u(theta/2,phi,0) t; }

Parameters:

Name Type Description Default
ctrl Qubit

The control qubit.

required
qarg Qubit

The target qubit.

required
theta float

The angle of rotation.

required
phi float

The angle of rotation.

required
lam float

The angle of rotation.

required
gamma float

The angle of rotation.

required
Source code in src/bloqade/qasm2/_wrappers.py
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
@wraps(uop.CU)
def cu(
    ctrl: Qubit, qarg: Qubit, theta: float, phi: float, lam: float, gamma: float
) -> None:
    """
    Controlled 4-parameter unitary gate.

    This is equal to:

    gate cu(theta,phi,lambda,gamma) c, t{
        p(gamma) c;
        p((lambda+phi)/2) c;
        p((lambda-phi)/2) t;
        cx c,t;
        u(-theta/2,0,-(phi+lambda)/2) t;
        cx c,t;
        u(theta/2,phi,0) t;
    }

    Args:
        ctrl: The control qubit.
        qarg: The target qubit.
        theta: The angle of rotation.
        phi: The angle of rotation.
        lam: The angle of rotation.
        gamma: The angle of rotation.
    """
    ...

cu1

cu1(ctrl: Qubit, qarg: Qubit, lam: float) -> None

Controlled phase rotation gate.

Parameters:

Name Type Description Default
ctrl Qubit

The control qubit.

required
qarg Qubit

The target qubit.

required
lam float

The angle of rotation.

required
Source code in src/bloqade/qasm2/_wrappers.py
470
471
472
473
474
475
476
477
478
479
480
481
@wraps(uop.CU1)
def cu1(ctrl: Qubit, qarg: Qubit, lam: float) -> None:
    """
    Controlled phase rotation gate.

    Args:
        ctrl: The control qubit.
        qarg: The target qubit.
        lam: The angle of rotation.
    """

    ...

cu3

cu3(
    ctrl: Qubit,
    qarg: Qubit,
    theta: float,
    phi: float,
    lam: float,
) -> None

Controlled 3-parameter unitary gate.

Parameters:

Name Type Description Default
ctrl Qubit

The control qubit.

required
qarg Qubit

The target qubit.

required
theta float

The angle of rotation.

required
phi float

The angle of rotation.

required
lam float

The angle of rotation.

required
Source code in src/bloqade/qasm2/_wrappers.py
498
499
500
501
502
503
504
505
506
507
508
509
510
511
@wraps(uop.CU3)
def cu3(ctrl: Qubit, qarg: Qubit, theta: float, phi: float, lam: float) -> None:
    """
    Controlled 3-parameter unitary gate.

    Args:
        ctrl: The control qubit.
        qarg: The target qubit.
        theta: The angle of rotation.
        phi: The angle of rotation.
        lam: The angle of rotation.

    """
    ...

cx

cx(ctrl: Qubit, qarg: Qubit) -> None

Controlled-X (CNOT) gate.

Parameters:

Name Type Description Default
ctrl Qubit

The control qubit.

required
qarg Qubit

The target qubit.

required
Source code in src/bloqade/qasm2/_wrappers.py
73
74
75
76
77
78
79
80
81
82
@wraps(uop.CX)
def cx(ctrl: Qubit, qarg: Qubit) -> None:
    """
    Controlled-X (CNOT) gate.

    Args:
        ctrl: The control qubit.
        qarg: The target qubit.
    """
    ...

cy

cy(ctrl: Qubit, qarg: Qubit) -> None

Controlled-Y gate.

Parameters:

Name Type Description Default
ctrl Qubit

The control qubit.

required
qarg Qubit

The target qubit

required
Source code in src/bloqade/qasm2/_wrappers.py
373
374
375
376
377
378
379
380
381
382
383
@wraps(uop.CY)
def cy(ctrl: Qubit, qarg: Qubit) -> None:
    """
    Controlled-Y gate.

    Args:
        ctrl: The control qubit.
        qarg: The target qubit
    """

    ...

cz

cz(ctrl: Qubit, qarg: Qubit) -> None

Controlled-Z gate.

Parameters:

Name Type Description Default
ctrl Qubit

The control qubit.

required
qarg Qubit

The target qubit

required
Source code in src/bloqade/qasm2/_wrappers.py
349
350
351
352
353
354
355
356
357
358
@wraps(uop.CZ)
def cz(ctrl: Qubit, qarg: Qubit) -> None:
    """
    Controlled-Z gate.

    Args:
        ctrl: The control qubit.
        qarg: The target qubit
    """
    ...

exp

exp(value: float) -> float

Exponential math function.

Parameters:

Name Type Description Default
value float

The value to exponentiate.

required

Returns:

Type Description
float

The exponential of value.

Source code in src/bloqade/qasm2/_wrappers.py
619
620
621
622
623
624
625
626
627
628
629
630
631
632
@wraps(expr.Exp)
def exp(value: float) -> float:
    """
    Exponential math function.

    Args:
        value: The value to exponentiate.

    Returns:
        The exponential of `value`.

    """

    ...

h

h(qarg: Qubit) -> None

Hadamard gate.

Parameters:

Name Type Description Default
qarg Qubit

The qubit to apply the gate to.

required
Source code in src/bloqade/qasm2/_wrappers.py
145
146
147
148
149
150
151
152
153
154
@wraps(uop.H)
def h(qarg: Qubit) -> None:
    """
    Hadamard gate.

    Args:
        qarg: The qubit to apply the gate to.

    """
    ...

id

id(qarg: Qubit) -> None

Identity gate.

Parameters:

Name Type Description Default
qarg Qubit

The qubit to apply the gate to.

required
Source code in src/bloqade/qasm2/_wrappers.py
133
134
135
136
137
138
139
140
141
142
@wraps(uop.Id)
def id(qarg: Qubit) -> None:
    """
    Identity gate.

    Args:
        qarg: The qubit to apply the gate to.

    """
    ...

inline

inline(text: str) -> None

Inline QASM code into the current program.

Parameters:

Name Type Description Default
text str

The QASM code to inline.

required
Source code in src/bloqade/qasm2/_wrappers.py
 7
 8
 9
10
11
12
13
14
15
@wraps(inline_.InlineQASM)
def inline(text: str) -> None:
    """
    Inline QASM code into the current program.

    Args:
        text: The QASM code to inline.
    """
    ...

ln

ln(value: float) -> float

logarithm math function.

Parameters:

Name Type Description Default
value float

The value to take the natural logarithm of.

required

Returns:

Type Description
float

The natural logarithm of value.

Source code in src/bloqade/qasm2/_wrappers.py
635
636
637
638
639
640
641
642
643
644
645
646
647
648
@wraps(expr.Log)
def ln(value: float) -> float:
    """
    logarithm math function.

    Args:
        value: The value to take the natural logarithm of.

    Returns:
        The natural logarithm of `value`.

    """

    ...

measure

measure(qarg: Qubit, cbit: Bit) -> None

Measure the qubit qarg and store the result in the classical bit cbit.

Parameters:

Name Type Description Default
qarg Qubit

The qubit to measure.

required
cbit Bit

The classical bit to store the result in.

required
Source code in src/bloqade/qasm2/_wrappers.py
61
62
63
64
65
66
67
68
69
70
@wraps(core.Measure)
def measure(qarg: Qubit, cbit: Bit) -> None:
    """
    Measure the qubit `qarg` and store the result in the classical bit `cbit`.

    Args:
        qarg: The qubit to measure.
        cbit: The classical bit to store the result in.
    """
    ...

p

p(qarg: Qubit, lam: float) -> None

Phase gate.

This is equivalent to u(0,0,lam), and u1(lam)

Parameters:

Name Type Description Default
qarg Qubit

The qubit to apply the gate to.

required
lam float

The angle of phase.

required
Source code in src/bloqade/qasm2/_wrappers.py
193
194
195
196
197
198
199
200
201
202
203
204
205
@wraps(uop.U1)
def p(qarg: Qubit, lam: float) -> None:
    """
    Phase gate.

    This is equivalent to u(0,0,lam), and u1(lam)

    Args:
        qarg: The qubit to apply the gate to.
        lam: The angle of phase.

    """
    ...

qreg

qreg(n_qubits: int) -> QReg

Create a new quantum register with n_qubits qubits.

Parameters:

Name Type Description Default
n_qubits int

The number of qubits in the register.

required

Returns:

Type Description
QReg

The newly created quantum register.

Source code in src/bloqade/qasm2/_wrappers.py
18
19
20
21
22
23
24
25
26
27
28
29
30
@wraps(core.QRegNew)
def qreg(n_qubits: int) -> QReg:
    """
    Create a new quantum register with `n_qubits` qubits.

    Args:
        n_qubits: The number of qubits in the register.

    Returns:
        The newly created quantum register.

    """
    ...

reset

reset(qarg: Qubit) -> None

Reset the qubit qarg to the |0⟩ state.

Parameters:

Name Type Description Default
qarg Qubit

The qubit to reset.

required
Source code in src/bloqade/qasm2/_wrappers.py
48
49
50
51
52
53
54
55
56
57
58
@wraps(core.Reset)
def reset(qarg: Qubit) -> None:
    """
    Reset the qubit `qarg` to the |0⟩ state.

    Args:
        qarg: The qubit to reset.

    """

    ...

rx

rx(qarg: Qubit, theta: float) -> None

Single qubit rotation about the X axis on block sphere

Parameters:

Name Type Description Default
qarg Qubit

The qubit to apply the gate to.

required
theta float

The angle of rotation.

required
Source code in src/bloqade/qasm2/_wrappers.py
282
283
284
285
286
287
288
289
290
291
@wraps(uop.RX)
def rx(qarg: Qubit, theta: float) -> None:
    """
    Single qubit rotation about the X axis on block sphere

    Args:
        qarg: The qubit to apply the gate to.
        theta: The angle of rotation.
    """
    ...

rxx

rxx(ctrl: Qubit, qarg: Qubit, theta: float) -> None

XX rotation gate.

Parameters:

Name Type Description Default
ctrl Qubit

The first qubit.

required
qarg Qubit

The second qubit.

required
theta float

The angle of rotation.

required
Source code in src/bloqade/qasm2/_wrappers.py
544
545
546
547
548
549
550
551
552
553
554
555
@wraps(uop.RXX)
def rxx(ctrl: Qubit, qarg: Qubit, theta: float) -> None:
    """
    XX rotation gate.

    Args:
        ctrl: The first qubit.
        qarg: The second qubit.
        theta: The angle of rotation.

    """
    ...

ry

ry(qarg: Qubit, theta: float) -> None

Single qubit rotation about the Y axis on block sphere

Parameters:

Name Type Description Default
qarg Qubit

The qubit to apply the gate to.

required
theta float

The angle of rotation.

required
Source code in src/bloqade/qasm2/_wrappers.py
294
295
296
297
298
299
300
301
302
303
304
305
@wraps(uop.RY)
def ry(qarg: Qubit, theta: float) -> None:
    """
    Single qubit rotation about the Y axis on block sphere

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

    """

    ...

rz

rz(qarg: Qubit, theta: float) -> None

Single qubit rotation about the Z axis on block sphere

Parameters:

Name Type Description Default
qarg Qubit

The qubit to apply the gate to.

required
theta float

The angle of rotation.

required
Source code in src/bloqade/qasm2/_wrappers.py
308
309
310
311
312
313
314
315
316
317
@wraps(uop.RZ)
def rz(qarg: Qubit, theta: float) -> None:
    """
    Single qubit rotation about the Z axis on block sphere

    Args:
        qarg: The qubit to apply the gate to.
        theta: The angle of rotation.
    """
    ...

rzz

rzz(ctrl: Qubit, qarg: Qubit, theta: float) -> None

ZZ rotation gate.

Parameters:

Name Type Description Default
ctrl Qubit

The first qubit.

required
qarg Qubit

The second qubit.

required
theta float

The angle of rotation.

required
Source code in src/bloqade/qasm2/_wrappers.py
558
559
560
561
562
563
564
565
566
567
568
569
@wraps(uop.RZZ)
def rzz(ctrl: Qubit, qarg: Qubit, theta: float) -> None:
    """
    ZZ rotation gate.

    Args:
        ctrl: The first qubit.
        qarg: The second qubit.
        theta: The angle of rotation.

    """
    ...

s

s(qarg: Qubit) -> None

S gate.

Parameters:

Name Type Description Default
qarg Qubit

The qubit to apply the gate to.

required
Source code in src/bloqade/qasm2/_wrappers.py
208
209
210
211
212
213
214
215
216
217
@wraps(uop.S)
def s(qarg: Qubit) -> None:
    """
    S gate.

    Args:
        qarg: The qubit to apply the gate to.
    """

    ...

sdg

sdg(qarg: Qubit) -> None

Hermitian conjugate of the S gate.

Parameters:

Name Type Description Default
qarg Qubit

The qubit to apply the gate to.

required
Source code in src/bloqade/qasm2/_wrappers.py
220
221
222
223
224
225
226
227
228
229
230
@wraps(uop.Sdag)
def sdg(qarg: Qubit) -> None:
    """
    Hermitian conjugate of the S gate.

    Args:
        qarg: The qubit to apply the gate to.

    """

    ...

sin

sin(value: float) -> float

Sine math function.

Parameters:

Name Type Description Default
value float

The value to take the sine of.

required

Returns:

Type Description
float

The sine of value.

Source code in src/bloqade/qasm2/_wrappers.py
572
573
574
575
576
577
578
579
580
581
582
583
584
@wraps(expr.Sin)
def sin(value: float) -> float:
    """
    Sine math function.

    Args:
        value: The value to take the sine of.

    Returns:
        The sine of `value`.

    """
    ...

sqrt

sqrt(value: float) -> float

Square root math function.

Parameters:

Name Type Description Default
value float

The value to take the square root of.

required

Returns:

Type Description
float

The square root of value.

Source code in src/bloqade/qasm2/_wrappers.py
651
652
653
654
655
656
657
658
659
660
661
662
@wraps(expr.Sqrt)
def sqrt(value: float) -> float:
    """
    Square root math function.

    Args:
        value: The value to take the square root of.

    Returns:
        The square root of `value`.
    """
    ...

sx

sx(qarg: Qubit) -> None

Sqrt(X) gate.

Parameters:

Name Type Description Default
qarg Qubit

The qubit to apply the gate to.

required
Source code in src/bloqade/qasm2/_wrappers.py
233
234
235
236
237
238
239
240
241
242
@wraps(uop.SX)
def sx(qarg: Qubit) -> None:
    """
    Sqrt(X) gate.

    Args:
        qarg: The qubit to apply the gate to.
    """

    ...

sxdg

sxdg(qarg: Qubit) -> None

Hermitian conjugate of Sqrt(X) gate.

Parameters:

Name Type Description Default
qarg Qubit

The qubit to apply the gate to.

required
Source code in src/bloqade/qasm2/_wrappers.py
245
246
247
248
249
250
251
252
253
254
@wraps(uop.SXdag)
def sxdg(qarg: Qubit) -> None:
    """
    Hermitian conjugate of Sqrt(X) gate.

    Args:
        qarg: The qubit to apply the gate to.
    """

    ...

t

t(qarg: Qubit) -> None

T gate.

Parameters:

Name Type Description Default
qarg Qubit

The qubit to apply the gate to.

required
Source code in src/bloqade/qasm2/_wrappers.py
257
258
259
260
261
262
263
264
265
266
@wraps(uop.T)
def t(qarg: Qubit) -> None:
    """
    T gate.

    Args:
        qarg: The qubit to apply the gate to.
    """

    ...

tan

tan(value: float) -> float

Tangent math function.

Parameters:

Name Type Description Default
value float

The value to take the tangent of.

required

Returns:

Type Description
float

The tangent of value.

Source code in src/bloqade/qasm2/_wrappers.py
603
604
605
606
607
608
609
610
611
612
613
614
615
616
@wraps(expr.Tan)
def tan(value: float) -> float:
    """
    Tangent math function.

    Args:
        value: The value to take the tangent of.

    Returns:
        The tangent of `value`.

    """

    ...

tdg

tdg(qarg: Qubit) -> None

Hermitian conjugate of the T gate.

Parameters:

Name Type Description Default
qarg Qubit

The qubit to apply the gate to.

required
Source code in src/bloqade/qasm2/_wrappers.py
269
270
271
272
273
274
275
276
277
278
279
@wraps(uop.Tdag)
def tdg(qarg: Qubit) -> None:
    """
    Hermitian conjugate of the T gate.

    Args:
        qarg: The qubit to apply the gate to.

    """

    ...

u

u(
    qarg: Qubit, theta: float, phi: float, lam: float
) -> None

U gate.

Note

See https://arxiv.org/pdf/1707.03429 for definition of angles.

Parameters:

Name Type Description Default
qarg Qubit

The qubit to apply the gate to.

required
theta float

The angle of rotation

required
phi float

The angle of rotation

required
lam float

The angle of rotation

required
Source code in src/bloqade/qasm2/_wrappers.py
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
@wraps(uop.UGate)
def u(qarg: Qubit, theta: float, phi: float, lam: float) -> None:
    """
    U gate.

    Note:
        See https://arxiv.org/pdf/1707.03429 for definition of angles.

    Args:
        qarg: The qubit to apply the gate to.
        theta: The angle of rotation
        phi: The angle of rotation
        lam: The angle of rotation

    """
    ...

u1

u1(qarg: Qubit, lam: float) -> None

1 Parameter single qubit unitary gate.

This is equivalent to u(0,0,lambda).

Parameters:

Name Type Description Default
qarg Qubit

The qubit to apply the gate to.

required
lam float

The angle of rotation.

required
Source code in src/bloqade/qasm2/_wrappers.py
320
321
322
323
324
325
326
327
328
329
330
331
@wraps(uop.U1)
def u1(qarg: Qubit, lam: float) -> None:
    """
    1 Parameter single qubit unitary gate.

    This is equivalent to u(0,0,lambda).

    Args:
        qarg: The qubit to apply the gate to.
        lam: The angle of rotation.
    """
    ...

u2

u2(qarg: Qubit, phi: float, lam: float) -> None

2 Parameter single qubit unitary gate.

This is equivalent to u(pi/2,phi,lambda)

Parameters:

Name Type Description Default
qarg Qubit

The qubit to apply the gate to.

required
phi float

The angle of rotation.

required
lam float

The angle of rotation.

required
Source code in src/bloqade/qasm2/_wrappers.py
334
335
336
337
338
339
340
341
342
343
344
345
346
@wraps(uop.U2)
def u2(qarg: Qubit, phi: float, lam: float) -> None:
    """
    2 Parameter single qubit unitary gate.

    This is equivalent to u(pi/2,phi,lambda)

    Args:
        qarg: The qubit to apply the gate to.
        phi: The angle of rotation.
        lam: The angle of rotation.
    """
    ...

u3

u3(
    qarg: Qubit, theta: float, phi: float, lam: float
) -> None

U3 gate, same as u

Note

See https://arxiv.org/pdf/1707.03429 for definition of angles.

Parameters:

Name Type Description Default
qarg Qubit

The qubit to apply the gate to.

required
theta float

The angle of rotation

required
phi float

The angle of rotation

required
lam float

The angle of rotation

required
Source code in src/bloqade/qasm2/_wrappers.py
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
@wraps(uop.UGate)
def u3(qarg: Qubit, theta: float, phi: float, lam: float) -> None:
    """
    U3 gate, same as u

    Note:
        See https://arxiv.org/pdf/1707.03429 for definition of angles.

    Args:
        qarg: The qubit to apply the gate to.
        theta: The angle of rotation
        phi: The angle of rotation
        lam: The angle of rotation

    """
    ...

x

x(qarg: Qubit) -> None

Pauli-X gate.

Parameters:

Name Type Description Default
qarg Qubit

The qubit to apply the gate to.

required
Source code in src/bloqade/qasm2/_wrappers.py
157
158
159
160
161
162
163
164
165
166
@wraps(uop.X)
def x(qarg: Qubit) -> None:
    """
    Pauli-X gate.

    Args:
        qarg: The qubit to apply the gate to.
    """

    ...

y

y(qarg: Qubit) -> None

Pauli-Y gate.

Parameters:

Name Type Description Default
qarg Qubit

The qubit to apply the gate to.

required
Source code in src/bloqade/qasm2/_wrappers.py
169
170
171
172
173
174
175
176
177
178
@wraps(uop.Y)
def y(qarg: Qubit) -> None:
    """
    Pauli-Y gate.

    Args:
        qarg: The qubit to apply the gate to.

    """
    ...

z

z(qarg: Qubit) -> None

Pauli-Z gate.

Parameters:

Name Type Description Default
qarg Qubit

The qubit to apply the gate to.

required
Source code in src/bloqade/qasm2/_wrappers.py
181
182
183
184
185
186
187
188
189
190
@wraps(uop.Z)
def z(qarg: Qubit) -> None:
    """
    Pauli-Z gate.

    Args:
        qarg: The qubit to apply the gate to.

    """
    ...