liveBook · Manning

Rotational gate

As explained in Building Quantum Software with Python

A Y rotation gate is a single-qubit quantum gate that rotates a qubit's state by an angle about the Y axis of the Bloch sphere.

The RY(θ) gate rotates a single-qubit state about the Y axis. Applied to the default state, it keeps amplitudes real and acts like a dial for setting a biased coin's outcome probabilities. section 3.2.4

Use the RY gate to:

  • Compose same-axis rotations by adding their angles: RY(θ₂)RY(θ₁) = RY(θ₁ + θ₂). section 3.2.4
  • Encode a Bernoulli distribution by choosing θ so that cos²(θ/2) = p and sin²(θ/2) = 1 − p. section 3.5.1
  • Encode a scaled number in the magnitude of an amplitude by setting θ = 2 arccos(x/scale). section 3.5.2

Encoding p = 0.7

Compute θ = 2 acos(√p), initialize a qubit, apply RY(θ), and inspect the state. The resulting probabilities are 0.7 for outcome 0 and 0.3 for outcome 1. section 3.5.1

from math import acos

p = 0.7
theta = 2*acos(sqrt(p))  #1

s = init_state()
transform(s, ry(theta))   #2

print_state(s)

Executable pseudocode shows angle calculation, state initialization, RY application, and state inspection for Bernoulli encoding. section 3.5.1

How Building Quantum Software with Python covers it

How deep it goes
Defines the gate through a matrix, explains angle effects, demonstrates composition, and stops short of deriving the matrix entries.
Examples
Demonstrates π/3 rotation, p = 0.7 Bernoulli encoding, and x = 273.5 encoding in amplitude magnitude.
What it assumes
Assumes single-qubit amplitudes and probabilities while introducing rotation angles, Bernoulli encoding, and amplitude-based number encoding.
What you can do after
Build it from scratch by calculating an angle, applying RY to an initialized qubit, and reading the resulting state probabilities.
How it connects
Connects single-qubit states with RX gates, Bernoulli distributions, Hadamard gates, phase gates, and amplitude encoding.

Also explained in

Compare how 2 books explain rotational gate →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building Quantum Software with Python. The section links point to the parts of the book it draws on.