Tutorials
qcr:2606.94330.1

Qubit Rotation: Basic PennyLane Tutorial

This is the canonical first tutorial for PennyLane, the gentlest possible introduction to quantum differentiable programming. It walks through optimizing the rotation of a single qubit so that its measured expectation value reaches a target, the quantum equivalent of a first hello-world optimization. Along the way it introduces every core PennyLane concept: defining a device (a simulator), writing a quantum function decorated as a QNode that applies parameterized rotation gates and returns an expectation value, evaluating the QNode, and crucially computing its gradient with respect to the gate parameters using PennyLane's automatic differentiation. It then plugs that gradient into a gradient-descent optimizer and iterates until the qubit is rotated into the desired state, printing the cost at each step. By keeping the problem to a single qubit and two parameters, the tutorial makes the full differentiable-programming loop, circuit, measurement, gradient, optimization, completely transparent. It is the recommended starting point for anyone new to PennyLane, establishing the QNode and autodifferentiation model that every later demo builds on.
Qubit
Circuit-based
Uploaded 2 days ago
13
Views
GitHub667
Citing this entry? Use this QCR ID
Uploaded by
QL
QCR Librarian

Overview

PennyLaneAI/demos
667238
README.md

Qubit Rotation: Basic PennyLane Tutorial

This is the canonical first tutorial for PennyLane, the gentlest possible introduction to quantum differentiable programming. It walks through optimizing the rotation of a single qubit so that its measured expectation value reaches a target, the quantum equivalent of a first hello-world optimization. Along the way it introduces every core PennyLane concept: defining a device (a simulator), writing a quantum function decorated as a QNode that applies parameterized rotation gates and returns an expectation value, evaluating the QNode, and crucially computing its gradient with respect to the gate parameters using PennyLane's automatic differentiation. It then plugs that gradient into a gradient-descent optimizer and iterates until the qubit is rotated into the desired state, printing the cost at each step. By keeping the problem to a single qubit and two parameters, the tutorial makes the full differentiable-programming loop, circuit, measurement, gradient, optimization, completely transparent. It is the recommended starting point for anyone new to PennyLane, establishing the QNode and autodifferentiation model that every later demo builds on.

Run it

pip install -r requirements.txt
python demo.py

Source and license

Imported from demonstrations_v2/tutorial_qubit_rotation/demo.py in PennyLaneAI/demos at c52c0abeb5122218aa96b38eea848864cce7323f, under the Apache License 2.0. Original authors: Xanadu and the PennyLane community. The upstream LICENSE is included alongside this example.

Join the Discussion

Comments (0)

No comments yet. Be the first to share your thoughts!

Indexed by QCR Librarian

This entry was created automatically from publicly available records. QCR links to public sources and only stores repository content where the license permits redistribution.

Versions

v1 Latest
Jun 16, 2026
qcr:2606.94330.1

Cite all versions? Use the base QCR ID to always reference the latest version of this entry.

Tools used

PennyLane

Keywords

getting-started
pennylane
optimization
autodiff
qnode

You may also like5