Skip to content

_gates_and_grads

qubit_approximant.core.circuit._gates_and_grads

Gates for our quantum circuit.

RX(angle)

Rotation around X axis.

Source code in qubit_approximant/core/circuit/_gates_and_grads.py
 8
 9
10
11
12
def RX(angle: float) -> NDArray:
    """Rotation around X axis."""
    return np.array(
        [[cos(angle / 2), -1j * sin(angle / 2)], [-1j * sin(angle / 2), cos(angle / 2)]]
    )

RY(angle)

Rotation around Y axis.

Source code in qubit_approximant/core/circuit/_gates_and_grads.py
15
16
17
def RY(angle: float) -> NDArray:
    """Rotation around Y axis."""
    return np.array([[cos(angle / 2), -sin(angle / 2)], [sin(angle / 2), cos(angle / 2)]])

RZ(angle)

Rotation around Z axis.

Source code in qubit_approximant/core/circuit/_gates_and_grads.py
20
21
22
23
24
def RZ(angle: float) -> NDArray:
    """Rotation around Z axis."""
    return np.array(
        [[cos(angle / 2) - 1j * sin(angle / 2), 0], [0, cos(angle / 2) + 1j * sin(angle / 2)]]
    )

grad_RX(angle)

Derivative of the rotation around X axis.

Source code in qubit_approximant/core/circuit/_gates_and_grads.py
27
28
29
30
31
def grad_RX(angle: float) -> NDArray:
    """Derivative of the rotation around X axis."""
    return 0.5 * np.array(
        [[-sin(angle / 2), -1j * cos(angle / 2)], [-1j * cos(angle / 2), -sin(angle / 2)]]
    )

grad_RY(angle)

Derivative of the rotation around Y axis.

Source code in qubit_approximant/core/circuit/_gates_and_grads.py
34
35
36
def grad_RY(angle: float) -> NDArray:
    """Derivative of the rotation around Y axis."""
    return 0.5 * np.array([[-sin(angle / 2), -cos(angle / 2)], [cos(angle / 2), -sin(angle / 2)]])

grad_RZ(angle)

Derivative of the rotation around Z axis.

Source code in qubit_approximant/core/circuit/_gates_and_grads.py
39
40
41
42
43
def grad_RZ(angle: float) -> NDArray:
    """Derivative of the rotation around Z axis."""
    return 0.5 * np.array(
        [[-1j * cos(angle / 2) - sin(angle / 2), 0], [0, 1j * cos(angle / 2) - sin(angle / 2)]]
    )