Rotate a qubit by any angle
RY sets the odds of reading 1 with an angle; RZ changes the phase and, on its own, leaves the tally unchanged.

A rotation gate turns a qubit by an angle you choose. With RY, the angle can set a fresh qubit's chance of reading 1 to any value from 0 to 1.
A gate that takes an angle
ry(theta, 0) rotates qubit 0 by the angle theta, in radians: pi is half a turn, so every angle in this lesson is a fraction of pi. At 0 it does nothing and the qubit stays at 0. At pi it flips a fresh qubit all the way to 1, the same tally the X gate gave in lesson 1.
At pi / 2, halfway, it gives the same even split the Hadamard gave in lesson 2.
After ry(theta) on a fresh qubit, the share of shots that read 1 is sin²(θ/2): take the sine of half the angle and square it.
The rule comes from the geometry of the qubit, which the Bloch sphere section below draws; the listing checks it against tallies, one press per angle.
Rotation around Y
ry(theta, qubit) rotates the qubit by an angle in radians: 0 leaves it at 0, pi flips it, pi / 2 is the even split. The share of 1 after it is sin²(θ/2), and two rotations in a row add their angles. The Y is the axis it turns around.
The circuit, then the code
The circuit has a single qubit, an RY rotation and a measurement; the angle sits at the top of the file so you can change it without touching the circuit:
theta = pi / 4
qc = QuantumCircuit(1, 1)
qc.ry(theta, 0) # rotate qubit 0 by theta
qc.measure(0, 0)
The plumbing gains two lines at the end. One pulls the measured share of 1 out of the dict, which was lesson 1's last assignment. The other computes what the rule says for this angle, so the console shows both side by side.
# 'backend' already exists when this runs: it is whatever you pick in the Run on Qollab dialog.
from math import pi, sin
from qiskit import QuantumCircuit
from qiskit.providers.jobstatus import JobStatus
import time
shots = 1000
1theta = pi / 4
qc = QuantumCircuit(1, 1)
2qc.ry(theta, 0)
qc.measure(0, 0)
print(qc)
job = backend.run(qc, shots=shots)
while job.status() not in (JobStatus.DONE, JobStatus.ERROR, JobStatus.CANCELLED):
time.sleep(5)
counts = job.result().get_counts()
print(counts)
3measured = counts.get("1", 0) / shots
4expected = sin(theta / 2) ** 2
print(f"theta = {theta:.4f} share of 1: measured {measured:.3f} rule says {expected:.3f}")
- 1the dial: change this, press Run, compare. 0 is no rotation, pi is a full flip
- 2rotate qubit 0 by theta around the Y axis
- 3the share of shots that read 1, from lesson 1's last task
- 4the rule this lesson is about
Run the circuit, five times
The listing runs one angle per press. Predict the share of 1 for pi / 4 first, then open the project, press Run on Qollab, choose IonQ Aria 1, and press Run.
Then fork the project, as in lesson 1, and in your fork set theta to 0, pi / 2, 3 * pi / 4 and pi, one press each.

