Skip to content

Commit 1d1b3e2

Browse files
authored
Add docstrings to basic gates like CZPowGate, Rx, Ry [Unitary hack] (#1651)
Fixes #1148 This PR adds detailed docstrings to the `Rx` and `Ry` bloqs in `qualtran.bloqs.basic_gates.rotation`. The docstrings now explicitly list the registers these gates operate on, improving clarity for users, as requested in issue #1148. Specifically, the `Registers:` section has been added to: - `Rx` - `Ry` This follows the existing convention for other gates like `CZPowGate` and `CHadamard`.
1 parent 7b5c8d5 commit 1d1b3e2

1 file changed

Lines changed: 70 additions & 0 deletions

File tree

qualtran/bloqs/basic_gates/rotation.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,41 @@ def _crz() -> CRz:
554554

555555
@frozen
556556
class Rx(CirqGateAsBloqBase):
557+
r"""Rotates a qubit about the X-axis of the Bloch sphere.
558+
559+
The unitary matrix for this gate is:
560+
$$
561+
R_x(\theta) = \exp(-i \frac{\theta}{2} X) =
562+
\begin{pmatrix}
563+
\cos{\frac{\theta}{2}} & -i\sin{\frac{\theta}{2}} \\
564+
-i\sin{\frac{\theta}{2}} & \cos{\frac{\theta}{2}}
565+
\end{pmatrix}
566+
$$
567+
where $\theta$ is the `angle` of rotation.
568+
569+
This gate is equivalent to `cirq.rx(angle)`.
570+
It differs from `XPowGate` by a global phase. Specifically,
571+
`Rx(angle)` is `XPowGate(exponent=angle/np.pi, global_shift=-0.5)`.
572+
573+
Args:
574+
angle: The angle of rotation in radians. This can be a symbolic expression
575+
or a float.
576+
eps: The precision of the rotation. This parameter is primarily for
577+
bookkeeping and does not directly affect the tensor representation
578+
of this gate. It becomes relevant when synthesizing rotations
579+
from a discrete gate set, where a target precision `eps` is required.
580+
581+
Registers:
582+
q: A single QBit register representing the qubit to be rotated.
583+
584+
References:
585+
[Elementary gates for quantum computation](https://arxiv.org/abs/quant-ph/9503016).
586+
Barenco et al. 1995. Section 4.2 discusses single-qubit rotations.
587+
588+
[Quantum Computation and Quantum Information](https://www.cambridge.org/highereducation/books/quantum-computation-and-quantum-information/01E10196D0A682A6AEFFEA52D53BE9AE).
589+
Nielsen and Chuang. 2010. Chapter 4.2, pp. 174-177.
590+
"""
591+
557592
angle: Union[sympy.Expr, float]
558593
eps: SymbolicFloat = 1e-11
559594

@@ -583,6 +618,41 @@ def __str__(self):
583618

584619
@frozen
585620
class Ry(CirqGateAsBloqBase):
621+
r"""Rotates a qubit about the Y-axis of the Bloch sphere.
622+
623+
The unitary matrix for this gate is:
624+
$$
625+
R_y(\theta) = \exp(-i \frac{\theta}{2} Y) =
626+
\begin{pmatrix}
627+
\cos{\frac{\theta}{2}} & -\sin{\frac{\theta}{2}} \\
628+
\sin{\frac{\theta}{2}} & \cos{\frac{\theta}{2}}
629+
\end{pmatrix}
630+
$$
631+
where $\theta$ is the `angle` of rotation.
632+
633+
This gate is equivalent to `cirq.ry(angle)`.
634+
It differs from `YPowGate` by a global phase. Specifically,
635+
`Ry(angle)` is `YPowGate(exponent=angle/np.pi, global_shift=-0.5)`.
636+
637+
Args:
638+
angle: The angle of rotation in radians. This can be a symbolic expression
639+
or a float.
640+
eps: The precision of the rotation. This parameter is primarily for
641+
bookkeeping and does not directly affect the tensor representation
642+
of this gate. It becomes relevant when synthesizing rotations
643+
from a discrete gate set, where a target precision `eps` is required.
644+
645+
Registers:
646+
q: A single QBit register representing the qubit to be rotated.
647+
648+
References:
649+
[Elementary gates for quantum computation](https://arxiv.org/abs/quant-ph/9503016).
650+
Barenco et al. 1995. Section 4.2 discusses single-qubit rotations.
651+
652+
[Quantum Computation and Quantum Information](https://www.cambridge.org/highereducation/books/quantum-computation-and-quantum-information/01E10196D0A682A6AEFFEA52D53BE9AE).
653+
Nielsen and Chuang. 2010. Chapter 4.2, pp. 174-177.
654+
"""
655+
586656
angle: Union[sympy.Expr, float]
587657
eps: SymbolicFloat = 1e-11
588658

0 commit comments

Comments
 (0)