QubitLab
IDELearnPlaygroundDocsCommunity
Log in
QubitLab
IDELearnPlaygroundDocsCommunity
Log in
QubitLab
IDELearnPlaygroundDocsCommunity
Log in
HomeLearnCatalogRanksPlaygroundDocs
03 · Variational circuits0%

You are reading without signing in. Sign in or continue as guest to take quizzes and climb the ranks.

Learn/QC 302Cutting and Quantum ML·Lesson 3 of 7

Variational circuits

Parameterised gates, a cost function and a classical optimiser: the loop behind VQE and QAOA.

Advanced12 min read4 sections · 2 questions+45
By the end you will be able to
  1. 01Draw the hybrid loop.
  2. 02Explain the parameter-shift rule.
  3. 03Recognise an ansatz and name its two knobs: depth and entangling pattern.

A variational algorithm keeps the quantum circuit short and lets a classical optimiser do the thinking. The circuit has rotation angles θ; running it and measuring gives a cost C(θ), such as the energy of a molecule or the number of satisfied constraints. The optimiser proposes new angles, and the loop repeats. The circuit is called an ansatz: layers of single-qubit rotations and an entangling pattern, repeated a few times.

∂θj​∂C​=21​[C(θj​+2π​)−C(θj​−2π​)]
The parameter-shift rule: for Pauli rotations the exact gradient is the difference of two circuit evaluations shifted by ±π/2. No finite-difference noise, two runs per parameter.
Hands-on

A two-qubit ansatz

Select an RY gate and drag its slider: the probabilities in the State tab move smoothly with the angle. That smooth dependence is what the optimiser climbs. Try to find angles that put all the weight on |11⟩.

OpenQASM 3
OPENQASM 3.0;
include "stdgates.inc";
qubit[2] q;
ry(pi/3) q[0];
ry(pi/5) q[1];
cx q[0], q[1];
ry(pi/4) q[0];
ry(pi/6) q[1];
Sign in to run (nothing is saved)
Open in the IDE Open in the Playground
Knowledge check

2 questions · one try each counts

Question 1

In a variational algorithm, what does the quantum computer compute?

Sign in to answer and climb the ranks; you will come back to this lesson.

Question 2

Why is the parameter-shift rule preferred over finite differences on hardware?

Sign in to answer and climb the ranks; you will come back to this lesson.

Key takeaway

Variational algorithms pair a short parameterised circuit with a classical optimiser; the parameter-shift rule gives exact gradients from two shifted runs per angle.

Finished reading?

Knowledge check: 2 questions waiting above. Questions are optional. Mark it complete, or press Next: moving on marks it complete too.

Up next
Lesson 4 · 10 min
Data encoding
Basis, angle and amplitude encoding: how classical data enters a circuit and what each choice costs.
Further reading
  • Docs: QML chapter
More in Cutting and Quantum ML
  • Circuit cutting
  • Classical ML vs. Quantum ML: The Hybrid Loop
  • Hands-On 2-Qubit Variational Classifier
Classical ML vs. Quantum ML: The Hybrid LoopData encoding
In this lesson0%
  1. Introduction
  2. Try it: A two-qubit ansatz
  3. Knowledge check
  4. Key takeaway
QubitLab
IDELearnPlaygroundDocsCommunity
Log in
QubitLab
IDELearnPlaygroundDocsCommunity
Log in