Our five presses on 15 September 2026, on the Aria 1 noise model:
theta | counts | measured share of 1 | rule says |
|---|---|---|---|
0 | {'0': 1000} | 0.000 | 0.000 |
pi / 4 | {'0': 851, '1': 149} | 0.149 | 0.146 |
pi / 2 | {'0': 507, '1': 493} | 0.493 | 0.500 |
3 * pi / 4 | {'0': 123, '1': 877} | 0.877 | 0.854 |
pi | {'0': 1, '1': 999} | 0.999 | 1.000 |
The measured shares track the rule to within a few hundredths, about the size of lesson 2's scatter at 1,000 shots; the 3 * pi / 4 press sits at the edge of that band, and one press cannot say whether that is scatter or a small bias in the model. At the two ends, where the ideal share is exactly 0 or 1, the noise model adds its small tail: one stray shot at pi, none at 0 this time.
Assignment: hit a quarter
- Invert the rule. You want sin²(θ/2) = 0.25. Work out what sin(θ/2) must be, then which angle has that sine, and remember that angle is θ/2, not θ.
- Set
thetato the angle that follows, written as a fraction ofpi;from math import piis already at the top of the file. - Press Run on Qollab and choose IonQ Aria 1.
- Compare the measured share with the rule line.
Solution
sin(θ/2) = 0.5 when θ/2 = π/6, so θ = π/3.
theta = pi / 3
The rule line prints 0.250, and the measured share lands near it: within about 0.03 at 1,000 shots, by lesson 2's scatter.
Rotations add
Two rotations in a row rotate by the sum of their angles. ry(pi / 2) twice is ry(pi), a full flip, even though each half on its own would give an even split.
Lesson 1 showed the same with two X gates: gates compose, and the answer depends on the whole sequence.
On a fresh qubit the Hadamard and ry(pi / 2) leave the same state, so they give the same tally. The two gates still differ: they act differently on a qubit that is already in superposition, such as the one the first gate leaves. Applying each gate twice shows the difference. Two Hadamards in a row gave every shot 0 in lesson 2, and two ry(pi / 2) in a row do something else, which the assignment below asks you to work out from the angle.
Assignment: two half turns
- Set
thetaback topi / 2. - Add a second
qc.ry(theta, 0)directly under the first. - Add the two angles and predict the share from the total.
- Press Run on Qollab and choose IonQ Aria 1.
- Compare the measured share with the rule for the summed angle. The console's rule line is computed from one
theta, so it keeps saying0.500.
Solution
π/2 + π/2 = π, a full flip: every shot reads 1, and the measured share prints as 1.000 or just under it.
qc.ry(theta, 0)
qc.ry(theta, 0)
The rule applies to the total angle, π.
RZ and the Bloch sphere
The Bloch sphere draws the qubit as an arrow from the centre of a globe: a fresh qubit points at the north pole, 0, and the south pole is 1. You can drag the arrow around one on Qollab.
RY tilts the arrow south, and the measurement reads how far it tilted.
RZ spins the arrow around the pole instead. The spin changes only the arrow's position around the pole, which is the qubit's phase; the north-south position does not change, so the share of 1 does not change either.
In lesson 2 a weight carried a sign, plus or minus. A phase is that sign made continuous: a sign has two values, and a phase can be any angle. Call the qubit's two weighted options, 0 and 1, its two paths. Two paths with the same phase add up, two with opposite phases cancel, and anything between does part of each. Lesson 5 turns a phase difference into a tally.
Rotation around Z
A rotation around the axis the measurement reads along. rz(phi, qubit) changes the qubit's phase and leaves the share of 1 exactly where it was.
On a fresh qubit the spin changes nothing at all: there is only one path, so there is no second path for its phase to differ from.
A Hadamard before the spin gives two paths, so the spin becomes a difference between them, and a Hadamard after it turns that difference into odds you can read.
Assignment: replace RY with RZ
- Remove the second RY again, so the circuit is back to one rotation.
- Replace
qc.ry(theta, 0)withqc.rz(theta, 0), with anythetayou like. - Predict with the globe: RY tips the arrow south, RZ spins it around the pole. Work out where the arrow is after a spin that starts at the pole, and what a measurement that only reports north or south reads.
- Press Run on Qollab and choose IonQ Aria 1. The rule line computes sin²(θ/2) whatever gate is in the circuit, so it prints a value that does not apply here; the tally is the answer.
Solution
Every shot reads 0, for any angle. The arrow started at the pole, and spinning around the pole leaves it there; the share of 1 stays at 0.
qc.rz(theta, 0)
The rule applies to RY. RZ has a different rule, and under it the share of 1 is always the share you started with.
Lesson 5 puts a Hadamard on each side of the RZ, so the same spin changes the tally, and then uses the effect in a two-qubit search.
Stay in the loop.
Get the latest tutorials, demos, and project showcases straight to your inbox. No noise, just the good stuff.
Enable JavaScript to sign up.
Qollab updates only. Unsubscribe any time. Privacy Policy.
On this page
